]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CoreBundle/Tests/Controller/TagControllerTest.php
assign tags to an entry
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Tests / Controller / TagControllerTest.php
1 <?php
2
3 namespace Wallabag\CoreBundle\Tests\Controller;
4
5 use Wallabag\CoreBundle\Tests\WallabagCoreTestCase;
6
7 class TagControllerTest extends WallabagCoreTestCase
8 {
9 public function testList()
10 {
11 $this->logInAs('admin');
12 $client = $this->getClient();
13
14 $client->request('GET', '/tag/list');
15
16 $this->assertEquals(200, $client->getResponse()->getStatusCode());
17 }
18
19 public function testAddTagToEntry()
20 {
21 $this->logInAs('admin');
22 $client = $this->getClient();
23
24 $entry = $client->getContainer()
25 ->get('doctrine.orm.entity_manager')
26 ->getRepository('WallabagCoreBundle:Entry')
27 ->findOneByIsArchived(false);
28
29 $crawler = $client->request('GET', '/view/'.$entry->getId());
30
31 $form = $crawler->filter('button[id=tag_save]')->form();
32
33 $data = array(
34 'tag[label]' => 'opensource',
35 );
36
37 $client->submit($form, $data);
38 $this->assertEquals(302, $client->getResponse()->getStatusCode());
39
40 $this->assertEquals(1, count($entry->getTags()));
41
42 # tag already exists and already assigned
43 $client->submit($form, $data);
44 $this->assertEquals(302, $client->getResponse()->getStatusCode());
45
46 $newEntry = $client->getContainer()
47 ->get('doctrine.orm.entity_manager')
48 ->getRepository('WallabagCoreBundle:Entry')
49 ->findOneById($entry->getId());
50
51 $this->assertEquals(1, count($newEntry->getTags()));
52
53 # tag already exists but still not assigned to this entry
54 $data = array(
55 'tag[label]' => 'foo',
56 );
57
58 $client->submit($form, $data);
59 $this->assertEquals(302, $client->getResponse()->getStatusCode());
60
61 $newEntry = $client->getContainer()
62 ->get('doctrine.orm.entity_manager')
63 ->getRepository('WallabagCoreBundle:Entry')
64 ->findOneById($entry->getId());
65
66 $this->assertEquals(2, count($newEntry->getTags()));
67 }
68 }