]>
Commit | Line | Data |
---|---|---|
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 | $this->assertEquals(1, count($entry->getTags())); | |
43 | ||
44 | # tag already exists and already assigned | |
45 | $client->submit($form, $data); | |
46 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
47 | ||
48 | $newEntry = $client->getContainer() | |
49 | ->get('doctrine.orm.entity_manager') | |
50 | ->getRepository('WallabagCoreBundle:Entry') | |
51 | ->find($entry->getId()); | |
52 | ||
53 | $this->assertEquals(1, count($newEntry->getTags())); | |
54 | ||
55 | # tag already exists but still not assigned to this entry | |
56 | $data = [ | |
57 | 'tag[label]' => 'foo', | |
58 | ]; | |
59 | ||
60 | $client->submit($form, $data); | |
61 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
62 | ||
63 | $newEntry = $client->getContainer() | |
64 | ->get('doctrine.orm.entity_manager') | |
65 | ->getRepository('WallabagCoreBundle:Entry') | |
66 | ->find($entry->getId()); | |
67 | ||
68 | $this->assertEquals(2, count($newEntry->getTags())); | |
69 | } | |
70 | ||
71 | public function testAddMultipleTagToEntry() | |
72 | { | |
73 | $this->logInAs('admin'); | |
74 | $client = $this->getClient(); | |
75 | ||
76 | $entry = $client->getContainer() | |
77 | ->get('doctrine.orm.entity_manager') | |
78 | ->getRepository('WallabagCoreBundle:Entry') | |
79 | ->findOneByUsernameAndNotArchived('admin'); | |
80 | ||
81 | $crawler = $client->request('GET', '/view/'.$entry->getId()); | |
82 | ||
83 | $form = $crawler->filter('form[name=tag]')->form(); | |
84 | ||
85 | $data = [ | |
86 | 'tag[label]' => 'foo2, bar2', | |
87 | ]; | |
88 | ||
89 | $client->submit($form, $data); | |
90 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
91 | ||
92 | $newEntry = $client->getContainer() | |
93 | ->get('doctrine.orm.entity_manager') | |
94 | ->getRepository('WallabagCoreBundle:Entry') | |
95 | ->find($entry->getId()); | |
96 | ||
97 | $tags = $newEntry->getTags()->toArray(); | |
98 | $this->assertGreaterThanOrEqual(2, count($tags)); | |
99 | $this->assertNotEquals(false, array_search('foo2', $tags), 'Tag foo2 is assigned to the entry'); | |
100 | $this->assertNotEquals(false, array_search('bar2', $tags), 'Tag bar2 is assigned to the entry'); | |
101 | } | |
102 | ||
103 | public function testRemoveTagFromEntry() | |
104 | { | |
105 | $this->logInAs('admin'); | |
106 | $client = $this->getClient(); | |
107 | ||
108 | $entry = $client->getContainer() | |
109 | ->get('doctrine.orm.entity_manager') | |
110 | ->getRepository('WallabagCoreBundle:Entry') | |
111 | ->findOneByUsernameAndNotArchived('admin'); | |
112 | ||
113 | $tag = $client->getContainer() | |
114 | ->get('doctrine.orm.entity_manager') | |
115 | ->getRepository('WallabagCoreBundle:Tag') | |
116 | ->findOneByEntryAndTagLabel($entry, $this->tagName); | |
117 | ||
118 | $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); | |
119 | ||
120 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
121 | ||
122 | $this->assertNotContains($this->tagName, $entry->getTags()); | |
123 | ||
124 | $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); | |
125 | ||
126 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | |
127 | } | |
128 | } |