Add tests for tag list routes

This commit is contained in:
Nicolas Lœuillet 2016-04-30 15:03:22 +02:00 committed by Jeremy Benoist
parent 371bcca0f6
commit 267e8d6361
No known key found for this signature in database
GPG key ID: BCA73962457ACC3C
3 changed files with 43 additions and 1 deletions

View file

@ -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);

View file

@ -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();
}

View file

@ -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]'));
}
}