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 testPostNewViaBookmarklet()
78 $this->logInAs('admin');
79 $client = $this->getClient();
81 $crawler = $client->request('GET', '/');
83 $this->assertCount(4, $crawler->filter('li.entry'));
86 $client->request('GET', '/bookmarklet', ['url' => $this->url
]);
87 $this->assertSame(302, $client->getResponse()->getStatusCode());
88 $client->followRedirect();
89 $crawler = $client->request('GET', '/');
90 $this->assertCount(5, $crawler->filter('li.entry'));
92 $em = $client->getContainer()
93 ->get('doctrine.orm.entity_manager');
95 ->getRepository('WallabagCoreBundle:Entry')
96 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
101 public function testPostNewEmpty()
103 $this->logInAs('admin');
104 $client = $this->getClient();
106 $crawler = $client->request('GET', '/new');
108 $this->assertSame(200, $client->getResponse()->getStatusCode());
110 $form = $crawler->filter('form[name=entry]')->form();
112 $crawler = $client->submit($form);
114 $this->assertSame(200, $client->getResponse()->getStatusCode());
115 $this->assertCount(1, $alert = $crawler->filter('form ul li')->extract(['_text']));
116 $this->assertSame('This value should not be blank.', $alert[0]);
120 * This test will require an internet connection.
122 public function testPostNewOk()
124 $this->logInAs('admin');
125 $client = $this->getClient();
127 $client->getContainer()->get('craue_config')->set('store_article_headers', 1);
129 $crawler = $client->request('GET', '/new');
131 $this->assertSame(200, $client->getResponse()->getStatusCode());
133 $form = $crawler->filter('form[name=entry]')->form();
136 'entry[url]' => $this->url
,
139 $client->submit($form, $data);
141 $this->assertSame(302, $client->getResponse()->getStatusCode());
143 $content = $client->getContainer()
144 ->get('doctrine.orm.entity_manager')
145 ->getRepository('WallabagCoreBundle:Entry')
146 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
148 $author = $content->getPublishedBy();
150 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
151 $this->assertSame($this->url
, $content->getUrl());
152 $this->assertContains('la cryptomonnaie de Facebook', $content->getTitle());
153 $this->assertSame('fr', $content->getLanguage());
154 $this->assertArrayHasKey('x-frame-options', $content->getHeaders());
155 $client->getContainer()->get('craue_config')->set('store_article_headers', 0);
158 public function testPostWithMultipleAuthors()
160 $url = 'https://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768';
161 $this->logInAs('admin');
162 $client = $this->getClient();
164 $crawler = $client->request('GET', '/new');
166 $this->assertSame(200, $client->getResponse()->getStatusCode());
168 $form = $crawler->filter('form[name=entry]')->form();
171 'entry[url]' => $url,
174 $client->submit($form, $data);
176 $this->assertSame(302, $client->getResponse()->getStatusCode());
178 $content = $client->getContainer()
179 ->get('doctrine.orm.entity_manager')
180 ->getRepository('WallabagCoreBundle:Entry')
181 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
183 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
184 $authors = $content->getPublishedBy();
185 $this->assertSame('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s'));
186 $this->assertSame('fr', $content->getLanguage());
187 $this->assertSame('Raphaël Balenieri', $authors[0]);
188 $this->assertSame('Frédéric Autran', $authors[1]);
191 public function testPostNewOkUrlExist()
193 $this->logInAs('admin');
195 $entry = new Entry($this->getLoggedInUser());
196 $entry->setUrl($this->url
);
197 $this->getEntityManager()->persist($entry);
198 $this->getEntityManager()->flush();
200 $client = $this->getClient();
202 $crawler = $client->request('GET', '/new');
204 $this->assertSame(200, $client->getResponse()->getStatusCode());
206 $form = $crawler->filter('form[name=entry]')->form();
209 'entry[url]' => $this->url
,
212 $client->submit($form, $data);
214 $this->assertSame(302, $client->getResponse()->getStatusCode());
215 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
218 public function testPostNewOkUrlExistWithAccent()
220 $this->logInAs('admin');
221 $client = $this->getClient();
223 $url = 'https://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing';
225 $crawler = $client->request('GET', '/new');
227 $this->assertSame(200, $client->getResponse()->getStatusCode());
229 $form = $crawler->filter('form[name=entry]')->form();
232 'entry[url]' => $url,
235 $client->submit($form, $data);
237 $crawler = $client->request('GET', '/new');
239 $this->assertSame(200, $client->getResponse()->getStatusCode());
241 $form = $crawler->filter('form[name=entry]')->form();
244 'entry[url]' => $url,
247 $client->submit($form, $data);
249 $this->assertSame(302, $client->getResponse()->getStatusCode());
250 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
254 * This test will require an internet connection.
256 public function testPostNewOkUrlExistWithRedirection()
258 $this->logInAs('admin');
259 $client = $this->getClient();
261 $url = 'https://wllbg.org/test-redirect/c51c';
263 $crawler = $client->request('GET', '/new');
265 $this->assertSame(200, $client->getResponse()->getStatusCode());
267 $form = $crawler->filter('form[name=entry]')->form();
270 'entry[url]' => $url,
273 $client->submit($form, $data);
275 $crawler = $client->request('GET', '/new');
277 $this->assertSame(200, $client->getResponse()->getStatusCode());
279 $form = $crawler->filter('form[name=entry]')->form();
282 'entry[url]' => $url,
285 $client->submit($form, $data);
287 $this->assertSame(302, $client->getResponse()->getStatusCode());
288 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
292 * This test will require an internet connection.
294 public function testPostNewThatWillBeTagged()
296 $this->logInAs('admin');
297 $client = $this->getClient();
299 $crawler = $client->request('GET', '/new');
301 $this->assertSame(200, $client->getResponse()->getStatusCode());
303 $form = $crawler->filter('form[name=entry]')->form();
306 'entry[url]' => $url = 'https://github.com/wallabag/wallabag',
309 $client->submit($form, $data);
311 $this->assertSame(302, $client->getResponse()->getStatusCode());
312 $this->assertContains('/', $client->getResponse()->getTargetUrl());
314 $em = $client->getContainer()
315 ->get('doctrine.orm.entity_manager');
317 ->getRepository('WallabagCoreBundle:Entry')
318 ->findOneByUrl($url);
319 $tags = $entry->getTags();
321 $this->assertCount(2, $tags);
322 $this->assertContains('wallabag', $tags);
323 $this->assertSame('en', $entry->getLanguage());
328 // and now re-submit it to test the cascade persistence for tags after entry removal
329 // related https://github.com/wallabag/wallabag/issues/2121
330 $crawler = $client->request('GET', '/new');
332 $this->assertSame(200, $client->getResponse()->getStatusCode());
334 $form = $crawler->filter('form[name=entry]')->form();
337 'entry[url]' => $url = 'https://github.com/wallabag/wallabag/tree/master',
340 $client->submit($form, $data);
342 $this->assertSame(302, $client->getResponse()->getStatusCode());
343 $this->assertContains('/', $client->getResponse()->getTargetUrl());
346 ->getRepository('WallabagCoreBundle:Entry')
347 ->findOneByUrl($url);
349 $tags = $entry->getTags();
351 $this->assertCount(2, $tags);
352 $this->assertContains('wallabag', $tags);
358 public function testArchive()
360 $this->logInAs('admin');
361 $client = $this->getClient();
363 $client->request('GET', '/archive/list');
365 $this->assertSame(200, $client->getResponse()->getStatusCode());
368 public function testUntagged()
370 $this->logInAs('admin');
371 $client = $this->getClient();
373 $client->request('GET', '/untagged/list');
375 $this->assertSame(200, $client->getResponse()->getStatusCode());
378 public function testStarred()
380 $this->logInAs('admin');
381 $client = $this->getClient();
383 $client->request('GET', '/starred/list');
385 $this->assertSame(200, $client->getResponse()->getStatusCode());
388 public function testRangeException()
390 $this->logInAs('admin');
391 $client = $this->getClient();
393 $client->request('GET', '/all/list/900');
395 $this->assertSame(302, $client->getResponse()->getStatusCode());
396 $this->assertSame('/all/list', $client->getResponse()->getTargetUrl());
399 public function testView()
401 $this->logInAs('admin');
402 $client = $this->getClient();
404 $entry = new Entry($this->getLoggedInUser());
405 $entry->setUrl('http://example.com/foo');
406 $entry->setTitle('title foo');
407 $entry->setContent('foo bar baz');
408 $this->getEntityManager()->persist($entry);
409 $this->getEntityManager()->flush();
411 $crawler = $client->request('GET', '/view/' . $entry->getId());
413 $this->assertSame(200, $client->getResponse()->getStatusCode());
414 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
415 $this->assertContains($entry->getTitle(), $body[0]);
419 * This test will require an internet connection.
421 public function testReload()
423 $this->logInAs('admin');
424 $client = $this->getClient();
426 $entry = new Entry($this->getLoggedInUser());
427 $entry->setUrl($this->url
);
428 $entry->setTitle('title foo');
429 $entry->setContent('');
430 $this->getEntityManager()->persist($entry);
431 $this->getEntityManager()->flush();
432 $this->getEntityManager()->clear();
434 $client->request('GET', '/reload/' . $entry->getId());
436 $this->assertSame(302, $client->getResponse()->getStatusCode());
438 $entry = $this->getEntityManager()
439 ->getRepository('WallabagCoreBundle:Entry')
440 ->find($entry->getId());
442 $this->assertNotEmpty($entry->getContent());
445 public function testReloadWithFetchingFailed()
447 $this->logInAs('admin');
448 $client = $this->getClient();
450 $entry = new Entry($this->getLoggedInUser());
451 $entry->setUrl('http://0.0.0.0/failed.html');
452 $this->getEntityManager()->persist($entry);
453 $this->getEntityManager()->flush();
455 $client->request('GET', '/reload/' . $entry->getId());
457 $this->assertSame(302, $client->getResponse()->getStatusCode());
459 // force EntityManager to clear previous entity
460 // otherwise, retrieve the same entity will retrieve change from the previous request :0
461 $this->getEntityManager()->clear();
462 $newContent = $this->getEntityManager()
463 ->getRepository('WallabagCoreBundle:Entry')
464 ->find($entry->getId());
466 $this->assertNotSame($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent());
469 public function testEdit()
471 $this->logInAs('admin');
472 $client = $this->getClient();
474 $entry = new Entry($this->getLoggedInUser());
475 $entry->setUrl($this->url
);
476 $this->getEntityManager()->persist($entry);
477 $this->getEntityManager()->flush();
479 $crawler = $client->request('GET', '/edit/' . $entry->getId());
481 $this->assertSame(200, $client->getResponse()->getStatusCode());
483 $this->assertCount(1, $crawler->filter('input[id=entry_title]'));
484 $this->assertCount(1, $crawler->filter('button[id=entry_save]'));
487 public function testEditUpdate()
489 $this->logInAs('admin');
490 $client = $this->getClient();
492 $entry = new Entry($this->getLoggedInUser());
493 $entry->setUrl($this->url
);
494 $this->getEntityManager()->persist($entry);
495 $this->getEntityManager()->flush();
497 $crawler = $client->request('GET', '/edit/' . $entry->getId());
499 $this->assertSame(200, $client->getResponse()->getStatusCode());
501 $form = $crawler->filter('button[id=entry_save]')->form();
504 'entry[title]' => 'My updated title hehe :)',
505 'entry[origin_url]' => 'https://example.io',
508 $client->submit($form, $data);
510 $this->assertSame(302, $client->getResponse()->getStatusCode());
512 $crawler = $client->followRedirect();
514 $this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text']));
515 $this->assertContains('My updated title hehe :)', $title[0]);
516 $this->assertGreaterThan(1, $stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']));
517 $this->assertContains('example.io', trim($stats[1]));
520 public function testEditRemoveOriginUrl()
522 $this->logInAs('admin');
523 $client = $this->getClient();
525 $entry = new Entry($this->getLoggedInUser());
526 $entry->setUrl($this->url
);
527 $this->getEntityManager()->persist($entry);
528 $this->getEntityManager()->flush();
530 $crawler = $client->request('GET', '/edit/' . $entry->getId());
532 $this->assertSame(200, $client->getResponse()->getStatusCode());
534 $form = $crawler->filter('button[id=entry_save]')->form();
537 'entry[title]' => 'My updated title hehe :)',
538 'entry[origin_url]' => '',
541 $client->submit($form, $data);
543 $this->assertSame(302, $client->getResponse()->getStatusCode());
545 $crawler = $client->followRedirect();
547 $title = $crawler->filter('div[id=article] h1')->extract(['_text']);
548 $this->assertGreaterThan(1, $title);
549 $this->assertContains('My updated title hehe :)', $title[0]);
551 $stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']);
552 $this->assertCount(1, $stats);
553 $this->assertNotContains('example.io', trim($stats[0]));
556 public function testToggleArchive()
558 $this->logInAs('admin');
559 $client = $this->getClient();
561 $entry = new Entry($this->getLoggedInUser());
562 $entry->setUrl($this->url
);
563 $this->getEntityManager()->persist($entry);
564 $this->getEntityManager()->flush();
565 $this->getEntityManager()->clear();
567 $client->request('GET', '/archive/' . $entry->getId());
569 $this->assertSame(302, $client->getResponse()->getStatusCode());
571 $res = $client->getContainer()
572 ->get('doctrine.orm.entity_manager')
573 ->getRepository('WallabagCoreBundle:Entry')
574 ->find($entry->getId());
576 $this->assertSame(1, $res->isArchived());
579 public function testToggleStar()
581 $this->logInAs('admin');
582 $client = $this->getClient();
584 $entry = new Entry($this->getLoggedInUser());
585 $entry->setUrl($this->url
);
586 $this->getEntityManager()->persist($entry);
587 $this->getEntityManager()->flush();
588 $this->getEntityManager()->clear();
590 $client->request('GET', '/star/' . $entry->getId());
592 $this->assertSame(302, $client->getResponse()->getStatusCode());
594 $res = $client->getContainer()
595 ->get('doctrine.orm.entity_manager')
596 ->getRepository('WallabagCoreBundle:Entry')
597 ->findOneById($entry->getId());
599 $this->assertSame(1, $res->isStarred());
602 public function testDelete()
604 $this->logInAs('admin');
605 $client = $this->getClient();
607 $entry = new Entry($this->getLoggedInUser());
608 $entry->setUrl($this->url
);
609 $this->getEntityManager()->persist($entry);
610 $this->getEntityManager()->flush();
612 $client->request('GET', '/delete/' . $entry->getId());
614 $this->assertSame(302, $client->getResponse()->getStatusCode());
616 $client->request('GET', '/delete/' . $entry->getId());
618 $this->assertSame(404, $client->getResponse()->getStatusCode());
622 * It will create a new entry.
626 * And it'll check that user won't be redirected to the view page of the content when it had been removed
628 public function testViewAndDelete()
630 $this->logInAs('admin');
631 $client = $this->getClient();
633 $em = $client->getContainer()
634 ->get('doctrine.orm.entity_manager');
636 // add a new content to be removed later
638 ->getRepository('WallabagUserBundle:User')
639 ->findOneByUserName('admin');
641 $content = new Entry($user);
642 $content->setUrl('http://1.1.1.1/entry');
643 $content->setReadingTime(12);
644 $content->setDomainName('domain.io');
645 $content->setMimetype('text/html');
646 $content->setTitle('test title entry');
647 $content->setContent('This is my content /o/');
648 $content->updateArchived(true);
649 $content->setLanguage('fr');
651 $em->persist($content);
654 $client->request('GET', '/view/' . $content->getId());
655 $this->assertSame(200, $client->getResponse()->getStatusCode());
657 $client->request('GET', '/delete/' . $content->getId());
658 $this->assertSame(302, $client->getResponse()->getStatusCode());
660 $client->followRedirect();
661 $this->assertSame(200, $client->getResponse()->getStatusCode());
664 public function testViewOtherUserEntry()
666 $this->logInAs('admin');
667 $client = $this->getClient();
669 $content = $client->getContainer()
670 ->get('doctrine.orm.entity_manager')
671 ->getRepository('WallabagCoreBundle:Entry')
672 ->findOneByUsernameAndNotArchived('bob');
674 $client->request('GET', '/view/' . $content->getId());
676 $this->assertSame(403, $client->getResponse()->getStatusCode());
679 public function testFilterOnReadingTime()
681 $this->logInAs('admin');
682 $client = $this->getClient();
683 $entry = new Entry($this->getLoggedInUser());
684 $entry->setUrl($this->url
);
685 $entry->setReadingTime(22);
686 $this->getEntityManager()->persist($entry);
687 $this->getEntityManager()->flush();
689 $crawler = $client->request('GET', '/unread/list');
691 $form = $crawler->filter('button[id=submit-filter]')->form();
694 'entry_filter[readingTime][right_number]' => 22,
695 'entry_filter[readingTime][left_number]' => 22,
698 $crawler = $client->submit($form, $data);
700 $this->assertCount(1, $crawler->filter('li.entry'));
703 public function testFilterOnReadingTimeWithNegativeValue()
705 $this->logInAs('admin');
706 $client = $this->getClient();
708 $crawler = $client->request('GET', '/unread/list');
710 $form = $crawler->filter('button[id=submit-filter]')->form();
713 'entry_filter[readingTime][right_number]' => -22,
714 'entry_filter[readingTime][left_number]' => -22,
717 $crawler = $client->submit($form, $data);
719 // forcing negative value results in no entry displayed
720 $this->assertCount(0, $crawler->filter('li.entry'));
723 public function testFilterOnReadingTimeOnlyUpper()
725 $this->logInAs('admin');
726 $client = $this->getClient();
728 $crawler = $client->request('GET', '/all/list');
729 $this->assertCount(5, $crawler->filter('li.entry'));
731 $entry = new Entry($this->getLoggedInUser());
732 $entry->setUrl($this->url
);
733 $entry->setReadingTime(23);
734 $this->getEntityManager()->persist($entry);
735 $this->getEntityManager()->flush();
737 $crawler = $client->request('GET', '/all/list');
738 $this->assertCount(6, $crawler->filter('li.entry'));
740 $form = $crawler->filter('button[id=submit-filter]')->form();
743 'entry_filter[readingTime][right_number]' => 22,
746 $crawler = $client->submit($form, $data);
748 $this->assertCount(5, $crawler->filter('li.entry'));
751 public function testFilterOnReadingTimeOnlyLower()
753 $this->logInAs('admin');
754 $client = $this->getClient();
756 $crawler = $client->request('GET', '/unread/list');
758 $form = $crawler->filter('button[id=submit-filter]')->form();
761 'entry_filter[readingTime][left_number]' => 22,
764 $crawler = $client->submit($form, $data);
766 $this->assertCount(0, $crawler->filter('li.entry'));
768 $entry = new Entry($this->getLoggedInUser());
769 $entry->setUrl($this->url
);
770 $entry->setReadingTime(23);
771 $this->getEntityManager()->persist($entry);
772 $this->getEntityManager()->flush();
774 $crawler = $client->submit($form, $data);
775 $this->assertCount(1, $crawler->filter('li.entry'));
778 public function testFilterOnUnreadStatus()
780 $this->logInAs('admin');
781 $client = $this->getClient();
783 $crawler = $client->request('GET', '/all/list');
785 $form = $crawler->filter('button[id=submit-filter]')->form();
788 'entry_filter[isUnread]' => true,
791 $crawler = $client->submit($form, $data);
793 $this->assertCount(4, $crawler->filter('li.entry'));
795 $entry = new Entry($this->getLoggedInUser());
796 $entry->setUrl($this->url
);
797 $entry->updateArchived(false);
798 $this->getEntityManager()->persist($entry);
799 $this->getEntityManager()->flush();
801 $crawler = $client->submit($form, $data);
803 $this->assertCount(5, $crawler->filter('li.entry'));
806 public function testFilterOnCreationDate()
808 $this->logInAs('admin');
809 $client = $this->getClient();
811 $em = $this->getEntityManager();
813 $today = new \
DateTimeImmutable();
814 $tomorrow = $today->add(new \
DateInterval('P1D'));
815 $yesterday = $today->sub(new \
DateInterval('P1D'));
817 $entry = new Entry($this->getLoggedInUser());
818 $entry->setUrl('http://0.0.0.0/testFilterOnCreationDate');
819 $entry->setCreatedAt($yesterday);
820 $em->persist($entry);
823 $crawler = $client->request('GET', '/unread/list');
825 $form = $crawler->filter('button[id=submit-filter]')->form();
828 'entry_filter[createdAt][left_date]' => $today->format('Y-m-d'),
829 'entry_filter[createdAt][right_date]' => $tomorrow->format('Y-m-d'),
832 $crawler = $client->submit($form, $data);
834 $this->assertCount(5, $crawler->filter('li.entry'));
837 'entry_filter[createdAt][left_date]' => $today->format('Y-m-d'),
838 'entry_filter[createdAt][right_date]' => $today->format('Y-m-d'),
841 $crawler = $client->submit($form, $data);
843 $this->assertCount(5, $crawler->filter('li.entry'));
846 'entry_filter[createdAt][left_date]' => '1970-01-01',
847 'entry_filter[createdAt][right_date]' => '1970-01-01',
850 $crawler = $client->submit($form, $data);
852 $this->assertCount(0, $crawler->filter('li.entry'));
855 public function testPaginationWithFilter()
857 $this->logInAs('admin');
858 $client = $this->getClient();
859 $crawler = $client->request('GET', '/config');
861 $form = $crawler->filter('button[id=config_save]')->form();
864 'config[items_per_page]' => '1',
867 $client->submit($form, $data);
869 $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D=';
871 $client->request('GET', 'unread/list' . $parameters);
873 $this->assertContains($parameters, $client->getResponse()->getContent());
876 $crawler = $client->request('GET', '/config');
877 $form = $crawler->filter('button[id=config_save]')->form();
879 'config[items_per_page]' => '12',
881 $client->submit($form, $data);
884 public function testFilterOnDomainName()
886 $this->logInAs('admin');
887 $client = $this->getClient();
889 $crawler = $client->request('GET', '/unread/list');
890 $form = $crawler->filter('button[id=submit-filter]')->form();
892 'entry_filter[domainName]' => 'domain',
895 $crawler = $client->submit($form, $data);
896 $this->assertCount(5, $crawler->filter('li.entry'));
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('li.entry'));
907 $form = $crawler->filter('button[id=submit-filter]')->form();
909 'entry_filter[domainName]' => 'wallabag',
912 $crawler = $client->submit($form, $data);
913 $this->assertCount(0, $crawler->filter('li.entry'));
916 public function testFilterOnStatus()
918 $this->logInAs('admin');
919 $client = $this->getClient();
921 $crawler = $client->request('GET', '/unread/list');
922 $form = $crawler->filter('button[id=submit-filter]')->form();
923 $form['entry_filter[isArchived]']->tick();
924 $form['entry_filter[isStarred]']->untick();
926 $crawler = $client->submit($form);
927 $this->assertCount(1, $crawler->filter('li.entry'));
929 $form = $crawler->filter('button[id=submit-filter]')->form();
930 $form['entry_filter[isArchived]']->untick();
931 $form['entry_filter[isStarred]']->tick();
933 $crawler = $client->submit($form);
934 $this->assertCount(1, $crawler->filter('li.entry'));
937 public function testFilterOnIsPublic()
939 $this->logInAs('admin');
940 $client = $this->getClient();
942 $crawler = $client->request('GET', '/unread/list');
943 $form = $crawler->filter('button[id=submit-filter]')->form();
944 $form['entry_filter[isPublic]']->tick();
946 $crawler = $client->submit($form);
947 $this->assertCount(0, $crawler->filter('li.entry'));
950 public function testPreviewPictureFilter()
952 $this->logInAs('admin');
953 $client = $this->getClient();
955 $crawler = $client->request('GET', '/unread/list');
956 $form = $crawler->filter('button[id=submit-filter]')->form();
957 $form['entry_filter[previewPicture]']->tick();
959 $crawler = $client->submit($form);
960 $this->assertCount(1, $crawler->filter('li.entry'));
963 public function testFilterOnLanguage()
965 $this->logInAs('admin');
966 $client = $this->getClient();
968 $entry = new Entry($this->getLoggedInUser());
969 $entry->setUrl($this->url
);
970 $entry->setLanguage('fr');
971 $this->getEntityManager()->persist($entry);
972 $this->getEntityManager()->flush();
974 $crawler = $client->request('GET', '/unread/list');
975 $form = $crawler->filter('button[id=submit-filter]')->form();
977 'entry_filter[language]' => 'fr',
980 $crawler = $client->submit($form, $data);
981 $this->assertCount(3, $crawler->filter('li.entry'));
983 $form = $crawler->filter('button[id=submit-filter]')->form();
985 'entry_filter[language]' => 'en',
988 $crawler = $client->submit($form, $data);
989 $this->assertCount(2, $crawler->filter('li.entry'));
992 public function testShareEntryPublicly()
994 $this->logInAs('admin');
995 $client = $this->getClient();
997 // sharing is enabled
998 $client->getContainer()->get('craue_config')->set('share_public', 1);
1000 $content = new Entry($this->getLoggedInUser());
1001 $content->setUrl($this->url
);
1002 $this->getEntityManager()->persist($content);
1003 $this->getEntityManager()->flush();
1004 $this->getEntityManager()->clear();
1007 $client->request('GET', '/share/' . $content->getUid());
1008 $this->assertSame(404, $client->getResponse()->getStatusCode());
1010 // generating the uid
1011 $client->request('GET', '/share/' . $content->getId());
1012 $this->assertSame(302, $client->getResponse()->getStatusCode());
1014 $shareUrl = $client->getResponse()->getTargetUrl();
1016 // use a new client to have a fresh empty session (instead of a logged one from the previous client)
1019 $client->request('GET', $shareUrl);
1021 $this->assertSame(200, $client->getResponse()->getStatusCode());
1022 $this->assertContains('max-age=25200', $client->getResponse()->headers
->get('cache-control'));
1023 $this->assertContains('public', $client->getResponse()->headers
->get('cache-control'));
1024 $this->assertContains('s-maxage=25200', $client->getResponse()->headers
->get('cache-control'));
1025 $this->assertNotContains('no-cache', $client->getResponse()->headers
->get('cache-control'));
1026 $this->assertContains('og:title', $client->getResponse()->getContent());
1027 $this->assertContains('og:type', $client->getResponse()->getContent());
1028 $this->assertContains('og:url', $client->getResponse()->getContent());
1029 $this->assertContains('og:image', $client->getResponse()->getContent());
1031 // sharing is now disabled
1032 $client->getContainer()->get('craue_config')->set('share_public', 0);
1033 $client->request('GET', '/share/' . $content->getUid());
1034 $this->assertSame(404, $client->getResponse()->getStatusCode());
1036 // removing the share
1037 $client->request('GET', '/share/delete/' . $content->getId());
1038 $this->assertSame(302, $client->getResponse()->getStatusCode());
1040 // share is now disable
1041 $client->request('GET', '/share/' . $content->getUid());
1042 $this->assertSame(404, $client->getResponse()->getStatusCode());
1045 public function testNewEntryWithDownloadImagesEnabled()
1047 $this->downloadImagesEnabled
= true;
1048 $this->logInAs('admin');
1049 $client = $this->getClient();
1051 $url = self
::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE
;
1052 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
1054 $crawler = $client->request('GET', '/new');
1056 $this->assertSame(200, $client->getResponse()->getStatusCode());
1058 $form = $crawler->filter('form[name=entry]')->form();
1061 'entry[url]' => $url,
1064 $client->submit($form, $data);
1066 $this->assertSame(302, $client->getResponse()->getStatusCode());
1068 $em = $client->getContainer()
1069 ->get('doctrine.orm.entity_manager');
1072 ->getRepository('WallabagCoreBundle:Entry')
1073 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1075 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry);
1076 $this->assertSame($url, $entry->getUrl());
1077 $this->assertContains('Judo', $entry->getTitle());
1078 // instead of checking for the filename (which might change) check that the image is now local
1079 $this->assertContains(rtrim($client->getContainer()->getParameter('domain_name'), '/') . '/assets/images/', $entry->getContent());
1081 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1085 * @depends testNewEntryWithDownloadImagesEnabled
1087 public function testRemoveEntryWithDownloadImagesEnabled()
1089 $this->downloadImagesEnabled
= true;
1090 $this->logInAs('admin');
1091 $client = $this->getClient();
1093 $url = self
::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE
;
1094 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
1096 $crawler = $client->request('GET', '/new');
1098 $this->assertSame(200, $client->getResponse()->getStatusCode());
1100 $form = $crawler->filter('form[name=entry]')->form();
1103 'entry[url]' => $url,
1106 $client->submit($form, $data);
1108 $this->assertSame(302, $client->getResponse()->getStatusCode());
1110 $content = $client->getContainer()
1111 ->get('doctrine.orm.entity_manager')
1112 ->getRepository('WallabagCoreBundle:Entry')
1113 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1115 $client->request('GET', '/delete/' . $content->getId());
1117 $this->assertSame(302, $client->getResponse()->getStatusCode());
1119 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1122 public function testRedirectToHomepage()
1124 $this->logInAs('empty');
1125 $client = $this->getClient();
1127 // Redirect to homepage
1128 $config = $this->getLoggedInUser()->getConfig();
1129 $config->setActionMarkAsRead(Config
::REDIRECT_TO_HOMEPAGE
);
1130 $this->getEntityManager()->persist($config);
1132 $entry = new Entry($this->getLoggedInUser());
1133 $entry->setUrl($this->url
);
1134 $this->getEntityManager()->persist($entry);
1136 $this->getEntityManager()->flush();
1138 $client->request('GET', '/view/' . $entry->getId());
1139 $client->request('GET', '/archive/' . $entry->getId());
1141 $this->assertSame(302, $client->getResponse()->getStatusCode());
1142 $this->assertSame('/', $client->getResponse()->headers
->get('location'));
1145 public function testRedirectToCurrentPage()
1147 $this->logInAs('empty');
1148 $client = $this->getClient();
1150 // Redirect to current page
1151 $config = $this->getLoggedInUser()->getConfig();
1152 $config->setActionMarkAsRead(Config
::REDIRECT_TO_CURRENT_PAGE
);
1153 $this->getEntityManager()->persist($config);
1155 $entry = new Entry($this->getLoggedInUser());
1156 $entry->setUrl($this->url
);
1157 $this->getEntityManager()->persist($entry);
1159 $this->getEntityManager()->flush();
1161 $client->request('GET', '/view/' . $entry->getId());
1162 $client->request('GET', '/archive/' . $entry->getId());
1164 $this->assertSame(302, $client->getResponse()->getStatusCode());
1165 $this->assertContains('/view/' . $entry->getId(), $client->getResponse()->headers
->get('location'));
1168 public function testFilterOnHttpStatus()
1170 $this->logInAs('admin');
1171 $client = $this->getClient();
1173 $entry = new Entry($this->getLoggedInUser());
1174 $entry->setUrl('https://www.lemonde.fr/incorrect-url/');
1175 $entry->setHttpStatus(404);
1176 $this->getEntityManager()->persist($entry);
1178 $this->getEntityManager()->flush();
1180 $crawler = $client->request('GET', '/all/list');
1181 $form = $crawler->filter('button[id=submit-filter]')->form();
1184 'entry_filter[httpStatus]' => 404,
1187 $crawler = $client->submit($form, $data);
1189 $this->assertCount(1, $crawler->filter('li.entry'));
1191 $entry = new Entry($this->getLoggedInUser());
1192 $entry->setUrl($this->url
);
1193 $entry->setHttpStatus(200);
1194 $this->getEntityManager()->persist($entry);
1196 $entry = new Entry($this->getLoggedInUser());
1197 $entry->setUrl('http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm');
1198 $entry->setHttpStatus(200);
1199 $this->getEntityManager()->persist($entry);
1201 $this->getEntityManager()->flush();
1203 $crawler = $client->request('GET', '/all/list');
1204 $form = $crawler->filter('button[id=submit-filter]')->form();
1207 'entry_filter[httpStatus]' => 200,
1210 $crawler = $client->submit($form, $data);
1212 $this->assertCount(2, $crawler->filter('li.entry'));
1214 $crawler = $client->request('GET', '/all/list');
1215 $form = $crawler->filter('button[id=submit-filter]')->form();
1218 'entry_filter[httpStatus]' => 1024,
1221 $crawler = $client->submit($form, $data);
1223 $this->assertCount(8, $crawler->filter('li.entry'));
1226 public function testSearch()
1228 $this->logInAs('admin');
1229 $client = $this->getClient();
1231 $entry = new Entry($this->getLoggedInUser());
1232 $entry->setUrl($this->url
);
1233 $entry->setTitle('test');
1234 $this->getEntityManager()->persist($entry);
1235 $this->getEntityManager()->flush();
1237 // Search on unread list
1238 $crawler = $client->request('GET', '/unread/list');
1240 $form = $crawler->filter('form[name=search]')->form();
1242 'search_entry[term]' => 'title',
1245 $crawler = $client->submit($form, $data);
1247 $this->assertCount(4, $crawler->filter('li.entry'));
1249 // Search on starred list
1250 $crawler = $client->request('GET', '/starred/list');
1252 $entry = new Entry($this->getLoggedInUser());
1253 $entry->setUrl('http://localhost/foo/bar');
1254 $entry->setTitle('testeur');
1255 $entry->setStarred(true);
1256 $this->getEntityManager()->persist($entry);
1257 $this->getEntityManager()->flush();
1259 $form = $crawler->filter('form[name=search]')->form();
1261 'search_entry[term]' => 'testeur',
1264 $crawler = $client->submit($form, $data);
1266 $this->assertCount(1, $crawler->filter('li.entry'));
1268 $crawler = $client->request('GET', '/archive/list');
1270 // Added new article to test on archive list
1271 $entry = new Entry($this->getLoggedInUser());
1272 $entry->setUrl('http://0.0.0.0/foo/baz/qux');
1273 $entry->setTitle('Le manège');
1274 $entry->updateArchived(true);
1275 $this->getEntityManager()->persist($entry);
1276 $this->getEntityManager()->flush();
1278 $form = $crawler->filter('form[name=search]')->form();
1280 'search_entry[term]' => 'manège',
1283 $crawler = $client->submit($form, $data);
1285 $this->assertCount(1, $crawler->filter('li.entry'));
1286 $client->request('GET', '/delete/' . $entry->getId());
1288 // test on list of all articles
1289 $crawler = $client->request('GET', '/all/list');
1291 $form = $crawler->filter('form[name=search]')->form();
1293 'search_entry[term]' => 'wxcvbnqsdf', // a string not available in the database
1296 $crawler = $client->submit($form, $data);
1298 $this->assertCount(0, $crawler->filter('li.entry'));
1300 // test url search on list of all articles
1301 $entry = new Entry($this->getLoggedInUser());
1302 $entry->setUrl('http://domain/qux');
1303 $entry->setTitle('Le manège');
1304 $entry->updateArchived(true);
1305 $this->getEntityManager()->persist($entry);
1306 $this->getEntityManager()->flush();
1308 $crawler = $client->request('GET', '/all/list');
1310 $form = $crawler->filter('form[name=search]')->form();
1312 'search_entry[term]' => 'domain', // the search will match an entry with 'domain' in its url
1315 $crawler = $client->submit($form, $data);
1317 $this->assertCount(1, $crawler->filter('li.entry'));
1319 // same as previous test but for case-sensitivity
1320 $crawler = $client->request('GET', '/all/list');
1322 $form = $crawler->filter('form[name=search]')->form();
1324 'search_entry[term]' => 'doMain', // the search will match an entry with 'domain' in its url
1327 $crawler = $client->submit($form, $data);
1329 $this->assertCount(1, $crawler->filter('li.entry'));
1332 public function dataForLanguage()
1336 'https://www.pravda.ru/world/09-06-2017/1337283-qatar-0/',
1340 'https://fr.wikipedia.org/wiki/Wallabag',
1344 'https://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html',
1348 'https://www.ansa.it/sito/notizie/mondo/europa/2017/06/08/voto-gb-seggi-aperti-misure-sicurezza-rafforzate_0cb71f7f-e23b-4d5f-95ca-bc12296419f0.html',
1352 'http://www.hao123.com/shequ?__noscript__-=1',
1356 'https://politica.estadao.com.br/noticias/eleicoes,campanha-catatonica,70002491983',
1359 'fucked_list_of_languages' => [
1360 'http://geocatalog.webservice-energy.org/geonetwork/srv/eng/main.home',
1364 'https://www.20minutos.es/noticia/3360685/0/gobierno-sanchez-primero-historia-mas-mujeres-que-hombres/',
1371 * @dataProvider dataForLanguage
1373 public function testLanguageValidation($url, $expectedLanguage)
1375 $this->logInAs('admin');
1376 $client = $this->getClient();
1378 $crawler = $client->request('GET', '/new');
1380 $this->assertSame(200, $client->getResponse()->getStatusCode());
1382 $form = $crawler->filter('form[name=entry]')->form();
1385 'entry[url]' => $url,
1388 $client->submit($form, $data);
1390 $this->assertSame(302, $client->getResponse()->getStatusCode());
1392 $content = $client->getContainer()
1393 ->get('doctrine.orm.entity_manager')
1394 ->getRepository('WallabagCoreBundle:Entry')
1395 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1397 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1398 $this->assertSame($url, $content->getUrl());
1399 $this->assertSame($expectedLanguage, $content->getLanguage());
1403 * This test will require an internet connection.
1405 public function testRestrictedArticle()
1407 $url = 'https://www.monde-diplomatique.fr/2017/05/BONNET/57475';
1408 $this->logInAs('admin');
1409 $client = $this->getClient();
1410 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
1412 // enable restricted access
1413 $client->getContainer()->get('craue_config')->set('restricted_access', 1);
1415 // create a new site_credential
1416 $user = $client->getContainer()->get('security.token_storage')->getToken()->getUser();
1417 $credential = new SiteCredential($user);
1418 $credential->setHost('monde-diplomatique.fr');
1419 $credential->setUsername($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('foo'));
1420 $credential->setPassword($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('bar'));
1422 $em->persist($credential);
1425 $crawler = $client->request('GET', '/new');
1427 $this->assertSame(200, $client->getResponse()->getStatusCode());
1429 $form = $crawler->filter('form[name=entry]')->form();
1432 'entry[url]' => $url,
1435 $client->submit($form, $data);
1437 $this->assertSame(302, $client->getResponse()->getStatusCode());
1439 $crawler = $client->followRedirect();
1441 $this->assertSame(200, $client->getResponse()->getStatusCode());
1442 $this->assertContains('flashes.entry.notice.entry_saved', $crawler->filter('body')->extract(['_text'])[0]);
1445 ->getRepository('WallabagCoreBundle:Entry')
1446 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1448 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1449 $this->assertSame('Crimes et réformes aux Philippines', $content->getTitle());
1451 $client->getContainer()->get('craue_config')->set('restricted_access', 0);
1454 public function testPostEntryWhenFetchFails()
1456 $url = 'http://example.com/papers/email_tracking.pdf';
1457 $this->logInAs('admin');
1458 $client = $this->getClient();
1460 $container = $client->getContainer();
1461 $contentProxy = $this->getMockBuilder(ContentProxy
::class)
1462 ->disableOriginalConstructor()
1463 ->setMethods(['updateEntry'])
1465 $contentProxy->expects($this->any())
1466 ->method('updateEntry')
1467 ->willThrowException(new \
Exception('Test Fetch content fails'));
1469 $crawler = $client->request('GET', '/new');
1471 $this->assertSame(200, $client->getResponse()->getStatusCode());
1473 $form = $crawler->filter('form[name=entry]')->form();
1476 'entry[url]' => $url,
1480 * We generate a new client to be able to use Mock ContentProxy
1481 * Also we reinject the cookie from the previous client to keep the
1484 $cookie = $client->getCookieJar()->all();
1485 $client = $this->getNewClient();
1486 $client->getCookieJar()->set($cookie[0]);
1487 $client->getContainer()->set('wallabag_core.content_proxy', $contentProxy);
1488 $client->submit($form, $data);
1490 $this->assertSame(302, $client->getResponse()->getStatusCode());
1492 $content = $client->getContainer()
1493 ->get('doctrine.orm.entity_manager')
1494 ->getRepository('WallabagCoreBundle:Entry')
1495 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1497 $authors = $content->getPublishedBy();
1498 $this->assertSame('email_tracking.pdf', $content->getTitle());
1499 $this->assertSame('example.com', $content->getDomainName());
1502 public function testEntryDeleteTagLink()
1504 $this->logInAs('admin');
1505 $client = $this->getClient();
1507 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
1508 $entry = $em->getRepository('WallabagCoreBundle:Entry')->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId());
1509 $tag = $entry->getTags()[0];
1511 $crawler = $client->request('GET', '/view/' . $entry->getId());
1513 // As long as the deletion link of a tag is following
1514 // a link to the tag view, we take the second one to retrieve
1515 // the deletion link of the first tag
1516 $link = $crawler->filter('body div#article div.tools ul.tags li.chip a')->extract('href')[1];
1518 $this->assertSame(sprintf('/remove-tag/%s/%s', $entry->getId(), $tag->getId()), $link);
1521 public function testRandom()
1523 $this->logInAs('admin');
1524 $client = $this->getClient();
1526 $client->request('GET', '/unread/random');
1527 $this->assertSame(302, $client->getResponse()->getStatusCode());
1528 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Unread random');
1530 $client->request('GET', '/starred/random');
1531 $this->assertSame(302, $client->getResponse()->getStatusCode());
1532 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Starred random');
1534 $client->request('GET', '/archive/random');
1535 $this->assertSame(302, $client->getResponse()->getStatusCode());
1536 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Archive random');
1538 $client->request('GET', '/untagged/random');
1539 $this->assertSame(302, $client->getResponse()->getStatusCode());
1540 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Untagged random');
1542 $client->request('GET', '/all/random');
1543 $this->assertSame(302, $client->getResponse()->getStatusCode());
1544 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'All random');