diff options
Diffstat (limited to 'tests/Wallabag/CoreBundle/Controller/TagControllerTest.php')
-rw-r--r-- | tests/Wallabag/CoreBundle/Controller/TagControllerTest.php | 101 |
1 files changed, 49 insertions, 52 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index fa1a3539..5a973a7e 100644 --- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php | |||
@@ -3,11 +3,13 @@ | |||
3 | namespace Tests\Wallabag\CoreBundle\Controller; | 3 | namespace Tests\Wallabag\CoreBundle\Controller; |
4 | 4 | ||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | 5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
6 | use Wallabag\CoreBundle\Entity\Entry; | ||
6 | use Wallabag\CoreBundle\Entity\Tag; | 7 | use Wallabag\CoreBundle\Entity\Tag; |
7 | 8 | ||
8 | class TagControllerTest extends WallabagCoreTestCase | 9 | class TagControllerTest extends WallabagCoreTestCase |
9 | { | 10 | { |
10 | public $tagName = 'opensource'; | 11 | public $tagName = 'opensource'; |
12 | public $caseTagName = 'OpenSource'; | ||
11 | 13 | ||
12 | public function testList() | 14 | public function testList() |
13 | { | 15 | { |
@@ -16,7 +18,7 @@ class TagControllerTest extends WallabagCoreTestCase | |||
16 | 18 | ||
17 | $client->request('GET', '/tag/list'); | 19 | $client->request('GET', '/tag/list'); |
18 | 20 | ||
19 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 21 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
20 | } | 22 | } |
21 | 23 | ||
22 | public function testAddTagToEntry() | 24 | public function testAddTagToEntry() |
@@ -24,40 +26,34 @@ class TagControllerTest extends WallabagCoreTestCase | |||
24 | $this->logInAs('admin'); | 26 | $this->logInAs('admin'); |
25 | $client = $this->getClient(); | 27 | $client = $this->getClient(); |
26 | 28 | ||
27 | $entry = $client->getContainer() | 29 | $entry = new Entry($this->getLoggedInUser()); |
28 | ->get('doctrine.orm.entity_manager') | 30 | $entry->setUrl('http://0.0.0.0/foo'); |
29 | ->getRepository('WallabagCoreBundle:Entry') | 31 | $this->getEntityManager()->persist($entry); |
30 | ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); | 32 | $this->getEntityManager()->flush(); |
33 | $this->getEntityManager()->clear(); | ||
31 | 34 | ||
32 | $crawler = $client->request('GET', '/view/'.$entry->getId()); | 35 | $crawler = $client->request('GET', '/view/' . $entry->getId()); |
33 | 36 | ||
34 | $form = $crawler->filter('form[name=tag]')->form(); | 37 | $form = $crawler->filter('form[name=tag]')->form(); |
35 | 38 | ||
36 | $data = [ | 39 | $data = [ |
37 | 'tag[label]' => $this->tagName, | 40 | 'tag[label]' => $this->caseTagName, |
38 | ]; | 41 | ]; |
39 | 42 | ||
40 | $client->submit($form, $data); | 43 | $client->submit($form, $data); |
41 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 44 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
42 | 45 | ||
43 | // be sure to reload the entry | 46 | // be sure to reload the entry |
44 | $entry = $client->getContainer() | 47 | $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId()); |
45 | ->get('doctrine.orm.entity_manager') | 48 | $this->assertCount(1, $entry->getTags()); |
46 | ->getRepository('WallabagCoreBundle:Entry') | 49 | $this->assertContains($this->tagName, $entry->getTags()); |
47 | ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); | ||
48 | |||
49 | $this->assertEquals(3, count($entry->getTags())); | ||
50 | 50 | ||
51 | // tag already exists and already assigned | 51 | // tag already exists and already assigned |
52 | $client->submit($form, $data); | 52 | $client->submit($form, $data); |
53 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 53 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
54 | 54 | ||
55 | $newEntry = $client->getContainer() | 55 | $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId()); |
56 | ->get('doctrine.orm.entity_manager') | 56 | $this->assertCount(1, $entry->getTags()); |
57 | ->getRepository('WallabagCoreBundle:Entry') | ||
58 | ->find($entry->getId()); | ||
59 | |||
60 | $this->assertEquals(3, count($newEntry->getTags())); | ||
61 | 57 | ||
62 | // tag already exists but still not assigned to this entry | 58 | // tag already exists but still not assigned to this entry |
63 | $data = [ | 59 | $data = [ |
@@ -65,14 +61,10 @@ class TagControllerTest extends WallabagCoreTestCase | |||
65 | ]; | 61 | ]; |
66 | 62 | ||
67 | $client->submit($form, $data); | 63 | $client->submit($form, $data); |
68 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 64 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
69 | |||
70 | $newEntry = $client->getContainer() | ||
71 | ->get('doctrine.orm.entity_manager') | ||
72 | ->getRepository('WallabagCoreBundle:Entry') | ||
73 | ->find($entry->getId()); | ||
74 | 65 | ||
75 | $this->assertEquals(3, count($newEntry->getTags())); | 66 | $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId()); |
67 | $this->assertCount(2, $entry->getTags()); | ||
76 | } | 68 | } |
77 | 69 | ||
78 | public function testAddMultipleTagToEntry() | 70 | public function testAddMultipleTagToEntry() |
@@ -85,16 +77,16 @@ class TagControllerTest extends WallabagCoreTestCase | |||
85 | ->getRepository('WallabagCoreBundle:Entry') | 77 | ->getRepository('WallabagCoreBundle:Entry') |
86 | ->findByUrlAndUserId('http://0.0.0.0/entry2', $this->getLoggedInUserId()); | 78 | ->findByUrlAndUserId('http://0.0.0.0/entry2', $this->getLoggedInUserId()); |
87 | 79 | ||
88 | $crawler = $client->request('GET', '/view/'.$entry->getId()); | 80 | $crawler = $client->request('GET', '/view/' . $entry->getId()); |
89 | 81 | ||
90 | $form = $crawler->filter('form[name=tag]')->form(); | 82 | $form = $crawler->filter('form[name=tag]')->form(); |
91 | 83 | ||
92 | $data = [ | 84 | $data = [ |
93 | 'tag[label]' => 'foo2, bar2', | 85 | 'tag[label]' => 'foo2, Bar2', |
94 | ]; | 86 | ]; |
95 | 87 | ||
96 | $client->submit($form, $data); | 88 | $client->submit($form, $data); |
97 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 89 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
98 | 90 | ||
99 | $newEntry = $client->getContainer() | 91 | $newEntry = $client->getContainer() |
100 | ->get('doctrine.orm.entity_manager') | 92 | ->get('doctrine.orm.entity_manager') |
@@ -107,8 +99,8 @@ class TagControllerTest extends WallabagCoreTestCase | |||
107 | } | 99 | } |
108 | 100 | ||
109 | $this->assertGreaterThanOrEqual(2, count($tags)); | 101 | $this->assertGreaterThanOrEqual(2, count($tags)); |
110 | $this->assertNotFalse(array_search('foo2', $tags), 'Tag foo2 is assigned to the entry'); | 102 | $this->assertNotFalse(array_search('foo2', $tags, true), 'Tag foo2 is assigned to the entry'); |
111 | $this->assertNotFalse(array_search('bar2', $tags), 'Tag bar2 is assigned to the entry'); | 103 | $this->assertNotFalse(array_search('bar2', $tags, true), 'Tag bar2 is assigned to the entry'); |
112 | } | 104 | } |
113 | 105 | ||
114 | public function testRemoveTagFromEntry() | 106 | public function testRemoveTagFromEntry() |
@@ -116,32 +108,37 @@ class TagControllerTest extends WallabagCoreTestCase | |||
116 | $this->logInAs('admin'); | 108 | $this->logInAs('admin'); |
117 | $client = $this->getClient(); | 109 | $client = $this->getClient(); |
118 | 110 | ||
119 | $entry = $client->getContainer() | 111 | $tag = new Tag(); |
120 | ->get('doctrine.orm.entity_manager') | 112 | $tag->setLabel($this->tagName); |
121 | ->getRepository('WallabagCoreBundle:Entry') | 113 | $entry = new Entry($this->getLoggedInUser()); |
122 | ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); | 114 | $entry->setUrl('http://0.0.0.0/foo'); |
123 | 115 | $entry->addTag($tag); | |
124 | $tag = $client->getContainer() | 116 | $this->getEntityManager()->persist($entry); |
125 | ->get('doctrine.orm.entity_manager') | 117 | $this->getEntityManager()->flush(); |
126 | ->getRepository('WallabagCoreBundle:Tag') | 118 | $this->getEntityManager()->clear(); |
127 | ->findOneByEntryAndTagLabel($entry, $this->tagName); | 119 | |
128 | 120 | // We make a first request to set an history and test redirection after tag deletion | |
129 | $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); | 121 | $client->request('GET', '/view/' . $entry->getId()); |
130 | 122 | $entryUri = $client->getRequest()->getUri(); | |
131 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 123 | $client->request('GET', '/remove-tag/' . $entry->getId() . '/' . $tag->getId()); |
132 | 124 | ||
125 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
126 | $this->assertSame($entryUri, $client->getResponse()->getTargetUrl()); | ||
127 | |||
128 | // re-retrieve the entry to be sure to get fresh data from database (mostly for tags) | ||
129 | $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId()); | ||
133 | $this->assertNotContains($this->tagName, $entry->getTags()); | 130 | $this->assertNotContains($this->tagName, $entry->getTags()); |
134 | 131 | ||
135 | $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); | 132 | $client->request('GET', '/remove-tag/' . $entry->getId() . '/' . $tag->getId()); |
136 | 133 | ||
137 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | 134 | $this->assertSame(404, $client->getResponse()->getStatusCode()); |
138 | 135 | ||
139 | $tag = $client->getContainer() | 136 | $tag = $client->getContainer() |
140 | ->get('doctrine.orm.entity_manager') | 137 | ->get('doctrine.orm.entity_manager') |
141 | ->getRepository('WallabagCoreBundle:Tag') | 138 | ->getRepository('WallabagCoreBundle:Tag') |
142 | ->findOneByLabel($this->tagName); | 139 | ->findOneByLabel($this->tagName); |
143 | 140 | ||
144 | $this->assertNull($tag, $this->tagName.' was removed because it begun an orphan tag'); | 141 | $this->assertNull($tag, $this->tagName . ' was removed because it begun an orphan tag'); |
145 | } | 142 | } |
146 | 143 | ||
147 | public function testShowEntriesForTagAction() | 144 | public function testShowEntriesForTagAction() |
@@ -170,9 +167,9 @@ class TagControllerTest extends WallabagCoreTestCase | |||
170 | ->getRepository('WallabagCoreBundle:Tag') | 167 | ->getRepository('WallabagCoreBundle:Tag') |
171 | ->findOneByEntryAndTagLabel($entry, $this->tagName); | 168 | ->findOneByEntryAndTagLabel($entry, $this->tagName); |
172 | 169 | ||
173 | $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug()); | 170 | $crawler = $client->request('GET', '/tag/list/' . $tag->getSlug()); |
174 | 171 | ||
175 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 172 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
176 | $this->assertCount(1, $crawler->filter('[id*="entry-"]')); | 173 | $this->assertCount(1, $crawler->filter('[id*="entry-"]')); |
177 | 174 | ||
178 | $entry->removeTag($tag); | 175 | $entry->removeTag($tag); |