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\Helper\ContentProxy
;
11 class EntryControllerTest
extends WallabagCoreTestCase
13 const AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE
= 'http://www.lemonde.fr/judo/article/2017/11/11/judo-la-decima-de-teddy-riner_5213605_1556020.html';
14 public $downloadImagesEnabled = false;
15 public $url = 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html';
20 * Ensure download_images_enabled is disabled after each script
22 public function tearDownImagesEnabled()
24 if ($this->downloadImagesEnabled
) {
25 $client = static::createClient();
26 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
28 $this->downloadImagesEnabled
= false;
32 public function testLogin()
34 $client = $this->getClient();
36 $client->request('GET', '/new');
38 $this->assertSame(302, $client->getResponse()->getStatusCode());
39 $this->assertContains('login', $client->getResponse()->headers
->get('location'));
42 public function testQuickstart()
44 $this->logInAs('empty');
45 $client = $this->getClient();
47 $client->request('GET', '/unread/list');
48 $this->assertSame(302, $client->getResponse()->getStatusCode());
49 $crawler = $client->followRedirect();
51 $this->assertSame(200, $client->getResponse()->getStatusCode());
52 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
53 $this->assertContains('quickstart.intro.title', $body[0]);
55 // Test if quickstart is disabled when user has 1 entry
56 $crawler = $client->request('GET', '/new');
58 $this->assertSame(200, $client->getResponse()->getStatusCode());
60 $form = $crawler->filter('form[name=entry]')->form();
63 'entry[url]' => $this->url
,
66 $client->submit($form, $data);
67 $this->assertSame(302, $client->getResponse()->getStatusCode());
68 $client->followRedirect();
70 $crawler = $client->request('GET', '/unread/list');
71 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
72 $this->assertContains('entry.list.number_on_the_page', $body[0]);
75 public function testGetNew()
77 $this->logInAs('admin');
78 $this->useTheme('baggy');
79 $client = $this->getClient();
81 $crawler = $client->request('GET', '/new');
83 $this->assertSame(200, $client->getResponse()->getStatusCode());
85 $this->assertCount(1, $crawler->filter('input[type=url]'));
86 $this->assertCount(1, $crawler->filter('form[name=entry]'));
89 public function testPostNewViaBookmarklet()
91 $this->logInAs('admin');
92 $this->useTheme('baggy');
93 $client = $this->getClient();
95 $crawler = $client->request('GET', '/');
97 $this->assertCount(4, $crawler->filter('div[class=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('div[class=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('Google', $content->getTitle());
167 $this->assertSame('fr', $content->getLanguage());
168 $this->assertSame('2015-03-28 11:43:19', $content->getPublishedAt()->format('Y-m-d H:i:s'));
169 $this->assertSame('Morgane Tual', $author[0]);
170 $this->assertArrayHasKey('x-varnish1', $content->getHeaders());
171 $client->getContainer()->get('craue_config')->set('store_article_headers', 0);
174 public function testPostWithMultipleAuthors()
176 $url = 'http://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768';
177 $this->logInAs('admin');
178 $client = $this->getClient();
180 $crawler = $client->request('GET', '/new');
182 $this->assertSame(200, $client->getResponse()->getStatusCode());
184 $form = $crawler->filter('form[name=entry]')->form();
187 'entry[url]' => $url,
190 $client->submit($form, $data);
192 $this->assertSame(302, $client->getResponse()->getStatusCode());
194 $content = $client->getContainer()
195 ->get('doctrine.orm.entity_manager')
196 ->getRepository('WallabagCoreBundle:Entry')
197 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
199 $authors = $content->getPublishedBy();
200 $this->assertSame('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s'));
201 $this->assertSame('fr', $content->getLanguage());
202 $this->assertSame('Raphaël Balenieri, correspondant à Pékin', $authors[0]);
203 $this->assertSame('Frédéric Autran, correspondant à New York', $authors[1]);
206 public function testPostNewOkUrlExist()
208 $this->logInAs('admin');
210 $entry = new Entry($this->getLoggedInUser());
211 $entry->setUrl($this->url
);
212 $this->getEntityManager()->persist($entry);
213 $this->getEntityManager()->flush();
215 $client = $this->getClient();
217 $crawler = $client->request('GET', '/new');
219 $this->assertSame(200, $client->getResponse()->getStatusCode());
221 $form = $crawler->filter('form[name=entry]')->form();
224 'entry[url]' => $this->url
,
227 $client->submit($form, $data);
229 $this->assertSame(302, $client->getResponse()->getStatusCode());
230 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
233 public function testPostNewOkUrlExistWithAccent()
235 $this->logInAs('admin');
236 $client = $this->getClient();
238 $url = 'http://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing';
240 $crawler = $client->request('GET', '/new');
242 $this->assertSame(200, $client->getResponse()->getStatusCode());
244 $form = $crawler->filter('form[name=entry]')->form();
247 'entry[url]' => $url,
250 $client->submit($form, $data);
252 $crawler = $client->request('GET', '/new');
254 $this->assertSame(200, $client->getResponse()->getStatusCode());
256 $form = $crawler->filter('form[name=entry]')->form();
259 'entry[url]' => $url,
262 $client->submit($form, $data);
264 $this->assertSame(302, $client->getResponse()->getStatusCode());
265 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
268 public function testPostNewOkUrlExistWithRedirection()
270 $this->logInAs('admin');
271 $client = $this->getClient();
273 $url = 'http://bit.ly/2t8Fwre';
275 $crawler = $client->request('GET', '/new');
277 $this->assertSame(200, $client->getResponse()->getStatusCode());
279 $form = $crawler->filter('form[name=entry]')->form();
282 'entry[url]' => $url,
285 $client->submit($form, $data);
287 $crawler = $client->request('GET', '/new');
289 $this->assertSame(200, $client->getResponse()->getStatusCode());
291 $form = $crawler->filter('form[name=entry]')->form();
294 'entry[url]' => $url,
297 $client->submit($form, $data);
299 $this->assertSame(302, $client->getResponse()->getStatusCode());
300 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
304 * This test will require an internet connection.
306 public function testPostNewThatWillBeTagged()
308 $this->logInAs('admin');
309 $client = $this->getClient();
311 $crawler = $client->request('GET', '/new');
313 $this->assertSame(200, $client->getResponse()->getStatusCode());
315 $form = $crawler->filter('form[name=entry]')->form();
318 'entry[url]' => $url = 'https://github.com/wallabag/wallabag',
321 $client->submit($form, $data);
323 $this->assertSame(302, $client->getResponse()->getStatusCode());
324 $this->assertContains('/', $client->getResponse()->getTargetUrl());
326 $em = $client->getContainer()
327 ->get('doctrine.orm.entity_manager');
329 ->getRepository('WallabagCoreBundle:Entry')
330 ->findOneByUrl($url);
331 $tags = $entry->getTags();
333 $this->assertCount(2, $tags);
334 $this->assertContains('wallabag', $tags);
335 $this->assertSame('en', $entry->getLanguage());
340 // and now re-submit it to test the cascade persistence for tags after entry removal
341 // related https://github.com/wallabag/wallabag/issues/2121
342 $crawler = $client->request('GET', '/new');
344 $this->assertSame(200, $client->getResponse()->getStatusCode());
346 $form = $crawler->filter('form[name=entry]')->form();
349 'entry[url]' => $url = 'https://github.com/wallabag/wallabag/tree/master',
352 $client->submit($form, $data);
354 $this->assertSame(302, $client->getResponse()->getStatusCode());
355 $this->assertContains('/', $client->getResponse()->getTargetUrl());
358 ->getRepository('WallabagCoreBundle:Entry')
359 ->findOneByUrl($url);
361 $tags = $entry->getTags();
363 $this->assertCount(2, $tags);
364 $this->assertContains('wallabag', $tags);
370 public function testArchive()
372 $this->logInAs('admin');
373 $client = $this->getClient();
375 $client->request('GET', '/archive/list');
377 $this->assertSame(200, $client->getResponse()->getStatusCode());
380 public function testUntagged()
382 $this->logInAs('admin');
383 $client = $this->getClient();
385 $client->request('GET', '/untagged/list');
387 $this->assertSame(200, $client->getResponse()->getStatusCode());
390 public function testStarred()
392 $this->logInAs('admin');
393 $client = $this->getClient();
395 $client->request('GET', '/starred/list');
397 $this->assertSame(200, $client->getResponse()->getStatusCode());
400 public function testRangeException()
402 $this->logInAs('admin');
403 $client = $this->getClient();
405 $client->request('GET', '/all/list/900');
407 $this->assertSame(302, $client->getResponse()->getStatusCode());
408 $this->assertSame('/all/list', $client->getResponse()->getTargetUrl());
411 public function testView()
413 $this->logInAs('admin');
414 $client = $this->getClient();
416 $entry = new Entry($this->getLoggedInUser());
417 $entry->setUrl('http://example.com/foo');
418 $entry->setTitle('title foo');
419 $entry->setContent('foo bar baz');
420 $this->getEntityManager()->persist($entry);
421 $this->getEntityManager()->flush();
423 $crawler = $client->request('GET', '/view/' . $entry->getId());
425 $this->assertSame(200, $client->getResponse()->getStatusCode());
426 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
427 $this->assertContains($entry->getTitle(), $body[0]);
431 * This test will require an internet connection.
433 public function testReload()
435 $this->logInAs('admin');
436 $client = $this->getClient();
438 $entry = new Entry($this->getLoggedInUser());
439 $entry->setUrl($this->url
);
440 $entry->setTitle('title foo');
441 $entry->setContent('');
442 $this->getEntityManager()->persist($entry);
443 $this->getEntityManager()->flush();
444 $this->getEntityManager()->clear();
446 $client->request('GET', '/reload/' . $entry->getId());
448 $this->assertSame(302, $client->getResponse()->getStatusCode());
450 $entry = $this->getEntityManager()
451 ->getRepository('WallabagCoreBundle:Entry')
452 ->find($entry->getId());
454 $this->assertNotEmpty($entry->getContent());
457 public function testReloadWithFetchingFailed()
459 $this->logInAs('admin');
460 $client = $this->getClient();
462 $entry = new Entry($this->getLoggedInUser());
463 $entry->setUrl('http://0.0.0.0/failed.html');
464 $this->getEntityManager()->persist($entry);
465 $this->getEntityManager()->flush();
467 $client->request('GET', '/reload/' . $entry->getId());
469 $this->assertSame(302, $client->getResponse()->getStatusCode());
471 // force EntityManager to clear previous entity
472 // otherwise, retrieve the same entity will retrieve change from the previous request :0
473 $this->getEntityManager()->clear();
474 $newContent = $this->getEntityManager()
475 ->getRepository('WallabagCoreBundle:Entry')
476 ->find($entry->getId());
478 $this->assertNotSame($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent());
481 public function testEdit()
483 $this->logInAs('admin');
484 $client = $this->getClient();
486 $entry = new Entry($this->getLoggedInUser());
487 $entry->setUrl($this->url
);
488 $this->getEntityManager()->persist($entry);
489 $this->getEntityManager()->flush();
491 $crawler = $client->request('GET', '/edit/' . $entry->getId());
493 $this->assertSame(200, $client->getResponse()->getStatusCode());
495 $this->assertCount(1, $crawler->filter('input[id=entry_title]'));
496 $this->assertCount(1, $crawler->filter('button[id=entry_save]'));
499 public function testEditUpdate()
501 $this->logInAs('admin');
502 $client = $this->getClient();
504 $entry = new Entry($this->getLoggedInUser());
505 $entry->setUrl($this->url
);
506 $this->getEntityManager()->persist($entry);
507 $this->getEntityManager()->flush();
509 $crawler = $client->request('GET', '/edit/' . $entry->getId());
511 $this->assertSame(200, $client->getResponse()->getStatusCode());
513 $form = $crawler->filter('button[type=submit]')->form();
516 'entry[title]' => 'My updated title hehe :)',
517 'entry[origin_url]' => 'https://example.io',
520 $client->submit($form, $data);
522 $this->assertSame(302, $client->getResponse()->getStatusCode());
524 $crawler = $client->followRedirect();
526 $this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text']));
527 $this->assertContains('My updated title hehe :)', $title[0]);
528 $this->assertGreaterThan(1, $stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']));
529 $this->assertContains('example.io', trim($stats[1]));
532 public function testEditRemoveOriginUrl()
534 $this->logInAs('admin');
535 $client = $this->getClient();
537 $entry = new Entry($this->getLoggedInUser());
538 $entry->setUrl($this->url
);
539 $this->getEntityManager()->persist($entry);
540 $this->getEntityManager()->flush();
542 $crawler = $client->request('GET', '/edit/' . $entry->getId());
544 $this->assertSame(200, $client->getResponse()->getStatusCode());
546 $form = $crawler->filter('button[type=submit]')->form();
549 'entry[title]' => 'My updated title hehe :)',
550 'entry[origin_url]' => '',
553 $client->submit($form, $data);
555 $this->assertSame(302, $client->getResponse()->getStatusCode());
557 $crawler = $client->followRedirect();
559 $this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text']));
560 $this->assertContains('My updated title hehe :)', $title[0]);
561 $this->assertSame(1, count($stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text'])));
562 $this->assertNotContains('example.io', trim($stats[0]));
565 public function testToggleArchive()
567 $this->logInAs('admin');
568 $client = $this->getClient();
570 $entry = new Entry($this->getLoggedInUser());
571 $entry->setUrl($this->url
);
572 $this->getEntityManager()->persist($entry);
573 $this->getEntityManager()->flush();
574 $this->getEntityManager()->clear();
576 $client->request('GET', '/archive/' . $entry->getId());
578 $this->assertSame(302, $client->getResponse()->getStatusCode());
580 $res = $client->getContainer()
581 ->get('doctrine.orm.entity_manager')
582 ->getRepository('WallabagCoreBundle:Entry')
583 ->find($entry->getId());
585 $this->assertSame(1, $res->isArchived());
588 public function testToggleStar()
590 $this->logInAs('admin');
591 $client = $this->getClient();
593 $entry = new Entry($this->getLoggedInUser());
594 $entry->setUrl($this->url
);
595 $this->getEntityManager()->persist($entry);
596 $this->getEntityManager()->flush();
597 $this->getEntityManager()->clear();
599 $client->request('GET', '/star/' . $entry->getId());
601 $this->assertSame(302, $client->getResponse()->getStatusCode());
603 $res = $client->getContainer()
604 ->get('doctrine.orm.entity_manager')
605 ->getRepository('WallabagCoreBundle:Entry')
606 ->findOneById($entry->getId());
608 $this->assertSame(1, $res->isStarred());
611 public function testDelete()
613 $this->logInAs('admin');
614 $client = $this->getClient();
616 $entry = new Entry($this->getLoggedInUser());
617 $entry->setUrl($this->url
);
618 $this->getEntityManager()->persist($entry);
619 $this->getEntityManager()->flush();
621 $client->request('GET', '/delete/' . $entry->getId());
623 $this->assertSame(302, $client->getResponse()->getStatusCode());
625 $client->request('GET', '/delete/' . $entry->getId());
627 $this->assertSame(404, $client->getResponse()->getStatusCode());
631 * It will create a new entry.
635 * And it'll check that user won't be redirected to the view page of the content when it had been removed
637 public function testViewAndDelete()
639 $this->logInAs('admin');
640 $client = $this->getClient();
642 $em = $client->getContainer()
643 ->get('doctrine.orm.entity_manager');
645 // add a new content to be removed later
647 ->getRepository('WallabagUserBundle:User')
648 ->findOneByUserName('admin');
650 $content = new Entry($user);
651 $content->setUrl('http://1.1.1.1/entry');
652 $content->setReadingTime(12);
653 $content->setDomainName('domain.io');
654 $content->setMimetype('text/html');
655 $content->setTitle('test title entry');
656 $content->setContent('This is my content /o/');
657 $content->setArchived(true);
658 $content->setLanguage('fr');
660 $em->persist($content);
663 $client->request('GET', '/view/' . $content->getId());
664 $this->assertSame(200, $client->getResponse()->getStatusCode());
666 $client->request('GET', '/delete/' . $content->getId());
667 $this->assertSame(302, $client->getResponse()->getStatusCode());
669 $client->followRedirect();
670 $this->assertSame(200, $client->getResponse()->getStatusCode());
673 public function testViewOtherUserEntry()
675 $this->logInAs('admin');
676 $client = $this->getClient();
678 $content = $client->getContainer()
679 ->get('doctrine.orm.entity_manager')
680 ->getRepository('WallabagCoreBundle:Entry')
681 ->findOneByUsernameAndNotArchived('bob');
683 $client->request('GET', '/view/' . $content->getId());
685 $this->assertSame(403, $client->getResponse()->getStatusCode());
688 public function testFilterOnReadingTime()
690 $this->logInAs('admin');
691 $this->useTheme('baggy');
692 $client = $this->getClient();
693 $entry = new Entry($this->getLoggedInUser());
694 $entry->setUrl($this->url
);
695 $entry->setReadingTime(22);
696 $this->getEntityManager()->persist($entry);
697 $this->getEntityManager()->flush();
699 $crawler = $client->request('GET', '/unread/list');
701 $form = $crawler->filter('button[id=submit-filter]')->form();
704 'entry_filter[readingTime][right_number]' => 22,
705 'entry_filter[readingTime][left_number]' => 22,
708 $crawler = $client->submit($form, $data);
710 $this->assertCount(1, $crawler->filter('div[class=entry]'));
713 public function testFilterOnReadingTimeWithNegativeValue()
715 $this->logInAs('admin');
716 $client = $this->getClient();
718 $crawler = $client->request('GET', '/unread/list');
720 $form = $crawler->filter('button[id=submit-filter]')->form();
723 'entry_filter[readingTime][right_number]' => -22,
724 'entry_filter[readingTime][left_number]' => -22,
727 $crawler = $client->submit($form, $data);
729 // forcing negative value results in no entry displayed
730 $this->assertCount(0, $crawler->filter('div[class=entry]'));
733 public function testFilterOnReadingTimeOnlyUpper()
735 $this->logInAs('admin');
736 $this->useTheme('baggy');
737 $client = $this->getClient();
739 $crawler = $client->request('GET', '/all/list');
740 $this->assertCount(5, $crawler->filter('div[class=entry]'));
742 $entry = new Entry($this->getLoggedInUser());
743 $entry->setUrl($this->url
);
744 $entry->setReadingTime(23);
745 $this->getEntityManager()->persist($entry);
746 $this->getEntityManager()->flush();
748 $crawler = $client->request('GET', '/all/list');
749 $this->assertCount(6, $crawler->filter('div[class=entry]'));
751 $form = $crawler->filter('button[id=submit-filter]')->form();
754 'entry_filter[readingTime][right_number]' => 22,
757 $crawler = $client->submit($form, $data);
759 $this->assertCount(5, $crawler->filter('div[class=entry]'));
762 public function testFilterOnReadingTimeOnlyLower()
764 $this->logInAs('admin');
765 $this->useTheme('baggy');
766 $client = $this->getClient();
768 $crawler = $client->request('GET', '/unread/list');
770 $form = $crawler->filter('button[id=submit-filter]')->form();
773 'entry_filter[readingTime][left_number]' => 22,
776 $crawler = $client->submit($form, $data);
778 $this->assertCount(0, $crawler->filter('div[class=entry]'));
780 $entry = new Entry($this->getLoggedInUser());
781 $entry->setUrl($this->url
);
782 $entry->setReadingTime(23);
783 $this->getEntityManager()->persist($entry);
784 $this->getEntityManager()->flush();
786 $crawler = $client->submit($form, $data);
787 $this->assertCount(1, $crawler->filter('div[class=entry]'));
790 public function testFilterOnUnreadStatus()
792 $this->logInAs('admin');
793 $this->useTheme('baggy');
794 $client = $this->getClient();
796 $crawler = $client->request('GET', '/all/list');
798 $form = $crawler->filter('button[id=submit-filter]')->form();
801 'entry_filter[isUnread]' => true,
804 $crawler = $client->submit($form, $data);
806 $this->assertCount(4, $crawler->filter('div[class=entry]'));
808 $entry = new Entry($this->getLoggedInUser());
809 $entry->setUrl($this->url
);
810 $entry->setArchived(false);
811 $this->getEntityManager()->persist($entry);
812 $this->getEntityManager()->flush();
814 $crawler = $client->submit($form, $data);
816 $this->assertCount(5, $crawler->filter('div[class=entry]'));
819 public function testFilterOnCreationDate()
821 $this->logInAs('admin');
822 $this->useTheme('baggy');
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('div[class=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('div[class=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('div[class=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 $this->useTheme('baggy');
890 $client = $this->getClient();
892 $crawler = $client->request('GET', '/unread/list');
893 $form = $crawler->filter('button[id=submit-filter]')->form();
895 'entry_filter[domainName]' => 'domain',
898 $crawler = $client->submit($form, $data);
899 $this->assertCount(5, $crawler->filter('div[class=entry]'));
901 $crawler = $client->request('GET', '/unread/list');
902 $form = $crawler->filter('button[id=submit-filter]')->form();
904 'entry_filter[domainName]' => 'dOmain',
907 $crawler = $client->submit($form, $data);
908 $this->assertCount(5, $crawler->filter('div[class=entry]'));
910 $form = $crawler->filter('button[id=submit-filter]')->form();
912 'entry_filter[domainName]' => 'wallabag',
915 $crawler = $client->submit($form, $data);
916 $this->assertCount(0, $crawler->filter('div[class=entry]'));
919 public function testFilterOnStatus()
921 $this->logInAs('admin');
922 $this->useTheme('baggy');
923 $client = $this->getClient();
925 $crawler = $client->request('GET', '/unread/list');
926 $form = $crawler->filter('button[id=submit-filter]')->form();
927 $form['entry_filter[isArchived]']->tick();
928 $form['entry_filter[isStarred]']->untick();
930 $crawler = $client->submit($form);
931 $this->assertCount(1, $crawler->filter('div[class=entry]'));
933 $form = $crawler->filter('button[id=submit-filter]')->form();
934 $form['entry_filter[isArchived]']->untick();
935 $form['entry_filter[isStarred]']->tick();
937 $crawler = $client->submit($form);
938 $this->assertCount(1, $crawler->filter('div[class=entry]'));
941 public function testFilterOnIsPublic()
943 $this->logInAs('admin');
944 $this->useTheme('baggy');
945 $client = $this->getClient();
947 $crawler = $client->request('GET', '/unread/list');
948 $form = $crawler->filter('button[id=submit-filter]')->form();
949 $form['entry_filter[isPublic]']->tick();
951 $crawler = $client->submit($form);
952 $this->assertCount(0, $crawler->filter('div[class=entry]'));
955 public function testPreviewPictureFilter()
957 $this->logInAs('admin');
958 $this->useTheme('baggy');
959 $client = $this->getClient();
961 $crawler = $client->request('GET', '/unread/list');
962 $form = $crawler->filter('button[id=submit-filter]')->form();
963 $form['entry_filter[previewPicture]']->tick();
965 $crawler = $client->submit($form);
966 $this->assertCount(1, $crawler->filter('div[class=entry]'));
969 public function testFilterOnLanguage()
971 $this->logInAs('admin');
972 $this->useTheme('baggy');
973 $client = $this->getClient();
975 $entry = new Entry($this->getLoggedInUser());
976 $entry->setUrl($this->url
);
977 $entry->setLanguage('fr');
978 $this->getEntityManager()->persist($entry);
979 $this->getEntityManager()->flush();
981 $crawler = $client->request('GET', '/unread/list');
982 $form = $crawler->filter('button[id=submit-filter]')->form();
984 'entry_filter[language]' => 'fr',
987 $crawler = $client->submit($form, $data);
988 $this->assertCount(3, $crawler->filter('div[class=entry]'));
990 $form = $crawler->filter('button[id=submit-filter]')->form();
992 'entry_filter[language]' => 'en',
995 $crawler = $client->submit($form, $data);
996 $this->assertCount(2, $crawler->filter('div[class=entry]'));
999 public function testShareEntryPublicly()
1001 $this->logInAs('admin');
1002 $client = $this->getClient();
1004 // sharing is enabled
1005 $client->getContainer()->get('craue_config')->set('share_public', 1);
1007 $content = new Entry($this->getLoggedInUser());
1008 $content->setUrl($this->url
);
1009 $this->getEntityManager()->persist($content);
1010 $this->getEntityManager()->flush();
1011 $this->getEntityManager()->clear();
1014 $client->request('GET', '/share/' . $content->getUid());
1015 $this->assertSame(404, $client->getResponse()->getStatusCode());
1017 // generating the uid
1018 $client->request('GET', '/share/' . $content->getId());
1019 $this->assertSame(302, $client->getResponse()->getStatusCode());
1021 // follow link with uid
1022 $crawler = $client->followRedirect();
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 $client->request('GET', '/view/' . $content->getId());
1039 $this->assertContains('no-cache', $client->getResponse()->headers
->get('cache-control'));
1041 // removing the share
1042 $client->request('GET', '/share/delete/' . $content->getId());
1043 $this->assertSame(302, $client->getResponse()->getStatusCode());
1045 // share is now disable
1046 $client->request('GET', '/share/' . $content->getUid());
1047 $this->assertSame(404, $client->getResponse()->getStatusCode());
1050 public function testNewEntryWithDownloadImagesEnabled()
1052 $this->downloadImagesEnabled
= true;
1053 $this->logInAs('admin');
1054 $client = $this->getClient();
1056 $url = self
::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE
;
1057 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
1059 $crawler = $client->request('GET', '/new');
1061 $this->assertSame(200, $client->getResponse()->getStatusCode());
1063 $form = $crawler->filter('form[name=entry]')->form();
1066 'entry[url]' => $url,
1069 $client->submit($form, $data);
1071 $this->assertSame(302, $client->getResponse()->getStatusCode());
1073 $em = $client->getContainer()
1074 ->get('doctrine.orm.entity_manager');
1077 ->getRepository('WallabagCoreBundle:Entry')
1078 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1080 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry);
1081 $this->assertSame($url, $entry->getUrl());
1082 $this->assertContains('Judo', $entry->getTitle());
1083 // instead of checking for the filename (which might change) check that the image is now local
1084 $this->assertContains(rtrim($client->getContainer()->getParameter('domain_name'), '/') . '/assets/images/', $entry->getContent());
1086 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1090 * @depends testNewEntryWithDownloadImagesEnabled
1092 public function testRemoveEntryWithDownloadImagesEnabled()
1094 $this->downloadImagesEnabled
= true;
1095 $this->logInAs('admin');
1096 $client = $this->getClient();
1098 $url = self
::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE
;
1099 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
1101 $crawler = $client->request('GET', '/new');
1103 $this->assertSame(200, $client->getResponse()->getStatusCode());
1105 $form = $crawler->filter('form[name=entry]')->form();
1108 'entry[url]' => $url,
1111 $client->submit($form, $data);
1113 $this->assertSame(302, $client->getResponse()->getStatusCode());
1115 $content = $client->getContainer()
1116 ->get('doctrine.orm.entity_manager')
1117 ->getRepository('WallabagCoreBundle:Entry')
1118 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1120 $client->request('GET', '/delete/' . $content->getId());
1122 $this->assertSame(302, $client->getResponse()->getStatusCode());
1124 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1127 public function testRedirectToHomepage()
1129 $this->logInAs('empty');
1130 $client = $this->getClient();
1132 // Redirect to homepage
1133 $config = $this->getLoggedInUser()->getConfig();
1134 $config->setActionMarkAsRead(Config
::REDIRECT_TO_HOMEPAGE
);
1135 $this->getEntityManager()->persist($config);
1137 $entry = new Entry($this->getLoggedInUser());
1138 $entry->setUrl($this->url
);
1139 $this->getEntityManager()->persist($entry);
1141 $this->getEntityManager()->flush();
1143 $client->request('GET', '/view/' . $entry->getId());
1144 $client->request('GET', '/archive/' . $entry->getId());
1146 $this->assertSame(302, $client->getResponse()->getStatusCode());
1147 $this->assertSame('/', $client->getResponse()->headers
->get('location'));
1150 public function testRedirectToCurrentPage()
1152 $this->logInAs('empty');
1153 $client = $this->getClient();
1155 // Redirect to current page
1156 $config = $this->getLoggedInUser()->getConfig();
1157 $config->setActionMarkAsRead(Config
::REDIRECT_TO_CURRENT_PAGE
);
1158 $this->getEntityManager()->persist($config);
1160 $entry = new Entry($this->getLoggedInUser());
1161 $entry->setUrl($this->url
);
1162 $this->getEntityManager()->persist($entry);
1164 $this->getEntityManager()->flush();
1166 $client->request('GET', '/view/' . $entry->getId());
1167 $client->request('GET', '/archive/' . $entry->getId());
1169 $this->assertSame(302, $client->getResponse()->getStatusCode());
1170 $this->assertContains('/view/' . $entry->getId(), $client->getResponse()->headers
->get('location'));
1173 public function testFilterOnHttpStatus()
1175 $this->logInAs('admin');
1176 $this->useTheme('baggy');
1177 $client = $this->getClient();
1179 $entry = new Entry($this->getLoggedInUser());
1180 $entry->setUrl('http://www.lemonde.fr/incorrect-url/');
1181 $entry->setHttpStatus(404);
1182 $this->getEntityManager()->persist($entry);
1184 $this->getEntityManager()->flush();
1186 $crawler = $client->request('GET', '/all/list');
1187 $form = $crawler->filter('button[id=submit-filter]')->form();
1190 'entry_filter[httpStatus]' => 404,
1193 $crawler = $client->submit($form, $data);
1195 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1197 $entry = new Entry($this->getLoggedInUser());
1198 $entry->setUrl($this->url
);
1199 $entry->setHttpStatus(200);
1200 $this->getEntityManager()->persist($entry);
1202 $entry = new Entry($this->getLoggedInUser());
1203 $entry->setUrl('http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm');
1204 $entry->setHttpStatus(200);
1205 $this->getEntityManager()->persist($entry);
1207 $this->getEntityManager()->flush();
1209 $crawler = $client->request('GET', '/all/list');
1210 $form = $crawler->filter('button[id=submit-filter]')->form();
1213 'entry_filter[httpStatus]' => 200,
1216 $crawler = $client->submit($form, $data);
1218 $this->assertCount(2, $crawler->filter('div[class=entry]'));
1220 $crawler = $client->request('GET', '/all/list');
1221 $form = $crawler->filter('button[id=submit-filter]')->form();
1224 'entry_filter[httpStatus]' => 1024,
1227 $crawler = $client->submit($form, $data);
1229 $this->assertCount(8, $crawler->filter('div[class=entry]'));
1232 public function testSearch()
1234 $this->logInAs('admin');
1235 $this->useTheme('baggy');
1236 $client = $this->getClient();
1238 $entry = new Entry($this->getLoggedInUser());
1239 $entry->setUrl($this->url
);
1240 $entry->setTitle('test');
1241 $this->getEntityManager()->persist($entry);
1242 $this->getEntityManager()->flush();
1244 // Search on unread list
1245 $crawler = $client->request('GET', '/unread/list');
1247 $form = $crawler->filter('form[name=search]')->form();
1249 'search_entry[term]' => 'title',
1252 $crawler = $client->submit($form, $data);
1254 $this->assertCount(4, $crawler->filter('div[class=entry]'));
1256 // Search on starred list
1257 $crawler = $client->request('GET', '/starred/list');
1259 $entry = new Entry($this->getLoggedInUser());
1260 $entry->setUrl('http://localhost/foo/bar');
1261 $entry->setTitle('testeur');
1262 $entry->setStarred(true);
1263 $this->getEntityManager()->persist($entry);
1264 $this->getEntityManager()->flush();
1266 $form = $crawler->filter('form[name=search]')->form();
1268 'search_entry[term]' => 'testeur',
1271 $crawler = $client->submit($form, $data);
1273 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1275 $crawler = $client->request('GET', '/archive/list');
1277 // Added new article to test on archive list
1278 $entry = new Entry($this->getLoggedInUser());
1279 $entry->setUrl('http://0.0.0.0/foo/baz/qux');
1280 $entry->setTitle('Le manège');
1281 $entry->setArchived(true);
1282 $this->getEntityManager()->persist($entry);
1283 $this->getEntityManager()->flush();
1285 $form = $crawler->filter('form[name=search]')->form();
1287 'search_entry[term]' => 'manège',
1290 $crawler = $client->submit($form, $data);
1292 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1293 $client->request('GET', '/delete/' . $entry->getId());
1295 // test on list of all articles
1296 $crawler = $client->request('GET', '/all/list');
1298 $form = $crawler->filter('form[name=search]')->form();
1300 'search_entry[term]' => 'wxcvbnqsdf', // a string not available in the database
1303 $crawler = $client->submit($form, $data);
1305 $this->assertCount(0, $crawler->filter('div[class=entry]'));
1307 // test url search on list of all articles
1308 $entry = new Entry($this->getLoggedInUser());
1309 $entry->setUrl('http://domain/qux');
1310 $entry->setTitle('Le manège');
1311 $entry->setArchived(true);
1312 $this->getEntityManager()->persist($entry);
1313 $this->getEntityManager()->flush();
1315 $crawler = $client->request('GET', '/all/list');
1317 $form = $crawler->filter('form[name=search]')->form();
1319 'search_entry[term]' => 'domain', // the search will match an entry with 'domain' in its url
1322 $crawler = $client->submit($form, $data);
1324 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1326 // same as previous test but for case-sensitivity
1327 $crawler = $client->request('GET', '/all/list');
1329 $form = $crawler->filter('form[name=search]')->form();
1331 'search_entry[term]' => 'doMain', // the search will match an entry with 'domain' in its url
1334 $crawler = $client->submit($form, $data);
1336 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1339 public function dataForLanguage()
1343 'https://www.pravda.ru/world/09-06-2017/1337283-qatar-0/',
1347 'https://www.zataz.com/90-des-dossiers-medicaux-des-coreens-du-sud-vendus-a-des-entreprises-privees/',
1351 'http://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html',
1355 'http://www.ansa.it/sito/notizie/mondo/europa/2017/06/08/voto-gb-seggi-aperti-misure-sicurezza-rafforzate_0cb71f7f-e23b-4d5f-95ca-bc12296419f0.html',
1359 'http://www.hao123.com/shequ?__noscript__-=1',
1363 'https://buy.garmin.com/de-AT/AT/catalog/product/compareResult.ep?compareProduct=112885&compareProduct=36728',
1367 'http://netler.ru/ikt/windows-error-reporting.htm',
1371 'http://precodoscombustiveis.com.br/postos/cidade/4121/pr/maringa',
1374 'fucked_list_of_languages' => [
1375 'http://geocatalog.webservice-energy.org/geonetwork/srv/eng/main.home',
1379 'https://www.muylinux.com/2015/04/17/odf-reino-unido-microsoft-google/',
1386 * @dataProvider dataForLanguage
1388 public function testLanguageValidation($url, $expectedLanguage)
1390 $this->logInAs('admin');
1391 $client = $this->getClient();
1393 $crawler = $client->request('GET', '/new');
1395 $this->assertSame(200, $client->getResponse()->getStatusCode());
1397 $form = $crawler->filter('form[name=entry]')->form();
1400 'entry[url]' => $url,
1403 $client->submit($form, $data);
1405 $this->assertSame(302, $client->getResponse()->getStatusCode());
1407 $content = $client->getContainer()
1408 ->get('doctrine.orm.entity_manager')
1409 ->getRepository('WallabagCoreBundle:Entry')
1410 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1412 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1413 $this->assertSame($url, $content->getUrl());
1414 $this->assertSame($expectedLanguage, $content->getLanguage());
1418 * This test will require an internet connection.
1420 public function testRestrictedArticle()
1422 $url = 'https://www.monde-diplomatique.fr/2017/05/BONNET/57475';
1423 $this->logInAs('admin');
1424 $client = $this->getClient();
1425 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
1427 // enable restricted access
1428 $client->getContainer()->get('craue_config')->set('restricted_access', 1);
1430 // create a new site_credential
1431 $user = $client->getContainer()->get('security.token_storage')->getToken()->getUser();
1432 $credential = new SiteCredential($user);
1433 $credential->setHost('monde-diplomatique.fr');
1434 $credential->setUsername($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('foo'));
1435 $credential->setPassword($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('bar'));
1437 $em->persist($credential);
1440 $crawler = $client->request('GET', '/new');
1442 $this->assertSame(200, $client->getResponse()->getStatusCode());
1444 $form = $crawler->filter('form[name=entry]')->form();
1447 'entry[url]' => $url,
1450 $client->submit($form, $data);
1452 $this->assertSame(302, $client->getResponse()->getStatusCode());
1454 $crawler = $client->followRedirect();
1456 $this->assertSame(200, $client->getResponse()->getStatusCode());
1457 $this->assertContains('flashes.entry.notice.entry_saved', $crawler->filter('body')->extract(['_text'])[0]);
1460 ->getRepository('WallabagCoreBundle:Entry')
1461 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1463 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1464 $this->assertSame('Crimes et réformes aux Philippines', $content->getTitle());
1466 $client->getContainer()->get('craue_config')->set('restricted_access', 0);
1469 public function testPostEntryWhenFetchFails()
1471 $url = 'http://example.com/papers/email_tracking.pdf';
1472 $this->logInAs('admin');
1473 $client = $this->getClient();
1475 $container = $client->getContainer();
1476 $contentProxy = $this->getMockBuilder(ContentProxy
::class)
1477 ->disableOriginalConstructor()
1478 ->setMethods(['updateEntry'])
1480 $contentProxy->expects($this->any())
1481 ->method('updateEntry')
1482 ->willThrowException(new \
Exception('Test Fetch content fails'));
1484 $crawler = $client->request('GET', '/new');
1486 $this->assertSame(200, $client->getResponse()->getStatusCode());
1488 $form = $crawler->filter('form[name=entry]')->form();
1491 'entry[url]' => $url,
1495 * We generate a new client to be able to use Mock ContentProxy
1496 * Also we reinject the cookie from the previous client to keep the
1499 $cookie = $client->getCookieJar()->all();
1500 $client = $this->getNewClient();
1501 $client->getCookieJar()->set($cookie[0]);
1502 $client->getContainer()->set('wallabag_core.content_proxy', $contentProxy);
1503 $client->submit($form, $data);
1505 $this->assertSame(302, $client->getResponse()->getStatusCode());
1507 $content = $client->getContainer()
1508 ->get('doctrine.orm.entity_manager')
1509 ->getRepository('WallabagCoreBundle:Entry')
1510 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1512 $authors = $content->getPublishedBy();
1513 $this->assertSame('email_tracking.pdf', $content->getTitle());
1514 $this->assertSame('example.com', $content->getDomainName());