3 namespace Tests\Wallabag\CoreBundle\Controller
;
5 use Tests\Wallabag\CoreBundle\WallabagCoreTestCase
;
6 use Wallabag\CoreBundle\Entity\Config
;
7 use Wallabag\CoreBundle\Entity\Entry
;
8 use Wallabag\CoreBundle\Entity\SiteCredential
;
9 use Wallabag\CoreBundle\Entity\Tag
;
10 use Wallabag\CoreBundle\Helper\ContentProxy
;
12 class EntryControllerTest
extends WallabagCoreTestCase
14 const AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE
= 'https://www.lemonde.fr/judo/article/2017/11/11/judo-la-decima-de-teddy-riner_5213605_1556020.html';
15 public $downloadImagesEnabled = false;
16 public $url = 'https://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';
21 * Ensure download_images_enabled is disabled after each script
23 public function tearDownImagesEnabled()
25 if ($this->downloadImagesEnabled
) {
26 $client = static::createClient();
27 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
29 $this->downloadImagesEnabled
= false;
33 public function testLogin()
35 $client = $this->getClient();
37 $client->request('GET', '/new');
39 $this->assertSame(302, $client->getResponse()->getStatusCode());
40 $this->assertContains('login', $client->getResponse()->headers
->get('location'));
43 public function testQuickstart()
45 $this->logInAs('empty');
46 $client = $this->getClient();
48 $client->request('GET', '/unread/list');
49 $this->assertSame(302, $client->getResponse()->getStatusCode());
50 $crawler = $client->followRedirect();
52 $this->assertSame(200, $client->getResponse()->getStatusCode());
53 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
54 $this->assertContains('quickstart.intro.title', $body[0]);
56 // Test if quickstart is disabled when user has 1 entry
57 $crawler = $client->request('GET', '/new');
59 $this->assertSame(200, $client->getResponse()->getStatusCode());
61 $form = $crawler->filter('form[name=entry]')->form();
64 'entry[url]' => $this->url
,
67 $client->submit($form, $data);
68 $this->assertSame(302, $client->getResponse()->getStatusCode());
69 $client->followRedirect();
71 $crawler = $client->request('GET', '/unread/list');
72 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
73 $this->assertContains('entry.list.number_on_the_page', $body[0]);
76 public function testGetNew()
78 $this->logInAs('admin');
79 $this->useTheme('baggy');
80 $client = $this->getClient();
82 $crawler = $client->request('GET', '/new');
84 $this->assertSame(200, $client->getResponse()->getStatusCode());
86 $this->assertCount(1, $crawler->filter('input[type=url]'));
87 $this->assertCount(1, $crawler->filter('form[name=entry]'));
90 public function testPostNewViaBookmarklet()
92 $this->logInAs('admin');
93 $this->useTheme('baggy');
94 $client = $this->getClient();
96 $crawler = $client->request('GET', '/');
98 $this->assertCount(4, $crawler->filter('div[class=entry]'));
101 $client->request('GET', '/bookmarklet', ['url' => $this->url
]);
102 $this->assertSame(302, $client->getResponse()->getStatusCode());
103 $client->followRedirect();
104 $crawler = $client->request('GET', '/');
105 $this->assertCount(5, $crawler->filter('div[class=entry]'));
107 $em = $client->getContainer()
108 ->get('doctrine.orm.entity_manager');
110 ->getRepository('WallabagCoreBundle:Entry')
111 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
116 public function testPostNewEmpty()
118 $this->logInAs('admin');
119 $client = $this->getClient();
121 $crawler = $client->request('GET', '/new');
123 $this->assertSame(200, $client->getResponse()->getStatusCode());
125 $form = $crawler->filter('form[name=entry]')->form();
127 $crawler = $client->submit($form);
129 $this->assertSame(200, $client->getResponse()->getStatusCode());
130 $this->assertCount(1, $alert = $crawler->filter('form ul li')->extract(['_text']));
131 $this->assertSame('This value should not be blank.', $alert[0]);
135 * This test will require an internet connection.
137 public function testPostNewOk()
139 $this->logInAs('admin');
140 $client = $this->getClient();
142 $client->getContainer()->get('craue_config')->set('store_article_headers', 1);
144 $crawler = $client->request('GET', '/new');
146 $this->assertSame(200, $client->getResponse()->getStatusCode());
148 $form = $crawler->filter('form[name=entry]')->form();
151 'entry[url]' => $this->url
,
154 $client->submit($form, $data);
156 $this->assertSame(302, $client->getResponse()->getStatusCode());
158 $content = $client->getContainer()
159 ->get('doctrine.orm.entity_manager')
160 ->getRepository('WallabagCoreBundle:Entry')
161 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
163 $author = $content->getPublishedBy();
165 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
166 $this->assertSame($this->url
, $content->getUrl());
167 $this->assertContains('Google', $content->getTitle());
168 $this->assertSame('fr', $content->getLanguage());
169 $this->assertArrayHasKey('x-frame-options', $content->getHeaders());
170 $client->getContainer()->get('craue_config')->set('store_article_headers', 0);
173 public function testPostWithMultipleAuthors()
175 $url = 'https://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768';
176 $this->logInAs('admin');
177 $client = $this->getClient();
179 $crawler = $client->request('GET', '/new');
181 $this->assertSame(200, $client->getResponse()->getStatusCode());
183 $form = $crawler->filter('form[name=entry]')->form();
186 'entry[url]' => $url,
189 $client->submit($form, $data);
191 $this->assertSame(302, $client->getResponse()->getStatusCode());
193 $content = $client->getContainer()
194 ->get('doctrine.orm.entity_manager')
195 ->getRepository('WallabagCoreBundle:Entry')
196 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
198 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
199 $authors = $content->getPublishedBy();
200 $this->assertSame('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s'));
201 $this->assertSame('fr', $content->getLanguage());
202 $this->assertSame('Raphaël Balenieri, correspondant à Pékin', $authors[0]);
203 $this->assertSame('Frédéric Autran, correspondant à New York', $authors[1]);
206 public function testPostNewOkUrlExist()
208 $this->logInAs('admin');
210 $entry = new Entry($this->getLoggedInUser());
211 $entry->setUrl($this->url
);
212 $this->getEntityManager()->persist($entry);
213 $this->getEntityManager()->flush();
215 $client = $this->getClient();
217 $crawler = $client->request('GET', '/new');
219 $this->assertSame(200, $client->getResponse()->getStatusCode());
221 $form = $crawler->filter('form[name=entry]')->form();
224 'entry[url]' => $this->url
,
227 $client->submit($form, $data);
229 $this->assertSame(302, $client->getResponse()->getStatusCode());
230 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
233 public function testPostNewOkUrlExistWithAccent()
235 $this->logInAs('admin');
236 $client = $this->getClient();
238 $url = 'https://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing';
240 $crawler = $client->request('GET', '/new');
242 $this->assertSame(200, $client->getResponse()->getStatusCode());
244 $form = $crawler->filter('form[name=entry]')->form();
247 'entry[url]' => $url,
250 $client->submit($form, $data);
252 $crawler = $client->request('GET', '/new');
254 $this->assertSame(200, $client->getResponse()->getStatusCode());
256 $form = $crawler->filter('form[name=entry]')->form();
259 'entry[url]' => $url,
262 $client->submit($form, $data);
264 $this->assertSame(302, $client->getResponse()->getStatusCode());
265 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
268 public function testPostNewOkUrlExistWithRedirection()
270 $this->logInAs('admin');
271 $client = $this->getClient();
273 $url = 'https://wllbg.org/test-redirect/c51c';
275 $crawler = $client->request('GET', '/new');
277 $this->assertSame(200, $client->getResponse()->getStatusCode());
279 $form = $crawler->filter('form[name=entry]')->form();
282 'entry[url]' => $url,
285 $client->submit($form, $data);
287 $crawler = $client->request('GET', '/new');
289 $this->assertSame(200, $client->getResponse()->getStatusCode());
291 $form = $crawler->filter('form[name=entry]')->form();
294 'entry[url]' => $url,
297 $client->submit($form, $data);
299 $this->assertSame(302, $client->getResponse()->getStatusCode());
300 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
304 * This test will require an internet connection.
306 public function testPostNewThatWillBeTagged()
308 $this->logInAs('admin');
309 $client = $this->getClient();
311 $crawler = $client->request('GET', '/new');
313 $this->assertSame(200, $client->getResponse()->getStatusCode());
315 $form = $crawler->filter('form[name=entry]')->form();
318 'entry[url]' => $url = 'https://github.com/wallabag/wallabag',
321 $client->submit($form, $data);
323 $this->assertSame(302, $client->getResponse()->getStatusCode());
324 $this->assertContains('/', $client->getResponse()->getTargetUrl());
326 $em = $client->getContainer()
327 ->get('doctrine.orm.entity_manager');
329 ->getRepository('WallabagCoreBundle:Entry')
330 ->findOneByUrl($url);
331 $tags = $entry->getTags();
333 $this->assertCount(2, $tags);
334 $this->assertContains('wallabag', $tags);
335 $this->assertSame('en', $entry->getLanguage());
340 // and now re-submit it to test the cascade persistence for tags after entry removal
341 // related https://github.com/wallabag/wallabag/issues/2121
342 $crawler = $client->request('GET', '/new');
344 $this->assertSame(200, $client->getResponse()->getStatusCode());
346 $form = $crawler->filter('form[name=entry]')->form();
349 'entry[url]' => $url = 'https://github.com/wallabag/wallabag/tree/master',
352 $client->submit($form, $data);
354 $this->assertSame(302, $client->getResponse()->getStatusCode());
355 $this->assertContains('/', $client->getResponse()->getTargetUrl());
358 ->getRepository('WallabagCoreBundle:Entry')
359 ->findOneByUrl($url);
361 $tags = $entry->getTags();
363 $this->assertCount(2, $tags);
364 $this->assertContains('wallabag', $tags);
370 public function testArchive()
372 $this->logInAs('admin');
373 $client = $this->getClient();
375 $client->request('GET', '/archive/list');
377 $this->assertSame(200, $client->getResponse()->getStatusCode());
380 public function testUntagged()
382 $this->logInAs('admin');
383 $client = $this->getClient();
385 $client->request('GET', '/untagged/list');
387 $this->assertSame(200, $client->getResponse()->getStatusCode());
390 public function testStarred()
392 $this->logInAs('admin');
393 $client = $this->getClient();
395 $client->request('GET', '/starred/list');
397 $this->assertSame(200, $client->getResponse()->getStatusCode());
400 public function testRangeException()
402 $this->logInAs('admin');
403 $client = $this->getClient();
405 $client->request('GET', '/all/list/900');
407 $this->assertSame(302, $client->getResponse()->getStatusCode());
408 $this->assertSame('/all/list', $client->getResponse()->getTargetUrl());
411 public function testView()
413 $this->logInAs('admin');
414 $client = $this->getClient();
416 $entry = new Entry($this->getLoggedInUser());
417 $entry->setUrl('http://example.com/foo');
418 $entry->setTitle('title foo');
419 $entry->setContent('foo bar baz');
420 $this->getEntityManager()->persist($entry);
421 $this->getEntityManager()->flush();
423 $crawler = $client->request('GET', '/view/' . $entry->getId());
425 $this->assertSame(200, $client->getResponse()->getStatusCode());
426 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
427 $this->assertContains($entry->getTitle(), $body[0]);
431 * This test will require an internet connection.
433 public function testReload()
435 $this->logInAs('admin');
436 $client = $this->getClient();
438 $entry = new Entry($this->getLoggedInUser());
439 $entry->setUrl($this->url
);
440 $entry->setTitle('title foo');
441 $entry->setContent('');
442 $this->getEntityManager()->persist($entry);
443 $this->getEntityManager()->flush();
444 $this->getEntityManager()->clear();
446 $client->request('GET', '/reload/' . $entry->getId());
448 $this->assertSame(302, $client->getResponse()->getStatusCode());
450 $entry = $this->getEntityManager()
451 ->getRepository('WallabagCoreBundle:Entry')
452 ->find($entry->getId());
454 $this->assertNotEmpty($entry->getContent());
457 public function testReloadWithFetchingFailed()
459 $this->logInAs('admin');
460 $client = $this->getClient();
462 $entry = new Entry($this->getLoggedInUser());
463 $entry->setUrl('http://0.0.0.0/failed.html');
464 $this->getEntityManager()->persist($entry);
465 $this->getEntityManager()->flush();
467 $client->request('GET', '/reload/' . $entry->getId());
469 $this->assertSame(302, $client->getResponse()->getStatusCode());
471 // force EntityManager to clear previous entity
472 // otherwise, retrieve the same entity will retrieve change from the previous request :0
473 $this->getEntityManager()->clear();
474 $newContent = $this->getEntityManager()
475 ->getRepository('WallabagCoreBundle:Entry')
476 ->find($entry->getId());
478 $this->assertNotSame($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent());
481 public function testEdit()
483 $this->logInAs('admin');
484 $client = $this->getClient();
486 $entry = new Entry($this->getLoggedInUser());
487 $entry->setUrl($this->url
);
488 $this->getEntityManager()->persist($entry);
489 $this->getEntityManager()->flush();
491 $crawler = $client->request('GET', '/edit/' . $entry->getId());
493 $this->assertSame(200, $client->getResponse()->getStatusCode());
495 $this->assertCount(1, $crawler->filter('input[id=entry_title]'));
496 $this->assertCount(1, $crawler->filter('button[id=entry_save]'));
499 public function testEditUpdate()
501 $this->logInAs('admin');
502 $client = $this->getClient();
504 $entry = new Entry($this->getLoggedInUser());
505 $entry->setUrl($this->url
);
506 $this->getEntityManager()->persist($entry);
507 $this->getEntityManager()->flush();
509 $crawler = $client->request('GET', '/edit/' . $entry->getId());
511 $this->assertSame(200, $client->getResponse()->getStatusCode());
513 $form = $crawler->filter('button[id=entry_save]')->form();
516 'entry[title]' => 'My updated title hehe :)',
517 'entry[origin_url]' => 'https://example.io',
520 $client->submit($form, $data);
522 $this->assertSame(302, $client->getResponse()->getStatusCode());
524 $crawler = $client->followRedirect();
526 $this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text']));
527 $this->assertContains('My updated title hehe :)', $title[0]);
528 $this->assertGreaterThan(1, $stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']));
529 $this->assertContains('example.io', trim($stats[1]));
532 public function testEditRemoveOriginUrl()
534 $this->logInAs('admin');
535 $client = $this->getClient();
537 $entry = new Entry($this->getLoggedInUser());
538 $entry->setUrl($this->url
);
539 $this->getEntityManager()->persist($entry);
540 $this->getEntityManager()->flush();
542 $crawler = $client->request('GET', '/edit/' . $entry->getId());
544 $this->assertSame(200, $client->getResponse()->getStatusCode());
546 $form = $crawler->filter('button[id=entry_save]')->form();
549 'entry[title]' => 'My updated title hehe :)',
550 'entry[origin_url]' => '',
553 $client->submit($form, $data);
555 $this->assertSame(302, $client->getResponse()->getStatusCode());
557 $crawler = $client->followRedirect();
559 $title = $crawler->filter('div[id=article] h1')->extract(['_text']);
560 $this->assertGreaterThan(1, $title);
561 $this->assertContains('My updated title hehe :)', $title[0]);
563 $stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']);
564 $this->assertCount(1, $stats);
565 $this->assertNotContains('example.io', trim($stats[0]));
568 public function testToggleArchive()
570 $this->logInAs('admin');
571 $client = $this->getClient();
573 $entry = new Entry($this->getLoggedInUser());
574 $entry->setUrl($this->url
);
575 $this->getEntityManager()->persist($entry);
576 $this->getEntityManager()->flush();
577 $this->getEntityManager()->clear();
579 $client->request('GET', '/archive/' . $entry->getId());
581 $this->assertSame(302, $client->getResponse()->getStatusCode());
583 $res = $client->getContainer()
584 ->get('doctrine.orm.entity_manager')
585 ->getRepository('WallabagCoreBundle:Entry')
586 ->find($entry->getId());
588 $this->assertSame(1, $res->isArchived());
591 public function testToggleStar()
593 $this->logInAs('admin');
594 $client = $this->getClient();
596 $entry = new Entry($this->getLoggedInUser());
597 $entry->setUrl($this->url
);
598 $this->getEntityManager()->persist($entry);
599 $this->getEntityManager()->flush();
600 $this->getEntityManager()->clear();
602 $client->request('GET', '/star/' . $entry->getId());
604 $this->assertSame(302, $client->getResponse()->getStatusCode());
606 $res = $client->getContainer()
607 ->get('doctrine.orm.entity_manager')
608 ->getRepository('WallabagCoreBundle:Entry')
609 ->findOneById($entry->getId());
611 $this->assertSame(1, $res->isStarred());
614 public function testDelete()
616 $this->logInAs('admin');
617 $client = $this->getClient();
619 $entry = new Entry($this->getLoggedInUser());
620 $entry->setUrl($this->url
);
621 $this->getEntityManager()->persist($entry);
622 $this->getEntityManager()->flush();
624 $client->request('GET', '/delete/' . $entry->getId());
626 $this->assertSame(302, $client->getResponse()->getStatusCode());
628 $client->request('GET', '/delete/' . $entry->getId());
630 $this->assertSame(404, $client->getResponse()->getStatusCode());
634 * It will create a new entry.
638 * And it'll check that user won't be redirected to the view page of the content when it had been removed
640 public function testViewAndDelete()
642 $this->logInAs('admin');
643 $client = $this->getClient();
645 $em = $client->getContainer()
646 ->get('doctrine.orm.entity_manager');
648 // add a new content to be removed later
650 ->getRepository('WallabagUserBundle:User')
651 ->findOneByUserName('admin');
653 $content = new Entry($user);
654 $content->setUrl('http://1.1.1.1/entry');
655 $content->setReadingTime(12);
656 $content->setDomainName('domain.io');
657 $content->setMimetype('text/html');
658 $content->setTitle('test title entry');
659 $content->setContent('This is my content /o/');
660 $content->updateArchived(true);
661 $content->setLanguage('fr');
663 $em->persist($content);
666 $client->request('GET', '/view/' . $content->getId());
667 $this->assertSame(200, $client->getResponse()->getStatusCode());
669 $client->request('GET', '/delete/' . $content->getId());
670 $this->assertSame(302, $client->getResponse()->getStatusCode());
672 $client->followRedirect();
673 $this->assertSame(200, $client->getResponse()->getStatusCode());
676 public function testViewOtherUserEntry()
678 $this->logInAs('admin');
679 $client = $this->getClient();
681 $content = $client->getContainer()
682 ->get('doctrine.orm.entity_manager')
683 ->getRepository('WallabagCoreBundle:Entry')
684 ->findOneByUsernameAndNotArchived('bob');
686 $client->request('GET', '/view/' . $content->getId());
688 $this->assertSame(403, $client->getResponse()->getStatusCode());
691 public function testFilterOnReadingTime()
693 $this->logInAs('admin');
694 $this->useTheme('baggy');
695 $client = $this->getClient();
696 $entry = new Entry($this->getLoggedInUser());
697 $entry->setUrl($this->url
);
698 $entry->setReadingTime(22);
699 $this->getEntityManager()->persist($entry);
700 $this->getEntityManager()->flush();
702 $crawler = $client->request('GET', '/unread/list');
704 $form = $crawler->filter('button[id=submit-filter]')->form();
707 'entry_filter[readingTime][right_number]' => 22,
708 'entry_filter[readingTime][left_number]' => 22,
711 $crawler = $client->submit($form, $data);
713 $this->assertCount(1, $crawler->filter('div[class=entry]'));
716 public function testFilterOnReadingTimeWithNegativeValue()
718 $this->logInAs('admin');
719 $client = $this->getClient();
721 $crawler = $client->request('GET', '/unread/list');
723 $form = $crawler->filter('button[id=submit-filter]')->form();
726 'entry_filter[readingTime][right_number]' => -22,
727 'entry_filter[readingTime][left_number]' => -22,
730 $crawler = $client->submit($form, $data);
732 // forcing negative value results in no entry displayed
733 $this->assertCount(0, $crawler->filter('div[class=entry]'));
736 public function testFilterOnReadingTimeOnlyUpper()
738 $this->logInAs('admin');
739 $this->useTheme('baggy');
740 $client = $this->getClient();
742 $crawler = $client->request('GET', '/all/list');
743 $this->assertCount(5, $crawler->filter('div[class=entry]'));
745 $entry = new Entry($this->getLoggedInUser());
746 $entry->setUrl($this->url
);
747 $entry->setReadingTime(23);
748 $this->getEntityManager()->persist($entry);
749 $this->getEntityManager()->flush();
751 $crawler = $client->request('GET', '/all/list');
752 $this->assertCount(6, $crawler->filter('div[class=entry]'));
754 $form = $crawler->filter('button[id=submit-filter]')->form();
757 'entry_filter[readingTime][right_number]' => 22,
760 $crawler = $client->submit($form, $data);
762 $this->assertCount(5, $crawler->filter('div[class=entry]'));
765 public function testFilterOnReadingTimeOnlyLower()
767 $this->logInAs('admin');
768 $this->useTheme('baggy');
769 $client = $this->getClient();
771 $crawler = $client->request('GET', '/unread/list');
773 $form = $crawler->filter('button[id=submit-filter]')->form();
776 'entry_filter[readingTime][left_number]' => 22,
779 $crawler = $client->submit($form, $data);
781 $this->assertCount(0, $crawler->filter('div[class=entry]'));
783 $entry = new Entry($this->getLoggedInUser());
784 $entry->setUrl($this->url
);
785 $entry->setReadingTime(23);
786 $this->getEntityManager()->persist($entry);
787 $this->getEntityManager()->flush();
789 $crawler = $client->submit($form, $data);
790 $this->assertCount(1, $crawler->filter('div[class=entry]'));
793 public function testFilterOnUnreadStatus()
795 $this->logInAs('admin');
796 $this->useTheme('baggy');
797 $client = $this->getClient();
799 $crawler = $client->request('GET', '/all/list');
801 $form = $crawler->filter('button[id=submit-filter]')->form();
804 'entry_filter[isUnread]' => true,
807 $crawler = $client->submit($form, $data);
809 $this->assertCount(4, $crawler->filter('div[class=entry]'));
811 $entry = new Entry($this->getLoggedInUser());
812 $entry->setUrl($this->url
);
813 $entry->updateArchived(false);
814 $this->getEntityManager()->persist($entry);
815 $this->getEntityManager()->flush();
817 $crawler = $client->submit($form, $data);
819 $this->assertCount(5, $crawler->filter('div[class=entry]'));
822 public function testFilterOnCreationDate()
824 $this->logInAs('admin');
825 $this->useTheme('baggy');
826 $client = $this->getClient();
828 $crawler = $client->request('GET', '/unread/list');
830 $form = $crawler->filter('button[id=submit-filter]')->form();
833 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
834 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')),
837 $crawler = $client->submit($form, $data);
839 $this->assertCount(5, $crawler->filter('div[class=entry]'));
842 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
843 'entry_filter[createdAt][right_date]' => date('d/m/Y'),
846 $crawler = $client->submit($form, $data);
848 $this->assertCount(5, $crawler->filter('div[class=entry]'));
851 'entry_filter[createdAt][left_date]' => '01/01/1970',
852 'entry_filter[createdAt][right_date]' => '01/01/1970',
855 $crawler = $client->submit($form, $data);
857 $this->assertCount(0, $crawler->filter('div[class=entry]'));
860 public function testPaginationWithFilter()
862 $this->logInAs('admin');
863 $client = $this->getClient();
864 $crawler = $client->request('GET', '/config');
866 $form = $crawler->filter('button[id=config_save]')->form();
869 'config[items_per_page]' => '1',
872 $client->submit($form, $data);
874 $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D=';
876 $client->request('GET', 'unread/list' . $parameters);
878 $this->assertContains($parameters, $client->getResponse()->getContent());
881 $crawler = $client->request('GET', '/config');
882 $form = $crawler->filter('button[id=config_save]')->form();
884 'config[items_per_page]' => '12',
886 $client->submit($form, $data);
889 public function testFilterOnDomainName()
891 $this->logInAs('admin');
892 $this->useTheme('baggy');
893 $client = $this->getClient();
895 $crawler = $client->request('GET', '/unread/list');
896 $form = $crawler->filter('button[id=submit-filter]')->form();
898 'entry_filter[domainName]' => 'domain',
901 $crawler = $client->submit($form, $data);
902 $this->assertCount(5, $crawler->filter('div[class=entry]'));
904 $crawler = $client->request('GET', '/unread/list');
905 $form = $crawler->filter('button[id=submit-filter]')->form();
907 'entry_filter[domainName]' => 'dOmain',
910 $crawler = $client->submit($form, $data);
911 $this->assertCount(5, $crawler->filter('div[class=entry]'));
913 $form = $crawler->filter('button[id=submit-filter]')->form();
915 'entry_filter[domainName]' => 'wallabag',
918 $crawler = $client->submit($form, $data);
919 $this->assertCount(0, $crawler->filter('div[class=entry]'));
922 public function testFilterOnStatus()
924 $this->logInAs('admin');
925 $this->useTheme('baggy');
926 $client = $this->getClient();
928 $crawler = $client->request('GET', '/unread/list');
929 $form = $crawler->filter('button[id=submit-filter]')->form();
930 $form['entry_filter[isArchived]']->tick();
931 $form['entry_filter[isStarred]']->untick();
933 $crawler = $client->submit($form);
934 $this->assertCount(1, $crawler->filter('div[class=entry]'));
936 $form = $crawler->filter('button[id=submit-filter]')->form();
937 $form['entry_filter[isArchived]']->untick();
938 $form['entry_filter[isStarred]']->tick();
940 $crawler = $client->submit($form);
941 $this->assertCount(1, $crawler->filter('div[class=entry]'));
944 public function testFilterOnIsPublic()
946 $this->logInAs('admin');
947 $this->useTheme('baggy');
948 $client = $this->getClient();
950 $crawler = $client->request('GET', '/unread/list');
951 $form = $crawler->filter('button[id=submit-filter]')->form();
952 $form['entry_filter[isPublic]']->tick();
954 $crawler = $client->submit($form);
955 $this->assertCount(0, $crawler->filter('div[class=entry]'));
958 public function testPreviewPictureFilter()
960 $this->logInAs('admin');
961 $this->useTheme('baggy');
962 $client = $this->getClient();
964 $crawler = $client->request('GET', '/unread/list');
965 $form = $crawler->filter('button[id=submit-filter]')->form();
966 $form['entry_filter[previewPicture]']->tick();
968 $crawler = $client->submit($form);
969 $this->assertCount(1, $crawler->filter('div[class=entry]'));
972 public function testFilterOnLanguage()
974 $this->logInAs('admin');
975 $this->useTheme('baggy');
976 $client = $this->getClient();
978 $entry = new Entry($this->getLoggedInUser());
979 $entry->setUrl($this->url
);
980 $entry->setLanguage('fr');
981 $this->getEntityManager()->persist($entry);
982 $this->getEntityManager()->flush();
984 $crawler = $client->request('GET', '/unread/list');
985 $form = $crawler->filter('button[id=submit-filter]')->form();
987 'entry_filter[language]' => 'fr',
990 $crawler = $client->submit($form, $data);
991 $this->assertCount(3, $crawler->filter('div[class=entry]'));
993 $form = $crawler->filter('button[id=submit-filter]')->form();
995 'entry_filter[language]' => 'en',
998 $crawler = $client->submit($form, $data);
999 $this->assertCount(2, $crawler->filter('div[class=entry]'));
1002 public function testShareEntryPublicly()
1004 $this->logInAs('admin');
1005 $client = $this->getClient();
1007 // sharing is enabled
1008 $client->getContainer()->get('craue_config')->set('share_public', 1);
1010 $content = new Entry($this->getLoggedInUser());
1011 $content->setUrl($this->url
);
1012 $this->getEntityManager()->persist($content);
1013 $this->getEntityManager()->flush();
1014 $this->getEntityManager()->clear();
1017 $client->request('GET', '/share/' . $content->getUid());
1018 $this->assertSame(404, $client->getResponse()->getStatusCode());
1020 // generating the uid
1021 $client->request('GET', '/share/' . $content->getId());
1022 $this->assertSame(302, $client->getResponse()->getStatusCode());
1024 $shareUrl = $client->getResponse()->getTargetUrl();
1026 // use a new client to have a fresh empty session (instead of a logged one from the previous client)
1029 $client->request('GET', $shareUrl);
1031 $this->assertSame(200, $client->getResponse()->getStatusCode());
1032 $this->assertContains('max-age=25200', $client->getResponse()->headers
->get('cache-control'));
1033 $this->assertContains('public', $client->getResponse()->headers
->get('cache-control'));
1034 $this->assertContains('s-maxage=25200', $client->getResponse()->headers
->get('cache-control'));
1035 $this->assertNotContains('no-cache', $client->getResponse()->headers
->get('cache-control'));
1036 $this->assertContains('og:title', $client->getResponse()->getContent());
1037 $this->assertContains('og:type', $client->getResponse()->getContent());
1038 $this->assertContains('og:url', $client->getResponse()->getContent());
1039 $this->assertContains('og:image', $client->getResponse()->getContent());
1041 // sharing is now disabled
1042 $client->getContainer()->get('craue_config')->set('share_public', 0);
1043 $client->request('GET', '/share/' . $content->getUid());
1044 $this->assertSame(404, $client->getResponse()->getStatusCode());
1046 // removing the share
1047 $client->request('GET', '/share/delete/' . $content->getId());
1048 $this->assertSame(302, $client->getResponse()->getStatusCode());
1050 // share is now disable
1051 $client->request('GET', '/share/' . $content->getUid());
1052 $this->assertSame(404, $client->getResponse()->getStatusCode());
1055 public function testNewEntryWithDownloadImagesEnabled()
1057 $this->downloadImagesEnabled
= true;
1058 $this->logInAs('admin');
1059 $client = $this->getClient();
1061 $url = self
::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE
;
1062 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
1064 $crawler = $client->request('GET', '/new');
1066 $this->assertSame(200, $client->getResponse()->getStatusCode());
1068 $form = $crawler->filter('form[name=entry]')->form();
1071 'entry[url]' => $url,
1074 $client->submit($form, $data);
1076 $this->assertSame(302, $client->getResponse()->getStatusCode());
1078 $em = $client->getContainer()
1079 ->get('doctrine.orm.entity_manager');
1082 ->getRepository('WallabagCoreBundle:Entry')
1083 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1085 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry);
1086 $this->assertSame($url, $entry->getUrl());
1087 $this->assertContains('Judo', $entry->getTitle());
1088 // instead of checking for the filename (which might change) check that the image is now local
1089 $this->assertContains(rtrim($client->getContainer()->getParameter('domain_name'), '/') . '/assets/images/', $entry->getContent());
1091 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1095 * @depends testNewEntryWithDownloadImagesEnabled
1097 public function testRemoveEntryWithDownloadImagesEnabled()
1099 $this->downloadImagesEnabled
= true;
1100 $this->logInAs('admin');
1101 $client = $this->getClient();
1103 $url = self
::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE
;
1104 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
1106 $crawler = $client->request('GET', '/new');
1108 $this->assertSame(200, $client->getResponse()->getStatusCode());
1110 $form = $crawler->filter('form[name=entry]')->form();
1113 'entry[url]' => $url,
1116 $client->submit($form, $data);
1118 $this->assertSame(302, $client->getResponse()->getStatusCode());
1120 $content = $client->getContainer()
1121 ->get('doctrine.orm.entity_manager')
1122 ->getRepository('WallabagCoreBundle:Entry')
1123 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1125 $client->request('GET', '/delete/' . $content->getId());
1127 $this->assertSame(302, $client->getResponse()->getStatusCode());
1129 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1132 public function testRedirectToHomepage()
1134 $this->logInAs('empty');
1135 $client = $this->getClient();
1137 // Redirect to homepage
1138 $config = $this->getLoggedInUser()->getConfig();
1139 $config->setActionMarkAsRead(Config
::REDIRECT_TO_HOMEPAGE
);
1140 $this->getEntityManager()->persist($config);
1142 $entry = new Entry($this->getLoggedInUser());
1143 $entry->setUrl($this->url
);
1144 $this->getEntityManager()->persist($entry);
1146 $this->getEntityManager()->flush();
1148 $client->request('GET', '/view/' . $entry->getId());
1149 $client->request('GET', '/archive/' . $entry->getId());
1151 $this->assertSame(302, $client->getResponse()->getStatusCode());
1152 $this->assertSame('/', $client->getResponse()->headers
->get('location'));
1155 public function testRedirectToCurrentPage()
1157 $this->logInAs('empty');
1158 $client = $this->getClient();
1160 // Redirect to current page
1161 $config = $this->getLoggedInUser()->getConfig();
1162 $config->setActionMarkAsRead(Config
::REDIRECT_TO_CURRENT_PAGE
);
1163 $this->getEntityManager()->persist($config);
1165 $entry = new Entry($this->getLoggedInUser());
1166 $entry->setUrl($this->url
);
1167 $this->getEntityManager()->persist($entry);
1169 $this->getEntityManager()->flush();
1171 $client->request('GET', '/view/' . $entry->getId());
1172 $client->request('GET', '/archive/' . $entry->getId());
1174 $this->assertSame(302, $client->getResponse()->getStatusCode());
1175 $this->assertContains('/view/' . $entry->getId(), $client->getResponse()->headers
->get('location'));
1178 public function testFilterOnHttpStatus()
1180 $this->logInAs('admin');
1181 $this->useTheme('baggy');
1182 $client = $this->getClient();
1184 $entry = new Entry($this->getLoggedInUser());
1185 $entry->setUrl('https://www.lemonde.fr/incorrect-url/');
1186 $entry->setHttpStatus(404);
1187 $this->getEntityManager()->persist($entry);
1189 $this->getEntityManager()->flush();
1191 $crawler = $client->request('GET', '/all/list');
1192 $form = $crawler->filter('button[id=submit-filter]')->form();
1195 'entry_filter[httpStatus]' => 404,
1198 $crawler = $client->submit($form, $data);
1200 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1202 $entry = new Entry($this->getLoggedInUser());
1203 $entry->setUrl($this->url
);
1204 $entry->setHttpStatus(200);
1205 $this->getEntityManager()->persist($entry);
1207 $entry = new Entry($this->getLoggedInUser());
1208 $entry->setUrl('http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm');
1209 $entry->setHttpStatus(200);
1210 $this->getEntityManager()->persist($entry);
1212 $this->getEntityManager()->flush();
1214 $crawler = $client->request('GET', '/all/list');
1215 $form = $crawler->filter('button[id=submit-filter]')->form();
1218 'entry_filter[httpStatus]' => 200,
1221 $crawler = $client->submit($form, $data);
1223 $this->assertCount(2, $crawler->filter('div[class=entry]'));
1225 $crawler = $client->request('GET', '/all/list');
1226 $form = $crawler->filter('button[id=submit-filter]')->form();
1229 'entry_filter[httpStatus]' => 1024,
1232 $crawler = $client->submit($form, $data);
1234 $this->assertCount(8, $crawler->filter('div[class=entry]'));
1237 public function testSearch()
1239 $this->logInAs('admin');
1240 $this->useTheme('baggy');
1241 $client = $this->getClient();
1243 $entry = new Entry($this->getLoggedInUser());
1244 $entry->setUrl($this->url
);
1245 $entry->setTitle('test');
1246 $this->getEntityManager()->persist($entry);
1247 $this->getEntityManager()->flush();
1249 // Search on unread list
1250 $crawler = $client->request('GET', '/unread/list');
1252 $form = $crawler->filter('form[name=search]')->form();
1254 'search_entry[term]' => 'title',
1257 $crawler = $client->submit($form, $data);
1259 $this->assertCount(4, $crawler->filter('div[class=entry]'));
1261 // Search on starred list
1262 $crawler = $client->request('GET', '/starred/list');
1264 $entry = new Entry($this->getLoggedInUser());
1265 $entry->setUrl('http://localhost/foo/bar');
1266 $entry->setTitle('testeur');
1267 $entry->setStarred(true);
1268 $this->getEntityManager()->persist($entry);
1269 $this->getEntityManager()->flush();
1271 $form = $crawler->filter('form[name=search]')->form();
1273 'search_entry[term]' => 'testeur',
1276 $crawler = $client->submit($form, $data);
1278 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1280 $crawler = $client->request('GET', '/archive/list');
1282 // Added new article to test on archive list
1283 $entry = new Entry($this->getLoggedInUser());
1284 $entry->setUrl('http://0.0.0.0/foo/baz/qux');
1285 $entry->setTitle('Le manège');
1286 $entry->updateArchived(true);
1287 $this->getEntityManager()->persist($entry);
1288 $this->getEntityManager()->flush();
1290 $form = $crawler->filter('form[name=search]')->form();
1292 'search_entry[term]' => 'manège',
1295 $crawler = $client->submit($form, $data);
1297 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1298 $client->request('GET', '/delete/' . $entry->getId());
1300 // test on list of all articles
1301 $crawler = $client->request('GET', '/all/list');
1303 $form = $crawler->filter('form[name=search]')->form();
1305 'search_entry[term]' => 'wxcvbnqsdf', // a string not available in the database
1308 $crawler = $client->submit($form, $data);
1310 $this->assertCount(0, $crawler->filter('div[class=entry]'));
1312 // test url search on list of all articles
1313 $entry = new Entry($this->getLoggedInUser());
1314 $entry->setUrl('http://domain/qux');
1315 $entry->setTitle('Le manège');
1316 $entry->updateArchived(true);
1317 $this->getEntityManager()->persist($entry);
1318 $this->getEntityManager()->flush();
1320 $crawler = $client->request('GET', '/all/list');
1322 $form = $crawler->filter('form[name=search]')->form();
1324 'search_entry[term]' => 'domain', // the search will match an entry with 'domain' in its url
1327 $crawler = $client->submit($form, $data);
1329 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1331 // same as previous test but for case-sensitivity
1332 $crawler = $client->request('GET', '/all/list');
1334 $form = $crawler->filter('form[name=search]')->form();
1336 'search_entry[term]' => 'doMain', // the search will match an entry with 'domain' in its url
1339 $crawler = $client->submit($form, $data);
1341 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1344 public function dataForLanguage()
1348 'https://www.pravda.ru/world/09-06-2017/1337283-qatar-0/',
1352 'https://fr.wikipedia.org/wiki/Wallabag',
1356 'https://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html',
1360 'http://www.ansa.it/sito/notizie/mondo/europa/2017/06/08/voto-gb-seggi-aperti-misure-sicurezza-rafforzate_0cb71f7f-e23b-4d5f-95ca-bc12296419f0.html',
1364 'http://www.hao123.com/shequ?__noscript__-=1',
1368 'https://politica.estadao.com.br/noticias/eleicoes,campanha-catatonica,70002491983',
1371 'fucked_list_of_languages' => [
1372 'http://geocatalog.webservice-energy.org/geonetwork/srv/eng/main.home',
1376 'https://www.20minutos.es/noticia/3360685/0/gobierno-sanchez-primero-historia-mas-mujeres-que-hombres/',
1383 * @dataProvider dataForLanguage
1385 public function testLanguageValidation($url, $expectedLanguage)
1387 $this->logInAs('admin');
1388 $client = $this->getClient();
1390 $crawler = $client->request('GET', '/new');
1392 $this->assertSame(200, $client->getResponse()->getStatusCode());
1394 $form = $crawler->filter('form[name=entry]')->form();
1397 'entry[url]' => $url,
1400 $client->submit($form, $data);
1402 $this->assertSame(302, $client->getResponse()->getStatusCode());
1404 $content = $client->getContainer()
1405 ->get('doctrine.orm.entity_manager')
1406 ->getRepository('WallabagCoreBundle:Entry')
1407 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1409 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1410 $this->assertSame($url, $content->getUrl());
1411 $this->assertSame($expectedLanguage, $content->getLanguage());
1415 * This test will require an internet connection.
1417 public function testRestrictedArticle()
1419 $url = 'https://www.monde-diplomatique.fr/2017/05/BONNET/57475';
1420 $this->logInAs('admin');
1421 $client = $this->getClient();
1422 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
1424 // enable restricted access
1425 $client->getContainer()->get('craue_config')->set('restricted_access', 1);
1427 // create a new site_credential
1428 $user = $client->getContainer()->get('security.token_storage')->getToken()->getUser();
1429 $credential = new SiteCredential($user);
1430 $credential->setHost('monde-diplomatique.fr');
1431 $credential->setUsername($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('foo'));
1432 $credential->setPassword($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('bar'));
1434 $em->persist($credential);
1437 $crawler = $client->request('GET', '/new');
1439 $this->assertSame(200, $client->getResponse()->getStatusCode());
1441 $form = $crawler->filter('form[name=entry]')->form();
1444 'entry[url]' => $url,
1447 $client->submit($form, $data);
1449 $this->assertSame(302, $client->getResponse()->getStatusCode());
1451 $crawler = $client->followRedirect();
1453 $this->assertSame(200, $client->getResponse()->getStatusCode());
1454 $this->assertContains('flashes.entry.notice.entry_saved', $crawler->filter('body')->extract(['_text'])[0]);
1457 ->getRepository('WallabagCoreBundle:Entry')
1458 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1460 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1461 $this->assertSame('Crimes et réformes aux Philippines', $content->getTitle());
1463 $client->getContainer()->get('craue_config')->set('restricted_access', 0);
1466 public function testPostEntryWhenFetchFails()
1468 $url = 'http://example.com/papers/email_tracking.pdf';
1469 $this->logInAs('admin');
1470 $client = $this->getClient();
1472 $container = $client->getContainer();
1473 $contentProxy = $this->getMockBuilder(ContentProxy
::class)
1474 ->disableOriginalConstructor()
1475 ->setMethods(['updateEntry'])
1477 $contentProxy->expects($this->any())
1478 ->method('updateEntry')
1479 ->willThrowException(new \
Exception('Test Fetch content fails'));
1481 $crawler = $client->request('GET', '/new');
1483 $this->assertSame(200, $client->getResponse()->getStatusCode());
1485 $form = $crawler->filter('form[name=entry]')->form();
1488 'entry[url]' => $url,
1492 * We generate a new client to be able to use Mock ContentProxy
1493 * Also we reinject the cookie from the previous client to keep the
1496 $cookie = $client->getCookieJar()->all();
1497 $client = $this->getNewClient();
1498 $client->getCookieJar()->set($cookie[0]);
1499 $client->getContainer()->set('wallabag_core.content_proxy', $contentProxy);
1500 $client->submit($form, $data);
1502 $this->assertSame(302, $client->getResponse()->getStatusCode());
1504 $content = $client->getContainer()
1505 ->get('doctrine.orm.entity_manager')
1506 ->getRepository('WallabagCoreBundle:Entry')
1507 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1509 $authors = $content->getPublishedBy();
1510 $this->assertSame('email_tracking.pdf', $content->getTitle());
1511 $this->assertSame('example.com', $content->getDomainName());
1514 public function testEntryDeleteTagLink()
1516 $this->logInAs('admin');
1517 $client = $this->getClient();
1519 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
1520 $entry = $em->getRepository('WallabagCoreBundle:Entry')->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId());
1521 $tag = $entry->getTags()[0];
1523 $crawler = $client->request('GET', '/view/' . $entry->getId());
1525 // As long as the deletion link of a tag is following
1526 // a link to the tag view, we take the second one to retrieve
1527 // the deletion link of the first tag
1528 $link = $crawler->filter('body div#article div.tools ul.tags li.chip a')->extract('href')[1];
1530 $this->assertSame(sprintf('/remove-tag/%s/%s', $entry->getId(), $tag->getId()), $link);
1533 public function testRandom()
1535 $this->logInAs('admin');
1536 $client = $this->getClient();
1538 $client->request('GET', '/unread/random');
1539 $this->assertSame(302, $client->getResponse()->getStatusCode());
1540 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Unread random');
1542 $client->request('GET', '/starred/random');
1543 $this->assertSame(302, $client->getResponse()->getStatusCode());
1544 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Starred random');
1546 $client->request('GET', '/archive/random');
1547 $this->assertSame(302, $client->getResponse()->getStatusCode());
1548 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Archive random');
1550 $client->request('GET', '/untagged/random');
1551 $this->assertSame(302, $client->getResponse()->getStatusCode());
1552 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Untagged random');
1554 $client->request('GET', '/all/random');
1555 $this->assertSame(302, $client->getResponse()->getStatusCode());
1556 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'All random');