diff options
Diffstat (limited to 'tests/Wallabag/CoreBundle/Controller')
6 files changed, 706 insertions, 212 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index beb0598a..5bc815ee 100644 --- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php | |||
@@ -67,8 +67,17 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
67 | public function testChangeReadingSpeed() | 67 | public function testChangeReadingSpeed() |
68 | { | 68 | { |
69 | $this->logInAs('admin'); | 69 | $this->logInAs('admin'); |
70 | $this->useTheme('baggy'); | ||
70 | $client = $this->getClient(); | 71 | $client = $this->getClient(); |
71 | 72 | ||
73 | $entry = new Entry($this->getLoggedInUser()); | ||
74 | $entry->setUrl('http://0.0.0.0/test-entry1') | ||
75 | ->setReadingTime(22); | ||
76 | $this->getEntityManager()->persist($entry); | ||
77 | |||
78 | $this->getEntityManager()->flush(); | ||
79 | $this->getEntityManager()->clear(); | ||
80 | |||
72 | $crawler = $client->request('GET', '/unread/list'); | 81 | $crawler = $client->request('GET', '/unread/list'); |
73 | $form = $crawler->filter('button[id=submit-filter]')->form(); | 82 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
74 | $dataFilters = [ | 83 | $dataFilters = [ |
@@ -409,6 +418,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
409 | public function testTaggingRuleCreation() | 418 | public function testTaggingRuleCreation() |
410 | { | 419 | { |
411 | $this->logInAs('admin'); | 420 | $this->logInAs('admin'); |
421 | $this->useTheme('baggy'); | ||
412 | $client = $this->getClient(); | 422 | $client = $this->getClient(); |
413 | 423 | ||
414 | $crawler = $client->request('GET', '/config'); | 424 | $crawler = $client->request('GET', '/config'); |
@@ -798,11 +808,87 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
798 | 808 | ||
799 | $entryReset = $em | 809 | $entryReset = $em |
800 | ->getRepository('WallabagCoreBundle:Entry') | 810 | ->getRepository('WallabagCoreBundle:Entry') |
801 | ->countAllEntriesByUsername($user->getId()); | 811 | ->countAllEntriesByUser($user->getId()); |
802 | 812 | ||
803 | $this->assertEquals(0, $entryReset, 'Entries were reset'); | 813 | $this->assertEquals(0, $entryReset, 'Entries were reset'); |
804 | } | 814 | } |
805 | 815 | ||
816 | public function testResetArchivedEntries() | ||
817 | { | ||
818 | $this->logInAs('empty'); | ||
819 | $client = $this->getClient(); | ||
820 | |||
821 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
822 | |||
823 | $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser(); | ||
824 | |||
825 | $tag = new Tag(); | ||
826 | $tag->setLabel('super'); | ||
827 | $em->persist($tag); | ||
828 | |||
829 | $entry = new Entry($user); | ||
830 | $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'); | ||
831 | $entry->setContent('Youhou'); | ||
832 | $entry->setTitle('Youhou'); | ||
833 | $entry->addTag($tag); | ||
834 | $em->persist($entry); | ||
835 | |||
836 | $annotation = new Annotation($user); | ||
837 | $annotation->setText('annotated'); | ||
838 | $annotation->setQuote('annotated'); | ||
839 | $annotation->setRanges([]); | ||
840 | $annotation->setEntry($entry); | ||
841 | $em->persist($annotation); | ||
842 | |||
843 | $tagArchived = new Tag(); | ||
844 | $tagArchived->setLabel('super'); | ||
845 | $em->persist($tagArchived); | ||
846 | |||
847 | $entryArchived = new Entry($user); | ||
848 | $entryArchived->setUrl('http://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html'); | ||
849 | $entryArchived->setContent('Youhou'); | ||
850 | $entryArchived->setTitle('Youhou'); | ||
851 | $entryArchived->addTag($tagArchived); | ||
852 | $entryArchived->setArchived(true); | ||
853 | $em->persist($entryArchived); | ||
854 | |||
855 | $annotationArchived = new Annotation($user); | ||
856 | $annotationArchived->setText('annotated'); | ||
857 | $annotationArchived->setQuote('annotated'); | ||
858 | $annotationArchived->setRanges([]); | ||
859 | $annotationArchived->setEntry($entryArchived); | ||
860 | $em->persist($annotationArchived); | ||
861 | |||
862 | $em->flush(); | ||
863 | |||
864 | $crawler = $client->request('GET', '/config#set3'); | ||
865 | |||
866 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
867 | |||
868 | $crawler = $client->click($crawler->selectLink('config.reset.archived')->link()); | ||
869 | |||
870 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
871 | $this->assertContains('flashes.config.notice.archived_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); | ||
872 | |||
873 | $entryReset = $em | ||
874 | ->getRepository('WallabagCoreBundle:Entry') | ||
875 | ->countAllEntriesByUser($user->getId()); | ||
876 | |||
877 | $this->assertEquals(1, $entryReset, 'Entries were reset'); | ||
878 | |||
879 | $tagReset = $em | ||
880 | ->getRepository('WallabagCoreBundle:Tag') | ||
881 | ->countAllTags($user->getId()); | ||
882 | |||
883 | $this->assertEquals(1, $tagReset, 'Tags were reset'); | ||
884 | |||
885 | $annotationsReset = $em | ||
886 | ->getRepository('WallabagAnnotationBundle:Annotation') | ||
887 | ->findAnnotationsByPageId($annotationArchived->getId(), $user->getId()); | ||
888 | |||
889 | $this->assertEmpty($annotationsReset, 'Annotations were reset'); | ||
890 | } | ||
891 | |||
806 | public function testResetEntriesCascade() | 892 | public function testResetEntriesCascade() |
807 | { | 893 | { |
808 | $this->logInAs('empty'); | 894 | $this->logInAs('empty'); |
@@ -843,7 +929,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
843 | 929 | ||
844 | $entryReset = $em | 930 | $entryReset = $em |
845 | ->getRepository('WallabagCoreBundle:Entry') | 931 | ->getRepository('WallabagCoreBundle:Entry') |
846 | ->countAllEntriesByUsername($user->getId()); | 932 | ->countAllEntriesByUser($user->getId()); |
847 | 933 | ||
848 | $this->assertEquals(0, $entryReset, 'Entries were reset'); | 934 | $this->assertEquals(0, $entryReset, 'Entries were reset'); |
849 | 935 | ||
@@ -863,6 +949,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
863 | public function testSwitchViewMode() | 949 | public function testSwitchViewMode() |
864 | { | 950 | { |
865 | $this->logInAs('admin'); | 951 | $this->logInAs('admin'); |
952 | $this->useTheme('baggy'); | ||
866 | $client = $this->getClient(); | 953 | $client = $this->getClient(); |
867 | 954 | ||
868 | $client->request('GET', '/unread/list'); | 955 | $client->request('GET', '/unread/list'); |
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 7db4cf1f..7cf28bfe 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php | |||
@@ -5,11 +5,28 @@ namespace Tests\Wallabag\CoreBundle\Controller; | |||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | 5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
6 | use Wallabag\CoreBundle\Entity\Config; | 6 | use Wallabag\CoreBundle\Entity\Config; |
7 | use Wallabag\CoreBundle\Entity\Entry; | 7 | use Wallabag\CoreBundle\Entity\Entry; |
8 | use Wallabag\CoreBundle\Entity\SiteCredential; | ||
8 | 9 | ||
9 | class EntryControllerTest extends WallabagCoreTestCase | 10 | class EntryControllerTest extends WallabagCoreTestCase |
10 | { | 11 | { |
12 | public $downloadImagesEnabled = false; | ||
11 | public $url = 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html'; | 13 | public $url = 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html'; |
12 | 14 | ||
15 | /** | ||
16 | * @after | ||
17 | * | ||
18 | * Ensure download_images_enabled is disabled after each script | ||
19 | */ | ||
20 | public function tearDownImagesEnabled() | ||
21 | { | ||
22 | if ($this->downloadImagesEnabled) { | ||
23 | $client = static::createClient(); | ||
24 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); | ||
25 | |||
26 | $this->downloadImagesEnabled = false; | ||
27 | } | ||
28 | } | ||
29 | |||
13 | public function testLogin() | 30 | public function testLogin() |
14 | { | 31 | { |
15 | $client = $this->getClient(); | 32 | $client = $this->getClient(); |
@@ -55,6 +72,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
55 | public function testGetNew() | 72 | public function testGetNew() |
56 | { | 73 | { |
57 | $this->logInAs('admin'); | 74 | $this->logInAs('admin'); |
75 | $this->useTheme('baggy'); | ||
58 | $client = $this->getClient(); | 76 | $client = $this->getClient(); |
59 | 77 | ||
60 | $crawler = $client->request('GET', '/new'); | 78 | $crawler = $client->request('GET', '/new'); |
@@ -68,6 +86,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
68 | public function testPostNewViaBookmarklet() | 86 | public function testPostNewViaBookmarklet() |
69 | { | 87 | { |
70 | $this->logInAs('admin'); | 88 | $this->logInAs('admin'); |
89 | $this->useTheme('baggy'); | ||
71 | $client = $this->getClient(); | 90 | $client = $this->getClient(); |
72 | 91 | ||
73 | $crawler = $client->request('GET', '/'); | 92 | $crawler = $client->request('GET', '/'); |
@@ -135,14 +154,58 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
135 | ->getRepository('WallabagCoreBundle:Entry') | 154 | ->getRepository('WallabagCoreBundle:Entry') |
136 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 155 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); |
137 | 156 | ||
157 | $author = $content->getPublishedBy(); | ||
158 | |||
138 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); | 159 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); |
139 | $this->assertEquals($this->url, $content->getUrl()); | 160 | $this->assertEquals($this->url, $content->getUrl()); |
140 | $this->assertContains('Google', $content->getTitle()); | 161 | $this->assertContains('Google', $content->getTitle()); |
162 | $this->assertEquals('fr', $content->getLanguage()); | ||
163 | $this->assertEquals('2015-03-28 15:37:39', $content->getPublishedAt()->format('Y-m-d H:i:s')); | ||
164 | $this->assertEquals('Morgane Tual', $author[0]); | ||
165 | $this->assertArrayHasKey('x-varnish1', $content->getHeaders()); | ||
166 | } | ||
167 | |||
168 | public function testPostWithMultipleAuthors() | ||
169 | { | ||
170 | $url = 'http://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768'; | ||
171 | $this->logInAs('admin'); | ||
172 | $client = $this->getClient(); | ||
173 | |||
174 | $crawler = $client->request('GET', '/new'); | ||
175 | |||
176 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
177 | |||
178 | $form = $crawler->filter('form[name=entry]')->form(); | ||
179 | |||
180 | $data = [ | ||
181 | 'entry[url]' => $url, | ||
182 | ]; | ||
183 | |||
184 | $client->submit($form, $data); | ||
185 | |||
186 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
187 | |||
188 | $content = $client->getContainer() | ||
189 | ->get('doctrine.orm.entity_manager') | ||
190 | ->getRepository('WallabagCoreBundle:Entry') | ||
191 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | ||
192 | |||
193 | $authors = $content->getPublishedBy(); | ||
194 | $this->assertEquals('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s')); | ||
195 | $this->assertEquals('fr', $content->getLanguage()); | ||
196 | $this->assertEquals('Raphaël Balenieri, correspondant à Pékin', $authors[0]); | ||
197 | $this->assertEquals('Frédéric Autran, correspondant à New York', $authors[1]); | ||
141 | } | 198 | } |
142 | 199 | ||
143 | public function testPostNewOkUrlExist() | 200 | public function testPostNewOkUrlExist() |
144 | { | 201 | { |
145 | $this->logInAs('admin'); | 202 | $this->logInAs('admin'); |
203 | |||
204 | $entry = new Entry($this->getLoggedInUser()); | ||
205 | $entry->setUrl($this->url); | ||
206 | $this->getEntityManager()->persist($entry); | ||
207 | $this->getEntityManager()->flush(); | ||
208 | |||
146 | $client = $this->getClient(); | 209 | $client = $this->getClient(); |
147 | 210 | ||
148 | $crawler = $client->request('GET', '/new'); | 211 | $crawler = $client->request('GET', '/new'); |
@@ -194,15 +257,6 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
194 | 257 | ||
195 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 258 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
196 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); | 259 | $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); |
197 | |||
198 | $em = $client->getContainer() | ||
199 | ->get('doctrine.orm.entity_manager'); | ||
200 | $entry = $em | ||
201 | ->getRepository('WallabagCoreBundle:Entry') | ||
202 | ->findOneByUrl(urldecode($url)); | ||
203 | |||
204 | $em->remove($entry); | ||
205 | $em->flush(); | ||
206 | } | 260 | } |
207 | 261 | ||
208 | /** | 262 | /** |
@@ -235,8 +289,9 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
235 | ->findOneByUrl($url); | 289 | ->findOneByUrl($url); |
236 | $tags = $entry->getTags(); | 290 | $tags = $entry->getTags(); |
237 | 291 | ||
238 | $this->assertCount(1, $tags); | 292 | $this->assertCount(2, $tags); |
239 | $this->assertEquals('wallabag', $tags[0]->getLabel()); | 293 | $this->assertContains('wallabag', $tags); |
294 | $this->assertEquals('en', $entry->getLanguage()); | ||
240 | 295 | ||
241 | $em->remove($entry); | 296 | $em->remove($entry); |
242 | $em->flush(); | 297 | $em->flush(); |
@@ -264,8 +319,8 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
264 | 319 | ||
265 | $tags = $entry->getTags(); | 320 | $tags = $entry->getTags(); |
266 | 321 | ||
267 | $this->assertCount(1, $tags); | 322 | $this->assertCount(2, $tags); |
268 | $this->assertEquals('wallabag', $tags[0]->getLabel()); | 323 | $this->assertContains('wallabag', $tags); |
269 | 324 | ||
270 | $em->remove($entry); | 325 | $em->remove($entry); |
271 | $em->flush(); | 326 | $em->flush(); |
@@ -312,29 +367,26 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
312 | $this->assertEquals('/all/list', $client->getResponse()->getTargetUrl()); | 367 | $this->assertEquals('/all/list', $client->getResponse()->getTargetUrl()); |
313 | } | 368 | } |
314 | 369 | ||
315 | /** | ||
316 | * @depends testPostNewOk | ||
317 | */ | ||
318 | public function testView() | 370 | public function testView() |
319 | { | 371 | { |
320 | $this->logInAs('admin'); | 372 | $this->logInAs('admin'); |
321 | $client = $this->getClient(); | 373 | $client = $this->getClient(); |
322 | 374 | ||
323 | $content = $client->getContainer() | 375 | $entry = new Entry($this->getLoggedInUser()); |
324 | ->get('doctrine.orm.entity_manager') | 376 | $entry->setUrl('http://example.com/foo'); |
325 | ->getRepository('WallabagCoreBundle:Entry') | 377 | $entry->setTitle('title foo'); |
326 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 378 | $entry->setContent('foo bar baz'); |
379 | $this->getEntityManager()->persist($entry); | ||
380 | $this->getEntityManager()->flush(); | ||
327 | 381 | ||
328 | $crawler = $client->request('GET', '/view/'.$content->getId()); | 382 | $crawler = $client->request('GET', '/view/'.$entry->getId()); |
329 | 383 | ||
330 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 384 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
331 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | 385 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
332 | $this->assertContains($content->getTitle(), $body[0]); | 386 | $this->assertContains($entry->getTitle(), $body[0]); |
333 | } | 387 | } |
334 | 388 | ||
335 | /** | 389 | /** |
336 | * @depends testPostNewOk | ||
337 | * | ||
338 | * This test will require an internet connection. | 390 | * This test will require an internet connection. |
339 | */ | 391 | */ |
340 | public function testReload() | 392 | public function testReload() |
@@ -342,63 +394,45 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
342 | $this->logInAs('admin'); | 394 | $this->logInAs('admin'); |
343 | $client = $this->getClient(); | 395 | $client = $this->getClient(); |
344 | 396 | ||
345 | $em = $client->getContainer() | 397 | $entry = new Entry($this->getLoggedInUser()); |
346 | ->get('doctrine.orm.entity_manager'); | 398 | $entry->setUrl($this->url); |
347 | 399 | $entry->setTitle('title foo'); | |
348 | $content = $em | 400 | $entry->setContent(''); |
349 | ->getRepository('WallabagCoreBundle:Entry') | 401 | $this->getEntityManager()->persist($entry); |
350 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 402 | $this->getEntityManager()->flush(); |
403 | $this->getEntityManager()->clear(); | ||
351 | 404 | ||
352 | // empty content | 405 | $client->request('GET', '/reload/'.$entry->getId()); |
353 | $content->setContent(''); | ||
354 | $em->persist($content); | ||
355 | $em->flush(); | ||
356 | |||
357 | $client->request('GET', '/reload/'.$content->getId()); | ||
358 | 406 | ||
359 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 407 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
360 | 408 | ||
361 | $content = $em | 409 | $entry = $this->getEntityManager() |
362 | ->getRepository('WallabagCoreBundle:Entry') | 410 | ->getRepository('WallabagCoreBundle:Entry') |
363 | ->find($content->getId()); | 411 | ->find($entry->getId()); |
364 | 412 | ||
365 | $this->assertNotEmpty($content->getContent()); | 413 | $this->assertNotEmpty($entry->getContent()); |
366 | } | 414 | } |
367 | 415 | ||
368 | /** | ||
369 | * @depends testPostNewOk | ||
370 | */ | ||
371 | public function testReloadWithFetchingFailed() | 416 | public function testReloadWithFetchingFailed() |
372 | { | 417 | { |
373 | $this->logInAs('admin'); | 418 | $this->logInAs('admin'); |
374 | $client = $this->getClient(); | 419 | $client = $this->getClient(); |
375 | 420 | ||
376 | $em = $client->getContainer() | 421 | $entry = new Entry($this->getLoggedInUser()); |
377 | ->get('doctrine.orm.entity_manager'); | 422 | $entry->setUrl('http://0.0.0.0/failed.html'); |
378 | 423 | $this->getEntityManager()->persist($entry); | |
379 | $content = $em | 424 | $this->getEntityManager()->flush(); |
380 | ->getRepository('WallabagCoreBundle:Entry') | ||
381 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | ||
382 | |||
383 | // put a known failed url | ||
384 | $content->setUrl('http://0.0.0.0/failed.html'); | ||
385 | $em->persist($content); | ||
386 | $em->flush(); | ||
387 | 425 | ||
388 | $client->request('GET', '/reload/'.$content->getId()); | 426 | $client->request('GET', '/reload/'.$entry->getId()); |
389 | 427 | ||
390 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 428 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
391 | 429 | ||
392 | // force EntityManager to clear previous entity | 430 | // force EntityManager to clear previous entity |
393 | // otherwise, retrieve the same entity will retrieve change from the previous request :0 | 431 | // otherwise, retrieve the same entity will retrieve change from the previous request :0 |
394 | $em->clear(); | 432 | $this->getEntityManager()->clear(); |
395 | $newContent = $em | 433 | $newContent = $this->getEntityManager() |
396 | ->getRepository('WallabagCoreBundle:Entry') | 434 | ->getRepository('WallabagCoreBundle:Entry') |
397 | ->find($content->getId()); | 435 | ->find($entry->getId()); |
398 | |||
399 | $newContent->setUrl($this->url); | ||
400 | $em->persist($newContent); | ||
401 | $em->flush(); | ||
402 | 436 | ||
403 | $this->assertNotEquals($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent()); | 437 | $this->assertNotEquals($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent()); |
404 | } | 438 | } |
@@ -408,12 +442,12 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
408 | $this->logInAs('admin'); | 442 | $this->logInAs('admin'); |
409 | $client = $this->getClient(); | 443 | $client = $this->getClient(); |
410 | 444 | ||
411 | $content = $client->getContainer() | 445 | $entry = new Entry($this->getLoggedInUser()); |
412 | ->get('doctrine.orm.entity_manager') | 446 | $entry->setUrl($this->url); |
413 | ->getRepository('WallabagCoreBundle:Entry') | 447 | $this->getEntityManager()->persist($entry); |
414 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 448 | $this->getEntityManager()->flush(); |
415 | 449 | ||
416 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | 450 | $crawler = $client->request('GET', '/edit/'.$entry->getId()); |
417 | 451 | ||
418 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 452 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
419 | 453 | ||
@@ -426,12 +460,12 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
426 | $this->logInAs('admin'); | 460 | $this->logInAs('admin'); |
427 | $client = $this->getClient(); | 461 | $client = $this->getClient(); |
428 | 462 | ||
429 | $content = $client->getContainer() | 463 | $entry = new Entry($this->getLoggedInUser()); |
430 | ->get('doctrine.orm.entity_manager') | 464 | $entry->setUrl($this->url); |
431 | ->getRepository('WallabagCoreBundle:Entry') | 465 | $this->getEntityManager()->persist($entry); |
432 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 466 | $this->getEntityManager()->flush(); |
433 | 467 | ||
434 | $crawler = $client->request('GET', '/edit/'.$content->getId()); | 468 | $crawler = $client->request('GET', '/edit/'.$entry->getId()); |
435 | 469 | ||
436 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 470 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
437 | 471 | ||
@@ -456,19 +490,20 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
456 | $this->logInAs('admin'); | 490 | $this->logInAs('admin'); |
457 | $client = $this->getClient(); | 491 | $client = $this->getClient(); |
458 | 492 | ||
459 | $content = $client->getContainer() | 493 | $entry = new Entry($this->getLoggedInUser()); |
460 | ->get('doctrine.orm.entity_manager') | 494 | $entry->setUrl($this->url); |
461 | ->getRepository('WallabagCoreBundle:Entry') | 495 | $this->getEntityManager()->persist($entry); |
462 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 496 | $this->getEntityManager()->flush(); |
497 | $this->getEntityManager()->clear(); | ||
463 | 498 | ||
464 | $client->request('GET', '/archive/'.$content->getId()); | 499 | $client->request('GET', '/archive/'.$entry->getId()); |
465 | 500 | ||
466 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 501 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
467 | 502 | ||
468 | $res = $client->getContainer() | 503 | $res = $client->getContainer() |
469 | ->get('doctrine.orm.entity_manager') | 504 | ->get('doctrine.orm.entity_manager') |
470 | ->getRepository('WallabagCoreBundle:Entry') | 505 | ->getRepository('WallabagCoreBundle:Entry') |
471 | ->find($content->getId()); | 506 | ->find($entry->getId()); |
472 | 507 | ||
473 | $this->assertEquals($res->isArchived(), true); | 508 | $this->assertEquals($res->isArchived(), true); |
474 | } | 509 | } |
@@ -478,19 +513,20 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
478 | $this->logInAs('admin'); | 513 | $this->logInAs('admin'); |
479 | $client = $this->getClient(); | 514 | $client = $this->getClient(); |
480 | 515 | ||
481 | $content = $client->getContainer() | 516 | $entry = new Entry($this->getLoggedInUser()); |
482 | ->get('doctrine.orm.entity_manager') | 517 | $entry->setUrl($this->url); |
483 | ->getRepository('WallabagCoreBundle:Entry') | 518 | $this->getEntityManager()->persist($entry); |
484 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 519 | $this->getEntityManager()->flush(); |
520 | $this->getEntityManager()->clear(); | ||
485 | 521 | ||
486 | $client->request('GET', '/star/'.$content->getId()); | 522 | $client->request('GET', '/star/'.$entry->getId()); |
487 | 523 | ||
488 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 524 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
489 | 525 | ||
490 | $res = $client->getContainer() | 526 | $res = $client->getContainer() |
491 | ->get('doctrine.orm.entity_manager') | 527 | ->get('doctrine.orm.entity_manager') |
492 | ->getRepository('WallabagCoreBundle:Entry') | 528 | ->getRepository('WallabagCoreBundle:Entry') |
493 | ->findOneById($content->getId()); | 529 | ->findOneById($entry->getId()); |
494 | 530 | ||
495 | $this->assertEquals($res->isStarred(), true); | 531 | $this->assertEquals($res->isStarred(), true); |
496 | } | 532 | } |
@@ -500,16 +536,16 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
500 | $this->logInAs('admin'); | 536 | $this->logInAs('admin'); |
501 | $client = $this->getClient(); | 537 | $client = $this->getClient(); |
502 | 538 | ||
503 | $content = $client->getContainer() | 539 | $entry = new Entry($this->getLoggedInUser()); |
504 | ->get('doctrine.orm.entity_manager') | 540 | $entry->setUrl($this->url); |
505 | ->getRepository('WallabagCoreBundle:Entry') | 541 | $this->getEntityManager()->persist($entry); |
506 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | 542 | $this->getEntityManager()->flush(); |
507 | 543 | ||
508 | $client->request('GET', '/delete/'.$content->getId()); | 544 | $client->request('GET', '/delete/'.$entry->getId()); |
509 | 545 | ||
510 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 546 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
511 | 547 | ||
512 | $client->request('GET', '/delete/'.$content->getId()); | 548 | $client->request('GET', '/delete/'.$entry->getId()); |
513 | 549 | ||
514 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | 550 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); |
515 | } | 551 | } |
@@ -575,7 +611,13 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
575 | public function testFilterOnReadingTime() | 611 | public function testFilterOnReadingTime() |
576 | { | 612 | { |
577 | $this->logInAs('admin'); | 613 | $this->logInAs('admin'); |
614 | $this->useTheme('baggy'); | ||
578 | $client = $this->getClient(); | 615 | $client = $this->getClient(); |
616 | $entry = new Entry($this->getLoggedInUser()); | ||
617 | $entry->setUrl($this->url); | ||
618 | $entry->setReadingTime(22); | ||
619 | $this->getEntityManager()->persist($entry); | ||
620 | $this->getEntityManager()->flush(); | ||
579 | 621 | ||
580 | $crawler = $client->request('GET', '/unread/list'); | 622 | $crawler = $client->request('GET', '/unread/list'); |
581 | 623 | ||
@@ -614,9 +656,20 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
614 | public function testFilterOnReadingTimeOnlyUpper() | 656 | public function testFilterOnReadingTimeOnlyUpper() |
615 | { | 657 | { |
616 | $this->logInAs('admin'); | 658 | $this->logInAs('admin'); |
659 | $this->useTheme('baggy'); | ||
617 | $client = $this->getClient(); | 660 | $client = $this->getClient(); |
618 | 661 | ||
619 | $crawler = $client->request('GET', '/unread/list'); | 662 | $crawler = $client->request('GET', '/all/list'); |
663 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | ||
664 | |||
665 | $entry = new Entry($this->getLoggedInUser()); | ||
666 | $entry->setUrl($this->url); | ||
667 | $entry->setReadingTime(23); | ||
668 | $this->getEntityManager()->persist($entry); | ||
669 | $this->getEntityManager()->flush(); | ||
670 | |||
671 | $crawler = $client->request('GET', '/all/list'); | ||
672 | $this->assertCount(6, $crawler->filter('div[class=entry]')); | ||
620 | 673 | ||
621 | $form = $crawler->filter('button[id=submit-filter]')->form(); | 674 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
622 | 675 | ||
@@ -626,12 +679,13 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
626 | 679 | ||
627 | $crawler = $client->submit($form, $data); | 680 | $crawler = $client->submit($form, $data); |
628 | 681 | ||
629 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | 682 | $this->assertCount(5, $crawler->filter('div[class=entry]')); |
630 | } | 683 | } |
631 | 684 | ||
632 | public function testFilterOnReadingTimeOnlyLower() | 685 | public function testFilterOnReadingTimeOnlyLower() |
633 | { | 686 | { |
634 | $this->logInAs('admin'); | 687 | $this->logInAs('admin'); |
688 | $this->useTheme('baggy'); | ||
635 | $client = $this->getClient(); | 689 | $client = $this->getClient(); |
636 | 690 | ||
637 | $crawler = $client->request('GET', '/unread/list'); | 691 | $crawler = $client->request('GET', '/unread/list'); |
@@ -644,12 +698,22 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
644 | 698 | ||
645 | $crawler = $client->submit($form, $data); | 699 | $crawler = $client->submit($form, $data); |
646 | 700 | ||
647 | $this->assertCount(4, $crawler->filter('div[class=entry]')); | 701 | $this->assertCount(0, $crawler->filter('div[class=entry]')); |
702 | |||
703 | $entry = new Entry($this->getLoggedInUser()); | ||
704 | $entry->setUrl($this->url); | ||
705 | $entry->setReadingTime(23); | ||
706 | $this->getEntityManager()->persist($entry); | ||
707 | $this->getEntityManager()->flush(); | ||
708 | |||
709 | $crawler = $client->submit($form, $data); | ||
710 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | ||
648 | } | 711 | } |
649 | 712 | ||
650 | public function testFilterOnUnreadStatus() | 713 | public function testFilterOnUnreadStatus() |
651 | { | 714 | { |
652 | $this->logInAs('admin'); | 715 | $this->logInAs('admin'); |
716 | $this->useTheme('baggy'); | ||
653 | $client = $this->getClient(); | 717 | $client = $this->getClient(); |
654 | 718 | ||
655 | $crawler = $client->request('GET', '/all/list'); | 719 | $crawler = $client->request('GET', '/all/list'); |
@@ -663,11 +727,22 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
663 | $crawler = $client->submit($form, $data); | 727 | $crawler = $client->submit($form, $data); |
664 | 728 | ||
665 | $this->assertCount(4, $crawler->filter('div[class=entry]')); | 729 | $this->assertCount(4, $crawler->filter('div[class=entry]')); |
730 | |||
731 | $entry = new Entry($this->getLoggedInUser()); | ||
732 | $entry->setUrl($this->url); | ||
733 | $entry->setArchived(false); | ||
734 | $this->getEntityManager()->persist($entry); | ||
735 | $this->getEntityManager()->flush(); | ||
736 | |||
737 | $crawler = $client->submit($form, $data); | ||
738 | |||
739 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | ||
666 | } | 740 | } |
667 | 741 | ||
668 | public function testFilterOnCreationDate() | 742 | public function testFilterOnCreationDate() |
669 | { | 743 | { |
670 | $this->logInAs('admin'); | 744 | $this->logInAs('admin'); |
745 | $this->useTheme('baggy'); | ||
671 | $client = $this->getClient(); | 746 | $client = $this->getClient(); |
672 | 747 | ||
673 | $crawler = $client->request('GET', '/unread/list'); | 748 | $crawler = $client->request('GET', '/unread/list'); |
@@ -734,6 +809,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
734 | public function testFilterOnDomainName() | 809 | public function testFilterOnDomainName() |
735 | { | 810 | { |
736 | $this->logInAs('admin'); | 811 | $this->logInAs('admin'); |
812 | $this->useTheme('baggy'); | ||
737 | $client = $this->getClient(); | 813 | $client = $this->getClient(); |
738 | 814 | ||
739 | $crawler = $client->request('GET', '/unread/list'); | 815 | $crawler = $client->request('GET', '/unread/list'); |
@@ -766,6 +842,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
766 | public function testFilterOnStatus() | 842 | public function testFilterOnStatus() |
767 | { | 843 | { |
768 | $this->logInAs('admin'); | 844 | $this->logInAs('admin'); |
845 | $this->useTheme('baggy'); | ||
769 | $client = $this->getClient(); | 846 | $client = $this->getClient(); |
770 | 847 | ||
771 | $crawler = $client->request('GET', '/unread/list'); | 848 | $crawler = $client->request('GET', '/unread/list'); |
@@ -784,9 +861,24 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
784 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | 861 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
785 | } | 862 | } |
786 | 863 | ||
864 | public function testFilterOnIsPublic() | ||
865 | { | ||
866 | $this->logInAs('admin'); | ||
867 | $this->useTheme('baggy'); | ||
868 | $client = $this->getClient(); | ||
869 | |||
870 | $crawler = $client->request('GET', '/unread/list'); | ||
871 | $form = $crawler->filter('button[id=submit-filter]')->form(); | ||
872 | $form['entry_filter[isPublic]']->tick(); | ||
873 | |||
874 | $crawler = $client->submit($form); | ||
875 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | ||
876 | } | ||
877 | |||
787 | public function testPreviewPictureFilter() | 878 | public function testPreviewPictureFilter() |
788 | { | 879 | { |
789 | $this->logInAs('admin'); | 880 | $this->logInAs('admin'); |
881 | $this->useTheme('baggy'); | ||
790 | $client = $this->getClient(); | 882 | $client = $this->getClient(); |
791 | 883 | ||
792 | $crawler = $client->request('GET', '/unread/list'); | 884 | $crawler = $client->request('GET', '/unread/list'); |
@@ -800,8 +892,15 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
800 | public function testFilterOnLanguage() | 892 | public function testFilterOnLanguage() |
801 | { | 893 | { |
802 | $this->logInAs('admin'); | 894 | $this->logInAs('admin'); |
895 | $this->useTheme('baggy'); | ||
803 | $client = $this->getClient(); | 896 | $client = $this->getClient(); |
804 | 897 | ||
898 | $entry = new Entry($this->getLoggedInUser()); | ||
899 | $entry->setUrl($this->url); | ||
900 | $entry->setLanguage('fr'); | ||
901 | $this->getEntityManager()->persist($entry); | ||
902 | $this->getEntityManager()->flush(); | ||
903 | |||
805 | $crawler = $client->request('GET', '/unread/list'); | 904 | $crawler = $client->request('GET', '/unread/list'); |
806 | $form = $crawler->filter('button[id=submit-filter]')->form(); | 905 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
807 | $data = [ | 906 | $data = [ |
@@ -809,7 +908,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
809 | ]; | 908 | ]; |
810 | 909 | ||
811 | $crawler = $client->submit($form, $data); | 910 | $crawler = $client->submit($form, $data); |
812 | $this->assertCount(2, $crawler->filter('div[class=entry]')); | 911 | $this->assertCount(3, $crawler->filter('div[class=entry]')); |
813 | 912 | ||
814 | $form = $crawler->filter('button[id=submit-filter]')->form(); | 913 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
815 | $data = [ | 914 | $data = [ |
@@ -825,10 +924,14 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
825 | $this->logInAs('admin'); | 924 | $this->logInAs('admin'); |
826 | $client = $this->getClient(); | 925 | $client = $this->getClient(); |
827 | 926 | ||
828 | $content = $client->getContainer() | 927 | // sharing is enabled |
829 | ->get('doctrine.orm.entity_manager') | 928 | $client->getContainer()->get('craue_config')->set('share_public', 1); |
830 | ->getRepository('WallabagCoreBundle:Entry') | 929 | |
831 | ->findOneByUser($this->getLoggedInUserId()); | 930 | $content = new Entry($this->getLoggedInUser()); |
931 | $content->setUrl($this->url); | ||
932 | $this->getEntityManager()->persist($content); | ||
933 | $this->getEntityManager()->flush(); | ||
934 | $this->getEntityManager()->clear(); | ||
832 | 935 | ||
833 | // no uid | 936 | // no uid |
834 | $client->request('GET', '/share/'.$content->getUid()); | 937 | $client->request('GET', '/share/'.$content->getUid()); |
@@ -869,6 +972,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
869 | 972 | ||
870 | public function testNewEntryWithDownloadImagesEnabled() | 973 | public function testNewEntryWithDownloadImagesEnabled() |
871 | { | 974 | { |
975 | $this->downloadImagesEnabled = true; | ||
872 | $this->logInAs('admin'); | 976 | $this->logInAs('admin'); |
873 | $client = $this->getClient(); | 977 | $client = $this->getClient(); |
874 | 978 | ||
@@ -899,7 +1003,8 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
899 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry); | 1003 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry); |
900 | $this->assertEquals($url, $entry->getUrl()); | 1004 | $this->assertEquals($url, $entry->getUrl()); |
901 | $this->assertContains('Perpignan', $entry->getTitle()); | 1005 | $this->assertContains('Perpignan', $entry->getTitle()); |
902 | $this->assertContains('/d9bc0fcd.jpeg', $entry->getContent()); | 1006 | // instead of checking for the filename (which might change) check that the image is now local |
1007 | $this->assertContains('https://your-wallabag-url-instance.com/assets/images/', $entry->getContent()); | ||
903 | 1008 | ||
904 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); | 1009 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 0); |
905 | } | 1010 | } |
@@ -909,12 +1014,27 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
909 | */ | 1014 | */ |
910 | public function testRemoveEntryWithDownloadImagesEnabled() | 1015 | public function testRemoveEntryWithDownloadImagesEnabled() |
911 | { | 1016 | { |
1017 | $this->downloadImagesEnabled = true; | ||
912 | $this->logInAs('admin'); | 1018 | $this->logInAs('admin'); |
913 | $client = $this->getClient(); | 1019 | $client = $this->getClient(); |
914 | 1020 | ||
915 | $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route'; | 1021 | $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route'; |
916 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 1); | 1022 | $client->getContainer()->get('craue_config')->set('download_images_enabled', 1); |
917 | 1023 | ||
1024 | $crawler = $client->request('GET', '/new'); | ||
1025 | |||
1026 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
1027 | |||
1028 | $form = $crawler->filter('form[name=entry]')->form(); | ||
1029 | |||
1030 | $data = [ | ||
1031 | 'entry[url]' => $url, | ||
1032 | ]; | ||
1033 | |||
1034 | $client->submit($form, $data); | ||
1035 | |||
1036 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
1037 | |||
918 | $content = $client->getContainer() | 1038 | $content = $client->getContainer() |
919 | ->get('doctrine.orm.entity_manager') | 1039 | ->get('doctrine.orm.entity_manager') |
920 | ->getRepository('WallabagCoreBundle:Entry') | 1040 | ->getRepository('WallabagCoreBundle:Entry') |
@@ -932,28 +1052,19 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
932 | $this->logInAs('empty'); | 1052 | $this->logInAs('empty'); |
933 | $client = $this->getClient(); | 1053 | $client = $this->getClient(); |
934 | 1054 | ||
935 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
936 | $user = $em | ||
937 | ->getRepository('WallabagUserBundle:User') | ||
938 | ->find($this->getLoggedInUserId()); | ||
939 | |||
940 | if (!$user) { | ||
941 | $this->markTestSkipped('No user found in db.'); | ||
942 | } | ||
943 | |||
944 | // Redirect to homepage | 1055 | // Redirect to homepage |
945 | $config = $user->getConfig(); | 1056 | $config = $this->getLoggedInUser()->getConfig(); |
946 | $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); | 1057 | $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE); |
947 | $em->persist($config); | 1058 | $this->getEntityManager()->persist($config); |
948 | $em->flush(); | ||
949 | 1059 | ||
950 | $content = $client->getContainer() | 1060 | $entry = new Entry($this->getLoggedInUser()); |
951 | ->get('doctrine.orm.entity_manager') | 1061 | $entry->setUrl($this->url); |
952 | ->getRepository('WallabagCoreBundle:Entry') | 1062 | $this->getEntityManager()->persist($entry); |
953 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | ||
954 | 1063 | ||
955 | $client->request('GET', '/view/'.$content->getId()); | 1064 | $this->getEntityManager()->flush(); |
956 | $client->request('GET', '/archive/'.$content->getId()); | 1065 | |
1066 | $client->request('GET', '/view/'.$entry->getId()); | ||
1067 | $client->request('GET', '/archive/'.$entry->getId()); | ||
957 | 1068 | ||
958 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 1069 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
959 | $this->assertEquals('/', $client->getResponse()->headers->get('location')); | 1070 | $this->assertEquals('/', $client->getResponse()->headers->get('location')); |
@@ -964,46 +1075,36 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
964 | $this->logInAs('empty'); | 1075 | $this->logInAs('empty'); |
965 | $client = $this->getClient(); | 1076 | $client = $this->getClient(); |
966 | 1077 | ||
967 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
968 | $user = $em | ||
969 | ->getRepository('WallabagUserBundle:User') | ||
970 | ->find($this->getLoggedInUserId()); | ||
971 | |||
972 | if (!$user) { | ||
973 | $this->markTestSkipped('No user found in db.'); | ||
974 | } | ||
975 | |||
976 | // Redirect to current page | 1078 | // Redirect to current page |
977 | $config = $user->getConfig(); | 1079 | $config = $this->getLoggedInUser()->getConfig(); |
978 | $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE); | 1080 | $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE); |
979 | $em->persist($config); | 1081 | $this->getEntityManager()->persist($config); |
980 | $em->flush(); | ||
981 | 1082 | ||
982 | $content = $client->getContainer() | 1083 | $entry = new Entry($this->getLoggedInUser()); |
983 | ->get('doctrine.orm.entity_manager') | 1084 | $entry->setUrl($this->url); |
984 | ->getRepository('WallabagCoreBundle:Entry') | 1085 | $this->getEntityManager()->persist($entry); |
985 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | ||
986 | 1086 | ||
987 | $client->request('GET', '/view/'.$content->getId()); | 1087 | $this->getEntityManager()->flush(); |
988 | $client->request('GET', '/archive/'.$content->getId()); | 1088 | |
1089 | $client->request('GET', '/view/'.$entry->getId()); | ||
1090 | $client->request('GET', '/archive/'.$entry->getId()); | ||
989 | 1091 | ||
990 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 1092 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
991 | $this->assertContains('/view/'.$content->getId(), $client->getResponse()->headers->get('location')); | 1093 | $this->assertContains('/view/'.$entry->getId(), $client->getResponse()->headers->get('location')); |
992 | } | 1094 | } |
993 | 1095 | ||
994 | public function testFilterOnHttpStatus() | 1096 | public function testFilterOnHttpStatus() |
995 | { | 1097 | { |
996 | $this->logInAs('admin'); | 1098 | $this->logInAs('admin'); |
1099 | $this->useTheme('baggy'); | ||
997 | $client = $this->getClient(); | 1100 | $client = $this->getClient(); |
998 | 1101 | ||
999 | $crawler = $client->request('GET', '/new'); | 1102 | $entry = new Entry($this->getLoggedInUser()); |
1000 | $form = $crawler->filter('form[name=entry]')->form(); | 1103 | $entry->setUrl('http://www.lemonde.fr/incorrect-url/'); |
1104 | $entry->setHttpStatus(404); | ||
1105 | $this->getEntityManager()->persist($entry); | ||
1001 | 1106 | ||
1002 | $data = [ | 1107 | $this->getEntityManager()->flush(); |
1003 | 'entry[url]' => 'http://www.lemonde.fr/incorrect-url/', | ||
1004 | ]; | ||
1005 | |||
1006 | $client->submit($form, $data); | ||
1007 | 1108 | ||
1008 | $crawler = $client->request('GET', '/all/list'); | 1109 | $crawler = $client->request('GET', '/all/list'); |
1009 | $form = $crawler->filter('button[id=submit-filter]')->form(); | 1110 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
@@ -1016,14 +1117,17 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1016 | 1117 | ||
1017 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | 1118 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
1018 | 1119 | ||
1019 | $crawler = $client->request('GET', '/new'); | 1120 | $entry = new Entry($this->getLoggedInUser()); |
1020 | $form = $crawler->filter('form[name=entry]')->form(); | 1121 | $entry->setUrl($this->url); |
1122 | $entry->setHttpStatus(200); | ||
1123 | $this->getEntityManager()->persist($entry); | ||
1021 | 1124 | ||
1022 | $data = [ | 1125 | $entry = new Entry($this->getLoggedInUser()); |
1023 | 'entry[url]' => 'http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm', | 1126 | $entry->setUrl('http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm'); |
1024 | ]; | 1127 | $entry->setHttpStatus(200); |
1128 | $this->getEntityManager()->persist($entry); | ||
1025 | 1129 | ||
1026 | $client->submit($form, $data); | 1130 | $this->getEntityManager()->flush(); |
1027 | 1131 | ||
1028 | $crawler = $client->request('GET', '/all/list'); | 1132 | $crawler = $client->request('GET', '/all/list'); |
1029 | $form = $crawler->filter('button[id=submit-filter]')->form(); | 1133 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
@@ -1034,7 +1138,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1034 | 1138 | ||
1035 | $crawler = $client->submit($form, $data); | 1139 | $crawler = $client->submit($form, $data); |
1036 | 1140 | ||
1037 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | 1141 | $this->assertCount(2, $crawler->filter('div[class=entry]')); |
1038 | 1142 | ||
1039 | $crawler = $client->request('GET', '/all/list'); | 1143 | $crawler = $client->request('GET', '/all/list'); |
1040 | $form = $crawler->filter('button[id=submit-filter]')->form(); | 1144 | $form = $crawler->filter('button[id=submit-filter]')->form(); |
@@ -1045,14 +1149,21 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1045 | 1149 | ||
1046 | $crawler = $client->submit($form, $data); | 1150 | $crawler = $client->submit($form, $data); |
1047 | 1151 | ||
1048 | $this->assertCount(7, $crawler->filter('div[class=entry]')); | 1152 | $this->assertCount(8, $crawler->filter('div[class=entry]')); |
1049 | } | 1153 | } |
1050 | 1154 | ||
1051 | public function testSearch() | 1155 | public function testSearch() |
1052 | { | 1156 | { |
1053 | $this->logInAs('admin'); | 1157 | $this->logInAs('admin'); |
1158 | $this->useTheme('baggy'); | ||
1054 | $client = $this->getClient(); | 1159 | $client = $this->getClient(); |
1055 | 1160 | ||
1161 | $entry = new Entry($this->getLoggedInUser()); | ||
1162 | $entry->setUrl($this->url); | ||
1163 | $entry->setTitle('test'); | ||
1164 | $this->getEntityManager()->persist($entry); | ||
1165 | $this->getEntityManager()->flush(); | ||
1166 | |||
1056 | // Search on unread list | 1167 | // Search on unread list |
1057 | $crawler = $client->request('GET', '/unread/list'); | 1168 | $crawler = $client->request('GET', '/unread/list'); |
1058 | 1169 | ||
@@ -1063,35 +1174,37 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1063 | 1174 | ||
1064 | $crawler = $client->submit($form, $data); | 1175 | $crawler = $client->submit($form, $data); |
1065 | 1176 | ||
1066 | $this->assertCount(5, $crawler->filter('div[class=entry]')); | 1177 | $this->assertCount(4, $crawler->filter('div[class=entry]')); |
1067 | 1178 | ||
1068 | // Search on starred list | 1179 | // Search on starred list |
1069 | $crawler = $client->request('GET', '/starred/list'); | 1180 | $crawler = $client->request('GET', '/starred/list'); |
1070 | 1181 | ||
1182 | $entry = new Entry($this->getLoggedInUser()); | ||
1183 | $entry->setUrl('http://localhost/foo/bar'); | ||
1184 | $entry->setTitle('testeur'); | ||
1185 | $entry->setStarred(true); | ||
1186 | $this->getEntityManager()->persist($entry); | ||
1187 | $this->getEntityManager()->flush(); | ||
1188 | |||
1071 | $form = $crawler->filter('form[name=search]')->form(); | 1189 | $form = $crawler->filter('form[name=search]')->form(); |
1072 | $data = [ | 1190 | $data = [ |
1073 | 'search_entry[term]' => 'title', | 1191 | 'search_entry[term]' => 'testeur', |
1074 | ]; | 1192 | ]; |
1075 | 1193 | ||
1076 | $crawler = $client->submit($form, $data); | 1194 | $crawler = $client->submit($form, $data); |
1077 | 1195 | ||
1078 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | 1196 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
1079 | 1197 | ||
1080 | // Added new article to test on archive list | ||
1081 | $crawler = $client->request('GET', '/new'); | ||
1082 | $form = $crawler->filter('form[name=entry]')->form(); | ||
1083 | $data = [ | ||
1084 | 'entry[url]' => $this->url, | ||
1085 | ]; | ||
1086 | $client->submit($form, $data); | ||
1087 | $content = $client->getContainer() | ||
1088 | ->get('doctrine.orm.entity_manager') | ||
1089 | ->getRepository('WallabagCoreBundle:Entry') | ||
1090 | ->findByUrlAndUserId($this->url, $this->getLoggedInUserId()); | ||
1091 | $client->request('GET', '/archive/'.$content->getId()); | ||
1092 | |||
1093 | $crawler = $client->request('GET', '/archive/list'); | 1198 | $crawler = $client->request('GET', '/archive/list'); |
1094 | 1199 | ||
1200 | // Added new article to test on archive list | ||
1201 | $entry = new Entry($this->getLoggedInUser()); | ||
1202 | $entry->setUrl('http://0.0.0.0/foo/baz/qux'); | ||
1203 | $entry->setTitle('Le manège'); | ||
1204 | $entry->setArchived(true); | ||
1205 | $this->getEntityManager()->persist($entry); | ||
1206 | $this->getEntityManager()->flush(); | ||
1207 | |||
1095 | $form = $crawler->filter('form[name=search]')->form(); | 1208 | $form = $crawler->filter('form[name=search]')->form(); |
1096 | $data = [ | 1209 | $data = [ |
1097 | 'search_entry[term]' => 'manège', | 1210 | 'search_entry[term]' => 'manège', |
@@ -1100,7 +1213,7 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1100 | $crawler = $client->submit($form, $data); | 1213 | $crawler = $client->submit($form, $data); |
1101 | 1214 | ||
1102 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | 1215 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
1103 | $client->request('GET', '/delete/'.$content->getId()); | 1216 | $client->request('GET', '/delete/'.$entry->getId()); |
1104 | 1217 | ||
1105 | // test on list of all articles | 1218 | // test on list of all articles |
1106 | $crawler = $client->request('GET', '/all/list'); | 1219 | $crawler = $client->request('GET', '/all/list'); |
@@ -1115,6 +1228,13 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1115 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | 1228 | $this->assertCount(0, $crawler->filter('div[class=entry]')); |
1116 | 1229 | ||
1117 | // test url search on list of all articles | 1230 | // test url search on list of all articles |
1231 | $entry = new Entry($this->getLoggedInUser()); | ||
1232 | $entry->setUrl('http://domain/qux'); | ||
1233 | $entry->setTitle('Le manège'); | ||
1234 | $entry->setArchived(true); | ||
1235 | $this->getEntityManager()->persist($entry); | ||
1236 | $this->getEntityManager()->flush(); | ||
1237 | |||
1118 | $crawler = $client->request('GET', '/all/list'); | 1238 | $crawler = $client->request('GET', '/all/list'); |
1119 | 1239 | ||
1120 | $form = $crawler->filter('form[name=search]')->form(); | 1240 | $form = $crawler->filter('form[name=search]')->form(); |
@@ -1138,4 +1258,134 @@ class EntryControllerTest extends WallabagCoreTestCase | |||
1138 | 1258 | ||
1139 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | 1259 | $this->assertCount(1, $crawler->filter('div[class=entry]')); |
1140 | } | 1260 | } |
1261 | |||
1262 | public function dataForLanguage() | ||
1263 | { | ||
1264 | return [ | ||
1265 | 'ru' => [ | ||
1266 | 'https://www.pravda.ru/world/09-06-2017/1337283-qatar-0/', | ||
1267 | 'ru', | ||
1268 | ], | ||
1269 | 'fr-FR' => [ | ||
1270 | 'http://www.zataz.com/90-des-dossiers-medicaux-des-coreens-du-sud-vendus-a-des-entreprises-privees/', | ||
1271 | 'fr_FR', | ||
1272 | ], | ||
1273 | 'de' => [ | ||
1274 | 'http://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html', | ||
1275 | 'de', | ||
1276 | ], | ||
1277 | 'it' => [ | ||
1278 | 'http://www.ansa.it/sito/notizie/mondo/europa/2017/06/08/voto-gb-seggi-aperti-misure-sicurezza-rafforzate_0cb71f7f-e23b-4d5f-95ca-bc12296419f0.html', | ||
1279 | 'it', | ||
1280 | ], | ||
1281 | 'zh_CN' => [ | ||
1282 | 'http://www.hao123.com/shequ?__noscript__-=1', | ||
1283 | 'zh_CN', | ||
1284 | ], | ||
1285 | 'de_AT' => [ | ||
1286 | 'https://buy.garmin.com/de-AT/AT/catalog/product/compareResult.ep?compareProduct=112885&compareProduct=36728', | ||
1287 | 'de_AT', | ||
1288 | ], | ||
1289 | 'ru_RU' => [ | ||
1290 | 'http://netler.ru/ikt/windows-error-reporting.htm', | ||
1291 | 'ru_RU', | ||
1292 | ], | ||
1293 | 'pt_BR' => [ | ||
1294 | 'http://precodoscombustiveis.com.br/postos/cidade/4121/pr/maringa', | ||
1295 | 'pt_BR', | ||
1296 | ], | ||
1297 | 'fucked_list_of_languages' => [ | ||
1298 | 'http://geocatalog.webservice-energy.org/geonetwork/srv/eng/main.home', | ||
1299 | '', | ||
1300 | ], | ||
1301 | 'es-ES' => [ | ||
1302 | 'http://www.muylinux.com/2015/04/17/odf-reino-unido-microsoft-google', | ||
1303 | 'es_ES', | ||
1304 | ], | ||
1305 | ]; | ||
1306 | } | ||
1307 | |||
1308 | /** | ||
1309 | * @dataProvider dataForLanguage | ||
1310 | */ | ||
1311 | public function testLanguageValidation($url, $expectedLanguage) | ||
1312 | { | ||
1313 | $this->logInAs('admin'); | ||
1314 | $client = $this->getClient(); | ||
1315 | |||
1316 | $crawler = $client->request('GET', '/new'); | ||
1317 | |||
1318 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
1319 | |||
1320 | $form = $crawler->filter('form[name=entry]')->form(); | ||
1321 | |||
1322 | $data = [ | ||
1323 | 'entry[url]' => $url, | ||
1324 | ]; | ||
1325 | |||
1326 | $client->submit($form, $data); | ||
1327 | |||
1328 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
1329 | |||
1330 | $content = $client->getContainer() | ||
1331 | ->get('doctrine.orm.entity_manager') | ||
1332 | ->getRepository('WallabagCoreBundle:Entry') | ||
1333 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | ||
1334 | |||
1335 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); | ||
1336 | $this->assertEquals($url, $content->getUrl()); | ||
1337 | $this->assertEquals($expectedLanguage, $content->getLanguage()); | ||
1338 | } | ||
1339 | |||
1340 | /** | ||
1341 | * This test will require an internet connection. | ||
1342 | */ | ||
1343 | public function testRestrictedArticle() | ||
1344 | { | ||
1345 | $url = 'http://www.monde-diplomatique.fr/2017/05/BONNET/57475'; | ||
1346 | $this->logInAs('admin'); | ||
1347 | $client = $this->getClient(); | ||
1348 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
1349 | |||
1350 | // enable restricted access | ||
1351 | $client->getContainer()->get('craue_config')->set('restricted_access', 1); | ||
1352 | |||
1353 | // create a new site_credential | ||
1354 | $user = $client->getContainer()->get('security.token_storage')->getToken()->getUser(); | ||
1355 | $credential = new SiteCredential($user); | ||
1356 | $credential->setHost('monde-diplomatique.fr'); | ||
1357 | $credential->setUsername($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('foo')); | ||
1358 | $credential->setPassword($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('bar')); | ||
1359 | |||
1360 | $em->persist($credential); | ||
1361 | $em->flush(); | ||
1362 | |||
1363 | $crawler = $client->request('GET', '/new'); | ||
1364 | |||
1365 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
1366 | |||
1367 | $form = $crawler->filter('form[name=entry]')->form(); | ||
1368 | |||
1369 | $data = [ | ||
1370 | 'entry[url]' => $url, | ||
1371 | ]; | ||
1372 | |||
1373 | $client->submit($form, $data); | ||
1374 | |||
1375 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
1376 | |||
1377 | $crawler = $client->followRedirect(); | ||
1378 | |||
1379 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
1380 | $this->assertContains('flashes.entry.notice.entry_saved', $crawler->filter('body')->extract(['_text'])[0]); | ||
1381 | |||
1382 | $content = $em | ||
1383 | ->getRepository('WallabagCoreBundle:Entry') | ||
1384 | ->findByUrlAndUserId($url, $this->getLoggedInUserId()); | ||
1385 | |||
1386 | $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content); | ||
1387 | $this->assertSame('Crimes et réformes aux Philippines', $content->getTitle()); | ||
1388 | |||
1389 | $client->getContainer()->get('craue_config')->set('restricted_access', 0); | ||
1390 | } | ||
1141 | } | 1391 | } |
diff --git a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php index 32a18e26..b38961d3 100644 --- a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php | |||
@@ -189,11 +189,9 @@ class ExportControllerTest extends WallabagCoreTestCase | |||
189 | $this->assertContains($contentInDB[0]['language'], $csv[1]); | 189 | $this->assertContains($contentInDB[0]['language'], $csv[1]); |
190 | $this->assertContains($contentInDB[0]['createdAt']->format('d/m/Y h:i:s'), $csv[1]); | 190 | $this->assertContains($contentInDB[0]['createdAt']->format('d/m/Y h:i:s'), $csv[1]); |
191 | 191 | ||
192 | $expectedTag = []; | ||
193 | foreach ($contentInDB[0]['tags'] as $tag) { | 192 | foreach ($contentInDB[0]['tags'] as $tag) { |
194 | $expectedTag[] = $tag['label']; | 193 | $this->assertContains($tag['label'], $csv[1]); |
195 | } | 194 | } |
196 | $this->assertContains(implode(', ', $expectedTag), $csv[1]); | ||
197 | } | 195 | } |
198 | 196 | ||
199 | public function testJsonExport() | 197 | public function testJsonExport() |
diff --git a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php index 5a59654d..530c8bbf 100644 --- a/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/RssControllerTest.php | |||
@@ -6,7 +6,7 @@ use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | |||
6 | 6 | ||
7 | class RssControllerTest extends WallabagCoreTestCase | 7 | class RssControllerTest extends WallabagCoreTestCase |
8 | { | 8 | { |
9 | public function validateDom($xml, $type, $nb = null) | 9 | public function validateDom($xml, $type, $urlPagination, $nb = null) |
10 | { | 10 | { |
11 | $doc = new \DOMDocument(); | 11 | $doc = new \DOMDocument(); |
12 | $doc->loadXML($xml); | 12 | $doc->loadXML($xml); |
@@ -23,7 +23,7 @@ class RssControllerTest extends WallabagCoreTestCase | |||
23 | $this->assertEquals(1, $xpath->query('/rss/channel')->length); | 23 | $this->assertEquals(1, $xpath->query('/rss/channel')->length); |
24 | 24 | ||
25 | $this->assertEquals(1, $xpath->query('/rss/channel/title')->length); | 25 | $this->assertEquals(1, $xpath->query('/rss/channel/title')->length); |
26 | $this->assertEquals('wallabag — '.$type.' feed', $xpath->query('/rss/channel/title')->item(0)->nodeValue); | 26 | $this->assertEquals('wallabag - '.$type.' feed', $xpath->query('/rss/channel/title')->item(0)->nodeValue); |
27 | 27 | ||
28 | $this->assertEquals(1, $xpath->query('/rss/channel/pubDate')->length); | 28 | $this->assertEquals(1, $xpath->query('/rss/channel/pubDate')->length); |
29 | 29 | ||
@@ -34,10 +34,10 @@ class RssControllerTest extends WallabagCoreTestCase | |||
34 | $this->assertEquals('wallabag '.$type.' elements', $xpath->query('/rss/channel/description')->item(0)->nodeValue); | 34 | $this->assertEquals('wallabag '.$type.' elements', $xpath->query('/rss/channel/description')->item(0)->nodeValue); |
35 | 35 | ||
36 | $this->assertEquals(1, $xpath->query('/rss/channel/link[@rel="self"]')->length); | 36 | $this->assertEquals(1, $xpath->query('/rss/channel/link[@rel="self"]')->length); |
37 | $this->assertContains($type.'.xml', $xpath->query('/rss/channel/link[@rel="self"]')->item(0)->getAttribute('href')); | 37 | $this->assertContains($urlPagination.'.xml', $xpath->query('/rss/channel/link[@rel="self"]')->item(0)->getAttribute('href')); |
38 | 38 | ||
39 | $this->assertEquals(1, $xpath->query('/rss/channel/link[@rel="last"]')->length); | 39 | $this->assertEquals(1, $xpath->query('/rss/channel/link[@rel="last"]')->length); |
40 | $this->assertContains($type.'.xml?page=', $xpath->query('/rss/channel/link[@rel="last"]')->item(0)->getAttribute('href')); | 40 | $this->assertContains($urlPagination.'.xml?page=', $xpath->query('/rss/channel/link[@rel="last"]')->item(0)->getAttribute('href')); |
41 | 41 | ||
42 | foreach ($xpath->query('//item') as $item) { | 42 | foreach ($xpath->query('//item') as $item) { |
43 | $this->assertEquals(1, $xpath->query('title', $item)->length); | 43 | $this->assertEquals(1, $xpath->query('title', $item)->length); |
@@ -94,7 +94,7 @@ class RssControllerTest extends WallabagCoreTestCase | |||
94 | 94 | ||
95 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 95 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
96 | 96 | ||
97 | $this->validateDom($client->getResponse()->getContent(), 'unread', 2); | 97 | $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread', 2); |
98 | } | 98 | } |
99 | 99 | ||
100 | public function testStarred() | 100 | public function testStarred() |
@@ -116,7 +116,7 @@ class RssControllerTest extends WallabagCoreTestCase | |||
116 | 116 | ||
117 | $this->assertEquals(200, $client->getResponse()->getStatusCode(), 1); | 117 | $this->assertEquals(200, $client->getResponse()->getStatusCode(), 1); |
118 | 118 | ||
119 | $this->validateDom($client->getResponse()->getContent(), 'starred'); | 119 | $this->validateDom($client->getResponse()->getContent(), 'starred', 'starred'); |
120 | } | 120 | } |
121 | 121 | ||
122 | public function testArchives() | 122 | public function testArchives() |
@@ -138,7 +138,7 @@ class RssControllerTest extends WallabagCoreTestCase | |||
138 | 138 | ||
139 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 139 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
140 | 140 | ||
141 | $this->validateDom($client->getResponse()->getContent(), 'archive'); | 141 | $this->validateDom($client->getResponse()->getContent(), 'archive', 'archive'); |
142 | } | 142 | } |
143 | 143 | ||
144 | public function testPagination() | 144 | public function testPagination() |
@@ -159,13 +159,38 @@ class RssControllerTest extends WallabagCoreTestCase | |||
159 | 159 | ||
160 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml'); | 160 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml'); |
161 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 161 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
162 | $this->validateDom($client->getResponse()->getContent(), 'unread'); | 162 | $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread'); |
163 | 163 | ||
164 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=2'); | 164 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=2'); |
165 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 165 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
166 | $this->validateDom($client->getResponse()->getContent(), 'unread'); | 166 | $this->validateDom($client->getResponse()->getContent(), 'unread', 'unread'); |
167 | 167 | ||
168 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=3000'); | 168 | $client->request('GET', '/admin/SUPERTOKEN/unread.xml?page=3000'); |
169 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 169 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
170 | } | 170 | } |
171 | |||
172 | public function testTags() | ||
173 | { | ||
174 | $client = $this->getClient(); | ||
175 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
176 | $user = $em | ||
177 | ->getRepository('WallabagUserBundle:User') | ||
178 | ->findOneByUsername('admin'); | ||
179 | |||
180 | $config = $user->getConfig(); | ||
181 | $config->setRssToken('SUPERTOKEN'); | ||
182 | $config->setRssLimit(null); | ||
183 | $em->persist($config); | ||
184 | $em->flush(); | ||
185 | |||
186 | $client = $this->getClient(); | ||
187 | $client->request('GET', '/admin/SUPERTOKEN/tags/foo-bar.xml'); | ||
188 | |||
189 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
190 | |||
191 | $this->validateDom($client->getResponse()->getContent(), 'tag (foo bar)', 'tags/foo-bar'); | ||
192 | |||
193 | $client->request('GET', '/admin/SUPERTOKEN/tags/foo-bar.xml?page=3000'); | ||
194 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
195 | } | ||
171 | } | 196 | } |
diff --git a/tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php b/tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php new file mode 100644 index 00000000..e73a9743 --- /dev/null +++ b/tests/Wallabag/CoreBundle/Controller/SiteCredentialControllerTest.php | |||
@@ -0,0 +1,139 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\CoreBundle\Controller; | ||
4 | |||
5 | use Symfony\Bundle\FrameworkBundle\Client; | ||
6 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | ||
7 | use Wallabag\CoreBundle\Entity\SiteCredential; | ||
8 | |||
9 | class SiteCredentialControllerTest extends WallabagCoreTestCase | ||
10 | { | ||
11 | public function testListSiteCredential() | ||
12 | { | ||
13 | $this->logInAs('admin'); | ||
14 | $client = $this->getClient(); | ||
15 | |||
16 | $crawler = $client->request('GET', '/site-credentials/'); | ||
17 | |||
18 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
19 | |||
20 | $body = $crawler->filter('body')->extract(['_text'])[0]; | ||
21 | |||
22 | $this->assertContains('site_credential.description', $body); | ||
23 | $this->assertContains('site_credential.list.create_new_one', $body); | ||
24 | } | ||
25 | |||
26 | public function testNewSiteCredential() | ||
27 | { | ||
28 | $this->logInAs('admin'); | ||
29 | $client = $this->getClient(); | ||
30 | |||
31 | $crawler = $client->request('GET', '/site-credentials/new'); | ||
32 | |||
33 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
34 | |||
35 | $body = $crawler->filter('body')->extract(['_text'])[0]; | ||
36 | |||
37 | $this->assertContains('site_credential.new_site_credential', $body); | ||
38 | $this->assertContains('site_credential.form.back_to_list', $body); | ||
39 | |||
40 | $form = $crawler->filter('button[id=site_credential_save]')->form(); | ||
41 | |||
42 | $data = [ | ||
43 | 'site_credential[host]' => 'google.io', | ||
44 | 'site_credential[username]' => 'sergei', | ||
45 | 'site_credential[password]' => 'microsoft', | ||
46 | ]; | ||
47 | |||
48 | $client->submit($form, $data); | ||
49 | |||
50 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
51 | |||
52 | $crawler = $client->followRedirect(); | ||
53 | |||
54 | $this->assertContains('flashes.site_credential.notice.added', $crawler->filter('body')->extract(['_text'])[0]); | ||
55 | } | ||
56 | |||
57 | public function testEditSiteCredential() | ||
58 | { | ||
59 | $this->logInAs('admin'); | ||
60 | $client = $this->getClient(); | ||
61 | |||
62 | $credential = $this->createSiteCredential($client); | ||
63 | |||
64 | $crawler = $client->request('GET', '/site-credentials/'.$credential->getId().'/edit'); | ||
65 | |||
66 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
67 | |||
68 | $body = $crawler->filter('body')->extract(['_text'])[0]; | ||
69 | |||
70 | $this->assertContains('site_credential.edit_site_credential', $body); | ||
71 | $this->assertContains('site_credential.form.back_to_list', $body); | ||
72 | |||
73 | $form = $crawler->filter('button[id=site_credential_save]')->form(); | ||
74 | |||
75 | $data = [ | ||
76 | 'site_credential[host]' => 'google.io', | ||
77 | 'site_credential[username]' => 'larry', | ||
78 | 'site_credential[password]' => 'microsoft', | ||
79 | ]; | ||
80 | |||
81 | $client->submit($form, $data); | ||
82 | |||
83 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
84 | |||
85 | $crawler = $client->followRedirect(); | ||
86 | |||
87 | $this->assertContains('flashes.site_credential.notice.updated', $crawler->filter('body')->extract(['_text'])[0]); | ||
88 | } | ||
89 | |||
90 | public function testEditFromADifferentUserSiteCredential() | ||
91 | { | ||
92 | $this->logInAs('admin'); | ||
93 | $client = $this->getClient(); | ||
94 | |||
95 | $credential = $this->createSiteCredential($client); | ||
96 | |||
97 | $this->logInAs('bob'); | ||
98 | |||
99 | $client->request('GET', '/site-credentials/'.$credential->getId().'/edit'); | ||
100 | |||
101 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | ||
102 | } | ||
103 | |||
104 | public function testDeleteSiteCredential() | ||
105 | { | ||
106 | $this->logInAs('admin'); | ||
107 | $client = $this->getClient(); | ||
108 | |||
109 | $credential = $this->createSiteCredential($client); | ||
110 | |||
111 | $crawler = $client->request('GET', '/site-credentials/'.$credential->getId().'/edit'); | ||
112 | |||
113 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
114 | |||
115 | $deleteForm = $crawler->filter('body')->selectButton('site_credential.form.delete')->form(); | ||
116 | |||
117 | $client->submit($deleteForm, []); | ||
118 | |||
119 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
120 | |||
121 | $crawler = $client->followRedirect(); | ||
122 | |||
123 | $this->assertContains('flashes.site_credential.notice.deleted', $crawler->filter('body')->extract(['_text'])[0]); | ||
124 | } | ||
125 | |||
126 | private function createSiteCredential(Client $client) | ||
127 | { | ||
128 | $credential = new SiteCredential($this->getLoggedInUser()); | ||
129 | $credential->setHost('google.io'); | ||
130 | $credential->setUsername('sergei'); | ||
131 | $credential->setPassword('microsoft'); | ||
132 | |||
133 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
134 | $em->persist($credential); | ||
135 | $em->flush(); | ||
136 | |||
137 | return $credential; | ||
138 | } | ||
139 | } | ||
diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index fa1a3539..af1ad7af 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\Entry; | ||
6 | use Wallabag\CoreBundle\Entity\Tag; | 7 | use Wallabag\CoreBundle\Entity\Tag; |
7 | 8 | ||
8 | class TagControllerTest extends WallabagCoreTestCase | 9 | class TagControllerTest extends WallabagCoreTestCase |
@@ -24,10 +25,11 @@ 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 | ||
@@ -41,23 +43,15 @@ class TagControllerTest extends WallabagCoreTestCase | |||
41 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 43 | $this->assertEquals(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->assertEquals(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 = [ |
@@ -67,12 +61,8 @@ class TagControllerTest extends WallabagCoreTestCase | |||
67 | $client->submit($form, $data); | 61 | $client->submit($form, $data); |
68 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 62 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
69 | 63 | ||
70 | $newEntry = $client->getContainer() | 64 | $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId()); |
71 | ->get('doctrine.orm.entity_manager') | 65 | $this->assertCount(2, $entry->getTags()); |
72 | ->getRepository('WallabagCoreBundle:Entry') | ||
73 | ->find($entry->getId()); | ||
74 | |||
75 | $this->assertEquals(3, count($newEntry->getTags())); | ||
76 | } | 66 | } |
77 | 67 | ||
78 | public function testAddMultipleTagToEntry() | 68 | public function testAddMultipleTagToEntry() |
@@ -116,20 +106,25 @@ 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 | |
119 | $client->request('GET', '/view/'.$entry->getId()); | ||
120 | $entryUri = $client->getRequest()->getUri(); | ||
129 | $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); | 121 | $client->request('GET', '/remove-tag/'.$entry->getId().'/'.$tag->getId()); |
130 | 122 | ||
131 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | 123 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); |
124 | $this->assertEquals($entryUri, $client->getResponse()->getTargetUrl()); | ||
132 | 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()); |