From 267e8d6361f8e7791a8687f2370a3e9d08af6648 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nicolas=20L=C5=93uillet?= Date: Sat, 30 Apr 2016 15:03:22 +0200 Subject: [PATCH] Add tests for tag list routes --- .../CoreBundle/Controller/TagController.php | 6 +++- .../DataFixtures/ORM/LoadTagData.php | 7 +++++ .../Controller/TagControllerTest.php | 31 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index b6514ea6..1cbc413d 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php @@ -105,7 +105,11 @@ class TagController extends Controller */ public function showEntriesForTagAction(Tag $tag, $page, Request $request) { - $pagerAdapter = new ArrayAdapter($tag->getEntries()->toArray()); + $entriesByTag = $this->getDoctrine() + ->getRepository('WallabagCoreBundle:Entry') + ->findAllByTagId($this->getUser()->getId(), $tag->getId()); + + $pagerAdapter = new ArrayAdapter($entriesByTag); $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries') ->prepare($pagerAdapter, $page); diff --git a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadTagData.php b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadTagData.php index 8553dced..09e99f36 100644 --- a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadTagData.php +++ b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadTagData.php @@ -28,6 +28,13 @@ class LoadTagData extends AbstractFixture implements OrderedFixtureInterface $this->addReference('bar-tag', $tag2); + $tag3 = new Tag(); + $tag3->setLabel('baz'); + + $manager->persist($tag3); + + $this->addReference('baz-tag', $tag3); + $manager->flush(); } diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index 58450e5f..71652760 100644 --- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php @@ -131,4 +131,35 @@ class TagControllerTest extends WallabagCoreTestCase $this->assertEquals(404, $client->getResponse()->getStatusCode()); } + + public function testShowEntriesForTagAction() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $entry = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findOneByUsernameAndNotArchived('admin'); + + $tag = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Tag') + ->findOneByEntryAndTagLabel($entry, 'foo'); + + $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug()); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertCount(2, $crawler->filter('div[class=entry]')); + + $tag = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Tag') + ->findOneByLabel('baz'); + + $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug()); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertCount(0, $crawler->filter('div[class=entry]')); + } } -- 2.41.0