diff options
author | Paulino Michelazzo <paulino@michelazzo.com.br> | 2016-10-18 22:48:23 +0200 |
---|---|---|
committer | Paulino Michelazzo <paulino@michelazzo.com.br> | 2016-10-18 22:48:23 +0200 |
commit | 99731f0bb1f6fd2815eeb9af504ce86df927657b (patch) | |
tree | b080efc608d2bbd52b77a4a0067402007f50c5a8 /tests/Wallabag/CoreBundle/Controller/TagControllerTest.php | |
parent | 3a3c6b866b52721431bed22426d9abfcd0d2dfe0 (diff) | |
parent | 7180aaed45dce62e40620a9e4b202526ebd6a3bb (diff) | |
download | wallabag-99731f0bb1f6fd2815eeb9af504ce86df927657b.tar.gz wallabag-99731f0bb1f6fd2815eeb9af504ce86df927657b.tar.zst wallabag-99731f0bb1f6fd2815eeb9af504ce86df927657b.zip |
Merge remote-tracking branch 'wallabag/master'
Diffstat (limited to 'tests/Wallabag/CoreBundle/Controller/TagControllerTest.php')
-rw-r--r-- | tests/Wallabag/CoreBundle/Controller/TagControllerTest.php | 70 |
1 files changed, 59 insertions, 11 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index 58450e5f..769ce66e 100644 --- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php | |||
@@ -3,6 +3,7 @@ | |||
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\Tag; | ||
6 | 7 | ||
7 | class TagControllerTest extends WallabagCoreTestCase | 8 | class TagControllerTest extends WallabagCoreTestCase |
8 | { | 9 | { |
@@ -26,7 +27,7 @@ class TagControllerTest extends WallabagCoreTestCase | |||
26 | $entry = $client->getContainer() | 27 | $entry = $client->getContainer() |
27 | ->get('doctrine.orm.entity_manager') | 28 | ->get('doctrine.orm.entity_manager') |
28 | ->getRepository('WallabagCoreBundle:Entry') | 29 | ->getRepository('WallabagCoreBundle:Entry') |
29 | ->findOneByUsernameAndNotArchived('admin'); | 30 | ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); |
30 | 31 | ||
31 | $crawler = $client->request('GET', '/view/'.$entry->getId()); | 32 | $crawler = $client->request('GET', '/view/'.$entry->getId()); |
32 | 33 | ||
@@ -43,11 +44,11 @@ class TagControllerTest extends WallabagCoreTestCase | |||
43 | $entry = $client->getContainer() | 44 | $entry = $client->getContainer() |
44 | ->get('doctrine.orm.entity_manager') | 45 | ->get('doctrine.orm.entity_manager') |
45 | ->getRepository('WallabagCoreBundle:Entry') | 46 | ->getRepository('WallabagCoreBundle:Entry') |
46 | ->findOneByUsernameAndNotArchived('admin'); | 47 | ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); |
47 | 48 | ||
48 | $this->assertEquals(1, count($entry->getTags())); | 49 | $this->assertEquals(3, count($entry->getTags())); |
49 | 50 | ||
50 | # tag already exists and already assigned | 51 | // tag already exists and already assigned |
51 | $client->submit($form, $data); | 52 | $client->submit($form, $data); |
52 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 53 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
53 | 54 | ||
@@ -56,9 +57,9 @@ class TagControllerTest extends WallabagCoreTestCase | |||
56 | ->getRepository('WallabagCoreBundle:Entry') | 57 | ->getRepository('WallabagCoreBundle:Entry') |
57 | ->find($entry->getId()); | 58 | ->find($entry->getId()); |
58 | 59 | ||
59 | $this->assertEquals(1, count($newEntry->getTags())); | 60 | $this->assertEquals(3, count($newEntry->getTags())); |
60 | 61 | ||
61 | # tag already exists but still not assigned to this entry | 62 | // tag already exists but still not assigned to this entry |
62 | $data = [ | 63 | $data = [ |
63 | 'tag[label]' => 'foo', | 64 | 'tag[label]' => 'foo', |
64 | ]; | 65 | ]; |
@@ -71,7 +72,7 @@ class TagControllerTest extends WallabagCoreTestCase | |||
71 | ->getRepository('WallabagCoreBundle:Entry') | 72 | ->getRepository('WallabagCoreBundle:Entry') |
72 | ->find($entry->getId()); | 73 | ->find($entry->getId()); |
73 | 74 | ||
74 | $this->assertEquals(2, count($newEntry->getTags())); | 75 | $this->assertEquals(3, count($newEntry->getTags())); |
75 | } | 76 | } |
76 | 77 | ||
77 | public function testAddMultipleTagToEntry() | 78 | public function testAddMultipleTagToEntry() |
@@ -82,7 +83,7 @@ class TagControllerTest extends WallabagCoreTestCase | |||
82 | $entry = $client->getContainer() | 83 | $entry = $client->getContainer() |
83 | ->get('doctrine.orm.entity_manager') | 84 | ->get('doctrine.orm.entity_manager') |
84 | ->getRepository('WallabagCoreBundle:Entry') | 85 | ->getRepository('WallabagCoreBundle:Entry') |
85 | ->findOneByUsernameAndNotArchived('admin'); | 86 | ->findByUrlAndUserId('http://0.0.0.0/entry2', $this->getLoggedInUserId()); |
86 | 87 | ||
87 | $crawler = $client->request('GET', '/view/'.$entry->getId()); | 88 | $crawler = $client->request('GET', '/view/'.$entry->getId()); |
88 | 89 | ||
@@ -101,9 +102,13 @@ class TagControllerTest extends WallabagCoreTestCase | |||
101 | ->find($entry->getId()); | 102 | ->find($entry->getId()); |
102 | 103 | ||
103 | $tags = $newEntry->getTags()->toArray(); | 104 | $tags = $newEntry->getTags()->toArray(); |
105 | foreach ($tags as $key => $tag) { | ||
106 | $tags[$key] = $tag->getLabel(); | ||
107 | } | ||
108 | |||
104 | $this->assertGreaterThanOrEqual(2, count($tags)); | 109 | $this->assertGreaterThanOrEqual(2, count($tags)); |
105 | $this->assertNotEquals(false, array_search('foo2', $tags), 'Tag foo2 is assigned to the entry'); | 110 | $this->assertNotFalse(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'); | 111 | $this->assertNotFalse(array_search('bar2', $tags), 'Tag bar2 is assigned to the entry'); |
107 | } | 112 | } |
108 | 113 | ||
109 | public function testRemoveTagFromEntry() | 114 | public function testRemoveTagFromEntry() |
@@ -114,7 +119,7 @@ class TagControllerTest extends WallabagCoreTestCase | |||
114 | $entry = $client->getContainer() | 119 | $entry = $client->getContainer() |
115 | ->get('doctrine.orm.entity_manager') | 120 | ->get('doctrine.orm.entity_manager') |
116 | ->getRepository('WallabagCoreBundle:Entry') | 121 | ->getRepository('WallabagCoreBundle:Entry') |
117 | ->findOneByUsernameAndNotArchived('admin'); | 122 | ->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId()); |
118 | 123 | ||
119 | $tag = $client->getContainer() | 124 | $tag = $client->getContainer() |
120 | ->get('doctrine.orm.entity_manager') | 125 | ->get('doctrine.orm.entity_manager') |
@@ -130,5 +135,48 @@ class TagControllerTest extends WallabagCoreTestCase | |||
130 | $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); | 135 | $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); |
131 | 136 | ||
132 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | 137 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); |
138 | |||
139 | $tag = $client->getContainer() | ||
140 | ->get('doctrine.orm.entity_manager') | ||
141 | ->getRepository('WallabagCoreBundle:Tag') | ||
142 | ->findOneByLabel($this->tagName); | ||
143 | |||
144 | $this->assertNull($tag, $this->tagName.' was removed because it begun an orphan tag'); | ||
145 | } | ||
146 | |||
147 | public function testShowEntriesForTagAction() | ||
148 | { | ||
149 | $this->logInAs('admin'); | ||
150 | $client = $this->getClient(); | ||
151 | $em = $client->getContainer() | ||
152 | ->get('doctrine.orm.entity_manager'); | ||
153 | |||
154 | $tag = new Tag(); | ||
155 | $tag->setLabel($this->tagName); | ||
156 | |||
157 | $entry = $client->getContainer() | ||
158 | ->get('doctrine.orm.entity_manager') | ||
159 | ->getRepository('WallabagCoreBundle:Entry') | ||
160 | ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getLoggedInUserId()); | ||
161 | |||
162 | $tag->addEntry($entry); | ||
163 | |||
164 | $em->persist($entry); | ||
165 | $em->persist($tag); | ||
166 | $em->flush(); | ||
167 | |||
168 | $tag = $client->getContainer() | ||
169 | ->get('doctrine.orm.entity_manager') | ||
170 | ->getRepository('WallabagCoreBundle:Tag') | ||
171 | ->findOneByEntryAndTagLabel($entry, $this->tagName); | ||
172 | |||
173 | $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug()); | ||
174 | |||
175 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
176 | $this->assertCount(1, $crawler->filter('[id*="entry-"]')); | ||
177 | |||
178 | $entry->removeTag($tag); | ||
179 | $em->remove($tag); | ||
180 | $em->flush(); | ||
133 | } | 181 | } |
134 | } | 182 | } |