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/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html';
21 * Ensure download_images_enabled is disabled after each script
23 public function tearDownImagesEnabled()
25 if ($this->downloadImagesEnabled
) {
26 $client = static::createClient();
27 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
29 $this->downloadImagesEnabled
= false;
33 public function testLogin()
35 $client = $this->getClient();
37 $client->request('GET', '/new');
39 $this->assertSame(302, $client->getResponse()->getStatusCode());
40 $this->assertContains('login', $client->getResponse()->headers
->get('location'));
43 public function testQuickstart()
45 $this->logInAs('empty');
46 $client = $this->getClient();
48 $client->request('GET', '/unread/list');
49 $this->assertSame(302, $client->getResponse()->getStatusCode());
50 $crawler = $client->followRedirect();
52 $this->assertSame(200, $client->getResponse()->getStatusCode());
53 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
54 $this->assertContains('quickstart.intro.title', $body[0]);
56 // Test if quickstart is disabled when user has 1 entry
57 $crawler = $client->request('GET', '/new');
59 $this->assertSame(200, $client->getResponse()->getStatusCode());
61 $form = $crawler->filter('form[name=entry]')->form();
64 'entry[url]' => $this->url
,
67 $client->submit($form, $data);
68 $this->assertSame(302, $client->getResponse()->getStatusCode());
69 $client->followRedirect();
71 $crawler = $client->request('GET', '/unread/list');
72 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
73 $this->assertContains('entry.list.number_on_the_page', $body[0]);
76 public function testGetNew()
78 $this->logInAs('admin');
79 $this->useTheme('baggy');
80 $client = $this->getClient();
82 $crawler = $client->request('GET', '/new');
84 $this->assertSame(200, $client->getResponse()->getStatusCode());
86 $this->assertCount(1, $crawler->filter('input[type=url]'));
87 $this->assertCount(1, $crawler->filter('form[name=entry]'));
90 public function testPostNewViaBookmarklet()
92 $this->logInAs('admin');
93 $this->useTheme('baggy');
94 $client = $this->getClient();
96 $crawler = $client->request('GET', '/');
98 $this->assertCount(4, $crawler->filter('div[class=entry]'));
101 $client->request('GET', '/bookmarklet', ['url' => $this->url
]);
102 $this->assertSame(302, $client->getResponse()->getStatusCode());
103 $client->followRedirect();
104 $crawler = $client->request('GET', '/');
105 $this->assertCount(5, $crawler->filter('div[class=entry]'));
107 $em = $client->getContainer()
108 ->get('doctrine.orm.entity_manager');
110 ->getRepository('WallabagCoreBundle:Entry')
111 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
116 public function testPostNewEmpty()
118 $this->logInAs('admin');
119 $client = $this->getClient();
121 $crawler = $client->request('GET', '/new');
123 $this->assertSame(200, $client->getResponse()->getStatusCode());
125 $form = $crawler->filter('form[name=entry]')->form();
127 $crawler = $client->submit($form);
129 $this->assertSame(200, $client->getResponse()->getStatusCode());
130 $this->assertCount(1, $alert = $crawler->filter('form ul li')->extract(['_text']));
131 $this->assertSame('This value should not be blank.', $alert[0]);
135 * This test will require an internet connection.
137 public function testPostNewOk()
139 $this->logInAs('admin');
140 $client = $this->getClient();
142 $client->getContainer()->get('craue_config')->set('store_article_headers', 1);
144 $crawler = $client->request('GET', '/new');
146 $this->assertSame(200, $client->getResponse()->getStatusCode());
148 $form = $crawler->filter('form[name=entry]')->form();
151 'entry[url]' => $this->url
,
154 $client->submit($form, $data);
156 $this->assertSame(302, $client->getResponse()->getStatusCode());
158 $content = $client->getContainer()
159 ->get('doctrine.orm.entity_manager')
160 ->getRepository('WallabagCoreBundle:Entry')
161 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
163 $author = $content->getPublishedBy();
165 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
166 $this->assertSame($this->url
, $content->getUrl());
167 $this->assertContains('Google', $content->getTitle());
168 $this->assertSame('fr', $content->getLanguage());
169 $this->assertSame('2016-04-07 19:01:35', $content->getPublishedAt()->format('Y-m-d H:i:s'));
170 $this->assertArrayHasKey('x-frame-options', $content->getHeaders());
171 $client->getContainer()->get('craue_config')->set('store_article_headers', 0);
174 public function testPostWithMultipleAuthors()
176 $url = 'https://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 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
200 $authors = $content->getPublishedBy();
201 $this->assertSame('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s'));
202 $this->assertSame('fr', $content->getLanguage());
203 $this->assertSame('Raphaël Balenieri, correspondant à Pékin', $authors[0]);
204 $this->assertSame('Frédéric Autran, correspondant à New York', $authors[1]);
207 public function testPostNewOkUrlExist()
209 $this->logInAs('admin');
211 $entry = new Entry($this->getLoggedInUser());
212 $entry->setUrl($this->url
);
213 $this->getEntityManager()->persist($entry);
214 $this->getEntityManager()->flush();
216 $client = $this->getClient();
218 $crawler = $client->request('GET', '/new');
220 $this->assertSame(200, $client->getResponse()->getStatusCode());
222 $form = $crawler->filter('form[name=entry]')->form();
225 'entry[url]' => $this->url
,
228 $client->submit($form, $data);
230 $this->assertSame(302, $client->getResponse()->getStatusCode());
231 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
234 public function testPostNewOkUrlExistWithAccent()
236 $this->logInAs('admin');
237 $client = $this->getClient();
239 $url = 'http://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing';
241 $crawler = $client->request('GET', '/new');
243 $this->assertSame(200, $client->getResponse()->getStatusCode());
245 $form = $crawler->filter('form[name=entry]')->form();
248 'entry[url]' => $url,
251 $client->submit($form, $data);
253 $crawler = $client->request('GET', '/new');
255 $this->assertSame(200, $client->getResponse()->getStatusCode());
257 $form = $crawler->filter('form[name=entry]')->form();
260 'entry[url]' => $url,
263 $client->submit($form, $data);
265 $this->assertSame(302, $client->getResponse()->getStatusCode());
266 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
270 * This test will require an internet connection.
272 public function testPostNewThatWillBeTagged()
274 $this->logInAs('admin');
275 $client = $this->getClient();
277 $crawler = $client->request('GET', '/new');
279 $this->assertSame(200, $client->getResponse()->getStatusCode());
281 $form = $crawler->filter('form[name=entry]')->form();
284 'entry[url]' => $url = 'https://github.com/wallabag/wallabag',
287 $client->submit($form, $data);
289 $this->assertSame(302, $client->getResponse()->getStatusCode());
290 $this->assertContains('/', $client->getResponse()->getTargetUrl());
292 $em = $client->getContainer()
293 ->get('doctrine.orm.entity_manager');
295 ->getRepository('WallabagCoreBundle:Entry')
296 ->findOneByUrl($url);
297 $tags = $entry->getTags();
299 $this->assertCount(2, $tags);
300 $this->assertContains('wallabag', $tags);
301 $this->assertSame('en', $entry->getLanguage());
306 // and now re-submit it to test the cascade persistence for tags after entry removal
307 // related https://github.com/wallabag/wallabag/issues/2121
308 $crawler = $client->request('GET', '/new');
310 $this->assertSame(200, $client->getResponse()->getStatusCode());
312 $form = $crawler->filter('form[name=entry]')->form();
315 'entry[url]' => $url = 'https://github.com/wallabag/wallabag/tree/master',
318 $client->submit($form, $data);
320 $this->assertSame(302, $client->getResponse()->getStatusCode());
321 $this->assertContains('/', $client->getResponse()->getTargetUrl());
324 ->getRepository('WallabagCoreBundle:Entry')
325 ->findOneByUrl($url);
327 $tags = $entry->getTags();
329 $this->assertCount(2, $tags);
330 $this->assertContains('wallabag', $tags);
336 public function testArchive()
338 $this->logInAs('admin');
339 $client = $this->getClient();
341 $client->request('GET', '/archive/list');
343 $this->assertSame(200, $client->getResponse()->getStatusCode());
346 public function testUntagged()
348 $this->logInAs('admin');
349 $client = $this->getClient();
351 $client->request('GET', '/untagged/list');
353 $this->assertSame(200, $client->getResponse()->getStatusCode());
356 public function testStarred()
358 $this->logInAs('admin');
359 $client = $this->getClient();
361 $client->request('GET', '/starred/list');
363 $this->assertSame(200, $client->getResponse()->getStatusCode());
366 public function testRangeException()
368 $this->logInAs('admin');
369 $client = $this->getClient();
371 $client->request('GET', '/all/list/900');
373 $this->assertSame(302, $client->getResponse()->getStatusCode());
374 $this->assertSame('/all/list', $client->getResponse()->getTargetUrl());
377 public function testView()
379 $this->logInAs('admin');
380 $client = $this->getClient();
382 $entry = new Entry($this->getLoggedInUser());
383 $entry->setUrl('http://example.com/foo');
384 $entry->setTitle('title foo');
385 $entry->setContent('foo bar baz');
386 $this->getEntityManager()->persist($entry);
387 $this->getEntityManager()->flush();
389 $crawler = $client->request('GET', '/view/' . $entry->getId());
391 $this->assertSame(200, $client->getResponse()->getStatusCode());
392 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
393 $this->assertContains($entry->getTitle(), $body[0]);
397 * This test will require an internet connection.
399 public function testReload()
401 $this->logInAs('admin');
402 $client = $this->getClient();
404 $entry = new Entry($this->getLoggedInUser());
405 $entry->setUrl($this->url
);
406 $entry->setTitle('title foo');
407 $entry->setContent('');
408 $this->getEntityManager()->persist($entry);
409 $this->getEntityManager()->flush();
410 $this->getEntityManager()->clear();
412 $client->request('GET', '/reload/' . $entry->getId());
414 $this->assertSame(302, $client->getResponse()->getStatusCode());
416 $entry = $this->getEntityManager()
417 ->getRepository('WallabagCoreBundle:Entry')
418 ->find($entry->getId());
420 $this->assertNotEmpty($entry->getContent());
423 public function testReloadWithFetchingFailed()
425 $this->logInAs('admin');
426 $client = $this->getClient();
428 $entry = new Entry($this->getLoggedInUser());
429 $entry->setUrl('http://0.0.0.0/failed.html');
430 $this->getEntityManager()->persist($entry);
431 $this->getEntityManager()->flush();
433 $client->request('GET', '/reload/' . $entry->getId());
435 $this->assertSame(302, $client->getResponse()->getStatusCode());
437 // force EntityManager to clear previous entity
438 // otherwise, retrieve the same entity will retrieve change from the previous request :0
439 $this->getEntityManager()->clear();
440 $newContent = $this->getEntityManager()
441 ->getRepository('WallabagCoreBundle:Entry')
442 ->find($entry->getId());
444 $this->assertNotSame($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent());
447 public function testEdit()
449 $this->logInAs('admin');
450 $client = $this->getClient();
452 $entry = new Entry($this->getLoggedInUser());
453 $entry->setUrl($this->url
);
454 $this->getEntityManager()->persist($entry);
455 $this->getEntityManager()->flush();
457 $crawler = $client->request('GET', '/edit/' . $entry->getId());
459 $this->assertSame(200, $client->getResponse()->getStatusCode());
461 $this->assertCount(1, $crawler->filter('input[id=entry_title]'));
462 $this->assertCount(1, $crawler->filter('button[id=entry_save]'));
465 public function testEditUpdate()
467 $this->logInAs('admin');
468 $client = $this->getClient();
470 $entry = new Entry($this->getLoggedInUser());
471 $entry->setUrl($this->url
);
472 $this->getEntityManager()->persist($entry);
473 $this->getEntityManager()->flush();
475 $crawler = $client->request('GET', '/edit/' . $entry->getId());
477 $this->assertSame(200, $client->getResponse()->getStatusCode());
479 $form = $crawler->filter('button[id=entry_save]')->form();
482 'entry[title]' => 'My updated title hehe :)',
483 'entry[origin_url]' => 'https://example.io',
486 $client->submit($form, $data);
488 $this->assertSame(302, $client->getResponse()->getStatusCode());
490 $crawler = $client->followRedirect();
492 $this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text']));
493 $this->assertContains('My updated title hehe :)', $title[0]);
494 $this->assertGreaterThan(1, $stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']));
495 $this->assertContains('example.io', trim($stats[1]));
498 public function testEditRemoveOriginUrl()
500 $this->logInAs('admin');
501 $client = $this->getClient();
503 $entry = new Entry($this->getLoggedInUser());
504 $entry->setUrl($this->url
);
505 $this->getEntityManager()->persist($entry);
506 $this->getEntityManager()->flush();
508 $crawler = $client->request('GET', '/edit/' . $entry->getId());
510 $this->assertSame(200, $client->getResponse()->getStatusCode());
512 $form = $crawler->filter('button[id=entry_save]')->form();
515 'entry[title]' => 'My updated title hehe :)',
516 'entry[origin_url]' => '',
519 $client->submit($form, $data);
521 $this->assertSame(302, $client->getResponse()->getStatusCode());
523 $crawler = $client->followRedirect();
525 $this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text']));
526 $this->assertContains('My updated title hehe :)', $title[0]);
527 $this->assertSame(1, \
count($stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text'])));
528 $this->assertNotContains('example.io', trim($stats[0]));
531 public function testToggleArchive()
533 $this->logInAs('admin');
534 $client = $this->getClient();
536 $entry = new Entry($this->getLoggedInUser());
537 $entry->setUrl($this->url
);
538 $this->getEntityManager()->persist($entry);
539 $this->getEntityManager()->flush();
540 $this->getEntityManager()->clear();
542 $client->request('GET', '/archive/' . $entry->getId());
544 $this->assertSame(302, $client->getResponse()->getStatusCode());
546 $res = $client->getContainer()
547 ->get('doctrine.orm.entity_manager')
548 ->getRepository('WallabagCoreBundle:Entry')
549 ->find($entry->getId());
551 $this->assertSame(1, $res->isArchived());
554 public function testToggleStar()
556 $this->logInAs('admin');
557 $client = $this->getClient();
559 $entry = new Entry($this->getLoggedInUser());
560 $entry->setUrl($this->url
);
561 $this->getEntityManager()->persist($entry);
562 $this->getEntityManager()->flush();
563 $this->getEntityManager()->clear();
565 $client->request('GET', '/star/' . $entry->getId());
567 $this->assertSame(302, $client->getResponse()->getStatusCode());
569 $res = $client->getContainer()
570 ->get('doctrine.orm.entity_manager')
571 ->getRepository('WallabagCoreBundle:Entry')
572 ->findOneById($entry->getId());
574 $this->assertSame(1, $res->isStarred());
577 public function testDelete()
579 $this->logInAs('admin');
580 $client = $this->getClient();
582 $entry = new Entry($this->getLoggedInUser());
583 $entry->setUrl($this->url
);
584 $this->getEntityManager()->persist($entry);
585 $this->getEntityManager()->flush();
587 $client->request('GET', '/delete/' . $entry->getId());
589 $this->assertSame(302, $client->getResponse()->getStatusCode());
591 $client->request('GET', '/delete/' . $entry->getId());
593 $this->assertSame(404, $client->getResponse()->getStatusCode());
597 * It will create a new entry.
601 * And it'll check that user won't be redirected to the view page of the content when it had been removed
603 public function testViewAndDelete()
605 $this->logInAs('admin');
606 $client = $this->getClient();
608 $em = $client->getContainer()
609 ->get('doctrine.orm.entity_manager');
611 // add a new content to be removed later
613 ->getRepository('WallabagUserBundle:User')
614 ->findOneByUserName('admin');
616 $content = new Entry($user);
617 $content->setUrl('http://1.1.1.1/entry');
618 $content->setReadingTime(12);
619 $content->setDomainName('domain.io');
620 $content->setMimetype('text/html');
621 $content->setTitle('test title entry');
622 $content->setContent('This is my content /o/');
623 $content->updateArchived(true);
624 $content->setLanguage('fr');
626 $em->persist($content);
629 $client->request('GET', '/view/' . $content->getId());
630 $this->assertSame(200, $client->getResponse()->getStatusCode());
632 $client->request('GET', '/delete/' . $content->getId());
633 $this->assertSame(302, $client->getResponse()->getStatusCode());
635 $client->followRedirect();
636 $this->assertSame(200, $client->getResponse()->getStatusCode());
639 public function testViewOtherUserEntry()
641 $this->logInAs('admin');
642 $client = $this->getClient();
644 $content = $client->getContainer()
645 ->get('doctrine.orm.entity_manager')
646 ->getRepository('WallabagCoreBundle:Entry')
647 ->findOneByUsernameAndNotArchived('bob');
649 $client->request('GET', '/view/' . $content->getId());
651 $this->assertSame(403, $client->getResponse()->getStatusCode());
654 public function testFilterOnReadingTime()
656 $this->logInAs('admin');
657 $this->useTheme('baggy');
658 $client = $this->getClient();
659 $entry = new Entry($this->getLoggedInUser());
660 $entry->setUrl($this->url
);
661 $entry->setReadingTime(22);
662 $this->getEntityManager()->persist($entry);
663 $this->getEntityManager()->flush();
665 $crawler = $client->request('GET', '/unread/list');
667 $form = $crawler->filter('button[id=submit-filter]')->form();
670 'entry_filter[readingTime][right_number]' => 22,
671 'entry_filter[readingTime][left_number]' => 22,
674 $crawler = $client->submit($form, $data);
676 $this->assertCount(1, $crawler->filter('div[class=entry]'));
679 public function testFilterOnReadingTimeWithNegativeValue()
681 $this->logInAs('admin');
682 $client = $this->getClient();
684 $crawler = $client->request('GET', '/unread/list');
686 $form = $crawler->filter('button[id=submit-filter]')->form();
689 'entry_filter[readingTime][right_number]' => -22,
690 'entry_filter[readingTime][left_number]' => -22,
693 $crawler = $client->submit($form, $data);
695 // forcing negative value results in no entry displayed
696 $this->assertCount(0, $crawler->filter('div[class=entry]'));
699 public function testFilterOnReadingTimeOnlyUpper()
701 $this->logInAs('admin');
702 $this->useTheme('baggy');
703 $client = $this->getClient();
705 $crawler = $client->request('GET', '/all/list');
706 $this->assertCount(5, $crawler->filter('div[class=entry]'));
708 $entry = new Entry($this->getLoggedInUser());
709 $entry->setUrl($this->url
);
710 $entry->setReadingTime(23);
711 $this->getEntityManager()->persist($entry);
712 $this->getEntityManager()->flush();
714 $crawler = $client->request('GET', '/all/list');
715 $this->assertCount(6, $crawler->filter('div[class=entry]'));
717 $form = $crawler->filter('button[id=submit-filter]')->form();
720 'entry_filter[readingTime][right_number]' => 22,
723 $crawler = $client->submit($form, $data);
725 $this->assertCount(5, $crawler->filter('div[class=entry]'));
728 public function testFilterOnReadingTimeOnlyLower()
730 $this->logInAs('admin');
731 $this->useTheme('baggy');
732 $client = $this->getClient();
734 $crawler = $client->request('GET', '/unread/list');
736 $form = $crawler->filter('button[id=submit-filter]')->form();
739 'entry_filter[readingTime][left_number]' => 22,
742 $crawler = $client->submit($form, $data);
744 $this->assertCount(0, $crawler->filter('div[class=entry]'));
746 $entry = new Entry($this->getLoggedInUser());
747 $entry->setUrl($this->url
);
748 $entry->setReadingTime(23);
749 $this->getEntityManager()->persist($entry);
750 $this->getEntityManager()->flush();
752 $crawler = $client->submit($form, $data);
753 $this->assertCount(1, $crawler->filter('div[class=entry]'));
756 public function testFilterOnUnreadStatus()
758 $this->logInAs('admin');
759 $this->useTheme('baggy');
760 $client = $this->getClient();
762 $crawler = $client->request('GET', '/all/list');
764 $form = $crawler->filter('button[id=submit-filter]')->form();
767 'entry_filter[isUnread]' => true,
770 $crawler = $client->submit($form, $data);
772 $this->assertCount(4, $crawler->filter('div[class=entry]'));
774 $entry = new Entry($this->getLoggedInUser());
775 $entry->setUrl($this->url
);
776 $entry->updateArchived(false);
777 $this->getEntityManager()->persist($entry);
778 $this->getEntityManager()->flush();
780 $crawler = $client->submit($form, $data);
782 $this->assertCount(5, $crawler->filter('div[class=entry]'));
785 public function testFilterOnCreationDate()
787 $this->logInAs('admin');
788 $this->useTheme('baggy');
789 $client = $this->getClient();
791 $crawler = $client->request('GET', '/unread/list');
793 $form = $crawler->filter('button[id=submit-filter]')->form();
796 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
797 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')),
800 $crawler = $client->submit($form, $data);
802 $this->assertCount(5, $crawler->filter('div[class=entry]'));
805 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
806 'entry_filter[createdAt][right_date]' => date('d/m/Y'),
809 $crawler = $client->submit($form, $data);
811 $this->assertCount(5, $crawler->filter('div[class=entry]'));
814 'entry_filter[createdAt][left_date]' => '01/01/1970',
815 'entry_filter[createdAt][right_date]' => '01/01/1970',
818 $crawler = $client->submit($form, $data);
820 $this->assertCount(0, $crawler->filter('div[class=entry]'));
823 public function testPaginationWithFilter()
825 $this->logInAs('admin');
826 $client = $this->getClient();
827 $crawler = $client->request('GET', '/config');
829 $form = $crawler->filter('button[id=config_save]')->form();
832 'config[items_per_page]' => '1',
835 $client->submit($form, $data);
837 $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D=';
839 $client->request('GET', 'unread/list' . $parameters);
841 $this->assertContains($parameters, $client->getResponse()->getContent());
844 $crawler = $client->request('GET', '/config');
845 $form = $crawler->filter('button[id=config_save]')->form();
847 'config[items_per_page]' => '12',
849 $client->submit($form, $data);
852 public function testFilterOnDomainName()
854 $this->logInAs('admin');
855 $this->useTheme('baggy');
856 $client = $this->getClient();
858 $crawler = $client->request('GET', '/unread/list');
859 $form = $crawler->filter('button[id=submit-filter]')->form();
861 'entry_filter[domainName]' => 'domain',
864 $crawler = $client->submit($form, $data);
865 $this->assertCount(5, $crawler->filter('div[class=entry]'));
867 $crawler = $client->request('GET', '/unread/list');
868 $form = $crawler->filter('button[id=submit-filter]')->form();
870 'entry_filter[domainName]' => 'dOmain',
873 $crawler = $client->submit($form, $data);
874 $this->assertCount(5, $crawler->filter('div[class=entry]'));
876 $form = $crawler->filter('button[id=submit-filter]')->form();
878 'entry_filter[domainName]' => 'wallabag',
881 $crawler = $client->submit($form, $data);
882 $this->assertCount(0, $crawler->filter('div[class=entry]'));
885 public function testFilterOnStatus()
887 $this->logInAs('admin');
888 $this->useTheme('baggy');
889 $client = $this->getClient();
891 $crawler = $client->request('GET', '/unread/list');
892 $form = $crawler->filter('button[id=submit-filter]')->form();
893 $form['entry_filter[isArchived]']->tick();
894 $form['entry_filter[isStarred]']->untick();
896 $crawler = $client->submit($form);
897 $this->assertCount(1, $crawler->filter('div[class=entry]'));
899 $form = $crawler->filter('button[id=submit-filter]')->form();
900 $form['entry_filter[isArchived]']->untick();
901 $form['entry_filter[isStarred]']->tick();
903 $crawler = $client->submit($form);
904 $this->assertCount(1, $crawler->filter('div[class=entry]'));
907 public function testFilterOnIsPublic()
909 $this->logInAs('admin');
910 $this->useTheme('baggy');
911 $client = $this->getClient();
913 $crawler = $client->request('GET', '/unread/list');
914 $form = $crawler->filter('button[id=submit-filter]')->form();
915 $form['entry_filter[isPublic]']->tick();
917 $crawler = $client->submit($form);
918 $this->assertCount(0, $crawler->filter('div[class=entry]'));
921 public function testPreviewPictureFilter()
923 $this->logInAs('admin');
924 $this->useTheme('baggy');
925 $client = $this->getClient();
927 $crawler = $client->request('GET', '/unread/list');
928 $form = $crawler->filter('button[id=submit-filter]')->form();
929 $form['entry_filter[previewPicture]']->tick();
931 $crawler = $client->submit($form);
932 $this->assertCount(1, $crawler->filter('div[class=entry]'));
935 public function testFilterOnLanguage()
937 $this->logInAs('admin');
938 $this->useTheme('baggy');
939 $client = $this->getClient();
941 $entry = new Entry($this->getLoggedInUser());
942 $entry->setUrl($this->url
);
943 $entry->setLanguage('fr');
944 $this->getEntityManager()->persist($entry);
945 $this->getEntityManager()->flush();
947 $crawler = $client->request('GET', '/unread/list');
948 $form = $crawler->filter('button[id=submit-filter]')->form();
950 'entry_filter[language]' => 'fr',
953 $crawler = $client->submit($form, $data);
954 $this->assertCount(3, $crawler->filter('div[class=entry]'));
956 $form = $crawler->filter('button[id=submit-filter]')->form();
958 'entry_filter[language]' => 'en',
961 $crawler = $client->submit($form, $data);
962 $this->assertCount(2, $crawler->filter('div[class=entry]'));
965 public function testShareEntryPublicly()
967 $this->logInAs('admin');
968 $client = $this->getClient();
970 // sharing is enabled
971 $client->getContainer()->get('craue_config')->set('share_public', 1);
973 $content = new Entry($this->getLoggedInUser());
974 $content->setUrl($this->url
);
975 $this->getEntityManager()->persist($content);
976 $this->getEntityManager()->flush();
977 $this->getEntityManager()->clear();
980 $client->request('GET', '/share/' . $content->getUid());
981 $this->assertSame(404, $client->getResponse()->getStatusCode());
983 // generating the uid
984 $client->request('GET', '/share/' . $content->getId());
985 $this->assertSame(302, $client->getResponse()->getStatusCode());
987 $shareUrl = $client->getResponse()->getTargetUrl();
989 // use a new client to have a fresh empty session (instead of a logged one from the previous client)
992 $client->request('GET', $shareUrl);
994 $this->assertSame(200, $client->getResponse()->getStatusCode());
995 $this->assertContains('max-age=25200', $client->getResponse()->headers
->get('cache-control'));
996 $this->assertContains('public', $client->getResponse()->headers
->get('cache-control'));
997 $this->assertContains('s-maxage=25200', $client->getResponse()->headers
->get('cache-control'));
998 $this->assertNotContains('no-cache', $client->getResponse()->headers
->get('cache-control'));
999 $this->assertContains('og:title', $client->getResponse()->getContent());
1000 $this->assertContains('og:type', $client->getResponse()->getContent());
1001 $this->assertContains('og:url', $client->getResponse()->getContent());
1002 $this->assertContains('og:image', $client->getResponse()->getContent());
1004 // sharing is now disabled
1005 $client->getContainer()->get('craue_config')->set('share_public', 0);
1006 $client->request('GET', '/share/' . $content->getUid());
1007 $this->assertSame(404, $client->getResponse()->getStatusCode());
1009 // removing the share
1010 $client->request('GET', '/share/delete/' . $content->getId());
1011 $this->assertSame(302, $client->getResponse()->getStatusCode());
1013 // share is now disable
1014 $client->request('GET', '/share/' . $content->getUid());
1015 $this->assertSame(404, $client->getResponse()->getStatusCode());
1018 public function testNewEntryWithDownloadImagesEnabled()
1020 $this->downloadImagesEnabled
= true;
1021 $this->logInAs('admin');
1022 $client = $this->getClient();
1024 $url = self
::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE
;
1025 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
1027 $crawler = $client->request('GET', '/new');
1029 $this->assertSame(200, $client->getResponse()->getStatusCode());
1031 $form = $crawler->filter('form[name=entry]')->form();
1034 'entry[url]' => $url,
1037 $client->submit($form, $data);
1039 $this->assertSame(302, $client->getResponse()->getStatusCode());
1041 $em = $client->getContainer()
1042 ->get('doctrine.orm.entity_manager');
1045 ->getRepository('WallabagCoreBundle:Entry')
1046 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1048 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry);
1049 $this->assertSame($url, $entry->getUrl());
1050 $this->assertContains('Judo', $entry->getTitle());
1051 // instead of checking for the filename (which might change) check that the image is now local
1052 $this->assertContains(rtrim($client->getContainer()->getParameter('domain_name'), '/') . '/assets/images/', $entry->getContent());
1054 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1058 * @depends testNewEntryWithDownloadImagesEnabled
1060 public function testRemoveEntryWithDownloadImagesEnabled()
1062 $this->downloadImagesEnabled
= true;
1063 $this->logInAs('admin');
1064 $client = $this->getClient();
1066 $url = self
::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE
;
1067 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
1069 $crawler = $client->request('GET', '/new');
1071 $this->assertSame(200, $client->getResponse()->getStatusCode());
1073 $form = $crawler->filter('form[name=entry]')->form();
1076 'entry[url]' => $url,
1079 $client->submit($form, $data);
1081 $this->assertSame(302, $client->getResponse()->getStatusCode());
1083 $content = $client->getContainer()
1084 ->get('doctrine.orm.entity_manager')
1085 ->getRepository('WallabagCoreBundle:Entry')
1086 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1088 $client->request('GET', '/delete/' . $content->getId());
1090 $this->assertSame(302, $client->getResponse()->getStatusCode());
1092 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1095 public function testRedirectToHomepage()
1097 $this->logInAs('empty');
1098 $client = $this->getClient();
1100 // Redirect to homepage
1101 $config = $this->getLoggedInUser()->getConfig();
1102 $config->setActionMarkAsRead(Config
::REDIRECT_TO_HOMEPAGE
);
1103 $this->getEntityManager()->persist($config);
1105 $entry = new Entry($this->getLoggedInUser());
1106 $entry->setUrl($this->url
);
1107 $this->getEntityManager()->persist($entry);
1109 $this->getEntityManager()->flush();
1111 $client->request('GET', '/view/' . $entry->getId());
1112 $client->request('GET', '/archive/' . $entry->getId());
1114 $this->assertSame(302, $client->getResponse()->getStatusCode());
1115 $this->assertSame('/', $client->getResponse()->headers
->get('location'));
1118 public function testRedirectToCurrentPage()
1120 $this->logInAs('empty');
1121 $client = $this->getClient();
1123 // Redirect to current page
1124 $config = $this->getLoggedInUser()->getConfig();
1125 $config->setActionMarkAsRead(Config
::REDIRECT_TO_CURRENT_PAGE
);
1126 $this->getEntityManager()->persist($config);
1128 $entry = new Entry($this->getLoggedInUser());
1129 $entry->setUrl($this->url
);
1130 $this->getEntityManager()->persist($entry);
1132 $this->getEntityManager()->flush();
1134 $client->request('GET', '/view/' . $entry->getId());
1135 $client->request('GET', '/archive/' . $entry->getId());
1137 $this->assertSame(302, $client->getResponse()->getStatusCode());
1138 $this->assertContains('/view/' . $entry->getId(), $client->getResponse()->headers
->get('location'));
1141 public function testFilterOnHttpStatus()
1143 $this->logInAs('admin');
1144 $this->useTheme('baggy');
1145 $client = $this->getClient();
1147 $entry = new Entry($this->getLoggedInUser());
1148 $entry->setUrl('https://www.lemonde.fr/incorrect-url/');
1149 $entry->setHttpStatus(404);
1150 $this->getEntityManager()->persist($entry);
1152 $this->getEntityManager()->flush();
1154 $crawler = $client->request('GET', '/all/list');
1155 $form = $crawler->filter('button[id=submit-filter]')->form();
1158 'entry_filter[httpStatus]' => 404,
1161 $crawler = $client->submit($form, $data);
1163 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1165 $entry = new Entry($this->getLoggedInUser());
1166 $entry->setUrl($this->url
);
1167 $entry->setHttpStatus(200);
1168 $this->getEntityManager()->persist($entry);
1170 $entry = new Entry($this->getLoggedInUser());
1171 $entry->setUrl('http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm');
1172 $entry->setHttpStatus(200);
1173 $this->getEntityManager()->persist($entry);
1175 $this->getEntityManager()->flush();
1177 $crawler = $client->request('GET', '/all/list');
1178 $form = $crawler->filter('button[id=submit-filter]')->form();
1181 'entry_filter[httpStatus]' => 200,
1184 $crawler = $client->submit($form, $data);
1186 $this->assertCount(2, $crawler->filter('div[class=entry]'));
1188 $crawler = $client->request('GET', '/all/list');
1189 $form = $crawler->filter('button[id=submit-filter]')->form();
1192 'entry_filter[httpStatus]' => 1024,
1195 $crawler = $client->submit($form, $data);
1197 $this->assertCount(8, $crawler->filter('div[class=entry]'));
1200 public function testSearch()
1202 $this->logInAs('admin');
1203 $this->useTheme('baggy');
1204 $client = $this->getClient();
1206 $entry = new Entry($this->getLoggedInUser());
1207 $entry->setUrl($this->url
);
1208 $entry->setTitle('test');
1209 $this->getEntityManager()->persist($entry);
1210 $this->getEntityManager()->flush();
1212 // Search on unread list
1213 $crawler = $client->request('GET', '/unread/list');
1215 $form = $crawler->filter('form[name=search]')->form();
1217 'search_entry[term]' => 'title',
1220 $crawler = $client->submit($form, $data);
1222 $this->assertCount(4, $crawler->filter('div[class=entry]'));
1224 // Search on starred list
1225 $crawler = $client->request('GET', '/starred/list');
1227 $entry = new Entry($this->getLoggedInUser());
1228 $entry->setUrl('http://localhost/foo/bar');
1229 $entry->setTitle('testeur');
1230 $entry->setStarred(true);
1231 $this->getEntityManager()->persist($entry);
1232 $this->getEntityManager()->flush();
1234 $form = $crawler->filter('form[name=search]')->form();
1236 'search_entry[term]' => 'testeur',
1239 $crawler = $client->submit($form, $data);
1241 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1243 $crawler = $client->request('GET', '/archive/list');
1245 // Added new article to test on archive list
1246 $entry = new Entry($this->getLoggedInUser());
1247 $entry->setUrl('http://0.0.0.0/foo/baz/qux');
1248 $entry->setTitle('Le manège');
1249 $entry->updateArchived(true);
1250 $this->getEntityManager()->persist($entry);
1251 $this->getEntityManager()->flush();
1253 $form = $crawler->filter('form[name=search]')->form();
1255 'search_entry[term]' => 'manège',
1258 $crawler = $client->submit($form, $data);
1260 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1261 $client->request('GET', '/delete/' . $entry->getId());
1263 // test on list of all articles
1264 $crawler = $client->request('GET', '/all/list');
1266 $form = $crawler->filter('form[name=search]')->form();
1268 'search_entry[term]' => 'wxcvbnqsdf', // a string not available in the database
1271 $crawler = $client->submit($form, $data);
1273 $this->assertCount(0, $crawler->filter('div[class=entry]'));
1275 // test url search on list of all articles
1276 $entry = new Entry($this->getLoggedInUser());
1277 $entry->setUrl('http://domain/qux');
1278 $entry->setTitle('Le manège');
1279 $entry->updateArchived(true);
1280 $this->getEntityManager()->persist($entry);
1281 $this->getEntityManager()->flush();
1283 $crawler = $client->request('GET', '/all/list');
1285 $form = $crawler->filter('form[name=search]')->form();
1287 'search_entry[term]' => 'domain', // the search will match an entry with 'domain' in its url
1290 $crawler = $client->submit($form, $data);
1292 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1294 // same as previous test but for case-sensitivity
1295 $crawler = $client->request('GET', '/all/list');
1297 $form = $crawler->filter('form[name=search]')->form();
1299 'search_entry[term]' => 'doMain', // the search will match an entry with 'domain' in its url
1302 $crawler = $client->submit($form, $data);
1304 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1307 public function dataForLanguage()
1311 'https://www.pravda.ru/world/09-06-2017/1337283-qatar-0/',
1315 'https://fr.wikipedia.org/wiki/Wallabag',
1319 'https://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html',
1323 'http://www.ansa.it/sito/notizie/mondo/europa/2017/06/08/voto-gb-seggi-aperti-misure-sicurezza-rafforzate_0cb71f7f-e23b-4d5f-95ca-bc12296419f0.html',
1327 'http://www.hao123.com/shequ?__noscript__-=1',
1331 'https://www.kp.ru/daily/26879.7/3921982/',
1335 'https://politica.estadao.com.br/noticias/eleicoes,campanha-catatonica,70002491983',
1338 'fucked_list_of_languages' => [
1339 'http://geocatalog.webservice-energy.org/geonetwork/srv/eng/main.home',
1343 'https://www.20minutos.es/noticia/3360685/0/gobierno-sanchez-primero-historia-mas-mujeres-que-hombres/',
1350 * @dataProvider dataForLanguage
1352 public function testLanguageValidation($url, $expectedLanguage)
1354 $this->logInAs('admin');
1355 $client = $this->getClient();
1357 $crawler = $client->request('GET', '/new');
1359 $this->assertSame(200, $client->getResponse()->getStatusCode());
1361 $form = $crawler->filter('form[name=entry]')->form();
1364 'entry[url]' => $url,
1367 $client->submit($form, $data);
1369 $this->assertSame(302, $client->getResponse()->getStatusCode());
1371 $content = $client->getContainer()
1372 ->get('doctrine.orm.entity_manager')
1373 ->getRepository('WallabagCoreBundle:Entry')
1374 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1376 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1377 $this->assertSame($url, $content->getUrl());
1378 $this->assertSame($expectedLanguage, $content->getLanguage());
1382 * This test will require an internet connection.
1384 public function testRestrictedArticle()
1386 $url = 'https://www.monde-diplomatique.fr/2017/05/BONNET/57475';
1387 $this->logInAs('admin');
1388 $client = $this->getClient();
1389 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
1391 // enable restricted access
1392 $client->getContainer()->get('craue_config')->set('restricted_access', 1);
1394 // create a new site_credential
1395 $user = $client->getContainer()->get('security.token_storage')->getToken()->getUser();
1396 $credential = new SiteCredential($user);
1397 $credential->setHost('monde-diplomatique.fr');
1398 $credential->setUsername($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('foo'));
1399 $credential->setPassword($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('bar'));
1401 $em->persist($credential);
1404 $crawler = $client->request('GET', '/new');
1406 $this->assertSame(200, $client->getResponse()->getStatusCode());
1408 $form = $crawler->filter('form[name=entry]')->form();
1411 'entry[url]' => $url,
1414 $client->submit($form, $data);
1416 $this->assertSame(302, $client->getResponse()->getStatusCode());
1418 $crawler = $client->followRedirect();
1420 $this->assertSame(200, $client->getResponse()->getStatusCode());
1421 $this->assertContains('flashes.entry.notice.entry_saved', $crawler->filter('body')->extract(['_text'])[0]);
1424 ->getRepository('WallabagCoreBundle:Entry')
1425 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1427 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1428 $this->assertSame('Crimes et réformes aux Philippines', $content->getTitle());
1430 $client->getContainer()->get('craue_config')->set('restricted_access', 0);
1433 public function testPostEntryWhenFetchFails()
1435 $url = 'http://example.com/papers/email_tracking.pdf';
1436 $this->logInAs('admin');
1437 $client = $this->getClient();
1439 $container = $client->getContainer();
1440 $contentProxy = $this->getMockBuilder(ContentProxy
::class)
1441 ->disableOriginalConstructor()
1442 ->setMethods(['updateEntry'])
1444 $contentProxy->expects($this->any())
1445 ->method('updateEntry')
1446 ->willThrowException(new \
Exception('Test Fetch content fails'));
1448 $crawler = $client->request('GET', '/new');
1450 $this->assertSame(200, $client->getResponse()->getStatusCode());
1452 $form = $crawler->filter('form[name=entry]')->form();
1455 'entry[url]' => $url,
1459 * We generate a new client to be able to use Mock ContentProxy
1460 * Also we reinject the cookie from the previous client to keep the
1463 $cookie = $client->getCookieJar()->all();
1464 $client = $this->getNewClient();
1465 $client->getCookieJar()->set($cookie[0]);
1466 $client->getContainer()->set('wallabag_core.content_proxy', $contentProxy);
1467 $client->submit($form, $data);
1469 $this->assertSame(302, $client->getResponse()->getStatusCode());
1471 $content = $client->getContainer()
1472 ->get('doctrine.orm.entity_manager')
1473 ->getRepository('WallabagCoreBundle:Entry')
1474 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1476 $authors = $content->getPublishedBy();
1477 $this->assertSame('email_tracking.pdf', $content->getTitle());
1478 $this->assertSame('example.com', $content->getDomainName());
1481 public function testEntryDeleteTagLink()
1483 $this->logInAs('admin');
1484 $client = $this->getClient();
1486 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
1487 $entry = $em->getRepository('WallabagCoreBundle:Entry')->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId());
1488 $tag = $entry->getTags()[0];
1490 $crawler = $client->request('GET', '/view/' . $entry->getId());
1492 // As long as the deletion link of a tag is following
1493 // a link to the tag view, we take the second one to retrieve
1494 // the deletion link of the first tag
1495 $link = $crawler->filter('body div#article div.tools ul.tags li.chip a')->extract('href')[1];
1497 $this->assertSame(sprintf('/remove-tag/%s/%s', $entry->getId(), $tag->getId()), $link);