aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-10-07 23:31:53 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-10-07 23:31:53 +0200
commitac8cf632bb3a225c1b69d16e714ff60a2e988c89 (patch)
tree6789145b0518564d943399fd1b37830089cc4376 /tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
parent3049afe190d125e4861059b6bbad7c6fbea6f1bb (diff)
downloadwallabag-ac8cf632bb3a225c1b69d16e714ff60a2e988c89.tar.gz
wallabag-ac8cf632bb3a225c1b69d16e714ff60a2e988c89.tar.zst
wallabag-ac8cf632bb3a225c1b69d16e714ff60a2e988c89.zip
Ensure orphan tag are remove in API
When the association between a tag and an entry is removed, if the tag doesn’t have other entries, we can remove it. Also add more tests for that part and ensure TagControllerTest is isolated from the rest of the test suite (finally!)
Diffstat (limited to 'tests/Wallabag/CoreBundle/Controller/TagControllerTest.php')
-rw-r--r--tests/Wallabag/CoreBundle/Controller/TagControllerTest.php33
1 files changed, 23 insertions, 10 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
index 86a6cca2..769ce66e 100644
--- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
@@ -3,6 +3,7 @@
3namespace Tests\Wallabag\CoreBundle\Controller; 3namespace Tests\Wallabag\CoreBundle\Controller;
4 4
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; 5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6use Wallabag\CoreBundle\Entity\Tag;
6 7
7class TagControllerTest extends WallabagCoreTestCase 8class TagControllerTest extends WallabagCoreTestCase
8{ 9{
@@ -134,36 +135,48 @@ class TagControllerTest extends WallabagCoreTestCase
134 $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); 135 $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId());
135 136
136 $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');
137 } 145 }
138 146
139 public function testShowEntriesForTagAction() 147 public function testShowEntriesForTagAction()
140 { 148 {
141 $this->logInAs('admin'); 149 $this->logInAs('admin');
142 $client = $this->getClient(); 150 $client = $this->getClient();
151 $em = $client->getContainer()
152 ->get('doctrine.orm.entity_manager');
153
154 $tag = new Tag();
155 $tag->setLabel($this->tagName);
143 156
144 $entry = $client->getContainer() 157 $entry = $client->getContainer()
145 ->get('doctrine.orm.entity_manager') 158 ->get('doctrine.orm.entity_manager')
146 ->getRepository('WallabagCoreBundle:Entry') 159 ->getRepository('WallabagCoreBundle:Entry')
147 ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getLoggedInUserId()); 160 ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getLoggedInUserId());
148 161
149 $tag = $client->getContainer() 162 $tag->addEntry($entry);
150 ->get('doctrine.orm.entity_manager')
151 ->getRepository('WallabagCoreBundle:Tag')
152 ->findOneByEntryAndTagLabel($entry, 'foo');
153
154 $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug());
155 163
156 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 164 $em->persist($entry);
157 $this->assertCount(2, $crawler->filter('div[class=entry]')); 165 $em->persist($tag);
166 $em->flush();
158 167
159 $tag = $client->getContainer() 168 $tag = $client->getContainer()
160 ->get('doctrine.orm.entity_manager') 169 ->get('doctrine.orm.entity_manager')
161 ->getRepository('WallabagCoreBundle:Tag') 170 ->getRepository('WallabagCoreBundle:Tag')
162 ->findOneByLabel('baz'); 171 ->findOneByEntryAndTagLabel($entry, $this->tagName);
163 172
164 $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug()); 173 $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug());
165 174
166 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 175 $this->assertEquals(200, $client->getResponse()->getStatusCode());
167 $this->assertCount(1, $crawler->filter('div[class=entry]')); 176 $this->assertCount(1, $crawler->filter('[id*="entry-"]'));
177
178 $entry->removeTag($tag);
179 $em->remove($tag);
180 $em->flush();
168 } 181 }
169} 182}