X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2FWallabag%2FApiBundle%2FController%2FTagRestControllerTest.php;h=9daa94cd5346bf0a99d8cc73e0366666d830f749;hb=c73025ad8b684de1ac21ba7583f1af6f1d185159;hp=430e548d204078178b42bbdc957b9e6ee3ab1ebc;hpb=1953a872932a63792293b4aec087880265ba89f7;p=github%2Fwallabag%2Fwallabag.git diff --git a/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php index 430e548d..9daa94cd 100644 --- a/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php @@ -7,6 +7,8 @@ use Wallabag\CoreBundle\Entity\Tag; class TagRestControllerTest extends WallabagApiTestCase { + private $otherUserTagLabel = 'bob'; + public function testGetUserTags() { $this->client->request('GET', '/api/tags.json'); @@ -19,17 +21,33 @@ class TagRestControllerTest extends WallabagApiTestCase $this->assertArrayHasKey('id', $content[0]); $this->assertArrayHasKey('label', $content[0]); + $tagLabels = array_map(function ($i) { + return $i['label']; + }, $content); + + $this->assertNotContains($this->otherUserTagLabel, $tagLabels, 'There is a possible tag leak'); + return end($content); } public function testDeleteUserTag() { + $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); + $entry = $this->client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneWithTags($this->user->getId()); + + $entry = $entry[0]; + $tagLabel = 'tagtest'; $tag = new Tag(); $tag->setLabel($tagLabel); - - $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); $em->persist($tag); + + $entry->addTag($tag); + + $em->persist($entry); $em->flush(); $em->clear(); @@ -53,6 +71,16 @@ class TagRestControllerTest extends WallabagApiTestCase $this->assertNull($tag, $tagLabel . ' was removed because it begun an orphan tag'); } + public function testDeleteOtherUserTag() + { + $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); + $tag = $em->getRepository('WallabagCoreBundle:Tag')->findOneByLabel($this->otherUserTagLabel); + + $this->client->request('DELETE', '/api/tags/' . $tag->getId() . '.json'); + + $this->assertSame(404, $this->client->getResponse()->getStatusCode()); + } + public function dataForDeletingTagByLabel() { return [ @@ -112,6 +140,13 @@ class TagRestControllerTest extends WallabagApiTestCase $this->assertSame(404, $this->client->getResponse()->getStatusCode()); } + public function testDeleteTagByLabelOtherUser() + { + $this->client->request('DELETE', '/api/tag/label.json', ['tag' => $this->otherUserTagLabel]); + + $this->assertSame(404, $this->client->getResponse()->getStatusCode()); + } + /** * @dataProvider dataForDeletingTagByLabel */ @@ -180,4 +215,11 @@ class TagRestControllerTest extends WallabagApiTestCase $this->assertSame(404, $this->client->getResponse()->getStatusCode()); } + + public function testDeleteTagsByLabelOtherUser() + { + $this->client->request('DELETE', '/api/tags/label.json', ['tags' => $this->otherUserTagLabel]); + + $this->assertSame(404, $this->client->getResponse()->getStatusCode()); + } }