From 1594a79fc5eefe217ed463144857d0693b6714fa Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 9 May 2017 23:15:25 +0200 Subject: Retrieve tag / tags value from query or request It allows to request to delete a tag using query string instead of body parameter (which seems to be the standard). Instead of breaking the previous behavior, I used a generic way to retrieve parameter (which looks into request attributes, query parameters and request parameters) --- .../ApiBundle/Controller/TagRestControllerTest.php | 30 +++++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php') diff --git a/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php index bde5251f..90b132eb 100644 --- a/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php @@ -54,7 +54,18 @@ class TagRestControllerTest extends WallabagApiTestCase $this->assertNull($tag, $tagName.' was removed because it begun an orphan tag'); } - public function testDeleteTagByLabel() + public function dataForDeletingTagByLabel() + { + return [ + 'by_query' => [true], + 'by_body' => [false], + ]; + } + + /** + * @dataProvider dataForDeletingTagByLabel + */ + public function testDeleteTagByLabel($useQueryString) { $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); $entry = $this->client->getContainer() @@ -73,7 +84,11 @@ class TagRestControllerTest extends WallabagApiTestCase $em->persist($entry); $em->flush(); - $this->client->request('DELETE', '/api/tag/label.json', ['tag' => $tag->getLabel()]); + if ($useQueryString) { + $this->client->request('DELETE', '/api/tag/label.json?tag='.$tag->getLabel()); + } else { + $this->client->request('DELETE', '/api/tag/label.json', ['tag' => $tag->getLabel()]); + } $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); @@ -98,7 +113,10 @@ class TagRestControllerTest extends WallabagApiTestCase $this->assertEquals(404, $this->client->getResponse()->getStatusCode()); } - public function testDeleteTagsByLabel() + /** + * @dataProvider dataForDeletingTagByLabel + */ + public function testDeleteTagsByLabel($useQueryString) { $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); $entry = $this->client->getContainer() @@ -122,7 +140,11 @@ class TagRestControllerTest extends WallabagApiTestCase $em->persist($entry); $em->flush(); - $this->client->request('DELETE', '/api/tags/label.json', ['tags' => $tag->getLabel().','.$tag2->getLabel()]); + if ($useQueryString) { + $this->client->request('DELETE', '/api/tags/label.json?tags='.$tag->getLabel().','.$tag2->getLabel()); + } else { + $this->client->request('DELETE', '/api/tags/label.json', ['tags' => $tag->getLabel().','.$tag2->getLabel()]); + } $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); -- cgit v1.2.3 From 7ab5eb9508921d84b4b4ec84a59135d536da748e Mon Sep 17 00:00:00 2001 From: adev Date: Mon, 15 May 2017 20:47:59 +0200 Subject: Isolated tests Use https://github.com/dmaicher/doctrine-test-bundle to have test isolation. --- .../ApiBundle/Controller/TagRestControllerTest.php | 33 +++++++++++----------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php') diff --git a/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php index 90b132eb..7f69bd67 100644 --- a/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php @@ -22,36 +22,35 @@ class TagRestControllerTest extends WallabagApiTestCase return end($content); } - /** - * @depends testGetUserTags - */ - public function testDeleteUserTag($tag) + public function testDeleteUserTag() { - $tagName = $tag['label']; + $tagLabel = 'tagtest'; + $tag = new Tag(); + $tag->setLabel($tagLabel); + + $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); + $em->persist($tag); + $em->flush(); + $em->clear(); - $this->client->request('DELETE', '/api/tags/'.$tag['id'].'.json'); + $this->client->request('DELETE', '/api/tags/'.$tag->getId().'.json'); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertArrayHasKey('label', $content); - $this->assertEquals($tag['label'], $content['label']); - $this->assertEquals($tag['slug'], $content['slug']); + $this->assertEquals($tag->getLabel(), $content['label']); + $this->assertEquals($tag->getSlug(), $content['slug']); - $entries = $this->client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findAllByTagId($this->user->getId(), $tag['id']); + $entries = $em->getRepository('WallabagCoreBundle:Entry') + ->findAllByTagId($this->user->getId(), $tag->getId()); $this->assertCount(0, $entries); - $tag = $this->client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Tag') - ->findOneByLabel($tagName); + $tag = $em->getRepository('WallabagCoreBundle:Tag')->findOneByLabel($tagLabel); - $this->assertNull($tag, $tagName.' was removed because it begun an orphan tag'); + $this->assertNull($tag, $tagLabel.' was removed because it begun an orphan tag'); } public function dataForDeletingTagByLabel() -- cgit v1.2.3 From f808b01692a835673f328d7221ba8c212caa9b61 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 1 Jul 2017 09:52:38 +0200 Subject: Add a real configuration for CS-Fixer --- .../ApiBundle/Controller/TagRestControllerTest.php | 38 +++++++++++----------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php') diff --git a/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php index 7f69bd67..430e548d 100644 --- a/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php @@ -11,7 +11,7 @@ class TagRestControllerTest extends WallabagApiTestCase { $this->client->request('GET', '/api/tags.json'); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); @@ -33,15 +33,15 @@ class TagRestControllerTest extends WallabagApiTestCase $em->flush(); $em->clear(); - $this->client->request('DELETE', '/api/tags/'.$tag->getId().'.json'); + $this->client->request('DELETE', '/api/tags/' . $tag->getId() . '.json'); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertArrayHasKey('label', $content); - $this->assertEquals($tag->getLabel(), $content['label']); - $this->assertEquals($tag->getSlug(), $content['slug']); + $this->assertSame($tag->getLabel(), $content['label']); + $this->assertSame($tag->getSlug(), $content['slug']); $entries = $em->getRepository('WallabagCoreBundle:Entry') ->findAllByTagId($this->user->getId(), $tag->getId()); @@ -50,7 +50,7 @@ class TagRestControllerTest extends WallabagApiTestCase $tag = $em->getRepository('WallabagCoreBundle:Tag')->findOneByLabel($tagLabel); - $this->assertNull($tag, $tagLabel.' was removed because it begun an orphan tag'); + $this->assertNull($tag, $tagLabel . ' was removed because it begun an orphan tag'); } public function dataForDeletingTagByLabel() @@ -84,18 +84,18 @@ class TagRestControllerTest extends WallabagApiTestCase $em->flush(); if ($useQueryString) { - $this->client->request('DELETE', '/api/tag/label.json?tag='.$tag->getLabel()); + $this->client->request('DELETE', '/api/tag/label.json?tag=' . $tag->getLabel()); } else { $this->client->request('DELETE', '/api/tag/label.json', ['tag' => $tag->getLabel()]); } - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertArrayHasKey('label', $content); - $this->assertEquals($tag->getLabel(), $content['label']); - $this->assertEquals($tag->getSlug(), $content['slug']); + $this->assertSame($tag->getLabel(), $content['label']); + $this->assertSame($tag->getSlug(), $content['slug']); $entries = $this->client->getContainer() ->get('doctrine.orm.entity_manager') @@ -109,7 +109,7 @@ class TagRestControllerTest extends WallabagApiTestCase { $this->client->request('DELETE', '/api/tag/label.json', ['tag' => 'does not exist']); - $this->assertEquals(404, $this->client->getResponse()->getStatusCode()); + $this->assertSame(404, $this->client->getResponse()->getStatusCode()); } /** @@ -140,24 +140,24 @@ class TagRestControllerTest extends WallabagApiTestCase $em->flush(); if ($useQueryString) { - $this->client->request('DELETE', '/api/tags/label.json?tags='.$tag->getLabel().','.$tag2->getLabel()); + $this->client->request('DELETE', '/api/tags/label.json?tags=' . $tag->getLabel() . ',' . $tag2->getLabel()); } else { - $this->client->request('DELETE', '/api/tags/label.json', ['tags' => $tag->getLabel().','.$tag2->getLabel()]); + $this->client->request('DELETE', '/api/tags/label.json', ['tags' => $tag->getLabel() . ',' . $tag2->getLabel()]); } - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); $content = json_decode($this->client->getResponse()->getContent(), true); $this->assertCount(2, $content); $this->assertArrayHasKey('label', $content[0]); - $this->assertEquals($tag->getLabel(), $content[0]['label']); - $this->assertEquals($tag->getSlug(), $content[0]['slug']); + $this->assertSame($tag->getLabel(), $content[0]['label']); + $this->assertSame($tag->getSlug(), $content[0]['slug']); $this->assertArrayHasKey('label', $content[1]); - $this->assertEquals($tag2->getLabel(), $content[1]['label']); - $this->assertEquals($tag2->getSlug(), $content[1]['slug']); + $this->assertSame($tag2->getLabel(), $content[1]['label']); + $this->assertSame($tag2->getSlug(), $content[1]['slug']); $entries = $this->client->getContainer() ->get('doctrine.orm.entity_manager') @@ -178,6 +178,6 @@ class TagRestControllerTest extends WallabagApiTestCase { $this->client->request('DELETE', '/api/tags/label.json', ['tags' => 'does not exist']); - $this->assertEquals(404, $this->client->getResponse()->getStatusCode()); + $this->assertSame(404, $this->client->getResponse()->getStatusCode()); } } -- cgit v1.2.3