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