aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/CoreBundle/Controller/TagControllerTest.php')
-rw-r--r--tests/Wallabag/CoreBundle/Controller/TagControllerTest.php57
1 files changed, 37 insertions, 20 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php
index 2c32393f..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{
@@ -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,9 +44,9 @@ 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);
@@ -56,7 +57,7 @@ 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 = [
@@ -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,36 +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');
133 } 145 }
134 146
135 public function testShowEntriesForTagAction() 147 public function testShowEntriesForTagAction()
136 { 148 {
137 $this->logInAs('admin'); 149 $this->logInAs('admin');
138 $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);
139 156
140 $entry = $client->getContainer() 157 $entry = $client->getContainer()
141 ->get('doctrine.orm.entity_manager') 158 ->get('doctrine.orm.entity_manager')
142 ->getRepository('WallabagCoreBundle:Entry') 159 ->getRepository('WallabagCoreBundle:Entry')
143 ->findOneByUsernameAndNotArchived('admin'); 160 ->findByUrlAndUserId('http://0.0.0.0/entry4', $this->getLoggedInUserId());
144 161
145 $tag = $client->getContainer() 162 $tag->addEntry($entry);
146 ->get('doctrine.orm.entity_manager')
147 ->getRepository('WallabagCoreBundle:Tag')
148 ->findOneByEntryAndTagLabel($entry, 'foo');
149 163
150 $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug()); 164 $em->persist($entry);
151 165 $em->persist($tag);
152 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 166 $em->flush();
153 $this->assertCount(2, $crawler->filter('div[class=entry]'));
154 167
155 $tag = $client->getContainer() 168 $tag = $client->getContainer()
156 ->get('doctrine.orm.entity_manager') 169 ->get('doctrine.orm.entity_manager')
157 ->getRepository('WallabagCoreBundle:Tag') 170 ->getRepository('WallabagCoreBundle:Tag')
158 ->findOneByLabel('baz'); 171 ->findOneByEntryAndTagLabel($entry, $this->tagName);
159 172
160 $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug()); 173 $crawler = $client->request('GET', '/tag/list/'.$tag->getSlug());
161 174
162 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 175 $this->assertEquals(200, $client->getResponse()->getStatusCode());
163 $this->assertCount(0, $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();
164 } 181 }
165} 182}