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());
269 * This test will require an internet connection.
271 public function testPostNewThatWillBeTagged()
273 $this->logInAs('admin');
274 $client = $this->getClient();
276 $crawler = $client->request('GET', '/new');
278 $this->assertSame(200, $client->getResponse()->getStatusCode());
280 $form = $crawler->filter('form[name=entry]')->form();
283 'entry[url]' => $url = 'https://github.com/wallabag/wallabag',
286 $client->submit($form, $data);
288 $this->assertSame(302, $client->getResponse()->getStatusCode());
289 $this->assertContains('/', $client->getResponse()->getTargetUrl());
291 $em = $client->getContainer()
292 ->get('doctrine.orm.entity_manager');
294 ->getRepository('WallabagCoreBundle:Entry')
295 ->findOneByUrl($url);
296 $tags = $entry->getTags();
298 $this->assertCount(2, $tags);
299 $this->assertContains('wallabag', $tags);
300 $this->assertSame('en', $entry->getLanguage());
305 // and now re-submit it to test the cascade persistence for tags after entry removal
306 // related https://github.com/wallabag/wallabag/issues/2121
307 $crawler = $client->request('GET', '/new');
309 $this->assertSame(200, $client->getResponse()->getStatusCode());
311 $form = $crawler->filter('form[name=entry]')->form();
314 'entry[url]' => $url = 'https://github.com/wallabag/wallabag/tree/master',
317 $client->submit($form, $data);
319 $this->assertSame(302, $client->getResponse()->getStatusCode());
320 $this->assertContains('/', $client->getResponse()->getTargetUrl());
323 ->getRepository('WallabagCoreBundle:Entry')
324 ->findOneByUrl($url);
326 $tags = $entry->getTags();
328 $this->assertCount(2, $tags);
329 $this->assertContains('wallabag', $tags);
335 public function testArchive()
337 $this->logInAs('admin');
338 $client = $this->getClient();
340 $client->request('GET', '/archive/list');
342 $this->assertSame(200, $client->getResponse()->getStatusCode());
345 public function testUntagged()
347 $this->logInAs('admin');
348 $client = $this->getClient();
350 $client->request('GET', '/untagged/list');
352 $this->assertSame(200, $client->getResponse()->getStatusCode());
355 public function testStarred()
357 $this->logInAs('admin');
358 $client = $this->getClient();
360 $client->request('GET', '/starred/list');
362 $this->assertSame(200, $client->getResponse()->getStatusCode());
365 public function testRangeException()
367 $this->logInAs('admin');
368 $client = $this->getClient();
370 $client->request('GET', '/all/list/900');
372 $this->assertSame(302, $client->getResponse()->getStatusCode());
373 $this->assertSame('/all/list', $client->getResponse()->getTargetUrl());
376 public function testView()
378 $this->logInAs('admin');
379 $client = $this->getClient();
381 $entry = new Entry($this->getLoggedInUser());
382 $entry->setUrl('http://example.com/foo');
383 $entry->setTitle('title foo');
384 $entry->setContent('foo bar baz');
385 $this->getEntityManager()->persist($entry);
386 $this->getEntityManager()->flush();
388 $crawler = $client->request('GET', '/view/' . $entry->getId());
390 $this->assertSame(200, $client->getResponse()->getStatusCode());
391 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
392 $this->assertContains($entry->getTitle(), $body[0]);
396 * This test will require an internet connection.
398 public function testReload()
400 $this->logInAs('admin');
401 $client = $this->getClient();
403 $entry = new Entry($this->getLoggedInUser());
404 $entry->setUrl($this->url
);
405 $entry->setTitle('title foo');
406 $entry->setContent('');
407 $this->getEntityManager()->persist($entry);
408 $this->getEntityManager()->flush();
409 $this->getEntityManager()->clear();
411 $client->request('GET', '/reload/' . $entry->getId());
413 $this->assertSame(302, $client->getResponse()->getStatusCode());
415 $entry = $this->getEntityManager()
416 ->getRepository('WallabagCoreBundle:Entry')
417 ->find($entry->getId());
419 $this->assertNotEmpty($entry->getContent());
422 public function testReloadWithFetchingFailed()
424 $this->logInAs('admin');
425 $client = $this->getClient();
427 $entry = new Entry($this->getLoggedInUser());
428 $entry->setUrl('http://0.0.0.0/failed.html');
429 $this->getEntityManager()->persist($entry);
430 $this->getEntityManager()->flush();
432 $client->request('GET', '/reload/' . $entry->getId());
434 $this->assertSame(302, $client->getResponse()->getStatusCode());
436 // force EntityManager to clear previous entity
437 // otherwise, retrieve the same entity will retrieve change from the previous request :0
438 $this->getEntityManager()->clear();
439 $newContent = $this->getEntityManager()
440 ->getRepository('WallabagCoreBundle:Entry')
441 ->find($entry->getId());
443 $this->assertNotSame($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent());
446 public function testEdit()
448 $this->logInAs('admin');
449 $client = $this->getClient();
451 $entry = new Entry($this->getLoggedInUser());
452 $entry->setUrl($this->url
);
453 $this->getEntityManager()->persist($entry);
454 $this->getEntityManager()->flush();
456 $crawler = $client->request('GET', '/edit/' . $entry->getId());
458 $this->assertSame(200, $client->getResponse()->getStatusCode());
460 $this->assertCount(1, $crawler->filter('input[id=entry_title]'));
461 $this->assertCount(1, $crawler->filter('button[id=entry_save]'));
464 public function testEditUpdate()
466 $this->logInAs('admin');
467 $client = $this->getClient();
469 $entry = new Entry($this->getLoggedInUser());
470 $entry->setUrl($this->url
);
471 $this->getEntityManager()->persist($entry);
472 $this->getEntityManager()->flush();
474 $crawler = $client->request('GET', '/edit/' . $entry->getId());
476 $this->assertSame(200, $client->getResponse()->getStatusCode());
478 $form = $crawler->filter('button[type=submit]')->form();
481 'entry[title]' => 'My updated title hehe :)',
482 'entry[origin_url]' => 'https://example.io',
485 $client->submit($form, $data);
487 $this->assertSame(302, $client->getResponse()->getStatusCode());
489 $crawler = $client->followRedirect();
491 $this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text']));
492 $this->assertContains('My updated title hehe :)', $title[0]);
493 $this->assertGreaterThan(1, $stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']));
494 $this->assertContains('example.io', trim($stats[1]));
497 public function testEditRemoveOriginUrl()
499 $this->logInAs('admin');
500 $client = $this->getClient();
502 $entry = new Entry($this->getLoggedInUser());
503 $entry->setUrl($this->url
);
504 $this->getEntityManager()->persist($entry);
505 $this->getEntityManager()->flush();
507 $crawler = $client->request('GET', '/edit/' . $entry->getId());
509 $this->assertSame(200, $client->getResponse()->getStatusCode());
511 $form = $crawler->filter('button[type=submit]')->form();
514 'entry[title]' => 'My updated title hehe :)',
515 'entry[origin_url]' => '',
518 $client->submit($form, $data);
520 $this->assertSame(302, $client->getResponse()->getStatusCode());
522 $crawler = $client->followRedirect();
524 $this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text']));
525 $this->assertContains('My updated title hehe :)', $title[0]);
526 $this->assertSame(1, count($stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text'])));
527 $this->assertNotContains('example.io', trim($stats[0]));
530 public function testToggleArchive()
532 $this->logInAs('admin');
533 $client = $this->getClient();
535 $entry = new Entry($this->getLoggedInUser());
536 $entry->setUrl($this->url
);
537 $this->getEntityManager()->persist($entry);
538 $this->getEntityManager()->flush();
539 $this->getEntityManager()->clear();
541 $client->request('GET', '/archive/' . $entry->getId());
543 $this->assertSame(302, $client->getResponse()->getStatusCode());
545 $res = $client->getContainer()
546 ->get('doctrine.orm.entity_manager')
547 ->getRepository('WallabagCoreBundle:Entry')
548 ->find($entry->getId());
550 $this->assertSame(1, $res->isArchived());
553 public function testToggleStar()
555 $this->logInAs('admin');
556 $client = $this->getClient();
558 $entry = new Entry($this->getLoggedInUser());
559 $entry->setUrl($this->url
);
560 $this->getEntityManager()->persist($entry);
561 $this->getEntityManager()->flush();
562 $this->getEntityManager()->clear();
564 $client->request('GET', '/star/' . $entry->getId());
566 $this->assertSame(302, $client->getResponse()->getStatusCode());
568 $res = $client->getContainer()
569 ->get('doctrine.orm.entity_manager')
570 ->getRepository('WallabagCoreBundle:Entry')
571 ->findOneById($entry->getId());
573 $this->assertSame(1, $res->isStarred());
576 public function testDelete()
578 $this->logInAs('admin');
579 $client = $this->getClient();
581 $entry = new Entry($this->getLoggedInUser());
582 $entry->setUrl($this->url
);
583 $this->getEntityManager()->persist($entry);
584 $this->getEntityManager()->flush();
586 $client->request('GET', '/delete/' . $entry->getId());
588 $this->assertSame(302, $client->getResponse()->getStatusCode());
590 $client->request('GET', '/delete/' . $entry->getId());
592 $this->assertSame(404, $client->getResponse()->getStatusCode());
596 * It will create a new entry.
600 * And it'll check that user won't be redirected to the view page of the content when it had been removed
602 public function testViewAndDelete()
604 $this->logInAs('admin');
605 $client = $this->getClient();
607 $em = $client->getContainer()
608 ->get('doctrine.orm.entity_manager');
610 // add a new content to be removed later
612 ->getRepository('WallabagUserBundle:User')
613 ->findOneByUserName('admin');
615 $content = new Entry($user);
616 $content->setUrl('http://1.1.1.1/entry');
617 $content->setReadingTime(12);
618 $content->setDomainName('domain.io');
619 $content->setMimetype('text/html');
620 $content->setTitle('test title entry');
621 $content->setContent('This is my content /o/');
622 $content->setArchived(true);
623 $content->setLanguage('fr');
625 $em->persist($content);
628 $client->request('GET', '/view/' . $content->getId());
629 $this->assertSame(200, $client->getResponse()->getStatusCode());
631 $client->request('GET', '/delete/' . $content->getId());
632 $this->assertSame(302, $client->getResponse()->getStatusCode());
634 $client->followRedirect();
635 $this->assertSame(200, $client->getResponse()->getStatusCode());
638 public function testViewOtherUserEntry()
640 $this->logInAs('admin');
641 $client = $this->getClient();
643 $content = $client->getContainer()
644 ->get('doctrine.orm.entity_manager')
645 ->getRepository('WallabagCoreBundle:Entry')
646 ->findOneByUsernameAndNotArchived('bob');
648 $client->request('GET', '/view/' . $content->getId());
650 $this->assertSame(403, $client->getResponse()->getStatusCode());
653 public function testFilterOnReadingTime()
655 $this->logInAs('admin');
656 $this->useTheme('baggy');
657 $client = $this->getClient();
658 $entry = new Entry($this->getLoggedInUser());
659 $entry->setUrl($this->url
);
660 $entry->setReadingTime(22);
661 $this->getEntityManager()->persist($entry);
662 $this->getEntityManager()->flush();
664 $crawler = $client->request('GET', '/unread/list');
666 $form = $crawler->filter('button[id=submit-filter]')->form();
669 'entry_filter[readingTime][right_number]' => 22,
670 'entry_filter[readingTime][left_number]' => 22,
673 $crawler = $client->submit($form, $data);
675 $this->assertCount(1, $crawler->filter('div[class=entry]'));
678 public function testFilterOnReadingTimeWithNegativeValue()
680 $this->logInAs('admin');
681 $client = $this->getClient();
683 $crawler = $client->request('GET', '/unread/list');
685 $form = $crawler->filter('button[id=submit-filter]')->form();
688 'entry_filter[readingTime][right_number]' => -22,
689 'entry_filter[readingTime][left_number]' => -22,
692 $crawler = $client->submit($form, $data);
694 // forcing negative value results in no entry displayed
695 $this->assertCount(0, $crawler->filter('div[class=entry]'));
698 public function testFilterOnReadingTimeOnlyUpper()
700 $this->logInAs('admin');
701 $this->useTheme('baggy');
702 $client = $this->getClient();
704 $crawler = $client->request('GET', '/all/list');
705 $this->assertCount(5, $crawler->filter('div[class=entry]'));
707 $entry = new Entry($this->getLoggedInUser());
708 $entry->setUrl($this->url
);
709 $entry->setReadingTime(23);
710 $this->getEntityManager()->persist($entry);
711 $this->getEntityManager()->flush();
713 $crawler = $client->request('GET', '/all/list');
714 $this->assertCount(6, $crawler->filter('div[class=entry]'));
716 $form = $crawler->filter('button[id=submit-filter]')->form();
719 'entry_filter[readingTime][right_number]' => 22,
722 $crawler = $client->submit($form, $data);
724 $this->assertCount(5, $crawler->filter('div[class=entry]'));
727 public function testFilterOnReadingTimeOnlyLower()
729 $this->logInAs('admin');
730 $this->useTheme('baggy');
731 $client = $this->getClient();
733 $crawler = $client->request('GET', '/unread/list');
735 $form = $crawler->filter('button[id=submit-filter]')->form();
738 'entry_filter[readingTime][left_number]' => 22,
741 $crawler = $client->submit($form, $data);
743 $this->assertCount(0, $crawler->filter('div[class=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->submit($form, $data);
752 $this->assertCount(1, $crawler->filter('div[class=entry]'));
755 public function testFilterOnUnreadStatus()
757 $this->logInAs('admin');
758 $this->useTheme('baggy');
759 $client = $this->getClient();
761 $crawler = $client->request('GET', '/all/list');
763 $form = $crawler->filter('button[id=submit-filter]')->form();
766 'entry_filter[isUnread]' => true,
769 $crawler = $client->submit($form, $data);
771 $this->assertCount(4, $crawler->filter('div[class=entry]'));
773 $entry = new Entry($this->getLoggedInUser());
774 $entry->setUrl($this->url
);
775 $entry->setArchived(false);
776 $this->getEntityManager()->persist($entry);
777 $this->getEntityManager()->flush();
779 $crawler = $client->submit($form, $data);
781 $this->assertCount(5, $crawler->filter('div[class=entry]'));
784 public function testFilterOnCreationDate()
786 $this->logInAs('admin');
787 $this->useTheme('baggy');
788 $client = $this->getClient();
790 $crawler = $client->request('GET', '/unread/list');
792 $form = $crawler->filter('button[id=submit-filter]')->form();
795 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
796 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')),
799 $crawler = $client->submit($form, $data);
801 $this->assertCount(5, $crawler->filter('div[class=entry]'));
804 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
805 'entry_filter[createdAt][right_date]' => date('d/m/Y'),
808 $crawler = $client->submit($form, $data);
810 $this->assertCount(5, $crawler->filter('div[class=entry]'));
813 'entry_filter[createdAt][left_date]' => '01/01/1970',
814 'entry_filter[createdAt][right_date]' => '01/01/1970',
817 $crawler = $client->submit($form, $data);
819 $this->assertCount(0, $crawler->filter('div[class=entry]'));
822 public function testPaginationWithFilter()
824 $this->logInAs('admin');
825 $client = $this->getClient();
826 $crawler = $client->request('GET', '/config');
828 $form = $crawler->filter('button[id=config_save]')->form();
831 'config[items_per_page]' => '1',
834 $client->submit($form, $data);
836 $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D=';
838 $client->request('GET', 'unread/list' . $parameters);
840 $this->assertContains($parameters, $client->getResponse()->getContent());
843 $crawler = $client->request('GET', '/config');
844 $form = $crawler->filter('button[id=config_save]')->form();
846 'config[items_per_page]' => '12',
848 $client->submit($form, $data);
851 public function testFilterOnDomainName()
853 $this->logInAs('admin');
854 $this->useTheme('baggy');
855 $client = $this->getClient();
857 $crawler = $client->request('GET', '/unread/list');
858 $form = $crawler->filter('button[id=submit-filter]')->form();
860 'entry_filter[domainName]' => 'domain',
863 $crawler = $client->submit($form, $data);
864 $this->assertCount(5, $crawler->filter('div[class=entry]'));
866 $crawler = $client->request('GET', '/unread/list');
867 $form = $crawler->filter('button[id=submit-filter]')->form();
869 'entry_filter[domainName]' => 'dOmain',
872 $crawler = $client->submit($form, $data);
873 $this->assertCount(5, $crawler->filter('div[class=entry]'));
875 $form = $crawler->filter('button[id=submit-filter]')->form();
877 'entry_filter[domainName]' => 'wallabag',
880 $crawler = $client->submit($form, $data);
881 $this->assertCount(0, $crawler->filter('div[class=entry]'));
884 public function testFilterOnStatus()
886 $this->logInAs('admin');
887 $this->useTheme('baggy');
888 $client = $this->getClient();
890 $crawler = $client->request('GET', '/unread/list');
891 $form = $crawler->filter('button[id=submit-filter]')->form();
892 $form['entry_filter[isArchived]']->tick();
893 $form['entry_filter[isStarred]']->untick();
895 $crawler = $client->submit($form);
896 $this->assertCount(1, $crawler->filter('div[class=entry]'));
898 $form = $crawler->filter('button[id=submit-filter]')->form();
899 $form['entry_filter[isArchived]']->untick();
900 $form['entry_filter[isStarred]']->tick();
902 $crawler = $client->submit($form);
903 $this->assertCount(1, $crawler->filter('div[class=entry]'));
906 public function testFilterOnIsPublic()
908 $this->logInAs('admin');
909 $this->useTheme('baggy');
910 $client = $this->getClient();
912 $crawler = $client->request('GET', '/unread/list');
913 $form = $crawler->filter('button[id=submit-filter]')->form();
914 $form['entry_filter[isPublic]']->tick();
916 $crawler = $client->submit($form);
917 $this->assertCount(0, $crawler->filter('div[class=entry]'));
920 public function testPreviewPictureFilter()
922 $this->logInAs('admin');
923 $this->useTheme('baggy');
924 $client = $this->getClient();
926 $crawler = $client->request('GET', '/unread/list');
927 $form = $crawler->filter('button[id=submit-filter]')->form();
928 $form['entry_filter[previewPicture]']->tick();
930 $crawler = $client->submit($form);
931 $this->assertCount(1, $crawler->filter('div[class=entry]'));
934 public function testFilterOnLanguage()
936 $this->logInAs('admin');
937 $this->useTheme('baggy');
938 $client = $this->getClient();
940 $entry = new Entry($this->getLoggedInUser());
941 $entry->setUrl($this->url
);
942 $entry->setLanguage('fr');
943 $this->getEntityManager()->persist($entry);
944 $this->getEntityManager()->flush();
946 $crawler = $client->request('GET', '/unread/list');
947 $form = $crawler->filter('button[id=submit-filter]')->form();
949 'entry_filter[language]' => 'fr',
952 $crawler = $client->submit($form, $data);
953 $this->assertCount(3, $crawler->filter('div[class=entry]'));
955 $form = $crawler->filter('button[id=submit-filter]')->form();
957 'entry_filter[language]' => 'en',
960 $crawler = $client->submit($form, $data);
961 $this->assertCount(2, $crawler->filter('div[class=entry]'));
964 public function testShareEntryPublicly()
966 $this->logInAs('admin');
967 $client = $this->getClient();
969 // sharing is enabled
970 $client->getContainer()->get('craue_config')->set('share_public', 1);
972 $content = new Entry($this->getLoggedInUser());
973 $content->setUrl($this->url
);
974 $this->getEntityManager()->persist($content);
975 $this->getEntityManager()->flush();
976 $this->getEntityManager()->clear();
979 $client->request('GET', '/share/' . $content->getUid());
980 $this->assertSame(404, $client->getResponse()->getStatusCode());
982 // generating the uid
983 $client->request('GET', '/share/' . $content->getId());
984 $this->assertSame(302, $client->getResponse()->getStatusCode());
986 // follow link with uid
987 $crawler = $client->followRedirect();
988 $this->assertSame(200, $client->getResponse()->getStatusCode());
989 $this->assertContains('max-age=25200', $client->getResponse()->headers
->get('cache-control'));
990 $this->assertContains('public', $client->getResponse()->headers
->get('cache-control'));
991 $this->assertContains('s-maxage=25200', $client->getResponse()->headers
->get('cache-control'));
992 $this->assertNotContains('no-cache', $client->getResponse()->headers
->get('cache-control'));
993 $this->assertContains('og:title', $client->getResponse()->getContent());
994 $this->assertContains('og:type', $client->getResponse()->getContent());
995 $this->assertContains('og:url', $client->getResponse()->getContent());
996 $this->assertContains('og:image', $client->getResponse()->getContent());
998 // sharing is now disabled
999 $client->getContainer()->get('craue_config')->set('share_public', 0);
1000 $client->request('GET', '/share/' . $content->getUid());
1001 $this->assertSame(404, $client->getResponse()->getStatusCode());
1003 $client->request('GET', '/view/' . $content->getId());
1004 $this->assertContains('no-cache', $client->getResponse()->headers
->get('cache-control'));
1006 // removing the share
1007 $client->request('GET', '/share/delete/' . $content->getId());
1008 $this->assertSame(302, $client->getResponse()->getStatusCode());
1010 // share is now disable
1011 $client->request('GET', '/share/' . $content->getUid());
1012 $this->assertSame(404, $client->getResponse()->getStatusCode());
1015 public function testNewEntryWithDownloadImagesEnabled()
1017 $this->downloadImagesEnabled
= true;
1018 $this->logInAs('admin');
1019 $client = $this->getClient();
1021 $url = self
::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE
;
1022 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
1024 $crawler = $client->request('GET', '/new');
1026 $this->assertSame(200, $client->getResponse()->getStatusCode());
1028 $form = $crawler->filter('form[name=entry]')->form();
1031 'entry[url]' => $url,
1034 $client->submit($form, $data);
1036 $this->assertSame(302, $client->getResponse()->getStatusCode());
1038 $em = $client->getContainer()
1039 ->get('doctrine.orm.entity_manager');
1042 ->getRepository('WallabagCoreBundle:Entry')
1043 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1045 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry);
1046 $this->assertSame($url, $entry->getUrl());
1047 $this->assertContains('Judo', $entry->getTitle());
1048 // instead of checking for the filename (which might change) check that the image is now local
1049 $this->assertContains(rtrim($client->getContainer()->getParameter('domain_name'), '/') . '/assets/images/', $entry->getContent());
1051 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1055 * @depends testNewEntryWithDownloadImagesEnabled
1057 public function testRemoveEntryWithDownloadImagesEnabled()
1059 $this->downloadImagesEnabled
= true;
1060 $this->logInAs('admin');
1061 $client = $this->getClient();
1063 $url = self
::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE
;
1064 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
1066 $crawler = $client->request('GET', '/new');
1068 $this->assertSame(200, $client->getResponse()->getStatusCode());
1070 $form = $crawler->filter('form[name=entry]')->form();
1073 'entry[url]' => $url,
1076 $client->submit($form, $data);
1078 $this->assertSame(302, $client->getResponse()->getStatusCode());
1080 $content = $client->getContainer()
1081 ->get('doctrine.orm.entity_manager')
1082 ->getRepository('WallabagCoreBundle:Entry')
1083 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1085 $client->request('GET', '/delete/' . $content->getId());
1087 $this->assertSame(302, $client->getResponse()->getStatusCode());
1089 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1092 public function testRedirectToHomepage()
1094 $this->logInAs('empty');
1095 $client = $this->getClient();
1097 // Redirect to homepage
1098 $config = $this->getLoggedInUser()->getConfig();
1099 $config->setActionMarkAsRead(Config
::REDIRECT_TO_HOMEPAGE
);
1100 $this->getEntityManager()->persist($config);
1102 $entry = new Entry($this->getLoggedInUser());
1103 $entry->setUrl($this->url
);
1104 $this->getEntityManager()->persist($entry);
1106 $this->getEntityManager()->flush();
1108 $client->request('GET', '/view/' . $entry->getId());
1109 $client->request('GET', '/archive/' . $entry->getId());
1111 $this->assertSame(302, $client->getResponse()->getStatusCode());
1112 $this->assertSame('/', $client->getResponse()->headers
->get('location'));
1115 public function testRedirectToCurrentPage()
1117 $this->logInAs('empty');
1118 $client = $this->getClient();
1120 // Redirect to current page
1121 $config = $this->getLoggedInUser()->getConfig();
1122 $config->setActionMarkAsRead(Config
::REDIRECT_TO_CURRENT_PAGE
);
1123 $this->getEntityManager()->persist($config);
1125 $entry = new Entry($this->getLoggedInUser());
1126 $entry->setUrl($this->url
);
1127 $this->getEntityManager()->persist($entry);
1129 $this->getEntityManager()->flush();
1131 $client->request('GET', '/view/' . $entry->getId());
1132 $client->request('GET', '/archive/' . $entry->getId());
1134 $this->assertSame(302, $client->getResponse()->getStatusCode());
1135 $this->assertContains('/view/' . $entry->getId(), $client->getResponse()->headers
->get('location'));
1138 public function testFilterOnHttpStatus()
1140 $this->logInAs('admin');
1141 $this->useTheme('baggy');
1142 $client = $this->getClient();
1144 $entry = new Entry($this->getLoggedInUser());
1145 $entry->setUrl('http://www.lemonde.fr/incorrect-url/');
1146 $entry->setHttpStatus(404);
1147 $this->getEntityManager()->persist($entry);
1149 $this->getEntityManager()->flush();
1151 $crawler = $client->request('GET', '/all/list');
1152 $form = $crawler->filter('button[id=submit-filter]')->form();
1155 'entry_filter[httpStatus]' => 404,
1158 $crawler = $client->submit($form, $data);
1160 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1162 $entry = new Entry($this->getLoggedInUser());
1163 $entry->setUrl($this->url
);
1164 $entry->setHttpStatus(200);
1165 $this->getEntityManager()->persist($entry);
1167 $entry = new Entry($this->getLoggedInUser());
1168 $entry->setUrl('http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm');
1169 $entry->setHttpStatus(200);
1170 $this->getEntityManager()->persist($entry);
1172 $this->getEntityManager()->flush();
1174 $crawler = $client->request('GET', '/all/list');
1175 $form = $crawler->filter('button[id=submit-filter]')->form();
1178 'entry_filter[httpStatus]' => 200,
1181 $crawler = $client->submit($form, $data);
1183 $this->assertCount(2, $crawler->filter('div[class=entry]'));
1185 $crawler = $client->request('GET', '/all/list');
1186 $form = $crawler->filter('button[id=submit-filter]')->form();
1189 'entry_filter[httpStatus]' => 1024,
1192 $crawler = $client->submit($form, $data);
1194 $this->assertCount(8, $crawler->filter('div[class=entry]'));
1197 public function testSearch()
1199 $this->logInAs('admin');
1200 $this->useTheme('baggy');
1201 $client = $this->getClient();
1203 $entry = new Entry($this->getLoggedInUser());
1204 $entry->setUrl($this->url
);
1205 $entry->setTitle('test');
1206 $this->getEntityManager()->persist($entry);
1207 $this->getEntityManager()->flush();
1209 // Search on unread list
1210 $crawler = $client->request('GET', '/unread/list');
1212 $form = $crawler->filter('form[name=search]')->form();
1214 'search_entry[term]' => 'title',
1217 $crawler = $client->submit($form, $data);
1219 $this->assertCount(4, $crawler->filter('div[class=entry]'));
1221 // Search on starred list
1222 $crawler = $client->request('GET', '/starred/list');
1224 $entry = new Entry($this->getLoggedInUser());
1225 $entry->setUrl('http://localhost/foo/bar');
1226 $entry->setTitle('testeur');
1227 $entry->setStarred(true);
1228 $this->getEntityManager()->persist($entry);
1229 $this->getEntityManager()->flush();
1231 $form = $crawler->filter('form[name=search]')->form();
1233 'search_entry[term]' => 'testeur',
1236 $crawler = $client->submit($form, $data);
1238 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1240 $crawler = $client->request('GET', '/archive/list');
1242 // Added new article to test on archive list
1243 $entry = new Entry($this->getLoggedInUser());
1244 $entry->setUrl('http://0.0.0.0/foo/baz/qux');
1245 $entry->setTitle('Le manège');
1246 $entry->setArchived(true);
1247 $this->getEntityManager()->persist($entry);
1248 $this->getEntityManager()->flush();
1250 $form = $crawler->filter('form[name=search]')->form();
1252 'search_entry[term]' => 'manège',
1255 $crawler = $client->submit($form, $data);
1257 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1258 $client->request('GET', '/delete/' . $entry->getId());
1260 // test on list of all articles
1261 $crawler = $client->request('GET', '/all/list');
1263 $form = $crawler->filter('form[name=search]')->form();
1265 'search_entry[term]' => 'wxcvbnqsdf', // a string not available in the database
1268 $crawler = $client->submit($form, $data);
1270 $this->assertCount(0, $crawler->filter('div[class=entry]'));
1272 // test url search on list of all articles
1273 $entry = new Entry($this->getLoggedInUser());
1274 $entry->setUrl('http://domain/qux');
1275 $entry->setTitle('Le manège');
1276 $entry->setArchived(true);
1277 $this->getEntityManager()->persist($entry);
1278 $this->getEntityManager()->flush();
1280 $crawler = $client->request('GET', '/all/list');
1282 $form = $crawler->filter('form[name=search]')->form();
1284 'search_entry[term]' => 'domain', // the search will match an entry with 'domain' in its url
1287 $crawler = $client->submit($form, $data);
1289 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1291 // same as previous test but for case-sensitivity
1292 $crawler = $client->request('GET', '/all/list');
1294 $form = $crawler->filter('form[name=search]')->form();
1296 'search_entry[term]' => 'doMain', // the search will match an entry with 'domain' in its url
1299 $crawler = $client->submit($form, $data);
1301 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1304 public function dataForLanguage()
1308 'https://www.pravda.ru/world/09-06-2017/1337283-qatar-0/',
1312 'https://www.zataz.com/90-des-dossiers-medicaux-des-coreens-du-sud-vendus-a-des-entreprises-privees/',
1316 'http://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html',
1320 'http://www.ansa.it/sito/notizie/mondo/europa/2017/06/08/voto-gb-seggi-aperti-misure-sicurezza-rafforzate_0cb71f7f-e23b-4d5f-95ca-bc12296419f0.html',
1324 'http://www.hao123.com/shequ?__noscript__-=1',
1328 'https://buy.garmin.com/de-AT/AT/catalog/product/compareResult.ep?compareProduct=112885&compareProduct=36728',
1332 'http://netler.ru/ikt/windows-error-reporting.htm',
1336 'http://precodoscombustiveis.com.br/postos/cidade/4121/pr/maringa',
1339 'fucked_list_of_languages' => [
1340 'http://geocatalog.webservice-energy.org/geonetwork/srv/eng/main.home',
1344 'https://www.muylinux.com/2015/04/17/odf-reino-unido-microsoft-google/',
1351 * @dataProvider dataForLanguage
1353 public function testLanguageValidation($url, $expectedLanguage)
1355 $this->logInAs('admin');
1356 $client = $this->getClient();
1358 $crawler = $client->request('GET', '/new');
1360 $this->assertSame(200, $client->getResponse()->getStatusCode());
1362 $form = $crawler->filter('form[name=entry]')->form();
1365 'entry[url]' => $url,
1368 $client->submit($form, $data);
1370 $this->assertSame(302, $client->getResponse()->getStatusCode());
1372 $content = $client->getContainer()
1373 ->get('doctrine.orm.entity_manager')
1374 ->getRepository('WallabagCoreBundle:Entry')
1375 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1377 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1378 $this->assertSame($url, $content->getUrl());
1379 $this->assertSame($expectedLanguage, $content->getLanguage());
1383 * This test will require an internet connection.
1385 public function testRestrictedArticle()
1387 $url = 'https://www.monde-diplomatique.fr/2017/05/BONNET/57475';
1388 $this->logInAs('admin');
1389 $client = $this->getClient();
1390 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
1392 // enable restricted access
1393 $client->getContainer()->get('craue_config')->set('restricted_access', 1);
1395 // create a new site_credential
1396 $user = $client->getContainer()->get('security.token_storage')->getToken()->getUser();
1397 $credential = new SiteCredential($user);
1398 $credential->setHost('monde-diplomatique.fr');
1399 $credential->setUsername($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('foo'));
1400 $credential->setPassword($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('bar'));
1402 $em->persist($credential);
1405 $crawler = $client->request('GET', '/new');
1407 $this->assertSame(200, $client->getResponse()->getStatusCode());
1409 $form = $crawler->filter('form[name=entry]')->form();
1412 'entry[url]' => $url,
1415 $client->submit($form, $data);
1417 $this->assertSame(302, $client->getResponse()->getStatusCode());
1419 $crawler = $client->followRedirect();
1421 $this->assertSame(200, $client->getResponse()->getStatusCode());
1422 $this->assertContains('flashes.entry.notice.entry_saved', $crawler->filter('body')->extract(['_text'])[0]);
1425 ->getRepository('WallabagCoreBundle:Entry')
1426 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1428 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1429 $this->assertSame('Crimes et réformes aux Philippines', $content->getTitle());
1431 $client->getContainer()->get('craue_config')->set('restricted_access', 0);
1434 public function testPostEntryWhenFetchFails()
1436 $url = 'http://example.com/papers/email_tracking.pdf';
1437 $this->logInAs('admin');
1438 $client = $this->getClient();
1440 $container = $client->getContainer();
1441 $contentProxy = $this->getMockBuilder(ContentProxy
::class)
1442 ->disableOriginalConstructor()
1443 ->setMethods(['updateEntry'])
1445 $contentProxy->expects($this->any())
1446 ->method('updateEntry')
1447 ->willThrowException(new \
Exception('Test Fetch content fails'));
1449 $crawler = $client->request('GET', '/new');
1451 $this->assertSame(200, $client->getResponse()->getStatusCode());
1453 $form = $crawler->filter('form[name=entry]')->form();
1456 'entry[url]' => $url,
1460 * We generate a new client to be able to use Mock ContentProxy
1461 * Also we reinject the cookie from the previous client to keep the
1464 $cookie = $client->getCookieJar()->all();
1465 $client = $this->getNewClient();
1466 $client->getCookieJar()->set($cookie[0]);
1467 $client->getContainer()->set('wallabag_core.content_proxy', $contentProxy);
1468 $client->submit($form, $data);
1470 $this->assertSame(302, $client->getResponse()->getStatusCode());
1472 $content = $client->getContainer()
1473 ->get('doctrine.orm.entity_manager')
1474 ->getRepository('WallabagCoreBundle:Entry')
1475 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1477 $authors = $content->getPublishedBy();
1478 $this->assertSame('email_tracking.pdf', $content->getTitle());
1479 $this->assertSame('example.com', $content->getDomainName());