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 $crawler = $client->request('GET', '/unread/list');
827 $form = $crawler->filter('button[id=submit-filter]')->form();
830 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
831 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')),
834 $crawler = $client->submit($form, $data);
836 $this->assertCount(5, $crawler->filter('li.entry'));
839 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
840 'entry_filter[createdAt][right_date]' => date('d/m/Y'),
843 $crawler = $client->submit($form, $data);
845 $this->assertCount(5, $crawler->filter('li.entry'));
848 'entry_filter[createdAt][left_date]' => '01/01/1970',
849 'entry_filter[createdAt][right_date]' => '01/01/1970',
852 $crawler = $client->submit($form, $data);
854 $this->assertCount(0, $crawler->filter('li.entry'));
857 public function testPaginationWithFilter()
859 $this->logInAs('admin');
860 $client = $this->getClient();
861 $crawler = $client->request('GET', '/config');
863 $form = $crawler->filter('button[id=config_save]')->form();
866 'config[items_per_page]' => '1',
869 $client->submit($form, $data);
871 $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D=';
873 $client->request('GET', 'unread/list' . $parameters);
875 $this->assertContains($parameters, $client->getResponse()->getContent());
878 $crawler = $client->request('GET', '/config');
879 $form = $crawler->filter('button[id=config_save]')->form();
881 'config[items_per_page]' => '12',
883 $client->submit($form, $data);
886 public function testFilterOnDomainName()
888 $this->logInAs('admin');
889 $client = $this->getClient();
891 $crawler = $client->request('GET', '/unread/list');
892 $form = $crawler->filter('button[id=submit-filter]')->form();
894 'entry_filter[domainName]' => 'domain',
897 $crawler = $client->submit($form, $data);
898 $this->assertCount(5, $crawler->filter('li.entry'));
900 $crawler = $client->request('GET', '/unread/list');
901 $form = $crawler->filter('button[id=submit-filter]')->form();
903 'entry_filter[domainName]' => 'dOmain',
906 $crawler = $client->submit($form, $data);
907 $this->assertCount(5, $crawler->filter('li.entry'));
909 $form = $crawler->filter('button[id=submit-filter]')->form();
911 'entry_filter[domainName]' => 'wallabag',
914 $crawler = $client->submit($form, $data);
915 $this->assertCount(0, $crawler->filter('li.entry'));
918 public function testFilterOnStatus()
920 $this->logInAs('admin');
921 $client = $this->getClient();
923 $crawler = $client->request('GET', '/unread/list');
924 $form = $crawler->filter('button[id=submit-filter]')->form();
925 $form['entry_filter[isArchived]']->tick();
926 $form['entry_filter[isStarred]']->untick();
928 $crawler = $client->submit($form);
929 $this->assertCount(1, $crawler->filter('li.entry'));
931 $form = $crawler->filter('button[id=submit-filter]')->form();
932 $form['entry_filter[isArchived]']->untick();
933 $form['entry_filter[isStarred]']->tick();
935 $crawler = $client->submit($form);
936 $this->assertCount(1, $crawler->filter('li.entry'));
939 public function testFilterOnIsPublic()
941 $this->logInAs('admin');
942 $client = $this->getClient();
944 $crawler = $client->request('GET', '/unread/list');
945 $form = $crawler->filter('button[id=submit-filter]')->form();
946 $form['entry_filter[isPublic]']->tick();
948 $crawler = $client->submit($form);
949 $this->assertCount(0, $crawler->filter('li.entry'));
952 public function testPreviewPictureFilter()
954 $this->logInAs('admin');
955 $client = $this->getClient();
957 $crawler = $client->request('GET', '/unread/list');
958 $form = $crawler->filter('button[id=submit-filter]')->form();
959 $form['entry_filter[previewPicture]']->tick();
961 $crawler = $client->submit($form);
962 $this->assertCount(1, $crawler->filter('li.entry'));
965 public function testFilterOnLanguage()
967 $this->logInAs('admin');
968 $client = $this->getClient();
970 $entry = new Entry($this->getLoggedInUser());
971 $entry->setUrl($this->url
);
972 $entry->setLanguage('fr');
973 $this->getEntityManager()->persist($entry);
974 $this->getEntityManager()->flush();
976 $crawler = $client->request('GET', '/unread/list');
977 $form = $crawler->filter('button[id=submit-filter]')->form();
979 'entry_filter[language]' => 'fr',
982 $crawler = $client->submit($form, $data);
983 $this->assertCount(3, $crawler->filter('li.entry'));
985 $form = $crawler->filter('button[id=submit-filter]')->form();
987 'entry_filter[language]' => 'en',
990 $crawler = $client->submit($form, $data);
991 $this->assertCount(2, $crawler->filter('li.entry'));
994 public function testShareEntryPublicly()
996 $this->logInAs('admin');
997 $client = $this->getClient();
999 // sharing is enabled
1000 $client->getContainer()->get('craue_config')->set('share_public', 1);
1002 $content = new Entry($this->getLoggedInUser());
1003 $content->setUrl($this->url
);
1004 $this->getEntityManager()->persist($content);
1005 $this->getEntityManager()->flush();
1006 $this->getEntityManager()->clear();
1009 $client->request('GET', '/share/' . $content->getUid());
1010 $this->assertSame(404, $client->getResponse()->getStatusCode());
1012 // generating the uid
1013 $client->request('GET', '/share/' . $content->getId());
1014 $this->assertSame(302, $client->getResponse()->getStatusCode());
1016 $shareUrl = $client->getResponse()->getTargetUrl();
1018 // use a new client to have a fresh empty session (instead of a logged one from the previous client)
1021 $client->request('GET', $shareUrl);
1023 $this->assertSame(200, $client->getResponse()->getStatusCode());
1024 $this->assertContains('max-age=25200', $client->getResponse()->headers
->get('cache-control'));
1025 $this->assertContains('public', $client->getResponse()->headers
->get('cache-control'));
1026 $this->assertContains('s-maxage=25200', $client->getResponse()->headers
->get('cache-control'));
1027 $this->assertNotContains('no-cache', $client->getResponse()->headers
->get('cache-control'));
1028 $this->assertContains('og:title', $client->getResponse()->getContent());
1029 $this->assertContains('og:type', $client->getResponse()->getContent());
1030 $this->assertContains('og:url', $client->getResponse()->getContent());
1031 $this->assertContains('og:image', $client->getResponse()->getContent());
1033 // sharing is now disabled
1034 $client->getContainer()->get('craue_config')->set('share_public', 0);
1035 $client->request('GET', '/share/' . $content->getUid());
1036 $this->assertSame(404, $client->getResponse()->getStatusCode());
1038 // removing the share
1039 $client->request('GET', '/share/delete/' . $content->getId());
1040 $this->assertSame(302, $client->getResponse()->getStatusCode());
1042 // share is now disable
1043 $client->request('GET', '/share/' . $content->getUid());
1044 $this->assertSame(404, $client->getResponse()->getStatusCode());
1047 public function testNewEntryWithDownloadImagesEnabled()
1049 $this->downloadImagesEnabled
= true;
1050 $this->logInAs('admin');
1051 $client = $this->getClient();
1053 $url = self
::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE
;
1054 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
1056 $crawler = $client->request('GET', '/new');
1058 $this->assertSame(200, $client->getResponse()->getStatusCode());
1060 $form = $crawler->filter('form[name=entry]')->form();
1063 'entry[url]' => $url,
1066 $client->submit($form, $data);
1068 $this->assertSame(302, $client->getResponse()->getStatusCode());
1070 $em = $client->getContainer()
1071 ->get('doctrine.orm.entity_manager');
1074 ->getRepository('WallabagCoreBundle:Entry')
1075 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1077 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry);
1078 $this->assertSame($url, $entry->getUrl());
1079 $this->assertContains('Judo', $entry->getTitle());
1080 // instead of checking for the filename (which might change) check that the image is now local
1081 $this->assertContains(rtrim($client->getContainer()->getParameter('domain_name'), '/') . '/assets/images/', $entry->getContent());
1083 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1087 * @depends testNewEntryWithDownloadImagesEnabled
1089 public function testRemoveEntryWithDownloadImagesEnabled()
1091 $this->downloadImagesEnabled
= true;
1092 $this->logInAs('admin');
1093 $client = $this->getClient();
1095 $url = self
::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE
;
1096 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
1098 $crawler = $client->request('GET', '/new');
1100 $this->assertSame(200, $client->getResponse()->getStatusCode());
1102 $form = $crawler->filter('form[name=entry]')->form();
1105 'entry[url]' => $url,
1108 $client->submit($form, $data);
1110 $this->assertSame(302, $client->getResponse()->getStatusCode());
1112 $content = $client->getContainer()
1113 ->get('doctrine.orm.entity_manager')
1114 ->getRepository('WallabagCoreBundle:Entry')
1115 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1117 $client->request('GET', '/delete/' . $content->getId());
1119 $this->assertSame(302, $client->getResponse()->getStatusCode());
1121 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1124 public function testRedirectToHomepage()
1126 $this->logInAs('empty');
1127 $client = $this->getClient();
1129 // Redirect to homepage
1130 $config = $this->getLoggedInUser()->getConfig();
1131 $config->setActionMarkAsRead(Config
::REDIRECT_TO_HOMEPAGE
);
1132 $this->getEntityManager()->persist($config);
1134 $entry = new Entry($this->getLoggedInUser());
1135 $entry->setUrl($this->url
);
1136 $this->getEntityManager()->persist($entry);
1138 $this->getEntityManager()->flush();
1140 $client->request('GET', '/view/' . $entry->getId());
1141 $client->request('GET', '/archive/' . $entry->getId());
1143 $this->assertSame(302, $client->getResponse()->getStatusCode());
1144 $this->assertSame('/', $client->getResponse()->headers
->get('location'));
1147 public function testRedirectToCurrentPage()
1149 $this->logInAs('empty');
1150 $client = $this->getClient();
1152 // Redirect to current page
1153 $config = $this->getLoggedInUser()->getConfig();
1154 $config->setActionMarkAsRead(Config
::REDIRECT_TO_CURRENT_PAGE
);
1155 $this->getEntityManager()->persist($config);
1157 $entry = new Entry($this->getLoggedInUser());
1158 $entry->setUrl($this->url
);
1159 $this->getEntityManager()->persist($entry);
1161 $this->getEntityManager()->flush();
1163 $client->request('GET', '/view/' . $entry->getId());
1164 $client->request('GET', '/archive/' . $entry->getId());
1166 $this->assertSame(302, $client->getResponse()->getStatusCode());
1167 $this->assertContains('/view/' . $entry->getId(), $client->getResponse()->headers
->get('location'));
1170 public function testFilterOnHttpStatus()
1172 $this->logInAs('admin');
1173 $client = $this->getClient();
1175 $entry = new Entry($this->getLoggedInUser());
1176 $entry->setUrl('https://www.lemonde.fr/incorrect-url/');
1177 $entry->setHttpStatus(404);
1178 $this->getEntityManager()->persist($entry);
1180 $this->getEntityManager()->flush();
1182 $crawler = $client->request('GET', '/all/list');
1183 $form = $crawler->filter('button[id=submit-filter]')->form();
1186 'entry_filter[httpStatus]' => 404,
1189 $crawler = $client->submit($form, $data);
1191 $this->assertCount(1, $crawler->filter('li.entry'));
1193 $entry = new Entry($this->getLoggedInUser());
1194 $entry->setUrl($this->url
);
1195 $entry->setHttpStatus(200);
1196 $this->getEntityManager()->persist($entry);
1198 $entry = new Entry($this->getLoggedInUser());
1199 $entry->setUrl('http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm');
1200 $entry->setHttpStatus(200);
1201 $this->getEntityManager()->persist($entry);
1203 $this->getEntityManager()->flush();
1205 $crawler = $client->request('GET', '/all/list');
1206 $form = $crawler->filter('button[id=submit-filter]')->form();
1209 'entry_filter[httpStatus]' => 200,
1212 $crawler = $client->submit($form, $data);
1214 $this->assertCount(2, $crawler->filter('li.entry'));
1216 $crawler = $client->request('GET', '/all/list');
1217 $form = $crawler->filter('button[id=submit-filter]')->form();
1220 'entry_filter[httpStatus]' => 1024,
1223 $crawler = $client->submit($form, $data);
1225 $this->assertCount(8, $crawler->filter('li.entry'));
1228 public function testSearch()
1230 $this->logInAs('admin');
1231 $client = $this->getClient();
1233 $entry = new Entry($this->getLoggedInUser());
1234 $entry->setUrl($this->url
);
1235 $entry->setTitle('test');
1236 $this->getEntityManager()->persist($entry);
1237 $this->getEntityManager()->flush();
1239 // Search on unread list
1240 $crawler = $client->request('GET', '/unread/list');
1242 $form = $crawler->filter('form[name=search]')->form();
1244 'search_entry[term]' => 'title',
1247 $crawler = $client->submit($form, $data);
1249 $this->assertCount(4, $crawler->filter('li.entry'));
1251 // Search on starred list
1252 $crawler = $client->request('GET', '/starred/list');
1254 $entry = new Entry($this->getLoggedInUser());
1255 $entry->setUrl('http://localhost/foo/bar');
1256 $entry->setTitle('testeur');
1257 $entry->setStarred(true);
1258 $this->getEntityManager()->persist($entry);
1259 $this->getEntityManager()->flush();
1261 $form = $crawler->filter('form[name=search]')->form();
1263 'search_entry[term]' => 'testeur',
1266 $crawler = $client->submit($form, $data);
1268 $this->assertCount(1, $crawler->filter('li.entry'));
1270 $crawler = $client->request('GET', '/archive/list');
1272 // Added new article to test on archive list
1273 $entry = new Entry($this->getLoggedInUser());
1274 $entry->setUrl('http://0.0.0.0/foo/baz/qux');
1275 $entry->setTitle('Le manège');
1276 $entry->updateArchived(true);
1277 $this->getEntityManager()->persist($entry);
1278 $this->getEntityManager()->flush();
1280 $form = $crawler->filter('form[name=search]')->form();
1282 'search_entry[term]' => 'manège',
1285 $crawler = $client->submit($form, $data);
1287 $this->assertCount(1, $crawler->filter('li.entry'));
1288 $client->request('GET', '/delete/' . $entry->getId());
1290 // test on list of all articles
1291 $crawler = $client->request('GET', '/all/list');
1293 $form = $crawler->filter('form[name=search]')->form();
1295 'search_entry[term]' => 'wxcvbnqsdf', // a string not available in the database
1298 $crawler = $client->submit($form, $data);
1300 $this->assertCount(0, $crawler->filter('li.entry'));
1302 // test url search on list of all articles
1303 $entry = new Entry($this->getLoggedInUser());
1304 $entry->setUrl('http://domain/qux');
1305 $entry->setTitle('Le manège');
1306 $entry->updateArchived(true);
1307 $this->getEntityManager()->persist($entry);
1308 $this->getEntityManager()->flush();
1310 $crawler = $client->request('GET', '/all/list');
1312 $form = $crawler->filter('form[name=search]')->form();
1314 'search_entry[term]' => 'domain', // the search will match an entry with 'domain' in its url
1317 $crawler = $client->submit($form, $data);
1319 $this->assertCount(1, $crawler->filter('li.entry'));
1321 // same as previous test but for case-sensitivity
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'));
1334 public function dataForLanguage()
1338 'https://www.pravda.ru/world/09-06-2017/1337283-qatar-0/',
1342 'https://fr.wikipedia.org/wiki/Wallabag',
1346 'https://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html',
1350 'http://www.ansa.it/sito/notizie/mondo/europa/2017/06/08/voto-gb-seggi-aperti-misure-sicurezza-rafforzate_0cb71f7f-e23b-4d5f-95ca-bc12296419f0.html',
1354 'http://www.hao123.com/shequ?__noscript__-=1',
1358 'https://politica.estadao.com.br/noticias/eleicoes,campanha-catatonica,70002491983',
1361 'fucked_list_of_languages' => [
1362 'http://geocatalog.webservice-energy.org/geonetwork/srv/eng/main.home',
1366 'https://www.20minutos.es/noticia/3360685/0/gobierno-sanchez-primero-historia-mas-mujeres-que-hombres/',
1373 * @dataProvider dataForLanguage
1375 public function testLanguageValidation($url, $expectedLanguage)
1377 $this->logInAs('admin');
1378 $client = $this->getClient();
1380 $crawler = $client->request('GET', '/new');
1382 $this->assertSame(200, $client->getResponse()->getStatusCode());
1384 $form = $crawler->filter('form[name=entry]')->form();
1387 'entry[url]' => $url,
1390 $client->submit($form, $data);
1392 $this->assertSame(302, $client->getResponse()->getStatusCode());
1394 $content = $client->getContainer()
1395 ->get('doctrine.orm.entity_manager')
1396 ->getRepository('WallabagCoreBundle:Entry')
1397 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1399 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1400 $this->assertSame($url, $content->getUrl());
1401 $this->assertSame($expectedLanguage, $content->getLanguage());
1405 * This test will require an internet connection.
1407 public function testRestrictedArticle()
1409 $url = 'https://www.monde-diplomatique.fr/2017/05/BONNET/57475';
1410 $this->logInAs('admin');
1411 $client = $this->getClient();
1412 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
1414 // enable restricted access
1415 $client->getContainer()->get('craue_config')->set('restricted_access', 1);
1417 // create a new site_credential
1418 $user = $client->getContainer()->get('security.token_storage')->getToken()->getUser();
1419 $credential = new SiteCredential($user);
1420 $credential->setHost('monde-diplomatique.fr');
1421 $credential->setUsername($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('foo'));
1422 $credential->setPassword($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('bar'));
1424 $em->persist($credential);
1427 $crawler = $client->request('GET', '/new');
1429 $this->assertSame(200, $client->getResponse()->getStatusCode());
1431 $form = $crawler->filter('form[name=entry]')->form();
1434 'entry[url]' => $url,
1437 $client->submit($form, $data);
1439 $this->assertSame(302, $client->getResponse()->getStatusCode());
1441 $crawler = $client->followRedirect();
1443 $this->assertSame(200, $client->getResponse()->getStatusCode());
1444 $this->assertContains('flashes.entry.notice.entry_saved', $crawler->filter('body')->extract(['_text'])[0]);
1447 ->getRepository('WallabagCoreBundle:Entry')
1448 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1450 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1451 $this->assertSame('Crimes et réformes aux Philippines', $content->getTitle());
1453 $client->getContainer()->get('craue_config')->set('restricted_access', 0);
1456 public function testPostEntryWhenFetchFails()
1458 $url = 'http://example.com/papers/email_tracking.pdf';
1459 $this->logInAs('admin');
1460 $client = $this->getClient();
1462 $container = $client->getContainer();
1463 $contentProxy = $this->getMockBuilder(ContentProxy
::class)
1464 ->disableOriginalConstructor()
1465 ->setMethods(['updateEntry'])
1467 $contentProxy->expects($this->any())
1468 ->method('updateEntry')
1469 ->willThrowException(new \
Exception('Test Fetch content fails'));
1471 $crawler = $client->request('GET', '/new');
1473 $this->assertSame(200, $client->getResponse()->getStatusCode());
1475 $form = $crawler->filter('form[name=entry]')->form();
1478 'entry[url]' => $url,
1482 * We generate a new client to be able to use Mock ContentProxy
1483 * Also we reinject the cookie from the previous client to keep the
1486 $cookie = $client->getCookieJar()->all();
1487 $client = $this->getNewClient();
1488 $client->getCookieJar()->set($cookie[0]);
1489 $client->getContainer()->set('wallabag_core.content_proxy', $contentProxy);
1490 $client->submit($form, $data);
1492 $this->assertSame(302, $client->getResponse()->getStatusCode());
1494 $content = $client->getContainer()
1495 ->get('doctrine.orm.entity_manager')
1496 ->getRepository('WallabagCoreBundle:Entry')
1497 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1499 $authors = $content->getPublishedBy();
1500 $this->assertSame('email_tracking.pdf', $content->getTitle());
1501 $this->assertSame('example.com', $content->getDomainName());
1504 public function testEntryDeleteTagLink()
1506 $this->logInAs('admin');
1507 $client = $this->getClient();
1509 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
1510 $entry = $em->getRepository('WallabagCoreBundle:Entry')->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId());
1511 $tag = $entry->getTags()[0];
1513 $crawler = $client->request('GET', '/view/' . $entry->getId());
1515 // As long as the deletion link of a tag is following
1516 // a link to the tag view, we take the second one to retrieve
1517 // the deletion link of the first tag
1518 $link = $crawler->filter('body div#article div.tools ul.tags li.chip a')->extract('href')[1];
1520 $this->assertSame(sprintf('/remove-tag/%s/%s', $entry->getId(), $tag->getId()), $link);
1523 public function testRandom()
1525 $this->logInAs('admin');
1526 $client = $this->getClient();
1528 $client->request('GET', '/unread/random');
1529 $this->assertSame(302, $client->getResponse()->getStatusCode());
1530 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Unread random');
1532 $client->request('GET', '/starred/random');
1533 $this->assertSame(302, $client->getResponse()->getStatusCode());
1534 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Starred random');
1536 $client->request('GET', '/archive/random');
1537 $this->assertSame(302, $client->getResponse()->getStatusCode());
1538 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Archive random');
1540 $client->request('GET', '/untagged/random');
1541 $this->assertSame(302, $client->getResponse()->getStatusCode());
1542 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Untagged random');
1544 $client->request('GET', '/all/random');
1545 $this->assertSame(302, $client->getResponse()->getStatusCode());
1546 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'All random');