diff options
Diffstat (limited to 'tests/Wallabag/CoreBundle/Controller/TagControllerTest.php')
-rw-r--r-- | tests/Wallabag/CoreBundle/Controller/TagControllerTest.php | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php new file mode 100644 index 00000000..58450e5f --- /dev/null +++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php | |||
@@ -0,0 +1,134 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\CoreBundle\Controller; | ||
4 | |||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | ||
6 | |||
7 | class TagControllerTest extends WallabagCoreTestCase | ||
8 | { | ||
9 | public $tagName = 'opensource'; | ||
10 | |||
11 | public function testList() | ||
12 | { | ||
13 | $this->logInAs('admin'); | ||
14 | $client = $this->getClient(); | ||
15 | |||
16 | $client->request('GET', '/tag/list'); | ||
17 | |||
18 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
19 | } | ||
20 | |||
21 | public function testAddTagToEntry() | ||
22 | { | ||
23 | $this->logInAs('admin'); | ||
24 | $client = $this->getClient(); | ||
25 | |||
26 | $entry = $client->getContainer() | ||
27 | ->get('doctrine.orm.entity_manager') | ||
28 | ->getRepository('WallabagCoreBundle:Entry') | ||
29 | ->findOneByUsernameAndNotArchived('admin'); | ||
30 | |||
31 | $crawler = $client->request('GET', '/view/'.$entry->getId()); | ||
32 | |||
33 | $form = $crawler->filter('form[name=tag]')->form(); | ||
34 | |||
35 | $data = [ | ||
36 | 'tag[label]' => $this->tagName, | ||
37 | ]; | ||
38 | |||
39 | $client->submit($form, $data); | ||
40 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
41 | |||
42 | // be sure to reload the entry | ||
43 | $entry = $client->getContainer() | ||
44 | ->get('doctrine.orm.entity_manager') | ||
45 | ->getRepository('WallabagCoreBundle:Entry') | ||
46 | ->findOneByUsernameAndNotArchived('admin'); | ||
47 | |||
48 | $this->assertEquals(1, count($entry->getTags())); | ||
49 | |||
50 | # tag already exists and already assigned | ||
51 | $client->submit($form, $data); | ||
52 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
53 | |||
54 | $newEntry = $client->getContainer() | ||
55 | ->get('doctrine.orm.entity_manager') | ||
56 | ->getRepository('WallabagCoreBundle:Entry') | ||
57 | ->find($entry->getId()); | ||
58 | |||
59 | $this->assertEquals(1, count($newEntry->getTags())); | ||
60 | |||
61 | # tag already exists but still not assigned to this entry | ||
62 | $data = [ | ||
63 | 'tag[label]' => 'foo', | ||
64 | ]; | ||
65 | |||
66 | $client->submit($form, $data); | ||
67 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
68 | |||
69 | $newEntry = $client->getContainer() | ||
70 | ->get('doctrine.orm.entity_manager') | ||
71 | ->getRepository('WallabagCoreBundle:Entry') | ||
72 | ->find($entry->getId()); | ||
73 | |||
74 | $this->assertEquals(2, count($newEntry->getTags())); | ||
75 | } | ||
76 | |||
77 | public function testAddMultipleTagToEntry() | ||
78 | { | ||
79 | $this->logInAs('admin'); | ||
80 | $client = $this->getClient(); | ||
81 | |||
82 | $entry = $client->getContainer() | ||
83 | ->get('doctrine.orm.entity_manager') | ||
84 | ->getRepository('WallabagCoreBundle:Entry') | ||
85 | ->findOneByUsernameAndNotArchived('admin'); | ||
86 | |||
87 | $crawler = $client->request('GET', '/view/'.$entry->getId()); | ||
88 | |||
89 | $form = $crawler->filter('form[name=tag]')->form(); | ||
90 | |||
91 | $data = [ | ||
92 | 'tag[label]' => 'foo2, bar2', | ||
93 | ]; | ||
94 | |||
95 | $client->submit($form, $data); | ||
96 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
97 | |||
98 | $newEntry = $client->getContainer() | ||
99 | ->get('doctrine.orm.entity_manager') | ||
100 | ->getRepository('WallabagCoreBundle:Entry') | ||
101 | ->find($entry->getId()); | ||
102 | |||
103 | $tags = $newEntry->getTags()->toArray(); | ||
104 | $this->assertGreaterThanOrEqual(2, count($tags)); | ||
105 | $this->assertNotEquals(false, array_search('foo2', $tags), 'Tag foo2 is assigned to the entry'); | ||
106 | $this->assertNotEquals(false, array_search('bar2', $tags), 'Tag bar2 is assigned to the entry'); | ||
107 | } | ||
108 | |||
109 | public function testRemoveTagFromEntry() | ||
110 | { | ||
111 | $this->logInAs('admin'); | ||
112 | $client = $this->getClient(); | ||
113 | |||
114 | $entry = $client->getContainer() | ||
115 | ->get('doctrine.orm.entity_manager') | ||
116 | ->getRepository('WallabagCoreBundle:Entry') | ||
117 | ->findOneByUsernameAndNotArchived('admin'); | ||
118 | |||
119 | $tag = $client->getContainer() | ||
120 | ->get('doctrine.orm.entity_manager') | ||
121 | ->getRepository('WallabagCoreBundle:Tag') | ||
122 | ->findOneByEntryAndTagLabel($entry, $this->tagName); | ||
123 | |||
124 | $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); | ||
125 | |||
126 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
127 | |||
128 | $this->assertNotContains($this->tagName, $entry->getTags()); | ||
129 | |||
130 | $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); | ||
131 | |||
132 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | ||
133 | } | ||
134 | } | ||