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 $client = $this->getClient();
95 $crawler = $client->request('GET', '/');
97 $this->assertCount(4, $crawler->filter('li.entry'));
100 $client->request('GET', '/bookmarklet', ['url' => $this->url
]);
101 $this->assertSame(302, $client->getResponse()->getStatusCode());
102 $client->followRedirect();
103 $crawler = $client->request('GET', '/');
104 $this->assertCount(5, $crawler->filter('li.entry'));
106 $em = $client->getContainer()
107 ->get('doctrine.orm.entity_manager');
109 ->getRepository('WallabagCoreBundle:Entry')
110 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
115 public function testPostNewEmpty()
117 $this->logInAs('admin');
118 $client = $this->getClient();
120 $crawler = $client->request('GET', '/new');
122 $this->assertSame(200, $client->getResponse()->getStatusCode());
124 $form = $crawler->filter('form[name=entry]')->form();
126 $crawler = $client->submit($form);
128 $this->assertSame(200, $client->getResponse()->getStatusCode());
129 $this->assertCount(1, $alert = $crawler->filter('form ul li')->extract(['_text']));
130 $this->assertSame('This value should not be blank.', $alert[0]);
134 * This test will require an internet connection.
136 public function testPostNewOk()
138 $this->logInAs('admin');
139 $client = $this->getClient();
141 $client->getContainer()->get('craue_config')->set('store_article_headers', 1);
143 $crawler = $client->request('GET', '/new');
145 $this->assertSame(200, $client->getResponse()->getStatusCode());
147 $form = $crawler->filter('form[name=entry]')->form();
150 'entry[url]' => $this->url
,
153 $client->submit($form, $data);
155 $this->assertSame(302, $client->getResponse()->getStatusCode());
157 $content = $client->getContainer()
158 ->get('doctrine.orm.entity_manager')
159 ->getRepository('WallabagCoreBundle:Entry')
160 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
162 $author = $content->getPublishedBy();
164 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
165 $this->assertSame($this->url
, $content->getUrl());
166 $this->assertContains('la cryptomonnaie de Facebook', $content->getTitle());
167 $this->assertSame('fr', $content->getLanguage());
168 $this->assertArrayHasKey('x-frame-options', $content->getHeaders());
169 $client->getContainer()->get('craue_config')->set('store_article_headers', 0);
172 public function testPostWithMultipleAuthors()
174 $url = 'https://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768';
175 $this->logInAs('admin');
176 $client = $this->getClient();
178 $crawler = $client->request('GET', '/new');
180 $this->assertSame(200, $client->getResponse()->getStatusCode());
182 $form = $crawler->filter('form[name=entry]')->form();
185 'entry[url]' => $url,
188 $client->submit($form, $data);
190 $this->assertSame(302, $client->getResponse()->getStatusCode());
192 $content = $client->getContainer()
193 ->get('doctrine.orm.entity_manager')
194 ->getRepository('WallabagCoreBundle:Entry')
195 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
197 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
198 $authors = $content->getPublishedBy();
199 $this->assertSame('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s'));
200 $this->assertSame('fr', $content->getLanguage());
201 $this->assertSame('Raphaël Balenieri', $authors[0]);
202 $this->assertSame('Frédéric Autran', $authors[1]);
205 public function testPostNewOkUrlExist()
207 $this->logInAs('admin');
209 $entry = new Entry($this->getLoggedInUser());
210 $entry->setUrl($this->url
);
211 $this->getEntityManager()->persist($entry);
212 $this->getEntityManager()->flush();
214 $client = $this->getClient();
216 $crawler = $client->request('GET', '/new');
218 $this->assertSame(200, $client->getResponse()->getStatusCode());
220 $form = $crawler->filter('form[name=entry]')->form();
223 'entry[url]' => $this->url
,
226 $client->submit($form, $data);
228 $this->assertSame(302, $client->getResponse()->getStatusCode());
229 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
232 public function testPostNewOkUrlExistWithAccent()
234 $this->logInAs('admin');
235 $client = $this->getClient();
237 $url = 'https://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing';
239 $crawler = $client->request('GET', '/new');
241 $this->assertSame(200, $client->getResponse()->getStatusCode());
243 $form = $crawler->filter('form[name=entry]')->form();
246 'entry[url]' => $url,
249 $client->submit($form, $data);
251 $crawler = $client->request('GET', '/new');
253 $this->assertSame(200, $client->getResponse()->getStatusCode());
255 $form = $crawler->filter('form[name=entry]')->form();
258 'entry[url]' => $url,
261 $client->submit($form, $data);
263 $this->assertSame(302, $client->getResponse()->getStatusCode());
264 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
268 * This test will require an internet connection.
270 public function testPostNewOkUrlExistWithRedirection()
272 $this->logInAs('admin');
273 $client = $this->getClient();
275 $url = 'https://wllbg.org/test-redirect/c51c';
277 $crawler = $client->request('GET', '/new');
279 $this->assertSame(200, $client->getResponse()->getStatusCode());
281 $form = $crawler->filter('form[name=entry]')->form();
284 'entry[url]' => $url,
287 $client->submit($form, $data);
289 $crawler = $client->request('GET', '/new');
291 $this->assertSame(200, $client->getResponse()->getStatusCode());
293 $form = $crawler->filter('form[name=entry]')->form();
296 'entry[url]' => $url,
299 $client->submit($form, $data);
301 $this->assertSame(302, $client->getResponse()->getStatusCode());
302 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
306 * This test will require an internet connection.
308 public function testPostNewThatWillBeTagged()
310 $this->logInAs('admin');
311 $client = $this->getClient();
313 $crawler = $client->request('GET', '/new');
315 $this->assertSame(200, $client->getResponse()->getStatusCode());
317 $form = $crawler->filter('form[name=entry]')->form();
320 'entry[url]' => $url = 'https://github.com/wallabag/wallabag',
323 $client->submit($form, $data);
325 $this->assertSame(302, $client->getResponse()->getStatusCode());
326 $this->assertContains('/', $client->getResponse()->getTargetUrl());
328 $em = $client->getContainer()
329 ->get('doctrine.orm.entity_manager');
331 ->getRepository('WallabagCoreBundle:Entry')
332 ->findOneByUrl($url);
333 $tags = $entry->getTags();
335 $this->assertCount(2, $tags);
336 $this->assertContains('wallabag', $tags);
337 $this->assertSame('en', $entry->getLanguage());
342 // and now re-submit it to test the cascade persistence for tags after entry removal
343 // related https://github.com/wallabag/wallabag/issues/2121
344 $crawler = $client->request('GET', '/new');
346 $this->assertSame(200, $client->getResponse()->getStatusCode());
348 $form = $crawler->filter('form[name=entry]')->form();
351 'entry[url]' => $url = 'https://github.com/wallabag/wallabag/tree/master',
354 $client->submit($form, $data);
356 $this->assertSame(302, $client->getResponse()->getStatusCode());
357 $this->assertContains('/', $client->getResponse()->getTargetUrl());
360 ->getRepository('WallabagCoreBundle:Entry')
361 ->findOneByUrl($url);
363 $tags = $entry->getTags();
365 $this->assertCount(2, $tags);
366 $this->assertContains('wallabag', $tags);
372 public function testArchive()
374 $this->logInAs('admin');
375 $client = $this->getClient();
377 $client->request('GET', '/archive/list');
379 $this->assertSame(200, $client->getResponse()->getStatusCode());
382 public function testUntagged()
384 $this->logInAs('admin');
385 $client = $this->getClient();
387 $client->request('GET', '/untagged/list');
389 $this->assertSame(200, $client->getResponse()->getStatusCode());
392 public function testStarred()
394 $this->logInAs('admin');
395 $client = $this->getClient();
397 $client->request('GET', '/starred/list');
399 $this->assertSame(200, $client->getResponse()->getStatusCode());
402 public function testRangeException()
404 $this->logInAs('admin');
405 $client = $this->getClient();
407 $client->request('GET', '/all/list/900');
409 $this->assertSame(302, $client->getResponse()->getStatusCode());
410 $this->assertSame('/all/list', $client->getResponse()->getTargetUrl());
413 public function testView()
415 $this->logInAs('admin');
416 $client = $this->getClient();
418 $entry = new Entry($this->getLoggedInUser());
419 $entry->setUrl('http://example.com/foo');
420 $entry->setTitle('title foo');
421 $entry->setContent('foo bar baz');
422 $this->getEntityManager()->persist($entry);
423 $this->getEntityManager()->flush();
425 $crawler = $client->request('GET', '/view/' . $entry->getId());
427 $this->assertSame(200, $client->getResponse()->getStatusCode());
428 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
429 $this->assertContains($entry->getTitle(), $body[0]);
433 * This test will require an internet connection.
435 public function testReload()
437 $this->logInAs('admin');
438 $client = $this->getClient();
440 $entry = new Entry($this->getLoggedInUser());
441 $entry->setUrl($this->url
);
442 $entry->setTitle('title foo');
443 $entry->setContent('');
444 $this->getEntityManager()->persist($entry);
445 $this->getEntityManager()->flush();
446 $this->getEntityManager()->clear();
448 $client->request('GET', '/reload/' . $entry->getId());
450 $this->assertSame(302, $client->getResponse()->getStatusCode());
452 $entry = $this->getEntityManager()
453 ->getRepository('WallabagCoreBundle:Entry')
454 ->find($entry->getId());
456 $this->assertNotEmpty($entry->getContent());
459 public function testReloadWithFetchingFailed()
461 $this->logInAs('admin');
462 $client = $this->getClient();
464 $entry = new Entry($this->getLoggedInUser());
465 $entry->setUrl('http://0.0.0.0/failed.html');
466 $this->getEntityManager()->persist($entry);
467 $this->getEntityManager()->flush();
469 $client->request('GET', '/reload/' . $entry->getId());
471 $this->assertSame(302, $client->getResponse()->getStatusCode());
473 // force EntityManager to clear previous entity
474 // otherwise, retrieve the same entity will retrieve change from the previous request :0
475 $this->getEntityManager()->clear();
476 $newContent = $this->getEntityManager()
477 ->getRepository('WallabagCoreBundle:Entry')
478 ->find($entry->getId());
480 $this->assertNotSame($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent());
483 public function testEdit()
485 $this->logInAs('admin');
486 $client = $this->getClient();
488 $entry = new Entry($this->getLoggedInUser());
489 $entry->setUrl($this->url
);
490 $this->getEntityManager()->persist($entry);
491 $this->getEntityManager()->flush();
493 $crawler = $client->request('GET', '/edit/' . $entry->getId());
495 $this->assertSame(200, $client->getResponse()->getStatusCode());
497 $this->assertCount(1, $crawler->filter('input[id=entry_title]'));
498 $this->assertCount(1, $crawler->filter('button[id=entry_save]'));
501 public function testEditUpdate()
503 $this->logInAs('admin');
504 $client = $this->getClient();
506 $entry = new Entry($this->getLoggedInUser());
507 $entry->setUrl($this->url
);
508 $this->getEntityManager()->persist($entry);
509 $this->getEntityManager()->flush();
511 $crawler = $client->request('GET', '/edit/' . $entry->getId());
513 $this->assertSame(200, $client->getResponse()->getStatusCode());
515 $form = $crawler->filter('button[id=entry_save]')->form();
518 'entry[title]' => 'My updated title hehe :)',
519 'entry[origin_url]' => 'https://example.io',
522 $client->submit($form, $data);
524 $this->assertSame(302, $client->getResponse()->getStatusCode());
526 $crawler = $client->followRedirect();
528 $this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text']));
529 $this->assertContains('My updated title hehe :)', $title[0]);
530 $this->assertGreaterThan(1, $stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']));
531 $this->assertContains('example.io', trim($stats[1]));
534 public function testEditRemoveOriginUrl()
536 $this->logInAs('admin');
537 $client = $this->getClient();
539 $entry = new Entry($this->getLoggedInUser());
540 $entry->setUrl($this->url
);
541 $this->getEntityManager()->persist($entry);
542 $this->getEntityManager()->flush();
544 $crawler = $client->request('GET', '/edit/' . $entry->getId());
546 $this->assertSame(200, $client->getResponse()->getStatusCode());
548 $form = $crawler->filter('button[id=entry_save]')->form();
551 'entry[title]' => 'My updated title hehe :)',
552 'entry[origin_url]' => '',
555 $client->submit($form, $data);
557 $this->assertSame(302, $client->getResponse()->getStatusCode());
559 $crawler = $client->followRedirect();
561 $title = $crawler->filter('div[id=article] h1')->extract(['_text']);
562 $this->assertGreaterThan(1, $title);
563 $this->assertContains('My updated title hehe :)', $title[0]);
565 $stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']);
566 $this->assertCount(1, $stats);
567 $this->assertNotContains('example.io', trim($stats[0]));
570 public function testToggleArchive()
572 $this->logInAs('admin');
573 $client = $this->getClient();
575 $entry = new Entry($this->getLoggedInUser());
576 $entry->setUrl($this->url
);
577 $this->getEntityManager()->persist($entry);
578 $this->getEntityManager()->flush();
579 $this->getEntityManager()->clear();
581 $client->request('GET', '/archive/' . $entry->getId());
583 $this->assertSame(302, $client->getResponse()->getStatusCode());
585 $res = $client->getContainer()
586 ->get('doctrine.orm.entity_manager')
587 ->getRepository('WallabagCoreBundle:Entry')
588 ->find($entry->getId());
590 $this->assertSame(1, $res->isArchived());
593 public function testToggleStar()
595 $this->logInAs('admin');
596 $client = $this->getClient();
598 $entry = new Entry($this->getLoggedInUser());
599 $entry->setUrl($this->url
);
600 $this->getEntityManager()->persist($entry);
601 $this->getEntityManager()->flush();
602 $this->getEntityManager()->clear();
604 $client->request('GET', '/star/' . $entry->getId());
606 $this->assertSame(302, $client->getResponse()->getStatusCode());
608 $res = $client->getContainer()
609 ->get('doctrine.orm.entity_manager')
610 ->getRepository('WallabagCoreBundle:Entry')
611 ->findOneById($entry->getId());
613 $this->assertSame(1, $res->isStarred());
616 public function testDelete()
618 $this->logInAs('admin');
619 $client = $this->getClient();
621 $entry = new Entry($this->getLoggedInUser());
622 $entry->setUrl($this->url
);
623 $this->getEntityManager()->persist($entry);
624 $this->getEntityManager()->flush();
626 $client->request('GET', '/delete/' . $entry->getId());
628 $this->assertSame(302, $client->getResponse()->getStatusCode());
630 $client->request('GET', '/delete/' . $entry->getId());
632 $this->assertSame(404, $client->getResponse()->getStatusCode());
636 * It will create a new entry.
640 * And it'll check that user won't be redirected to the view page of the content when it had been removed
642 public function testViewAndDelete()
644 $this->logInAs('admin');
645 $client = $this->getClient();
647 $em = $client->getContainer()
648 ->get('doctrine.orm.entity_manager');
650 // add a new content to be removed later
652 ->getRepository('WallabagUserBundle:User')
653 ->findOneByUserName('admin');
655 $content = new Entry($user);
656 $content->setUrl('http://1.1.1.1/entry');
657 $content->setReadingTime(12);
658 $content->setDomainName('domain.io');
659 $content->setMimetype('text/html');
660 $content->setTitle('test title entry');
661 $content->setContent('This is my content /o/');
662 $content->updateArchived(true);
663 $content->setLanguage('fr');
665 $em->persist($content);
668 $client->request('GET', '/view/' . $content->getId());
669 $this->assertSame(200, $client->getResponse()->getStatusCode());
671 $client->request('GET', '/delete/' . $content->getId());
672 $this->assertSame(302, $client->getResponse()->getStatusCode());
674 $client->followRedirect();
675 $this->assertSame(200, $client->getResponse()->getStatusCode());
678 public function testViewOtherUserEntry()
680 $this->logInAs('admin');
681 $client = $this->getClient();
683 $content = $client->getContainer()
684 ->get('doctrine.orm.entity_manager')
685 ->getRepository('WallabagCoreBundle:Entry')
686 ->findOneByUsernameAndNotArchived('bob');
688 $client->request('GET', '/view/' . $content->getId());
690 $this->assertSame(403, $client->getResponse()->getStatusCode());
693 public function testFilterOnReadingTime()
695 $this->logInAs('admin');
696 $client = $this->getClient();
697 $entry = new Entry($this->getLoggedInUser());
698 $entry->setUrl($this->url
);
699 $entry->setReadingTime(22);
700 $this->getEntityManager()->persist($entry);
701 $this->getEntityManager()->flush();
703 $crawler = $client->request('GET', '/unread/list');
705 $form = $crawler->filter('button[id=submit-filter]')->form();
708 'entry_filter[readingTime][right_number]' => 22,
709 'entry_filter[readingTime][left_number]' => 22,
712 $crawler = $client->submit($form, $data);
714 $this->assertCount(1, $crawler->filter('li.entry'));
717 public function testFilterOnReadingTimeWithNegativeValue()
719 $this->logInAs('admin');
720 $client = $this->getClient();
722 $crawler = $client->request('GET', '/unread/list');
724 $form = $crawler->filter('button[id=submit-filter]')->form();
727 'entry_filter[readingTime][right_number]' => -22,
728 'entry_filter[readingTime][left_number]' => -22,
731 $crawler = $client->submit($form, $data);
733 // forcing negative value results in no entry displayed
734 $this->assertCount(0, $crawler->filter('li.entry'));
737 public function testFilterOnReadingTimeOnlyUpper()
739 $this->logInAs('admin');
740 $client = $this->getClient();
742 $crawler = $client->request('GET', '/all/list');
743 $this->assertCount(5, $crawler->filter('li.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('li.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('li.entry'));
765 public function testFilterOnReadingTimeOnlyLower()
767 $this->logInAs('admin');
768 $client = $this->getClient();
770 $crawler = $client->request('GET', '/unread/list');
772 $form = $crawler->filter('button[id=submit-filter]')->form();
775 'entry_filter[readingTime][left_number]' => 22,
778 $crawler = $client->submit($form, $data);
780 $this->assertCount(0, $crawler->filter('li.entry'));
782 $entry = new Entry($this->getLoggedInUser());
783 $entry->setUrl($this->url
);
784 $entry->setReadingTime(23);
785 $this->getEntityManager()->persist($entry);
786 $this->getEntityManager()->flush();
788 $crawler = $client->submit($form, $data);
789 $this->assertCount(1, $crawler->filter('li.entry'));
792 public function testFilterOnUnreadStatus()
794 $this->logInAs('admin');
795 $client = $this->getClient();
797 $crawler = $client->request('GET', '/all/list');
799 $form = $crawler->filter('button[id=submit-filter]')->form();
802 'entry_filter[isUnread]' => true,
805 $crawler = $client->submit($form, $data);
807 $this->assertCount(4, $crawler->filter('li.entry'));
809 $entry = new Entry($this->getLoggedInUser());
810 $entry->setUrl($this->url
);
811 $entry->updateArchived(false);
812 $this->getEntityManager()->persist($entry);
813 $this->getEntityManager()->flush();
815 $crawler = $client->submit($form, $data);
817 $this->assertCount(5, $crawler->filter('li.entry'));
820 public function testFilterOnCreationDate()
822 $this->logInAs('admin');
823 $client = $this->getClient();
825 $em = $this->getEntityManager();
827 $today = new \
DateTimeImmutable();
828 $tomorrow = $today->add(new \
DateInterval('P1D'));
829 $yesterday = $today->sub(new \
DateInterval('P1D'));
831 $entry = new Entry($this->getLoggedInUser());
832 $entry->setUrl('http://0.0.0.0/testFilterOnCreationDate');
833 $entry->setCreatedAt($yesterday);
834 $em->persist($entry);
837 $crawler = $client->request('GET', '/unread/list');
839 $form = $crawler->filter('button[id=submit-filter]')->form();
842 'entry_filter[createdAt][left_date]' => $today->format('Y-m-d'),
843 'entry_filter[createdAt][right_date]' => $tomorrow->format('Y-m-d'),
846 $crawler = $client->submit($form, $data);
848 $this->assertCount(5, $crawler->filter('li.entry'));
851 'entry_filter[createdAt][left_date]' => $today->format('Y-m-d'),
852 'entry_filter[createdAt][right_date]' => $today->format('Y-m-d'),
855 $crawler = $client->submit($form, $data);
857 $this->assertCount(5, $crawler->filter('li.entry'));
860 'entry_filter[createdAt][left_date]' => '1970-01-01',
861 'entry_filter[createdAt][right_date]' => '1970-01-01',
864 $crawler = $client->submit($form, $data);
866 $this->assertCount(0, $crawler->filter('li.entry'));
869 public function testPaginationWithFilter()
871 $this->logInAs('admin');
872 $client = $this->getClient();
873 $crawler = $client->request('GET', '/config');
875 $form = $crawler->filter('button[id=config_save]')->form();
878 'config[items_per_page]' => '1',
881 $client->submit($form, $data);
883 $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D=';
885 $client->request('GET', 'unread/list' . $parameters);
887 $this->assertContains($parameters, $client->getResponse()->getContent());
890 $crawler = $client->request('GET', '/config');
891 $form = $crawler->filter('button[id=config_save]')->form();
893 'config[items_per_page]' => '12',
895 $client->submit($form, $data);
898 public function testFilterOnDomainName()
900 $this->logInAs('admin');
901 $client = $this->getClient();
903 $crawler = $client->request('GET', '/unread/list');
904 $form = $crawler->filter('button[id=submit-filter]')->form();
906 'entry_filter[domainName]' => 'domain',
909 $crawler = $client->submit($form, $data);
910 $this->assertCount(5, $crawler->filter('li.entry'));
912 $crawler = $client->request('GET', '/unread/list');
913 $form = $crawler->filter('button[id=submit-filter]')->form();
915 'entry_filter[domainName]' => 'dOmain',
918 $crawler = $client->submit($form, $data);
919 $this->assertCount(5, $crawler->filter('li.entry'));
921 $form = $crawler->filter('button[id=submit-filter]')->form();
923 'entry_filter[domainName]' => 'wallabag',
926 $crawler = $client->submit($form, $data);
927 $this->assertCount(0, $crawler->filter('li.entry'));
930 public function testFilterOnStatus()
932 $this->logInAs('admin');
933 $client = $this->getClient();
935 $crawler = $client->request('GET', '/unread/list');
936 $form = $crawler->filter('button[id=submit-filter]')->form();
937 $form['entry_filter[isArchived]']->tick();
938 $form['entry_filter[isStarred]']->untick();
940 $crawler = $client->submit($form);
941 $this->assertCount(1, $crawler->filter('li.entry'));
943 $form = $crawler->filter('button[id=submit-filter]')->form();
944 $form['entry_filter[isArchived]']->untick();
945 $form['entry_filter[isStarred]']->tick();
947 $crawler = $client->submit($form);
948 $this->assertCount(1, $crawler->filter('li.entry'));
951 public function testFilterOnIsPublic()
953 $this->logInAs('admin');
954 $client = $this->getClient();
956 $crawler = $client->request('GET', '/unread/list');
957 $form = $crawler->filter('button[id=submit-filter]')->form();
958 $form['entry_filter[isPublic]']->tick();
960 $crawler = $client->submit($form);
961 $this->assertCount(0, $crawler->filter('li.entry'));
964 public function testPreviewPictureFilter()
966 $this->logInAs('admin');
967 $client = $this->getClient();
969 $crawler = $client->request('GET', '/unread/list');
970 $form = $crawler->filter('button[id=submit-filter]')->form();
971 $form['entry_filter[previewPicture]']->tick();
973 $crawler = $client->submit($form);
974 $this->assertCount(1, $crawler->filter('li.entry'));
977 public function testFilterOnLanguage()
979 $this->logInAs('admin');
980 $client = $this->getClient();
982 $entry = new Entry($this->getLoggedInUser());
983 $entry->setUrl($this->url
);
984 $entry->setLanguage('fr');
985 $this->getEntityManager()->persist($entry);
986 $this->getEntityManager()->flush();
988 $crawler = $client->request('GET', '/unread/list');
989 $form = $crawler->filter('button[id=submit-filter]')->form();
991 'entry_filter[language]' => 'fr',
994 $crawler = $client->submit($form, $data);
995 $this->assertCount(3, $crawler->filter('li.entry'));
997 $form = $crawler->filter('button[id=submit-filter]')->form();
999 'entry_filter[language]' => 'en',
1002 $crawler = $client->submit($form, $data);
1003 $this->assertCount(2, $crawler->filter('li.entry'));
1006 public function testShareEntryPublicly()
1008 $this->logInAs('admin');
1009 $client = $this->getClient();
1011 // sharing is enabled
1012 $client->getContainer()->get('craue_config')->set('share_public', 1);
1014 $content = new Entry($this->getLoggedInUser());
1015 $content->setUrl($this->url
);
1016 $this->getEntityManager()->persist($content);
1017 $this->getEntityManager()->flush();
1018 $this->getEntityManager()->clear();
1021 $client->request('GET', '/share/' . $content->getUid());
1022 $this->assertSame(404, $client->getResponse()->getStatusCode());
1024 // generating the uid
1025 $client->request('GET', '/share/' . $content->getId());
1026 $this->assertSame(302, $client->getResponse()->getStatusCode());
1028 $shareUrl = $client->getResponse()->getTargetUrl();
1030 // use a new client to have a fresh empty session (instead of a logged one from the previous client)
1033 $client->request('GET', $shareUrl);
1035 $this->assertSame(200, $client->getResponse()->getStatusCode());
1036 $this->assertContains('max-age=25200', $client->getResponse()->headers
->get('cache-control'));
1037 $this->assertContains('public', $client->getResponse()->headers
->get('cache-control'));
1038 $this->assertContains('s-maxage=25200', $client->getResponse()->headers
->get('cache-control'));
1039 $this->assertNotContains('no-cache', $client->getResponse()->headers
->get('cache-control'));
1040 $this->assertContains('og:title', $client->getResponse()->getContent());
1041 $this->assertContains('og:type', $client->getResponse()->getContent());
1042 $this->assertContains('og:url', $client->getResponse()->getContent());
1043 $this->assertContains('og:image', $client->getResponse()->getContent());
1045 // sharing is now disabled
1046 $client->getContainer()->get('craue_config')->set('share_public', 0);
1047 $client->request('GET', '/share/' . $content->getUid());
1048 $this->assertSame(404, $client->getResponse()->getStatusCode());
1050 // removing the share
1051 $client->request('GET', '/share/delete/' . $content->getId());
1052 $this->assertSame(302, $client->getResponse()->getStatusCode());
1054 // share is now disable
1055 $client->request('GET', '/share/' . $content->getUid());
1056 $this->assertSame(404, $client->getResponse()->getStatusCode());
1059 public function testNewEntryWithDownloadImagesEnabled()
1061 $this->downloadImagesEnabled
= true;
1062 $this->logInAs('admin');
1063 $client = $this->getClient();
1065 $url = self
::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE
;
1066 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
1068 $crawler = $client->request('GET', '/new');
1070 $this->assertSame(200, $client->getResponse()->getStatusCode());
1072 $form = $crawler->filter('form[name=entry]')->form();
1075 'entry[url]' => $url,
1078 $client->submit($form, $data);
1080 $this->assertSame(302, $client->getResponse()->getStatusCode());
1082 $em = $client->getContainer()
1083 ->get('doctrine.orm.entity_manager');
1086 ->getRepository('WallabagCoreBundle:Entry')
1087 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1089 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry);
1090 $this->assertSame($url, $entry->getUrl());
1091 $this->assertContains('Judo', $entry->getTitle());
1092 // instead of checking for the filename (which might change) check that the image is now local
1093 $this->assertContains(rtrim($client->getContainer()->getParameter('domain_name'), '/') . '/assets/images/', $entry->getContent());
1095 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1099 * @depends testNewEntryWithDownloadImagesEnabled
1101 public function testRemoveEntryWithDownloadImagesEnabled()
1103 $this->downloadImagesEnabled
= true;
1104 $this->logInAs('admin');
1105 $client = $this->getClient();
1107 $url = self
::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE
;
1108 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
1110 $crawler = $client->request('GET', '/new');
1112 $this->assertSame(200, $client->getResponse()->getStatusCode());
1114 $form = $crawler->filter('form[name=entry]')->form();
1117 'entry[url]' => $url,
1120 $client->submit($form, $data);
1122 $this->assertSame(302, $client->getResponse()->getStatusCode());
1124 $content = $client->getContainer()
1125 ->get('doctrine.orm.entity_manager')
1126 ->getRepository('WallabagCoreBundle:Entry')
1127 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1129 $client->request('GET', '/delete/' . $content->getId());
1131 $this->assertSame(302, $client->getResponse()->getStatusCode());
1133 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1136 public function testRedirectToHomepage()
1138 $this->logInAs('empty');
1139 $client = $this->getClient();
1141 // Redirect to homepage
1142 $config = $this->getLoggedInUser()->getConfig();
1143 $config->setActionMarkAsRead(Config
::REDIRECT_TO_HOMEPAGE
);
1144 $this->getEntityManager()->persist($config);
1146 $entry = new Entry($this->getLoggedInUser());
1147 $entry->setUrl($this->url
);
1148 $this->getEntityManager()->persist($entry);
1150 $this->getEntityManager()->flush();
1152 $client->request('GET', '/view/' . $entry->getId());
1153 $client->request('GET', '/archive/' . $entry->getId());
1155 $this->assertSame(302, $client->getResponse()->getStatusCode());
1156 $this->assertSame('/', $client->getResponse()->headers
->get('location'));
1159 public function testRedirectToCurrentPage()
1161 $this->logInAs('empty');
1162 $client = $this->getClient();
1164 // Redirect to current page
1165 $config = $this->getLoggedInUser()->getConfig();
1166 $config->setActionMarkAsRead(Config
::REDIRECT_TO_CURRENT_PAGE
);
1167 $this->getEntityManager()->persist($config);
1169 $entry = new Entry($this->getLoggedInUser());
1170 $entry->setUrl($this->url
);
1171 $this->getEntityManager()->persist($entry);
1173 $this->getEntityManager()->flush();
1175 $client->request('GET', '/view/' . $entry->getId());
1176 $client->request('GET', '/archive/' . $entry->getId());
1178 $this->assertSame(302, $client->getResponse()->getStatusCode());
1179 $this->assertContains('/view/' . $entry->getId(), $client->getResponse()->headers
->get('location'));
1182 public function testFilterOnHttpStatus()
1184 $this->logInAs('admin');
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('li.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('li.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('li.entry'));
1240 public function testSearch()
1242 $this->logInAs('admin');
1243 $client = $this->getClient();
1245 $entry = new Entry($this->getLoggedInUser());
1246 $entry->setUrl($this->url
);
1247 $entry->setTitle('test');
1248 $this->getEntityManager()->persist($entry);
1249 $this->getEntityManager()->flush();
1251 // Search on unread list
1252 $crawler = $client->request('GET', '/unread/list');
1254 $form = $crawler->filter('form[name=search]')->form();
1256 'search_entry[term]' => 'title',
1259 $crawler = $client->submit($form, $data);
1261 $this->assertCount(4, $crawler->filter('li.entry'));
1263 // Search on starred list
1264 $crawler = $client->request('GET', '/starred/list');
1266 $entry = new Entry($this->getLoggedInUser());
1267 $entry->setUrl('http://localhost/foo/bar');
1268 $entry->setTitle('testeur');
1269 $entry->setStarred(true);
1270 $this->getEntityManager()->persist($entry);
1271 $this->getEntityManager()->flush();
1273 $form = $crawler->filter('form[name=search]')->form();
1275 'search_entry[term]' => 'testeur',
1278 $crawler = $client->submit($form, $data);
1280 $this->assertCount(1, $crawler->filter('li.entry'));
1282 $crawler = $client->request('GET', '/archive/list');
1284 // Added new article to test on archive list
1285 $entry = new Entry($this->getLoggedInUser());
1286 $entry->setUrl('http://0.0.0.0/foo/baz/qux');
1287 $entry->setTitle('Le manège');
1288 $entry->updateArchived(true);
1289 $this->getEntityManager()->persist($entry);
1290 $this->getEntityManager()->flush();
1292 $form = $crawler->filter('form[name=search]')->form();
1294 'search_entry[term]' => 'manège',
1297 $crawler = $client->submit($form, $data);
1299 $this->assertCount(1, $crawler->filter('li.entry'));
1300 $client->request('GET', '/delete/' . $entry->getId());
1302 // test on list of all articles
1303 $crawler = $client->request('GET', '/all/list');
1305 $form = $crawler->filter('form[name=search]')->form();
1307 'search_entry[term]' => 'wxcvbnqsdf', // a string not available in the database
1310 $crawler = $client->submit($form, $data);
1312 $this->assertCount(0, $crawler->filter('li.entry'));
1314 // test url search on list of all articles
1315 $entry = new Entry($this->getLoggedInUser());
1316 $entry->setUrl('http://domain/qux');
1317 $entry->setTitle('Le manège');
1318 $entry->updateArchived(true);
1319 $this->getEntityManager()->persist($entry);
1320 $this->getEntityManager()->flush();
1322 $crawler = $client->request('GET', '/all/list');
1324 $form = $crawler->filter('form[name=search]')->form();
1326 'search_entry[term]' => 'domain', // the search will match an entry with 'domain' in its url
1329 $crawler = $client->submit($form, $data);
1331 $this->assertCount(1, $crawler->filter('li.entry'));
1333 // same as previous test but for case-sensitivity
1334 $crawler = $client->request('GET', '/all/list');
1336 $form = $crawler->filter('form[name=search]')->form();
1338 'search_entry[term]' => 'doMain', // the search will match an entry with 'domain' in its url
1341 $crawler = $client->submit($form, $data);
1343 $this->assertCount(1, $crawler->filter('li.entry'));
1346 public function dataForLanguage()
1350 'https://www.pravda.ru/world/09-06-2017/1337283-qatar-0/',
1354 'https://fr.wikipedia.org/wiki/Wallabag',
1358 'https://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html',
1362 'http://www.ansa.it/sito/notizie/mondo/europa/2017/06/08/voto-gb-seggi-aperti-misure-sicurezza-rafforzate_0cb71f7f-e23b-4d5f-95ca-bc12296419f0.html',
1366 'http://www.hao123.com/shequ?__noscript__-=1',
1370 'https://politica.estadao.com.br/noticias/eleicoes,campanha-catatonica,70002491983',
1373 'fucked_list_of_languages' => [
1374 'http://geocatalog.webservice-energy.org/geonetwork/srv/eng/main.home',
1378 'https://www.20minutos.es/noticia/3360685/0/gobierno-sanchez-primero-historia-mas-mujeres-que-hombres/',
1385 * @dataProvider dataForLanguage
1387 public function testLanguageValidation($url, $expectedLanguage)
1389 $this->logInAs('admin');
1390 $client = $this->getClient();
1392 $crawler = $client->request('GET', '/new');
1394 $this->assertSame(200, $client->getResponse()->getStatusCode());
1396 $form = $crawler->filter('form[name=entry]')->form();
1399 'entry[url]' => $url,
1402 $client->submit($form, $data);
1404 $this->assertSame(302, $client->getResponse()->getStatusCode());
1406 $content = $client->getContainer()
1407 ->get('doctrine.orm.entity_manager')
1408 ->getRepository('WallabagCoreBundle:Entry')
1409 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1411 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1412 $this->assertSame($url, $content->getUrl());
1413 $this->assertSame($expectedLanguage, $content->getLanguage());
1417 * This test will require an internet connection.
1419 public function testRestrictedArticle()
1421 $url = 'https://www.monde-diplomatique.fr/2017/05/BONNET/57475';
1422 $this->logInAs('admin');
1423 $client = $this->getClient();
1424 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
1426 // enable restricted access
1427 $client->getContainer()->get('craue_config')->set('restricted_access', 1);
1429 // create a new site_credential
1430 $user = $client->getContainer()->get('security.token_storage')->getToken()->getUser();
1431 $credential = new SiteCredential($user);
1432 $credential->setHost('monde-diplomatique.fr');
1433 $credential->setUsername($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('foo'));
1434 $credential->setPassword($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('bar'));
1436 $em->persist($credential);
1439 $crawler = $client->request('GET', '/new');
1441 $this->assertSame(200, $client->getResponse()->getStatusCode());
1443 $form = $crawler->filter('form[name=entry]')->form();
1446 'entry[url]' => $url,
1449 $client->submit($form, $data);
1451 $this->assertSame(302, $client->getResponse()->getStatusCode());
1453 $crawler = $client->followRedirect();
1455 $this->assertSame(200, $client->getResponse()->getStatusCode());
1456 $this->assertContains('flashes.entry.notice.entry_saved', $crawler->filter('body')->extract(['_text'])[0]);
1459 ->getRepository('WallabagCoreBundle:Entry')
1460 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1462 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1463 $this->assertSame('Crimes et réformes aux Philippines', $content->getTitle());
1465 $client->getContainer()->get('craue_config')->set('restricted_access', 0);
1468 public function testPostEntryWhenFetchFails()
1470 $url = 'http://example.com/papers/email_tracking.pdf';
1471 $this->logInAs('admin');
1472 $client = $this->getClient();
1474 $container = $client->getContainer();
1475 $contentProxy = $this->getMockBuilder(ContentProxy
::class)
1476 ->disableOriginalConstructor()
1477 ->setMethods(['updateEntry'])
1479 $contentProxy->expects($this->any())
1480 ->method('updateEntry')
1481 ->willThrowException(new \
Exception('Test Fetch content fails'));
1483 $crawler = $client->request('GET', '/new');
1485 $this->assertSame(200, $client->getResponse()->getStatusCode());
1487 $form = $crawler->filter('form[name=entry]')->form();
1490 'entry[url]' => $url,
1494 * We generate a new client to be able to use Mock ContentProxy
1495 * Also we reinject the cookie from the previous client to keep the
1498 $cookie = $client->getCookieJar()->all();
1499 $client = $this->getNewClient();
1500 $client->getCookieJar()->set($cookie[0]);
1501 $client->getContainer()->set('wallabag_core.content_proxy', $contentProxy);
1502 $client->submit($form, $data);
1504 $this->assertSame(302, $client->getResponse()->getStatusCode());
1506 $content = $client->getContainer()
1507 ->get('doctrine.orm.entity_manager')
1508 ->getRepository('WallabagCoreBundle:Entry')
1509 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1511 $authors = $content->getPublishedBy();
1512 $this->assertSame('email_tracking.pdf', $content->getTitle());
1513 $this->assertSame('example.com', $content->getDomainName());
1516 public function testEntryDeleteTagLink()
1518 $this->logInAs('admin');
1519 $client = $this->getClient();
1521 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
1522 $entry = $em->getRepository('WallabagCoreBundle:Entry')->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId());
1523 $tag = $entry->getTags()[0];
1525 $crawler = $client->request('GET', '/view/' . $entry->getId());
1527 // As long as the deletion link of a tag is following
1528 // a link to the tag view, we take the second one to retrieve
1529 // the deletion link of the first tag
1530 $link = $crawler->filter('body div#article div.tools ul.tags li.chip a')->extract('href')[1];
1532 $this->assertSame(sprintf('/remove-tag/%s/%s', $entry->getId(), $tag->getId()), $link);
1535 public function testRandom()
1537 $this->logInAs('admin');
1538 $client = $this->getClient();
1540 $client->request('GET', '/unread/random');
1541 $this->assertSame(302, $client->getResponse()->getStatusCode());
1542 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Unread random');
1544 $client->request('GET', '/starred/random');
1545 $this->assertSame(302, $client->getResponse()->getStatusCode());
1546 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Starred random');
1548 $client->request('GET', '/archive/random');
1549 $this->assertSame(302, $client->getResponse()->getStatusCode());
1550 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Archive random');
1552 $client->request('GET', '/untagged/random');
1553 $this->assertSame(302, $client->getResponse()->getStatusCode());
1554 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Untagged random');
1556 $client->request('GET', '/all/random');
1557 $this->assertSame(302, $client->getResponse()->getStatusCode());
1558 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'All random');