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/2019/06/18/ce-qu-il-faut-savoir-sur-le-libra-la-cryptomonnaie-de-facebook_5477887_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('la cryptomonnaie de Facebook', $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());
269 * This test will require an internet connection.
271 public function testPostNewOkUrlExistWithRedirection()
273 $this->logInAs('admin');
274 $client = $this->getClient();
276 $url = 'https://wllbg.org/test-redirect/c51c';
278 $crawler = $client->request('GET', '/new');
280 $this->assertSame(200, $client->getResponse()->getStatusCode());
282 $form = $crawler->filter('form[name=entry]')->form();
285 'entry[url]' => $url,
288 $client->submit($form, $data);
290 $crawler = $client->request('GET', '/new');
292 $this->assertSame(200, $client->getResponse()->getStatusCode());
294 $form = $crawler->filter('form[name=entry]')->form();
297 'entry[url]' => $url,
300 $client->submit($form, $data);
302 $this->assertSame(302, $client->getResponse()->getStatusCode());
303 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
307 * This test will require an internet connection.
309 public function testPostNewThatWillBeTagged()
311 $this->logInAs('admin');
312 $client = $this->getClient();
314 $crawler = $client->request('GET', '/new');
316 $this->assertSame(200, $client->getResponse()->getStatusCode());
318 $form = $crawler->filter('form[name=entry]')->form();
321 'entry[url]' => $url = 'https://github.com/wallabag/wallabag',
324 $client->submit($form, $data);
326 $this->assertSame(302, $client->getResponse()->getStatusCode());
327 $this->assertContains('/', $client->getResponse()->getTargetUrl());
329 $em = $client->getContainer()
330 ->get('doctrine.orm.entity_manager');
332 ->getRepository('WallabagCoreBundle:Entry')
333 ->findOneByUrl($url);
334 $tags = $entry->getTags();
336 $this->assertCount(2, $tags);
337 $this->assertContains('wallabag', $tags);
338 $this->assertSame('en', $entry->getLanguage());
343 // and now re-submit it to test the cascade persistence for tags after entry removal
344 // related https://github.com/wallabag/wallabag/issues/2121
345 $crawler = $client->request('GET', '/new');
347 $this->assertSame(200, $client->getResponse()->getStatusCode());
349 $form = $crawler->filter('form[name=entry]')->form();
352 'entry[url]' => $url = 'https://github.com/wallabag/wallabag/tree/master',
355 $client->submit($form, $data);
357 $this->assertSame(302, $client->getResponse()->getStatusCode());
358 $this->assertContains('/', $client->getResponse()->getTargetUrl());
361 ->getRepository('WallabagCoreBundle:Entry')
362 ->findOneByUrl($url);
364 $tags = $entry->getTags();
366 $this->assertCount(2, $tags);
367 $this->assertContains('wallabag', $tags);
373 public function testArchive()
375 $this->logInAs('admin');
376 $client = $this->getClient();
378 $client->request('GET', '/archive/list');
380 $this->assertSame(200, $client->getResponse()->getStatusCode());
383 public function testUntagged()
385 $this->logInAs('admin');
386 $client = $this->getClient();
388 $client->request('GET', '/untagged/list');
390 $this->assertSame(200, $client->getResponse()->getStatusCode());
393 public function testStarred()
395 $this->logInAs('admin');
396 $client = $this->getClient();
398 $client->request('GET', '/starred/list');
400 $this->assertSame(200, $client->getResponse()->getStatusCode());
403 public function testRangeException()
405 $this->logInAs('admin');
406 $client = $this->getClient();
408 $client->request('GET', '/all/list/900');
410 $this->assertSame(302, $client->getResponse()->getStatusCode());
411 $this->assertSame('/all/list', $client->getResponse()->getTargetUrl());
414 public function testView()
416 $this->logInAs('admin');
417 $client = $this->getClient();
419 $entry = new Entry($this->getLoggedInUser());
420 $entry->setUrl('http://example.com/foo');
421 $entry->setTitle('title foo');
422 $entry->setContent('foo bar baz');
423 $this->getEntityManager()->persist($entry);
424 $this->getEntityManager()->flush();
426 $crawler = $client->request('GET', '/view/' . $entry->getId());
428 $this->assertSame(200, $client->getResponse()->getStatusCode());
429 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
430 $this->assertContains($entry->getTitle(), $body[0]);
434 * This test will require an internet connection.
436 public function testReload()
438 $this->logInAs('admin');
439 $client = $this->getClient();
441 $entry = new Entry($this->getLoggedInUser());
442 $entry->setUrl($this->url
);
443 $entry->setTitle('title foo');
444 $entry->setContent('');
445 $this->getEntityManager()->persist($entry);
446 $this->getEntityManager()->flush();
447 $this->getEntityManager()->clear();
449 $client->request('GET', '/reload/' . $entry->getId());
451 $this->assertSame(302, $client->getResponse()->getStatusCode());
453 $entry = $this->getEntityManager()
454 ->getRepository('WallabagCoreBundle:Entry')
455 ->find($entry->getId());
457 $this->assertNotEmpty($entry->getContent());
460 public function testReloadWithFetchingFailed()
462 $this->logInAs('admin');
463 $client = $this->getClient();
465 $entry = new Entry($this->getLoggedInUser());
466 $entry->setUrl('http://0.0.0.0/failed.html');
467 $this->getEntityManager()->persist($entry);
468 $this->getEntityManager()->flush();
470 $client->request('GET', '/reload/' . $entry->getId());
472 $this->assertSame(302, $client->getResponse()->getStatusCode());
474 // force EntityManager to clear previous entity
475 // otherwise, retrieve the same entity will retrieve change from the previous request :0
476 $this->getEntityManager()->clear();
477 $newContent = $this->getEntityManager()
478 ->getRepository('WallabagCoreBundle:Entry')
479 ->find($entry->getId());
481 $this->assertNotSame($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent());
484 public function testEdit()
486 $this->logInAs('admin');
487 $client = $this->getClient();
489 $entry = new Entry($this->getLoggedInUser());
490 $entry->setUrl($this->url
);
491 $this->getEntityManager()->persist($entry);
492 $this->getEntityManager()->flush();
494 $crawler = $client->request('GET', '/edit/' . $entry->getId());
496 $this->assertSame(200, $client->getResponse()->getStatusCode());
498 $this->assertCount(1, $crawler->filter('input[id=entry_title]'));
499 $this->assertCount(1, $crawler->filter('button[id=entry_save]'));
502 public function testEditUpdate()
504 $this->logInAs('admin');
505 $client = $this->getClient();
507 $entry = new Entry($this->getLoggedInUser());
508 $entry->setUrl($this->url
);
509 $this->getEntityManager()->persist($entry);
510 $this->getEntityManager()->flush();
512 $crawler = $client->request('GET', '/edit/' . $entry->getId());
514 $this->assertSame(200, $client->getResponse()->getStatusCode());
516 $form = $crawler->filter('button[id=entry_save]')->form();
519 'entry[title]' => 'My updated title hehe :)',
520 'entry[origin_url]' => 'https://example.io',
523 $client->submit($form, $data);
525 $this->assertSame(302, $client->getResponse()->getStatusCode());
527 $crawler = $client->followRedirect();
529 $this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text']));
530 $this->assertContains('My updated title hehe :)', $title[0]);
531 $this->assertGreaterThan(1, $stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']));
532 $this->assertContains('example.io', trim($stats[1]));
535 public function testEditRemoveOriginUrl()
537 $this->logInAs('admin');
538 $client = $this->getClient();
540 $entry = new Entry($this->getLoggedInUser());
541 $entry->setUrl($this->url
);
542 $this->getEntityManager()->persist($entry);
543 $this->getEntityManager()->flush();
545 $crawler = $client->request('GET', '/edit/' . $entry->getId());
547 $this->assertSame(200, $client->getResponse()->getStatusCode());
549 $form = $crawler->filter('button[id=entry_save]')->form();
552 'entry[title]' => 'My updated title hehe :)',
553 'entry[origin_url]' => '',
556 $client->submit($form, $data);
558 $this->assertSame(302, $client->getResponse()->getStatusCode());
560 $crawler = $client->followRedirect();
562 $title = $crawler->filter('div[id=article] h1')->extract(['_text']);
563 $this->assertGreaterThan(1, $title);
564 $this->assertContains('My updated title hehe :)', $title[0]);
566 $stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']);
567 $this->assertCount(1, $stats);
568 $this->assertNotContains('example.io', trim($stats[0]));
571 public function testToggleArchive()
573 $this->logInAs('admin');
574 $client = $this->getClient();
576 $entry = new Entry($this->getLoggedInUser());
577 $entry->setUrl($this->url
);
578 $this->getEntityManager()->persist($entry);
579 $this->getEntityManager()->flush();
580 $this->getEntityManager()->clear();
582 $client->request('GET', '/archive/' . $entry->getId());
584 $this->assertSame(302, $client->getResponse()->getStatusCode());
586 $res = $client->getContainer()
587 ->get('doctrine.orm.entity_manager')
588 ->getRepository('WallabagCoreBundle:Entry')
589 ->find($entry->getId());
591 $this->assertSame(1, $res->isArchived());
594 public function testToggleStar()
596 $this->logInAs('admin');
597 $client = $this->getClient();
599 $entry = new Entry($this->getLoggedInUser());
600 $entry->setUrl($this->url
);
601 $this->getEntityManager()->persist($entry);
602 $this->getEntityManager()->flush();
603 $this->getEntityManager()->clear();
605 $client->request('GET', '/star/' . $entry->getId());
607 $this->assertSame(302, $client->getResponse()->getStatusCode());
609 $res = $client->getContainer()
610 ->get('doctrine.orm.entity_manager')
611 ->getRepository('WallabagCoreBundle:Entry')
612 ->findOneById($entry->getId());
614 $this->assertSame(1, $res->isStarred());
617 public function testDelete()
619 $this->logInAs('admin');
620 $client = $this->getClient();
622 $entry = new Entry($this->getLoggedInUser());
623 $entry->setUrl($this->url
);
624 $this->getEntityManager()->persist($entry);
625 $this->getEntityManager()->flush();
627 $client->request('GET', '/delete/' . $entry->getId());
629 $this->assertSame(302, $client->getResponse()->getStatusCode());
631 $client->request('GET', '/delete/' . $entry->getId());
633 $this->assertSame(404, $client->getResponse()->getStatusCode());
637 * It will create a new entry.
641 * And it'll check that user won't be redirected to the view page of the content when it had been removed
643 public function testViewAndDelete()
645 $this->logInAs('admin');
646 $client = $this->getClient();
648 $em = $client->getContainer()
649 ->get('doctrine.orm.entity_manager');
651 // add a new content to be removed later
653 ->getRepository('WallabagUserBundle:User')
654 ->findOneByUserName('admin');
656 $content = new Entry($user);
657 $content->setUrl('http://1.1.1.1/entry');
658 $content->setReadingTime(12);
659 $content->setDomainName('domain.io');
660 $content->setMimetype('text/html');
661 $content->setTitle('test title entry');
662 $content->setContent('This is my content /o/');
663 $content->updateArchived(true);
664 $content->setLanguage('fr');
666 $em->persist($content);
669 $client->request('GET', '/view/' . $content->getId());
670 $this->assertSame(200, $client->getResponse()->getStatusCode());
672 $client->request('GET', '/delete/' . $content->getId());
673 $this->assertSame(302, $client->getResponse()->getStatusCode());
675 $client->followRedirect();
676 $this->assertSame(200, $client->getResponse()->getStatusCode());
679 public function testViewOtherUserEntry()
681 $this->logInAs('admin');
682 $client = $this->getClient();
684 $content = $client->getContainer()
685 ->get('doctrine.orm.entity_manager')
686 ->getRepository('WallabagCoreBundle:Entry')
687 ->findOneByUsernameAndNotArchived('bob');
689 $client->request('GET', '/view/' . $content->getId());
691 $this->assertSame(403, $client->getResponse()->getStatusCode());
694 public function testFilterOnReadingTime()
696 $this->logInAs('admin');
697 $this->useTheme('baggy');
698 $client = $this->getClient();
699 $entry = new Entry($this->getLoggedInUser());
700 $entry->setUrl($this->url
);
701 $entry->setReadingTime(22);
702 $this->getEntityManager()->persist($entry);
703 $this->getEntityManager()->flush();
705 $crawler = $client->request('GET', '/unread/list');
707 $form = $crawler->filter('button[id=submit-filter]')->form();
710 'entry_filter[readingTime][right_number]' => 22,
711 'entry_filter[readingTime][left_number]' => 22,
714 $crawler = $client->submit($form, $data);
716 $this->assertCount(1, $crawler->filter('div[class=entry]'));
719 public function testFilterOnReadingTimeWithNegativeValue()
721 $this->logInAs('admin');
722 $client = $this->getClient();
724 $crawler = $client->request('GET', '/unread/list');
726 $form = $crawler->filter('button[id=submit-filter]')->form();
729 'entry_filter[readingTime][right_number]' => -22,
730 'entry_filter[readingTime][left_number]' => -22,
733 $crawler = $client->submit($form, $data);
735 // forcing negative value results in no entry displayed
736 $this->assertCount(0, $crawler->filter('div[class=entry]'));
739 public function testFilterOnReadingTimeOnlyUpper()
741 $this->logInAs('admin');
742 $this->useTheme('baggy');
743 $client = $this->getClient();
745 $crawler = $client->request('GET', '/all/list');
746 $this->assertCount(5, $crawler->filter('div[class=entry]'));
748 $entry = new Entry($this->getLoggedInUser());
749 $entry->setUrl($this->url
);
750 $entry->setReadingTime(23);
751 $this->getEntityManager()->persist($entry);
752 $this->getEntityManager()->flush();
754 $crawler = $client->request('GET', '/all/list');
755 $this->assertCount(6, $crawler->filter('div[class=entry]'));
757 $form = $crawler->filter('button[id=submit-filter]')->form();
760 'entry_filter[readingTime][right_number]' => 22,
763 $crawler = $client->submit($form, $data);
765 $this->assertCount(5, $crawler->filter('div[class=entry]'));
768 public function testFilterOnReadingTimeOnlyLower()
770 $this->logInAs('admin');
771 $this->useTheme('baggy');
772 $client = $this->getClient();
774 $crawler = $client->request('GET', '/unread/list');
776 $form = $crawler->filter('button[id=submit-filter]')->form();
779 'entry_filter[readingTime][left_number]' => 22,
782 $crawler = $client->submit($form, $data);
784 $this->assertCount(0, $crawler->filter('div[class=entry]'));
786 $entry = new Entry($this->getLoggedInUser());
787 $entry->setUrl($this->url
);
788 $entry->setReadingTime(23);
789 $this->getEntityManager()->persist($entry);
790 $this->getEntityManager()->flush();
792 $crawler = $client->submit($form, $data);
793 $this->assertCount(1, $crawler->filter('div[class=entry]'));
796 public function testFilterOnUnreadStatus()
798 $this->logInAs('admin');
799 $this->useTheme('baggy');
800 $client = $this->getClient();
802 $crawler = $client->request('GET', '/all/list');
804 $form = $crawler->filter('button[id=submit-filter]')->form();
807 'entry_filter[isUnread]' => true,
810 $crawler = $client->submit($form, $data);
812 $this->assertCount(4, $crawler->filter('div[class=entry]'));
814 $entry = new Entry($this->getLoggedInUser());
815 $entry->setUrl($this->url
);
816 $entry->updateArchived(false);
817 $this->getEntityManager()->persist($entry);
818 $this->getEntityManager()->flush();
820 $crawler = $client->submit($form, $data);
822 $this->assertCount(5, $crawler->filter('div[class=entry]'));
825 public function testFilterOnCreationDate()
827 $this->logInAs('admin');
828 $this->useTheme('baggy');
829 $client = $this->getClient();
831 $crawler = $client->request('GET', '/unread/list');
833 $form = $crawler->filter('button[id=submit-filter]')->form();
836 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
837 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')),
840 $crawler = $client->submit($form, $data);
842 $this->assertCount(5, $crawler->filter('div[class=entry]'));
845 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
846 'entry_filter[createdAt][right_date]' => date('d/m/Y'),
849 $crawler = $client->submit($form, $data);
851 $this->assertCount(5, $crawler->filter('div[class=entry]'));
854 'entry_filter[createdAt][left_date]' => '01/01/1970',
855 'entry_filter[createdAt][right_date]' => '01/01/1970',
858 $crawler = $client->submit($form, $data);
860 $this->assertCount(0, $crawler->filter('div[class=entry]'));
863 public function testPaginationWithFilter()
865 $this->logInAs('admin');
866 $client = $this->getClient();
867 $crawler = $client->request('GET', '/config');
869 $form = $crawler->filter('button[id=config_save]')->form();
872 'config[items_per_page]' => '1',
875 $client->submit($form, $data);
877 $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D=';
879 $client->request('GET', 'unread/list' . $parameters);
881 $this->assertContains($parameters, $client->getResponse()->getContent());
884 $crawler = $client->request('GET', '/config');
885 $form = $crawler->filter('button[id=config_save]')->form();
887 'config[items_per_page]' => '12',
889 $client->submit($form, $data);
892 public function testFilterOnDomainName()
894 $this->logInAs('admin');
895 $this->useTheme('baggy');
896 $client = $this->getClient();
898 $crawler = $client->request('GET', '/unread/list');
899 $form = $crawler->filter('button[id=submit-filter]')->form();
901 'entry_filter[domainName]' => 'domain',
904 $crawler = $client->submit($form, $data);
905 $this->assertCount(5, $crawler->filter('div[class=entry]'));
907 $crawler = $client->request('GET', '/unread/list');
908 $form = $crawler->filter('button[id=submit-filter]')->form();
910 'entry_filter[domainName]' => 'dOmain',
913 $crawler = $client->submit($form, $data);
914 $this->assertCount(5, $crawler->filter('div[class=entry]'));
916 $form = $crawler->filter('button[id=submit-filter]')->form();
918 'entry_filter[domainName]' => 'wallabag',
921 $crawler = $client->submit($form, $data);
922 $this->assertCount(0, $crawler->filter('div[class=entry]'));
925 public function testFilterOnStatus()
927 $this->logInAs('admin');
928 $this->useTheme('baggy');
929 $client = $this->getClient();
931 $crawler = $client->request('GET', '/unread/list');
932 $form = $crawler->filter('button[id=submit-filter]')->form();
933 $form['entry_filter[isArchived]']->tick();
934 $form['entry_filter[isStarred]']->untick();
936 $crawler = $client->submit($form);
937 $this->assertCount(1, $crawler->filter('div[class=entry]'));
939 $form = $crawler->filter('button[id=submit-filter]')->form();
940 $form['entry_filter[isArchived]']->untick();
941 $form['entry_filter[isStarred]']->tick();
943 $crawler = $client->submit($form);
944 $this->assertCount(1, $crawler->filter('div[class=entry]'));
947 public function testFilterOnIsPublic()
949 $this->logInAs('admin');
950 $this->useTheme('baggy');
951 $client = $this->getClient();
953 $crawler = $client->request('GET', '/unread/list');
954 $form = $crawler->filter('button[id=submit-filter]')->form();
955 $form['entry_filter[isPublic]']->tick();
957 $crawler = $client->submit($form);
958 $this->assertCount(0, $crawler->filter('div[class=entry]'));
961 public function testPreviewPictureFilter()
963 $this->logInAs('admin');
964 $this->useTheme('baggy');
965 $client = $this->getClient();
967 $crawler = $client->request('GET', '/unread/list');
968 $form = $crawler->filter('button[id=submit-filter]')->form();
969 $form['entry_filter[previewPicture]']->tick();
971 $crawler = $client->submit($form);
972 $this->assertCount(1, $crawler->filter('div[class=entry]'));
975 public function testFilterOnLanguage()
977 $this->logInAs('admin');
978 $this->useTheme('baggy');
979 $client = $this->getClient();
981 $entry = new Entry($this->getLoggedInUser());
982 $entry->setUrl($this->url
);
983 $entry->setLanguage('fr');
984 $this->getEntityManager()->persist($entry);
985 $this->getEntityManager()->flush();
987 $crawler = $client->request('GET', '/unread/list');
988 $form = $crawler->filter('button[id=submit-filter]')->form();
990 'entry_filter[language]' => 'fr',
993 $crawler = $client->submit($form, $data);
994 $this->assertCount(3, $crawler->filter('div[class=entry]'));
996 $form = $crawler->filter('button[id=submit-filter]')->form();
998 'entry_filter[language]' => 'en',
1001 $crawler = $client->submit($form, $data);
1002 $this->assertCount(2, $crawler->filter('div[class=entry]'));
1005 public function testShareEntryPublicly()
1007 $this->logInAs('admin');
1008 $client = $this->getClient();
1010 // sharing is enabled
1011 $client->getContainer()->get('craue_config')->set('share_public', 1);
1013 $content = new Entry($this->getLoggedInUser());
1014 $content->setUrl($this->url
);
1015 $this->getEntityManager()->persist($content);
1016 $this->getEntityManager()->flush();
1017 $this->getEntityManager()->clear();
1020 $client->request('GET', '/share/' . $content->getUid());
1021 $this->assertSame(404, $client->getResponse()->getStatusCode());
1023 // generating the uid
1024 $client->request('GET', '/share/' . $content->getId());
1025 $this->assertSame(302, $client->getResponse()->getStatusCode());
1027 $shareUrl = $client->getResponse()->getTargetUrl();
1029 // use a new client to have a fresh empty session (instead of a logged one from the previous client)
1032 $client->request('GET', $shareUrl);
1034 $this->assertSame(200, $client->getResponse()->getStatusCode());
1035 $this->assertContains('max-age=25200', $client->getResponse()->headers
->get('cache-control'));
1036 $this->assertContains('public', $client->getResponse()->headers
->get('cache-control'));
1037 $this->assertContains('s-maxage=25200', $client->getResponse()->headers
->get('cache-control'));
1038 $this->assertNotContains('no-cache', $client->getResponse()->headers
->get('cache-control'));
1039 $this->assertContains('og:title', $client->getResponse()->getContent());
1040 $this->assertContains('og:type', $client->getResponse()->getContent());
1041 $this->assertContains('og:url', $client->getResponse()->getContent());
1042 $this->assertContains('og:image', $client->getResponse()->getContent());
1044 // sharing is now disabled
1045 $client->getContainer()->get('craue_config')->set('share_public', 0);
1046 $client->request('GET', '/share/' . $content->getUid());
1047 $this->assertSame(404, $client->getResponse()->getStatusCode());
1049 // removing the share
1050 $client->request('GET', '/share/delete/' . $content->getId());
1051 $this->assertSame(302, $client->getResponse()->getStatusCode());
1053 // share is now disable
1054 $client->request('GET', '/share/' . $content->getUid());
1055 $this->assertSame(404, $client->getResponse()->getStatusCode());
1058 public function testNewEntryWithDownloadImagesEnabled()
1060 $this->downloadImagesEnabled
= true;
1061 $this->logInAs('admin');
1062 $client = $this->getClient();
1064 $url = self
::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE
;
1065 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
1067 $crawler = $client->request('GET', '/new');
1069 $this->assertSame(200, $client->getResponse()->getStatusCode());
1071 $form = $crawler->filter('form[name=entry]')->form();
1074 'entry[url]' => $url,
1077 $client->submit($form, $data);
1079 $this->assertSame(302, $client->getResponse()->getStatusCode());
1081 $em = $client->getContainer()
1082 ->get('doctrine.orm.entity_manager');
1085 ->getRepository('WallabagCoreBundle:Entry')
1086 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1088 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry);
1089 $this->assertSame($url, $entry->getUrl());
1090 $this->assertContains('Judo', $entry->getTitle());
1091 // instead of checking for the filename (which might change) check that the image is now local
1092 $this->assertContains(rtrim($client->getContainer()->getParameter('domain_name'), '/') . '/assets/images/', $entry->getContent());
1094 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1098 * @depends testNewEntryWithDownloadImagesEnabled
1100 public function testRemoveEntryWithDownloadImagesEnabled()
1102 $this->downloadImagesEnabled
= true;
1103 $this->logInAs('admin');
1104 $client = $this->getClient();
1106 $url = self
::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE
;
1107 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
1109 $crawler = $client->request('GET', '/new');
1111 $this->assertSame(200, $client->getResponse()->getStatusCode());
1113 $form = $crawler->filter('form[name=entry]')->form();
1116 'entry[url]' => $url,
1119 $client->submit($form, $data);
1121 $this->assertSame(302, $client->getResponse()->getStatusCode());
1123 $content = $client->getContainer()
1124 ->get('doctrine.orm.entity_manager')
1125 ->getRepository('WallabagCoreBundle:Entry')
1126 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1128 $client->request('GET', '/delete/' . $content->getId());
1130 $this->assertSame(302, $client->getResponse()->getStatusCode());
1132 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1135 public function testRedirectToHomepage()
1137 $this->logInAs('empty');
1138 $client = $this->getClient();
1140 // Redirect to homepage
1141 $config = $this->getLoggedInUser()->getConfig();
1142 $config->setActionMarkAsRead(Config
::REDIRECT_TO_HOMEPAGE
);
1143 $this->getEntityManager()->persist($config);
1145 $entry = new Entry($this->getLoggedInUser());
1146 $entry->setUrl($this->url
);
1147 $this->getEntityManager()->persist($entry);
1149 $this->getEntityManager()->flush();
1151 $client->request('GET', '/view/' . $entry->getId());
1152 $client->request('GET', '/archive/' . $entry->getId());
1154 $this->assertSame(302, $client->getResponse()->getStatusCode());
1155 $this->assertSame('/', $client->getResponse()->headers
->get('location'));
1158 public function testRedirectToCurrentPage()
1160 $this->logInAs('empty');
1161 $client = $this->getClient();
1163 // Redirect to current page
1164 $config = $this->getLoggedInUser()->getConfig();
1165 $config->setActionMarkAsRead(Config
::REDIRECT_TO_CURRENT_PAGE
);
1166 $this->getEntityManager()->persist($config);
1168 $entry = new Entry($this->getLoggedInUser());
1169 $entry->setUrl($this->url
);
1170 $this->getEntityManager()->persist($entry);
1172 $this->getEntityManager()->flush();
1174 $client->request('GET', '/view/' . $entry->getId());
1175 $client->request('GET', '/archive/' . $entry->getId());
1177 $this->assertSame(302, $client->getResponse()->getStatusCode());
1178 $this->assertContains('/view/' . $entry->getId(), $client->getResponse()->headers
->get('location'));
1181 public function testFilterOnHttpStatus()
1183 $this->logInAs('admin');
1184 $this->useTheme('baggy');
1185 $client = $this->getClient();
1187 $entry = new Entry($this->getLoggedInUser());
1188 $entry->setUrl('https://www.lemonde.fr/incorrect-url/');
1189 $entry->setHttpStatus(404);
1190 $this->getEntityManager()->persist($entry);
1192 $this->getEntityManager()->flush();
1194 $crawler = $client->request('GET', '/all/list');
1195 $form = $crawler->filter('button[id=submit-filter]')->form();
1198 'entry_filter[httpStatus]' => 404,
1201 $crawler = $client->submit($form, $data);
1203 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1205 $entry = new Entry($this->getLoggedInUser());
1206 $entry->setUrl($this->url
);
1207 $entry->setHttpStatus(200);
1208 $this->getEntityManager()->persist($entry);
1210 $entry = new Entry($this->getLoggedInUser());
1211 $entry->setUrl('http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm');
1212 $entry->setHttpStatus(200);
1213 $this->getEntityManager()->persist($entry);
1215 $this->getEntityManager()->flush();
1217 $crawler = $client->request('GET', '/all/list');
1218 $form = $crawler->filter('button[id=submit-filter]')->form();
1221 'entry_filter[httpStatus]' => 200,
1224 $crawler = $client->submit($form, $data);
1226 $this->assertCount(2, $crawler->filter('div[class=entry]'));
1228 $crawler = $client->request('GET', '/all/list');
1229 $form = $crawler->filter('button[id=submit-filter]')->form();
1232 'entry_filter[httpStatus]' => 1024,
1235 $crawler = $client->submit($form, $data);
1237 $this->assertCount(8, $crawler->filter('div[class=entry]'));
1240 public function testSearch()
1242 $this->logInAs('admin');
1243 $this->useTheme('baggy');
1244 $client = $this->getClient();
1246 $entry = new Entry($this->getLoggedInUser());
1247 $entry->setUrl($this->url
);
1248 $entry->setTitle('test');
1249 $this->getEntityManager()->persist($entry);
1250 $this->getEntityManager()->flush();
1252 // Search on unread list
1253 $crawler = $client->request('GET', '/unread/list');
1255 $form = $crawler->filter('form[name=search]')->form();
1257 'search_entry[term]' => 'title',
1260 $crawler = $client->submit($form, $data);
1262 $this->assertCount(4, $crawler->filter('div[class=entry]'));
1264 // Search on starred list
1265 $crawler = $client->request('GET', '/starred/list');
1267 $entry = new Entry($this->getLoggedInUser());
1268 $entry->setUrl('http://localhost/foo/bar');
1269 $entry->setTitle('testeur');
1270 $entry->setStarred(true);
1271 $this->getEntityManager()->persist($entry);
1272 $this->getEntityManager()->flush();
1274 $form = $crawler->filter('form[name=search]')->form();
1276 'search_entry[term]' => 'testeur',
1279 $crawler = $client->submit($form, $data);
1281 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1283 $crawler = $client->request('GET', '/archive/list');
1285 // Added new article to test on archive list
1286 $entry = new Entry($this->getLoggedInUser());
1287 $entry->setUrl('http://0.0.0.0/foo/baz/qux');
1288 $entry->setTitle('Le manège');
1289 $entry->updateArchived(true);
1290 $this->getEntityManager()->persist($entry);
1291 $this->getEntityManager()->flush();
1293 $form = $crawler->filter('form[name=search]')->form();
1295 'search_entry[term]' => 'manège',
1298 $crawler = $client->submit($form, $data);
1300 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1301 $client->request('GET', '/delete/' . $entry->getId());
1303 // test on list of all articles
1304 $crawler = $client->request('GET', '/all/list');
1306 $form = $crawler->filter('form[name=search]')->form();
1308 'search_entry[term]' => 'wxcvbnqsdf', // a string not available in the database
1311 $crawler = $client->submit($form, $data);
1313 $this->assertCount(0, $crawler->filter('div[class=entry]'));
1315 // test url search on list of all articles
1316 $entry = new Entry($this->getLoggedInUser());
1317 $entry->setUrl('http://domain/qux');
1318 $entry->setTitle('Le manège');
1319 $entry->updateArchived(true);
1320 $this->getEntityManager()->persist($entry);
1321 $this->getEntityManager()->flush();
1323 $crawler = $client->request('GET', '/all/list');
1325 $form = $crawler->filter('form[name=search]')->form();
1327 'search_entry[term]' => 'domain', // the search will match an entry with 'domain' in its url
1330 $crawler = $client->submit($form, $data);
1332 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1334 // same as previous test but for case-sensitivity
1335 $crawler = $client->request('GET', '/all/list');
1337 $form = $crawler->filter('form[name=search]')->form();
1339 'search_entry[term]' => 'doMain', // the search will match an entry with 'domain' in its url
1342 $crawler = $client->submit($form, $data);
1344 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1347 public function dataForLanguage()
1351 'https://www.pravda.ru/world/09-06-2017/1337283-qatar-0/',
1355 'https://fr.wikipedia.org/wiki/Wallabag',
1359 'https://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html',
1363 'http://www.ansa.it/sito/notizie/mondo/europa/2017/06/08/voto-gb-seggi-aperti-misure-sicurezza-rafforzate_0cb71f7f-e23b-4d5f-95ca-bc12296419f0.html',
1367 'http://www.hao123.com/shequ?__noscript__-=1',
1371 'https://politica.estadao.com.br/noticias/eleicoes,campanha-catatonica,70002491983',
1374 'fucked_list_of_languages' => [
1375 'http://geocatalog.webservice-energy.org/geonetwork/srv/eng/main.home',
1379 'https://www.20minutos.es/noticia/3360685/0/gobierno-sanchez-primero-historia-mas-mujeres-que-hombres/',
1386 * @dataProvider dataForLanguage
1388 public function testLanguageValidation($url, $expectedLanguage)
1390 $this->logInAs('admin');
1391 $client = $this->getClient();
1393 $crawler = $client->request('GET', '/new');
1395 $this->assertSame(200, $client->getResponse()->getStatusCode());
1397 $form = $crawler->filter('form[name=entry]')->form();
1400 'entry[url]' => $url,
1403 $client->submit($form, $data);
1405 $this->assertSame(302, $client->getResponse()->getStatusCode());
1407 $content = $client->getContainer()
1408 ->get('doctrine.orm.entity_manager')
1409 ->getRepository('WallabagCoreBundle:Entry')
1410 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1412 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1413 $this->assertSame($url, $content->getUrl());
1414 $this->assertSame($expectedLanguage, $content->getLanguage());
1418 * This test will require an internet connection.
1420 public function testRestrictedArticle()
1422 $url = 'https://www.monde-diplomatique.fr/2017/05/BONNET/57475';
1423 $this->logInAs('admin');
1424 $client = $this->getClient();
1425 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
1427 // enable restricted access
1428 $client->getContainer()->get('craue_config')->set('restricted_access', 1);
1430 // create a new site_credential
1431 $user = $client->getContainer()->get('security.token_storage')->getToken()->getUser();
1432 $credential = new SiteCredential($user);
1433 $credential->setHost('monde-diplomatique.fr');
1434 $credential->setUsername($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('foo'));
1435 $credential->setPassword($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('bar'));
1437 $em->persist($credential);
1440 $crawler = $client->request('GET', '/new');
1442 $this->assertSame(200, $client->getResponse()->getStatusCode());
1444 $form = $crawler->filter('form[name=entry]')->form();
1447 'entry[url]' => $url,
1450 $client->submit($form, $data);
1452 $this->assertSame(302, $client->getResponse()->getStatusCode());
1454 $crawler = $client->followRedirect();
1456 $this->assertSame(200, $client->getResponse()->getStatusCode());
1457 $this->assertContains('flashes.entry.notice.entry_saved', $crawler->filter('body')->extract(['_text'])[0]);
1460 ->getRepository('WallabagCoreBundle:Entry')
1461 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1463 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1464 $this->assertSame('Crimes et réformes aux Philippines', $content->getTitle());
1466 $client->getContainer()->get('craue_config')->set('restricted_access', 0);
1469 public function testPostEntryWhenFetchFails()
1471 $url = 'http://example.com/papers/email_tracking.pdf';
1472 $this->logInAs('admin');
1473 $client = $this->getClient();
1475 $container = $client->getContainer();
1476 $contentProxy = $this->getMockBuilder(ContentProxy
::class)
1477 ->disableOriginalConstructor()
1478 ->setMethods(['updateEntry'])
1480 $contentProxy->expects($this->any())
1481 ->method('updateEntry')
1482 ->willThrowException(new \
Exception('Test Fetch content fails'));
1484 $crawler = $client->request('GET', '/new');
1486 $this->assertSame(200, $client->getResponse()->getStatusCode());
1488 $form = $crawler->filter('form[name=entry]')->form();
1491 'entry[url]' => $url,
1495 * We generate a new client to be able to use Mock ContentProxy
1496 * Also we reinject the cookie from the previous client to keep the
1499 $cookie = $client->getCookieJar()->all();
1500 $client = $this->getNewClient();
1501 $client->getCookieJar()->set($cookie[0]);
1502 $client->getContainer()->set('wallabag_core.content_proxy', $contentProxy);
1503 $client->submit($form, $data);
1505 $this->assertSame(302, $client->getResponse()->getStatusCode());
1507 $content = $client->getContainer()
1508 ->get('doctrine.orm.entity_manager')
1509 ->getRepository('WallabagCoreBundle:Entry')
1510 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1512 $authors = $content->getPublishedBy();
1513 $this->assertSame('email_tracking.pdf', $content->getTitle());
1514 $this->assertSame('example.com', $content->getDomainName());
1517 public function testEntryDeleteTagLink()
1519 $this->logInAs('admin');
1520 $client = $this->getClient();
1522 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
1523 $entry = $em->getRepository('WallabagCoreBundle:Entry')->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId());
1524 $tag = $entry->getTags()[0];
1526 $crawler = $client->request('GET', '/view/' . $entry->getId());
1528 // As long as the deletion link of a tag is following
1529 // a link to the tag view, we take the second one to retrieve
1530 // the deletion link of the first tag
1531 $link = $crawler->filter('body div#article div.tools ul.tags li.chip a')->extract('href')[1];
1533 $this->assertSame(sprintf('/remove-tag/%s/%s', $entry->getId(), $tag->getId()), $link);
1536 public function testRandom()
1538 $this->logInAs('admin');
1539 $client = $this->getClient();
1541 $client->request('GET', '/unread/random');
1542 $this->assertSame(302, $client->getResponse()->getStatusCode());
1543 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Unread random');
1545 $client->request('GET', '/starred/random');
1546 $this->assertSame(302, $client->getResponse()->getStatusCode());
1547 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Starred random');
1549 $client->request('GET', '/archive/random');
1550 $this->assertSame(302, $client->getResponse()->getStatusCode());
1551 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Archive random');
1553 $client->request('GET', '/untagged/random');
1554 $this->assertSame(302, $client->getResponse()->getStatusCode());
1555 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Untagged random');
1557 $client->request('GET', '/all/random');
1558 $this->assertSame(302, $client->getResponse()->getStatusCode());
1559 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'All random');