diff options
Diffstat (limited to 'tests')
4 files changed, 440 insertions, 85 deletions
diff --git a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php index 70849f74..cee0b847 100644 --- a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php +++ b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php | |||
@@ -3,35 +3,80 @@ | |||
3 | namespace Tests\AnnotationBundle\Controller; | 3 | namespace Tests\AnnotationBundle\Controller; |
4 | 4 | ||
5 | use Tests\Wallabag\AnnotationBundle\WallabagAnnotationTestCase; | 5 | use Tests\Wallabag\AnnotationBundle\WallabagAnnotationTestCase; |
6 | use Wallabag\AnnotationBundle\Entity\Annotation; | ||
7 | use Wallabag\CoreBundle\Entity\Entry; | ||
6 | 8 | ||
7 | class AnnotationControllerTest extends WallabagAnnotationTestCase | 9 | class AnnotationControllerTest extends WallabagAnnotationTestCase |
8 | { | 10 | { |
9 | public function testGetAnnotations() | 11 | /** |
12 | * This data provider allow to tests annotation from the : | ||
13 | * - API POV (when user use the api to manage annotations) | ||
14 | * - and User POV (when user use the web interface - using javascript - to manage annotations) | ||
15 | */ | ||
16 | public function dataForEachAnnotations() | ||
10 | { | 17 | { |
11 | $annotation = $this->client->getContainer() | 18 | return [ |
12 | ->get('doctrine.orm.entity_manager') | 19 | ['/api/annotations'], |
13 | ->getRepository('WallabagAnnotationBundle:Annotation') | 20 | ['annotations'], |
14 | ->findOneByUsername('admin'); | 21 | ]; |
22 | } | ||
23 | |||
24 | /** | ||
25 | * Test fetching annotations for an entry. | ||
26 | * | ||
27 | * @dataProvider dataForEachAnnotations | ||
28 | */ | ||
29 | public function testGetAnnotations($prefixUrl) | ||
30 | { | ||
31 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | ||
32 | |||
33 | $user = $em | ||
34 | ->getRepository('WallabagUserBundle:User') | ||
35 | ->findOneByUserName('admin'); | ||
36 | $entry = $em | ||
37 | ->getRepository('WallabagCoreBundle:Entry') | ||
38 | ->findOneByUsernameAndNotArchived('admin'); | ||
15 | 39 | ||
16 | if (!$annotation) { | 40 | $annotation = new Annotation($user); |
17 | $this->markTestSkipped('No content found in db.'); | 41 | $annotation->setEntry($entry); |
42 | $annotation->setText('This is my annotation /o/'); | ||
43 | $annotation->setQuote('content'); | ||
44 | |||
45 | $em->persist($annotation); | ||
46 | $em->flush(); | ||
47 | |||
48 | if ('annotations' === $prefixUrl) { | ||
49 | $this->logInAs('admin'); | ||
18 | } | 50 | } |
19 | 51 | ||
20 | $this->logInAs('admin'); | 52 | $this->client->request('GET', $prefixUrl.'/'.$entry->getId().'.json'); |
21 | $crawler = $this->client->request('GET', 'annotations/'.$annotation->getEntry()->getId().'.json'); | ||
22 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | 53 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
23 | 54 | ||
24 | $content = json_decode($this->client->getResponse()->getContent(), true); | 55 | $content = json_decode($this->client->getResponse()->getContent(), true); |
25 | $this->assertEquals(1, $content['total']); | 56 | $this->assertGreaterThanOrEqual(1, $content['total']); |
26 | $this->assertEquals($annotation->getText(), $content['rows'][0]['text']); | 57 | $this->assertEquals($annotation->getText(), $content['rows'][0]['text']); |
58 | |||
59 | // we need to re-fetch the annotation becase after the flush, it has been "detached" from the entity manager | ||
60 | $annotation = $em->getRepository('WallabagAnnotationBundle:Annotation')->findAnnotationById($annotation->getId()); | ||
61 | $em->remove($annotation); | ||
62 | $em->flush(); | ||
27 | } | 63 | } |
28 | 64 | ||
29 | public function testSetAnnotation() | 65 | /** |
66 | * Test creating an annotation for an entry. | ||
67 | * | ||
68 | * @dataProvider dataForEachAnnotations | ||
69 | */ | ||
70 | public function testSetAnnotation($prefixUrl) | ||
30 | { | 71 | { |
31 | $this->logInAs('admin'); | 72 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); |
32 | 73 | ||
33 | $entry = $this->client->getContainer() | 74 | if ('annotations' === $prefixUrl) { |
34 | ->get('doctrine.orm.entity_manager') | 75 | $this->logInAs('admin'); |
76 | } | ||
77 | |||
78 | /** @var Entry $entry */ | ||
79 | $entry = $em | ||
35 | ->getRepository('WallabagCoreBundle:Entry') | 80 | ->getRepository('WallabagCoreBundle:Entry') |
36 | ->findOneByUsernameAndNotArchived('admin'); | 81 | ->findOneByUsernameAndNotArchived('admin'); |
37 | 82 | ||
@@ -41,7 +86,7 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase | |||
41 | 'quote' => 'my quote', | 86 | 'quote' => 'my quote', |
42 | 'ranges' => ['start' => '', 'startOffset' => 24, 'end' => '', 'endOffset' => 31], | 87 | 'ranges' => ['start' => '', 'startOffset' => 24, 'end' => '', 'endOffset' => 31], |
43 | ]); | 88 | ]); |
44 | $crawler = $this->client->request('POST', 'annotations/'.$entry->getId().'.json', [], [], $headers, $content); | 89 | $this->client->request('POST', $prefixUrl.'/'.$entry->getId().'.json', [], [], $headers, $content); |
45 | 90 | ||
46 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | 91 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
47 | 92 | ||
@@ -52,6 +97,7 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase | |||
52 | $this->assertEquals('my annotation', $content['text']); | 97 | $this->assertEquals('my annotation', $content['text']); |
53 | $this->assertEquals('my quote', $content['quote']); | 98 | $this->assertEquals('my quote', $content['quote']); |
54 | 99 | ||
100 | /** @var Annotation $annotation */ | ||
55 | $annotation = $this->client->getContainer() | 101 | $annotation = $this->client->getContainer() |
56 | ->get('doctrine.orm.entity_manager') | 102 | ->get('doctrine.orm.entity_manager') |
57 | ->getRepository('WallabagAnnotationBundle:Annotation') | 103 | ->getRepository('WallabagAnnotationBundle:Annotation') |
@@ -60,20 +106,35 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase | |||
60 | $this->assertEquals('my annotation', $annotation->getText()); | 106 | $this->assertEquals('my annotation', $annotation->getText()); |
61 | } | 107 | } |
62 | 108 | ||
63 | public function testEditAnnotation() | 109 | /** |
110 | * Test editing an existing annotation. | ||
111 | * | ||
112 | * @dataProvider dataForEachAnnotations | ||
113 | */ | ||
114 | public function testEditAnnotation($prefixUrl) | ||
64 | { | 115 | { |
65 | $annotation = $this->client->getContainer() | 116 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); |
66 | ->get('doctrine.orm.entity_manager') | ||
67 | ->getRepository('WallabagAnnotationBundle:Annotation') | ||
68 | ->findOneByUsername('admin'); | ||
69 | 117 | ||
70 | $this->logInAs('admin'); | 118 | $user = $em |
119 | ->getRepository('WallabagUserBundle:User') | ||
120 | ->findOneByUserName('admin'); | ||
121 | $entry = $em | ||
122 | ->getRepository('WallabagCoreBundle:Entry') | ||
123 | ->findOneByUsernameAndNotArchived('admin'); | ||
124 | |||
125 | $annotation = new Annotation($user); | ||
126 | $annotation->setEntry($entry); | ||
127 | $annotation->setText('This is my annotation /o/'); | ||
128 | $annotation->setQuote('my quote'); | ||
129 | |||
130 | $em->persist($annotation); | ||
131 | $em->flush(); | ||
71 | 132 | ||
72 | $headers = ['CONTENT_TYPE' => 'application/json']; | 133 | $headers = ['CONTENT_TYPE' => 'application/json']; |
73 | $content = json_encode([ | 134 | $content = json_encode([ |
74 | 'text' => 'a modified annotation', | 135 | 'text' => 'a modified annotation', |
75 | ]); | 136 | ]); |
76 | $crawler = $this->client->request('PUT', 'annotations/'.$annotation->getId().'.json', [], [], $headers, $content); | 137 | $this->client->request('PUT', $prefixUrl.'/'.$annotation->getId().'.json', [], [], $headers, $content); |
77 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | 138 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
78 | 139 | ||
79 | $content = json_decode($this->client->getResponse()->getContent(), true); | 140 | $content = json_decode($this->client->getResponse()->getContent(), true); |
@@ -83,35 +144,56 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase | |||
83 | $this->assertEquals('a modified annotation', $content['text']); | 144 | $this->assertEquals('a modified annotation', $content['text']); |
84 | $this->assertEquals('my quote', $content['quote']); | 145 | $this->assertEquals('my quote', $content['quote']); |
85 | 146 | ||
86 | $annotationUpdated = $this->client->getContainer() | 147 | /** @var Annotation $annotationUpdated */ |
87 | ->get('doctrine.orm.entity_manager') | 148 | $annotationUpdated = $em |
88 | ->getRepository('WallabagAnnotationBundle:Annotation') | 149 | ->getRepository('WallabagAnnotationBundle:Annotation') |
89 | ->findOneById($annotation->getId()); | 150 | ->findOneById($annotation->getId()); |
90 | $this->assertEquals('a modified annotation', $annotationUpdated->getText()); | 151 | $this->assertEquals('a modified annotation', $annotationUpdated->getText()); |
152 | |||
153 | $em->remove($annotationUpdated); | ||
154 | $em->flush(); | ||
91 | } | 155 | } |
92 | 156 | ||
93 | public function testDeleteAnnotation() | 157 | /** |
158 | * Test deleting an annotation. | ||
159 | * | ||
160 | * @dataProvider dataForEachAnnotations | ||
161 | */ | ||
162 | public function testDeleteAnnotation($prefixUrl) | ||
94 | { | 163 | { |
95 | $annotation = $this->client->getContainer() | 164 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); |
96 | ->get('doctrine.orm.entity_manager') | ||
97 | ->getRepository('WallabagAnnotationBundle:Annotation') | ||
98 | ->findOneByUsername('admin'); | ||
99 | 165 | ||
100 | $this->logInAs('admin'); | 166 | $user = $em |
167 | ->getRepository('WallabagUserBundle:User') | ||
168 | ->findOneByUserName('admin'); | ||
169 | $entry = $em | ||
170 | ->getRepository('WallabagCoreBundle:Entry') | ||
171 | ->findOneByUsernameAndNotArchived('admin'); | ||
172 | |||
173 | $annotation = new Annotation($user); | ||
174 | $annotation->setEntry($entry); | ||
175 | $annotation->setText('This is my annotation /o/'); | ||
176 | $annotation->setQuote('my quote'); | ||
177 | |||
178 | $em->persist($annotation); | ||
179 | $em->flush(); | ||
180 | |||
181 | if ('annotations' === $prefixUrl) { | ||
182 | $this->logInAs('admin'); | ||
183 | } | ||
101 | 184 | ||
102 | $headers = ['CONTENT_TYPE' => 'application/json']; | 185 | $headers = ['CONTENT_TYPE' => 'application/json']; |
103 | $content = json_encode([ | 186 | $content = json_encode([ |
104 | 'text' => 'a modified annotation', | 187 | 'text' => 'a modified annotation', |
105 | ]); | 188 | ]); |
106 | $crawler = $this->client->request('DELETE', 'annotations/'.$annotation->getId().'.json', [], [], $headers, $content); | 189 | $this->client->request('DELETE', $prefixUrl.'/'.$annotation->getId().'.json', [], [], $headers, $content); |
107 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | 190 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
108 | 191 | ||
109 | $content = json_decode($this->client->getResponse()->getContent(), true); | 192 | $content = json_decode($this->client->getResponse()->getContent(), true); |
110 | 193 | ||
111 | $this->assertEquals('a modified annotation', $content['text']); | 194 | $this->assertEquals('This is my annotation /o/', $content['text']); |
112 | 195 | ||
113 | $annotationDeleted = $this->client->getContainer() | 196 | $annotationDeleted = $em |
114 | ->get('doctrine.orm.entity_manager') | ||
115 | ->getRepository('WallabagAnnotationBundle:Annotation') | 197 | ->getRepository('WallabagAnnotationBundle:Annotation') |
116 | ->findOneById($annotation->getId()); | 198 | ->findOneById($annotation->getId()); |
117 | 199 | ||
diff --git a/tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php b/tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php index 82790a5c..ef3f1324 100644 --- a/tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php +++ b/tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php | |||
@@ -8,7 +8,7 @@ use Symfony\Component\BrowserKit\Cookie; | |||
8 | abstract class WallabagAnnotationTestCase extends WebTestCase | 8 | abstract class WallabagAnnotationTestCase extends WebTestCase |
9 | { | 9 | { |
10 | /** | 10 | /** |
11 | * @var Client | 11 | * @var \Symfony\Bundle\FrameworkBundle\Client |
12 | */ | 12 | */ |
13 | protected $client = null; | 13 | protected $client = null; |
14 | 14 | ||
@@ -35,7 +35,7 @@ abstract class WallabagAnnotationTestCase extends WebTestCase | |||
35 | } | 35 | } |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * @return Client | 38 | * @return \Symfony\Bundle\FrameworkBundle\Client |
39 | */ | 39 | */ |
40 | protected function createAuthorizedClient() | 40 | protected function createAuthorizedClient() |
41 | { | 41 | { |
@@ -49,7 +49,7 @@ abstract class WallabagAnnotationTestCase extends WebTestCase | |||
49 | $firewallName = $container->getParameter('fos_user.firewall_name'); | 49 | $firewallName = $container->getParameter('fos_user.firewall_name'); |
50 | 50 | ||
51 | $this->user = $userManager->findUserBy(['username' => 'admin']); | 51 | $this->user = $userManager->findUserBy(['username' => 'admin']); |
52 | $loginManager->loginUser($firewallName, $this->user); | 52 | $loginManager->logInUser($firewallName, $this->user); |
53 | 53 | ||
54 | // save the login token into the session and put it in a cookie | 54 | // save the login token into the session and put it in a cookie |
55 | $container->get('session')->set('_security_'.$firewallName, serialize($container->get('security.token_storage')->getToken())); | 55 | $container->get('session')->set('_security_'.$firewallName, serialize($container->get('security.token_storage')->getToken())); |
diff --git a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php index 5dcb3e00..6bca3c8b 100644 --- a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php | |||
@@ -32,12 +32,55 @@ class WallabagRestControllerTest extends WallabagApiTestCase | |||
32 | $this->assertEquals($entry->getUserEmail(), $content['user_email']); | 32 | $this->assertEquals($entry->getUserEmail(), $content['user_email']); |
33 | $this->assertEquals($entry->getUserId(), $content['user_id']); | 33 | $this->assertEquals($entry->getUserId(), $content['user_id']); |
34 | 34 | ||
35 | $this->assertTrue( | 35 | $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); |
36 | $this->client->getResponse()->headers->contains( | 36 | } |
37 | 'Content-Type', | 37 | |
38 | 'application/json' | 38 | public function testExportEntry() |
39 | ) | 39 | { |
40 | ); | 40 | $entry = $this->client->getContainer() |
41 | ->get('doctrine.orm.entity_manager') | ||
42 | ->getRepository('WallabagCoreBundle:Entry') | ||
43 | ->findOneBy(['user' => 1, 'isArchived' => false]); | ||
44 | |||
45 | if (!$entry) { | ||
46 | $this->markTestSkipped('No content found in db.'); | ||
47 | } | ||
48 | |||
49 | $this->client->request('GET', '/api/entries/'.$entry->getId().'/export.epub'); | ||
50 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
51 | |||
52 | // epub format got the content type in the content | ||
53 | $this->assertContains('application/epub', $this->client->getResponse()->getContent()); | ||
54 | $this->assertEquals('application/epub+zip', $this->client->getResponse()->headers->get('Content-Type')); | ||
55 | |||
56 | // re-auth client for mobi | ||
57 | $client = $this->createAuthorizedClient(); | ||
58 | $client->request('GET', '/api/entries/'.$entry->getId().'/export.mobi'); | ||
59 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
60 | |||
61 | $this->assertEquals('application/x-mobipocket-ebook', $client->getResponse()->headers->get('Content-Type')); | ||
62 | |||
63 | // re-auth client for pdf | ||
64 | $client = $this->createAuthorizedClient(); | ||
65 | $client->request('GET', '/api/entries/'.$entry->getId().'/export.pdf'); | ||
66 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
67 | |||
68 | $this->assertContains('PDF-', $client->getResponse()->getContent()); | ||
69 | $this->assertEquals('application/pdf', $client->getResponse()->headers->get('Content-Type')); | ||
70 | |||
71 | // re-auth client for pdf | ||
72 | $client = $this->createAuthorizedClient(); | ||
73 | $client->request('GET', '/api/entries/'.$entry->getId().'/export.txt'); | ||
74 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
75 | |||
76 | $this->assertContains('text/plain', $client->getResponse()->headers->get('Content-Type')); | ||
77 | |||
78 | // re-auth client for pdf | ||
79 | $client = $this->createAuthorizedClient(); | ||
80 | $client->request('GET', '/api/entries/'.$entry->getId().'/export.csv'); | ||
81 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
82 | |||
83 | $this->assertContains('application/csv', $client->getResponse()->headers->get('Content-Type')); | ||
41 | } | 84 | } |
42 | 85 | ||
43 | public function testGetOneEntryWrongUser() | 86 | public function testGetOneEntryWrongUser() |
@@ -70,12 +113,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase | |||
70 | $this->assertEquals(1, $content['page']); | 113 | $this->assertEquals(1, $content['page']); |
71 | $this->assertGreaterThanOrEqual(1, $content['pages']); | 114 | $this->assertGreaterThanOrEqual(1, $content['pages']); |
72 | 115 | ||
73 | $this->assertTrue( | 116 | $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); |
74 | $this->client->getResponse()->headers->contains( | ||
75 | 'Content-Type', | ||
76 | 'application/json' | ||
77 | ) | ||
78 | ); | ||
79 | } | 117 | } |
80 | 118 | ||
81 | public function testGetEntriesWithFullOptions() | 119 | public function testGetEntriesWithFullOptions() |
@@ -117,12 +155,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase | |||
117 | $this->assertContains('since=1443274283', $content['_links'][$link]['href']); | 155 | $this->assertContains('since=1443274283', $content['_links'][$link]['href']); |
118 | } | 156 | } |
119 | 157 | ||
120 | $this->assertTrue( | 158 | $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); |
121 | $this->client->getResponse()->headers->contains( | ||
122 | 'Content-Type', | ||
123 | 'application/json' | ||
124 | ) | ||
125 | ); | ||
126 | } | 159 | } |
127 | 160 | ||
128 | public function testGetStarredEntries() | 161 | public function testGetStarredEntries() |
@@ -150,12 +183,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase | |||
150 | $this->assertContains('sort=updated', $content['_links'][$link]['href']); | 183 | $this->assertContains('sort=updated', $content['_links'][$link]['href']); |
151 | } | 184 | } |
152 | 185 | ||
153 | $this->assertTrue( | 186 | $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); |
154 | $this->client->getResponse()->headers->contains( | ||
155 | 'Content-Type', | ||
156 | 'application/json' | ||
157 | ) | ||
158 | ); | ||
159 | } | 187 | } |
160 | 188 | ||
161 | public function testGetArchiveEntries() | 189 | public function testGetArchiveEntries() |
@@ -182,12 +210,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase | |||
182 | $this->assertContains('archive=1', $content['_links'][$link]['href']); | 210 | $this->assertContains('archive=1', $content['_links'][$link]['href']); |
183 | } | 211 | } |
184 | 212 | ||
185 | $this->assertTrue( | 213 | $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); |
186 | $this->client->getResponse()->headers->contains( | ||
187 | 'Content-Type', | ||
188 | 'application/json' | ||
189 | ) | ||
190 | ); | ||
191 | } | 214 | } |
192 | 215 | ||
193 | public function testGetTaggedEntries() | 216 | public function testGetTaggedEntries() |
@@ -214,12 +237,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase | |||
214 | $this->assertContains('tags='.urlencode('foo,bar'), $content['_links'][$link]['href']); | 237 | $this->assertContains('tags='.urlencode('foo,bar'), $content['_links'][$link]['href']); |
215 | } | 238 | } |
216 | 239 | ||
217 | $this->assertTrue( | 240 | $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); |
218 | $this->client->getResponse()->headers->contains( | ||
219 | 'Content-Type', | ||
220 | 'application/json' | ||
221 | ) | ||
222 | ); | ||
223 | } | 241 | } |
224 | 242 | ||
225 | public function testGetDatedEntries() | 243 | public function testGetDatedEntries() |
@@ -246,12 +264,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase | |||
246 | $this->assertContains('since=1443274283', $content['_links'][$link]['href']); | 264 | $this->assertContains('since=1443274283', $content['_links'][$link]['href']); |
247 | } | 265 | } |
248 | 266 | ||
249 | $this->assertTrue( | 267 | $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); |
250 | $this->client->getResponse()->headers->contains( | ||
251 | 'Content-Type', | ||
252 | 'application/json' | ||
253 | ) | ||
254 | ); | ||
255 | } | 268 | } |
256 | 269 | ||
257 | public function testGetDatedSupEntries() | 270 | public function testGetDatedSupEntries() |
@@ -279,12 +292,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase | |||
279 | $this->assertContains('since='.($future->getTimestamp() + 1000), $content['_links'][$link]['href']); | 292 | $this->assertContains('since='.($future->getTimestamp() + 1000), $content['_links'][$link]['href']); |
280 | } | 293 | } |
281 | 294 | ||
282 | $this->assertTrue( | 295 | $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); |
283 | $this->client->getResponse()->headers->contains( | ||
284 | 'Content-Type', | ||
285 | 'application/json' | ||
286 | ) | ||
287 | ); | ||
288 | } | 296 | } |
289 | 297 | ||
290 | public function testDeleteEntry() | 298 | public function testDeleteEntry() |
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index 1954c654..8d0644d1 100644 --- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php | |||
@@ -3,6 +3,11 @@ | |||
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\Config; | ||
7 | use Wallabag\UserBundle\Entity\User; | ||
8 | use Wallabag\CoreBundle\Entity\Entry; | ||
9 | use Wallabag\CoreBundle\Entity\Tag; | ||
10 | use Wallabag\AnnotationBundle\Entity\Annotation; | ||
6 | 11 | ||
7 | class ConfigControllerTest extends WallabagCoreTestCase | 12 | class ConfigControllerTest extends WallabagCoreTestCase |
8 | { | 13 | { |
@@ -570,4 +575,264 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
570 | $config->set('demo_mode_enabled', 0); | 575 | $config->set('demo_mode_enabled', 0); |
571 | $config->set('demo_mode_username', 'wallabag'); | 576 | $config->set('demo_mode_username', 'wallabag'); |
572 | } | 577 | } |
578 | |||
579 | public function testDeleteUserButtonVisibility() | ||
580 | { | ||
581 | $this->logInAs('admin'); | ||
582 | $client = $this->getClient(); | ||
583 | |||
584 | $crawler = $client->request('GET', '/config'); | ||
585 | |||
586 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | ||
587 | $this->assertContains('config.form_user.delete.button', $body[0]); | ||
588 | |||
589 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
590 | |||
591 | $user = $em | ||
592 | ->getRepository('WallabagUserBundle:User') | ||
593 | ->findOneByUsername('empty'); | ||
594 | $user->setExpired(1); | ||
595 | $em->persist($user); | ||
596 | |||
597 | $user = $em | ||
598 | ->getRepository('WallabagUserBundle:User') | ||
599 | ->findOneByUsername('bob'); | ||
600 | $user->setExpired(1); | ||
601 | $em->persist($user); | ||
602 | |||
603 | $em->flush(); | ||
604 | |||
605 | $crawler = $client->request('GET', '/config'); | ||
606 | |||
607 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | ||
608 | $this->assertNotContains('config.form_user.delete.button', $body[0]); | ||
609 | |||
610 | $client->request('GET', '/account/delete'); | ||
611 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | ||
612 | |||
613 | $user = $em | ||
614 | ->getRepository('WallabagUserBundle:User') | ||
615 | ->findOneByUsername('empty'); | ||
616 | $user->setExpired(0); | ||
617 | $em->persist($user); | ||
618 | |||
619 | $user = $em | ||
620 | ->getRepository('WallabagUserBundle:User') | ||
621 | ->findOneByUsername('bob'); | ||
622 | $user->setExpired(0); | ||
623 | $em->persist($user); | ||
624 | |||
625 | $em->flush(); | ||
626 | } | ||
627 | |||
628 | public function testDeleteAccount() | ||
629 | { | ||
630 | $client = $this->getClient(); | ||
631 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
632 | |||
633 | $user = new User(); | ||
634 | $user->setName('Wallace'); | ||
635 | $user->setEmail('wallace@wallabag.org'); | ||
636 | $user->setUsername('wallace'); | ||
637 | $user->setPlainPassword('wallace'); | ||
638 | $user->setEnabled(true); | ||
639 | $user->addRole('ROLE_SUPER_ADMIN'); | ||
640 | |||
641 | $em->persist($user); | ||
642 | |||
643 | $config = new Config($user); | ||
644 | |||
645 | $config->setTheme('material'); | ||
646 | $config->setItemsPerPage(30); | ||
647 | $config->setReadingSpeed(1); | ||
648 | $config->setLanguage('en'); | ||
649 | $config->setPocketConsumerKey('xxxxx'); | ||
650 | |||
651 | $em->persist($config); | ||
652 | $em->flush(); | ||
653 | |||
654 | $this->logInAs('wallace'); | ||
655 | $loggedInUserId = $this->getLoggedInUserId(); | ||
656 | |||
657 | // create entry to check after user deletion | ||
658 | // that this entry is also deleted | ||
659 | $crawler = $client->request('GET', '/new'); | ||
660 | |||
661 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
662 | |||
663 | $form = $crawler->filter('form[name=entry]')->form(); | ||
664 | $data = [ | ||
665 | 'entry[url]' => $url = 'https://github.com/wallabag/wallabag', | ||
666 | ]; | ||
667 | |||
668 | $client->submit($form, $data); | ||
669 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
670 | |||
671 | $crawler = $client->request('GET', '/config'); | ||
672 | |||
673 | $deleteLink = $crawler->filter('.delete-account')->last()->link(); | ||
674 | |||
675 | $client->click($deleteLink); | ||
676 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
677 | |||
678 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
679 | $user = $em | ||
680 | ->getRepository('WallabagUserBundle:User') | ||
681 | ->createQueryBuilder('u') | ||
682 | ->where('u.username = :username')->setParameter('username', 'wallace') | ||
683 | ->getQuery() | ||
684 | ->getOneOrNullResult() | ||
685 | ; | ||
686 | |||
687 | $this->assertNull($user); | ||
688 | |||
689 | $entries = $client->getContainer() | ||
690 | ->get('doctrine.orm.entity_manager') | ||
691 | ->getRepository('WallabagCoreBundle:Entry') | ||
692 | ->findByUser($loggedInUserId); | ||
693 | |||
694 | $this->assertEmpty($entries); | ||
695 | } | ||
696 | |||
697 | public function testReset() | ||
698 | { | ||
699 | $this->logInAs('empty'); | ||
700 | $client = $this->getClient(); | ||
701 | |||
702 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
703 | |||
704 | $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser(); | ||
705 | |||
706 | $tag = new Tag(); | ||
707 | $tag->setLabel('super'); | ||
708 | $em->persist($tag); | ||
709 | |||
710 | $entry = new Entry($user); | ||
711 | $entry->setUrl('http://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html'); | ||
712 | $entry->setContent('Youhou'); | ||
713 | $entry->setTitle('Youhou'); | ||
714 | $entry->addTag($tag); | ||
715 | $em->persist($entry); | ||
716 | |||
717 | $entry2 = new Entry($user); | ||
718 | $entry2->setUrl('http://www.lemonde.de/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html'); | ||
719 | $entry2->setContent('Youhou'); | ||
720 | $entry2->setTitle('Youhou'); | ||
721 | $entry2->addTag($tag); | ||
722 | $em->persist($entry2); | ||
723 | |||
724 | $annotation = new Annotation($user); | ||
725 | $annotation->setText('annotated'); | ||
726 | $annotation->setQuote('annotated'); | ||
727 | $annotation->setRanges([]); | ||
728 | $annotation->setEntry($entry); | ||
729 | $em->persist($annotation); | ||
730 | |||
731 | $em->flush(); | ||
732 | |||
733 | // reset annotations | ||
734 | $crawler = $client->request('GET', '/config#set3'); | ||
735 | |||
736 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
737 | |||
738 | $crawler = $client->click($crawler->selectLink('config.reset.annotations')->link()); | ||
739 | |||
740 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
741 | $this->assertContains('flashes.config.notice.annotations_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); | ||
742 | |||
743 | $annotationsReset = $em | ||
744 | ->getRepository('WallabagAnnotationBundle:Annotation') | ||
745 | ->findAnnotationsByPageId($entry->getId(), $user->getId()); | ||
746 | |||
747 | $this->assertEmpty($annotationsReset, 'Annotations were reset'); | ||
748 | |||
749 | // reset tags | ||
750 | $crawler = $client->request('GET', '/config#set3'); | ||
751 | |||
752 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
753 | |||
754 | $crawler = $client->click($crawler->selectLink('config.reset.tags')->link()); | ||
755 | |||
756 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
757 | $this->assertContains('flashes.config.notice.tags_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); | ||
758 | |||
759 | $tagReset = $em | ||
760 | ->getRepository('WallabagCoreBundle:Tag') | ||
761 | ->countAllTags($user->getId()); | ||
762 | |||
763 | $this->assertEquals(0, $tagReset, 'Tags were reset'); | ||
764 | |||
765 | // reset entries | ||
766 | $crawler = $client->request('GET', '/config#set3'); | ||
767 | |||
768 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
769 | |||
770 | $crawler = $client->click($crawler->selectLink('config.reset.entries')->link()); | ||
771 | |||
772 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
773 | $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); | ||
774 | |||
775 | $entryReset = $em | ||
776 | ->getRepository('WallabagCoreBundle:Entry') | ||
777 | ->countAllEntriesByUsername($user->getId()); | ||
778 | |||
779 | $this->assertEquals(0, $entryReset, 'Entries were reset'); | ||
780 | } | ||
781 | |||
782 | public function testResetEntriesCascade() | ||
783 | { | ||
784 | $this->logInAs('empty'); | ||
785 | $client = $this->getClient(); | ||
786 | |||
787 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
788 | |||
789 | $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser(); | ||
790 | |||
791 | $tag = new Tag(); | ||
792 | $tag->setLabel('super'); | ||
793 | $em->persist($tag); | ||
794 | |||
795 | $entry = new Entry($user); | ||
796 | $entry->setUrl('http://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html'); | ||
797 | $entry->setContent('Youhou'); | ||
798 | $entry->setTitle('Youhou'); | ||
799 | $entry->addTag($tag); | ||
800 | $em->persist($entry); | ||
801 | |||
802 | $annotation = new Annotation($user); | ||
803 | $annotation->setText('annotated'); | ||
804 | $annotation->setQuote('annotated'); | ||
805 | $annotation->setRanges([]); | ||
806 | $annotation->setEntry($entry); | ||
807 | $em->persist($annotation); | ||
808 | |||
809 | $em->flush(); | ||
810 | |||
811 | $crawler = $client->request('GET', '/config#set3'); | ||
812 | |||
813 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
814 | |||
815 | $crawler = $client->click($crawler->selectLink('config.reset.entries')->link()); | ||
816 | |||
817 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
818 | $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); | ||
819 | |||
820 | $entryReset = $em | ||
821 | ->getRepository('WallabagCoreBundle:Entry') | ||
822 | ->countAllEntriesByUsername($user->getId()); | ||
823 | |||
824 | $this->assertEquals(0, $entryReset, 'Entries were reset'); | ||
825 | |||
826 | $tagReset = $em | ||
827 | ->getRepository('WallabagCoreBundle:Tag') | ||
828 | ->countAllTags($user->getId()); | ||
829 | |||
830 | $this->assertEquals(0, $tagReset, 'Tags were reset'); | ||
831 | |||
832 | $annotationsReset = $em | ||
833 | ->getRepository('WallabagAnnotationBundle:Annotation') | ||
834 | ->findAnnotationsByPageId($entry->getId(), $user->getId()); | ||
835 | |||
836 | $this->assertEmpty($annotationsReset, 'Annotations were reset'); | ||
837 | } | ||
573 | } | 838 | } |