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 $title = $crawler->filter('div[id=article] h1')->extract(['_text']);
526 $this->assertGreaterThan(1, $title);
527 $this->assertContains('My updated title hehe :)', $title[0]);
529 $stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']);
530 $this->assertCount(1, $stats);
531 $this->assertNotContains('example.io', trim($stats[0]));
534 public function testToggleArchive()
536 $this->logInAs('admin');
537 $client = $this->getClient();
539 $entry = new Entry($this->getLoggedInUser());
540 $entry->setUrl($this->url
);
541 $this->getEntityManager()->persist($entry);
542 $this->getEntityManager()->flush();
543 $this->getEntityManager()->clear();
545 $client->request('GET', '/archive/' . $entry->getId());
547 $this->assertSame(302, $client->getResponse()->getStatusCode());
549 $res = $client->getContainer()
550 ->get('doctrine.orm.entity_manager')
551 ->getRepository('WallabagCoreBundle:Entry')
552 ->find($entry->getId());
554 $this->assertSame(1, $res->isArchived());
557 public function testToggleStar()
559 $this->logInAs('admin');
560 $client = $this->getClient();
562 $entry = new Entry($this->getLoggedInUser());
563 $entry->setUrl($this->url
);
564 $this->getEntityManager()->persist($entry);
565 $this->getEntityManager()->flush();
566 $this->getEntityManager()->clear();
568 $client->request('GET', '/star/' . $entry->getId());
570 $this->assertSame(302, $client->getResponse()->getStatusCode());
572 $res = $client->getContainer()
573 ->get('doctrine.orm.entity_manager')
574 ->getRepository('WallabagCoreBundle:Entry')
575 ->findOneById($entry->getId());
577 $this->assertSame(1, $res->isStarred());
580 public function testDelete()
582 $this->logInAs('admin');
583 $client = $this->getClient();
585 $entry = new Entry($this->getLoggedInUser());
586 $entry->setUrl($this->url
);
587 $this->getEntityManager()->persist($entry);
588 $this->getEntityManager()->flush();
590 $client->request('GET', '/delete/' . $entry->getId());
592 $this->assertSame(302, $client->getResponse()->getStatusCode());
594 $client->request('GET', '/delete/' . $entry->getId());
596 $this->assertSame(404, $client->getResponse()->getStatusCode());
600 * It will create a new entry.
604 * And it'll check that user won't be redirected to the view page of the content when it had been removed
606 public function testViewAndDelete()
608 $this->logInAs('admin');
609 $client = $this->getClient();
611 $em = $client->getContainer()
612 ->get('doctrine.orm.entity_manager');
614 // add a new content to be removed later
616 ->getRepository('WallabagUserBundle:User')
617 ->findOneByUserName('admin');
619 $content = new Entry($user);
620 $content->setUrl('http://1.1.1.1/entry');
621 $content->setReadingTime(12);
622 $content->setDomainName('domain.io');
623 $content->setMimetype('text/html');
624 $content->setTitle('test title entry');
625 $content->setContent('This is my content /o/');
626 $content->updateArchived(true);
627 $content->setLanguage('fr');
629 $em->persist($content);
632 $client->request('GET', '/view/' . $content->getId());
633 $this->assertSame(200, $client->getResponse()->getStatusCode());
635 $client->request('GET', '/delete/' . $content->getId());
636 $this->assertSame(302, $client->getResponse()->getStatusCode());
638 $client->followRedirect();
639 $this->assertSame(200, $client->getResponse()->getStatusCode());
642 public function testViewOtherUserEntry()
644 $this->logInAs('admin');
645 $client = $this->getClient();
647 $content = $client->getContainer()
648 ->get('doctrine.orm.entity_manager')
649 ->getRepository('WallabagCoreBundle:Entry')
650 ->findOneByUsernameAndNotArchived('bob');
652 $client->request('GET', '/view/' . $content->getId());
654 $this->assertSame(403, $client->getResponse()->getStatusCode());
657 public function testFilterOnReadingTime()
659 $this->logInAs('admin');
660 $this->useTheme('baggy');
661 $client = $this->getClient();
662 $entry = new Entry($this->getLoggedInUser());
663 $entry->setUrl($this->url
);
664 $entry->setReadingTime(22);
665 $this->getEntityManager()->persist($entry);
666 $this->getEntityManager()->flush();
668 $crawler = $client->request('GET', '/unread/list');
670 $form = $crawler->filter('button[id=submit-filter]')->form();
673 'entry_filter[readingTime][right_number]' => 22,
674 'entry_filter[readingTime][left_number]' => 22,
677 $crawler = $client->submit($form, $data);
679 $this->assertCount(1, $crawler->filter('div[class=entry]'));
682 public function testFilterOnReadingTimeWithNegativeValue()
684 $this->logInAs('admin');
685 $client = $this->getClient();
687 $crawler = $client->request('GET', '/unread/list');
689 $form = $crawler->filter('button[id=submit-filter]')->form();
692 'entry_filter[readingTime][right_number]' => -22,
693 'entry_filter[readingTime][left_number]' => -22,
696 $crawler = $client->submit($form, $data);
698 // forcing negative value results in no entry displayed
699 $this->assertCount(0, $crawler->filter('div[class=entry]'));
702 public function testFilterOnReadingTimeOnlyUpper()
704 $this->logInAs('admin');
705 $this->useTheme('baggy');
706 $client = $this->getClient();
708 $crawler = $client->request('GET', '/all/list');
709 $this->assertCount(5, $crawler->filter('div[class=entry]'));
711 $entry = new Entry($this->getLoggedInUser());
712 $entry->setUrl($this->url
);
713 $entry->setReadingTime(23);
714 $this->getEntityManager()->persist($entry);
715 $this->getEntityManager()->flush();
717 $crawler = $client->request('GET', '/all/list');
718 $this->assertCount(6, $crawler->filter('div[class=entry]'));
720 $form = $crawler->filter('button[id=submit-filter]')->form();
723 'entry_filter[readingTime][right_number]' => 22,
726 $crawler = $client->submit($form, $data);
728 $this->assertCount(5, $crawler->filter('div[class=entry]'));
731 public function testFilterOnReadingTimeOnlyLower()
733 $this->logInAs('admin');
734 $this->useTheme('baggy');
735 $client = $this->getClient();
737 $crawler = $client->request('GET', '/unread/list');
739 $form = $crawler->filter('button[id=submit-filter]')->form();
742 'entry_filter[readingTime][left_number]' => 22,
745 $crawler = $client->submit($form, $data);
747 $this->assertCount(0, $crawler->filter('div[class=entry]'));
749 $entry = new Entry($this->getLoggedInUser());
750 $entry->setUrl($this->url
);
751 $entry->setReadingTime(23);
752 $this->getEntityManager()->persist($entry);
753 $this->getEntityManager()->flush();
755 $crawler = $client->submit($form, $data);
756 $this->assertCount(1, $crawler->filter('div[class=entry]'));
759 public function testFilterOnUnreadStatus()
761 $this->logInAs('admin');
762 $this->useTheme('baggy');
763 $client = $this->getClient();
765 $crawler = $client->request('GET', '/all/list');
767 $form = $crawler->filter('button[id=submit-filter]')->form();
770 'entry_filter[isUnread]' => true,
773 $crawler = $client->submit($form, $data);
775 $this->assertCount(4, $crawler->filter('div[class=entry]'));
777 $entry = new Entry($this->getLoggedInUser());
778 $entry->setUrl($this->url
);
779 $entry->updateArchived(false);
780 $this->getEntityManager()->persist($entry);
781 $this->getEntityManager()->flush();
783 $crawler = $client->submit($form, $data);
785 $this->assertCount(5, $crawler->filter('div[class=entry]'));
788 public function testFilterOnCreationDate()
790 $this->logInAs('admin');
791 $this->useTheme('baggy');
792 $client = $this->getClient();
794 $crawler = $client->request('GET', '/unread/list');
796 $form = $crawler->filter('button[id=submit-filter]')->form();
799 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
800 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')),
803 $crawler = $client->submit($form, $data);
805 $this->assertCount(5, $crawler->filter('div[class=entry]'));
808 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
809 'entry_filter[createdAt][right_date]' => date('d/m/Y'),
812 $crawler = $client->submit($form, $data);
814 $this->assertCount(5, $crawler->filter('div[class=entry]'));
817 'entry_filter[createdAt][left_date]' => '01/01/1970',
818 'entry_filter[createdAt][right_date]' => '01/01/1970',
821 $crawler = $client->submit($form, $data);
823 $this->assertCount(0, $crawler->filter('div[class=entry]'));
826 public function testPaginationWithFilter()
828 $this->logInAs('admin');
829 $client = $this->getClient();
830 $crawler = $client->request('GET', '/config');
832 $form = $crawler->filter('button[id=config_save]')->form();
835 'config[items_per_page]' => '1',
838 $client->submit($form, $data);
840 $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D=';
842 $client->request('GET', 'unread/list' . $parameters);
844 $this->assertContains($parameters, $client->getResponse()->getContent());
847 $crawler = $client->request('GET', '/config');
848 $form = $crawler->filter('button[id=config_save]')->form();
850 'config[items_per_page]' => '12',
852 $client->submit($form, $data);
855 public function testFilterOnDomainName()
857 $this->logInAs('admin');
858 $this->useTheme('baggy');
859 $client = $this->getClient();
861 $crawler = $client->request('GET', '/unread/list');
862 $form = $crawler->filter('button[id=submit-filter]')->form();
864 'entry_filter[domainName]' => 'domain',
867 $crawler = $client->submit($form, $data);
868 $this->assertCount(5, $crawler->filter('div[class=entry]'));
870 $crawler = $client->request('GET', '/unread/list');
871 $form = $crawler->filter('button[id=submit-filter]')->form();
873 'entry_filter[domainName]' => 'dOmain',
876 $crawler = $client->submit($form, $data);
877 $this->assertCount(5, $crawler->filter('div[class=entry]'));
879 $form = $crawler->filter('button[id=submit-filter]')->form();
881 'entry_filter[domainName]' => 'wallabag',
884 $crawler = $client->submit($form, $data);
885 $this->assertCount(0, $crawler->filter('div[class=entry]'));
888 public function testFilterOnStatus()
890 $this->logInAs('admin');
891 $this->useTheme('baggy');
892 $client = $this->getClient();
894 $crawler = $client->request('GET', '/unread/list');
895 $form = $crawler->filter('button[id=submit-filter]')->form();
896 $form['entry_filter[isArchived]']->tick();
897 $form['entry_filter[isStarred]']->untick();
899 $crawler = $client->submit($form);
900 $this->assertCount(1, $crawler->filter('div[class=entry]'));
902 $form = $crawler->filter('button[id=submit-filter]')->form();
903 $form['entry_filter[isArchived]']->untick();
904 $form['entry_filter[isStarred]']->tick();
906 $crawler = $client->submit($form);
907 $this->assertCount(1, $crawler->filter('div[class=entry]'));
910 public function testFilterOnIsPublic()
912 $this->logInAs('admin');
913 $this->useTheme('baggy');
914 $client = $this->getClient();
916 $crawler = $client->request('GET', '/unread/list');
917 $form = $crawler->filter('button[id=submit-filter]')->form();
918 $form['entry_filter[isPublic]']->tick();
920 $crawler = $client->submit($form);
921 $this->assertCount(0, $crawler->filter('div[class=entry]'));
924 public function testPreviewPictureFilter()
926 $this->logInAs('admin');
927 $this->useTheme('baggy');
928 $client = $this->getClient();
930 $crawler = $client->request('GET', '/unread/list');
931 $form = $crawler->filter('button[id=submit-filter]')->form();
932 $form['entry_filter[previewPicture]']->tick();
934 $crawler = $client->submit($form);
935 $this->assertCount(1, $crawler->filter('div[class=entry]'));
938 public function testFilterOnLanguage()
940 $this->logInAs('admin');
941 $this->useTheme('baggy');
942 $client = $this->getClient();
944 $entry = new Entry($this->getLoggedInUser());
945 $entry->setUrl($this->url
);
946 $entry->setLanguage('fr');
947 $this->getEntityManager()->persist($entry);
948 $this->getEntityManager()->flush();
950 $crawler = $client->request('GET', '/unread/list');
951 $form = $crawler->filter('button[id=submit-filter]')->form();
953 'entry_filter[language]' => 'fr',
956 $crawler = $client->submit($form, $data);
957 $this->assertCount(3, $crawler->filter('div[class=entry]'));
959 $form = $crawler->filter('button[id=submit-filter]')->form();
961 'entry_filter[language]' => 'en',
964 $crawler = $client->submit($form, $data);
965 $this->assertCount(2, $crawler->filter('div[class=entry]'));
968 public function testShareEntryPublicly()
970 $this->logInAs('admin');
971 $client = $this->getClient();
973 // sharing is enabled
974 $client->getContainer()->get('craue_config')->set('share_public', 1);
976 $content = new Entry($this->getLoggedInUser());
977 $content->setUrl($this->url
);
978 $this->getEntityManager()->persist($content);
979 $this->getEntityManager()->flush();
980 $this->getEntityManager()->clear();
983 $client->request('GET', '/share/' . $content->getUid());
984 $this->assertSame(404, $client->getResponse()->getStatusCode());
986 // generating the uid
987 $client->request('GET', '/share/' . $content->getId());
988 $this->assertSame(302, $client->getResponse()->getStatusCode());
990 $shareUrl = $client->getResponse()->getTargetUrl();
992 // use a new client to have a fresh empty session (instead of a logged one from the previous client)
995 $client->request('GET', $shareUrl);
997 $this->assertSame(200, $client->getResponse()->getStatusCode());
998 $this->assertContains('max-age=25200', $client->getResponse()->headers
->get('cache-control'));
999 $this->assertContains('public', $client->getResponse()->headers
->get('cache-control'));
1000 $this->assertContains('s-maxage=25200', $client->getResponse()->headers
->get('cache-control'));
1001 $this->assertNotContains('no-cache', $client->getResponse()->headers
->get('cache-control'));
1002 $this->assertContains('og:title', $client->getResponse()->getContent());
1003 $this->assertContains('og:type', $client->getResponse()->getContent());
1004 $this->assertContains('og:url', $client->getResponse()->getContent());
1005 $this->assertContains('og:image', $client->getResponse()->getContent());
1007 // sharing is now disabled
1008 $client->getContainer()->get('craue_config')->set('share_public', 0);
1009 $client->request('GET', '/share/' . $content->getUid());
1010 $this->assertSame(404, $client->getResponse()->getStatusCode());
1012 // removing the share
1013 $client->request('GET', '/share/delete/' . $content->getId());
1014 $this->assertSame(302, $client->getResponse()->getStatusCode());
1016 // share is now disable
1017 $client->request('GET', '/share/' . $content->getUid());
1018 $this->assertSame(404, $client->getResponse()->getStatusCode());
1021 public function testNewEntryWithDownloadImagesEnabled()
1023 $this->downloadImagesEnabled
= true;
1024 $this->logInAs('admin');
1025 $client = $this->getClient();
1027 $url = self
::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE
;
1028 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
1030 $crawler = $client->request('GET', '/new');
1032 $this->assertSame(200, $client->getResponse()->getStatusCode());
1034 $form = $crawler->filter('form[name=entry]')->form();
1037 'entry[url]' => $url,
1040 $client->submit($form, $data);
1042 $this->assertSame(302, $client->getResponse()->getStatusCode());
1044 $em = $client->getContainer()
1045 ->get('doctrine.orm.entity_manager');
1048 ->getRepository('WallabagCoreBundle:Entry')
1049 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1051 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry);
1052 $this->assertSame($url, $entry->getUrl());
1053 $this->assertContains('Judo', $entry->getTitle());
1054 // instead of checking for the filename (which might change) check that the image is now local
1055 $this->assertContains(rtrim($client->getContainer()->getParameter('domain_name'), '/') . '/assets/images/', $entry->getContent());
1057 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1061 * @depends testNewEntryWithDownloadImagesEnabled
1063 public function testRemoveEntryWithDownloadImagesEnabled()
1065 $this->downloadImagesEnabled
= true;
1066 $this->logInAs('admin');
1067 $client = $this->getClient();
1069 $url = self
::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE
;
1070 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
1072 $crawler = $client->request('GET', '/new');
1074 $this->assertSame(200, $client->getResponse()->getStatusCode());
1076 $form = $crawler->filter('form[name=entry]')->form();
1079 'entry[url]' => $url,
1082 $client->submit($form, $data);
1084 $this->assertSame(302, $client->getResponse()->getStatusCode());
1086 $content = $client->getContainer()
1087 ->get('doctrine.orm.entity_manager')
1088 ->getRepository('WallabagCoreBundle:Entry')
1089 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1091 $client->request('GET', '/delete/' . $content->getId());
1093 $this->assertSame(302, $client->getResponse()->getStatusCode());
1095 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1098 public function testRedirectToHomepage()
1100 $this->logInAs('empty');
1101 $client = $this->getClient();
1103 // Redirect to homepage
1104 $config = $this->getLoggedInUser()->getConfig();
1105 $config->setActionMarkAsRead(Config
::REDIRECT_TO_HOMEPAGE
);
1106 $this->getEntityManager()->persist($config);
1108 $entry = new Entry($this->getLoggedInUser());
1109 $entry->setUrl($this->url
);
1110 $this->getEntityManager()->persist($entry);
1112 $this->getEntityManager()->flush();
1114 $client->request('GET', '/view/' . $entry->getId());
1115 $client->request('GET', '/archive/' . $entry->getId());
1117 $this->assertSame(302, $client->getResponse()->getStatusCode());
1118 $this->assertSame('/', $client->getResponse()->headers
->get('location'));
1121 public function testRedirectToCurrentPage()
1123 $this->logInAs('empty');
1124 $client = $this->getClient();
1126 // Redirect to current page
1127 $config = $this->getLoggedInUser()->getConfig();
1128 $config->setActionMarkAsRead(Config
::REDIRECT_TO_CURRENT_PAGE
);
1129 $this->getEntityManager()->persist($config);
1131 $entry = new Entry($this->getLoggedInUser());
1132 $entry->setUrl($this->url
);
1133 $this->getEntityManager()->persist($entry);
1135 $this->getEntityManager()->flush();
1137 $client->request('GET', '/view/' . $entry->getId());
1138 $client->request('GET', '/archive/' . $entry->getId());
1140 $this->assertSame(302, $client->getResponse()->getStatusCode());
1141 $this->assertContains('/view/' . $entry->getId(), $client->getResponse()->headers
->get('location'));
1144 public function testFilterOnHttpStatus()
1146 $this->logInAs('admin');
1147 $this->useTheme('baggy');
1148 $client = $this->getClient();
1150 $entry = new Entry($this->getLoggedInUser());
1151 $entry->setUrl('https://www.lemonde.fr/incorrect-url/');
1152 $entry->setHttpStatus(404);
1153 $this->getEntityManager()->persist($entry);
1155 $this->getEntityManager()->flush();
1157 $crawler = $client->request('GET', '/all/list');
1158 $form = $crawler->filter('button[id=submit-filter]')->form();
1161 'entry_filter[httpStatus]' => 404,
1164 $crawler = $client->submit($form, $data);
1166 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1168 $entry = new Entry($this->getLoggedInUser());
1169 $entry->setUrl($this->url
);
1170 $entry->setHttpStatus(200);
1171 $this->getEntityManager()->persist($entry);
1173 $entry = new Entry($this->getLoggedInUser());
1174 $entry->setUrl('http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm');
1175 $entry->setHttpStatus(200);
1176 $this->getEntityManager()->persist($entry);
1178 $this->getEntityManager()->flush();
1180 $crawler = $client->request('GET', '/all/list');
1181 $form = $crawler->filter('button[id=submit-filter]')->form();
1184 'entry_filter[httpStatus]' => 200,
1187 $crawler = $client->submit($form, $data);
1189 $this->assertCount(2, $crawler->filter('div[class=entry]'));
1191 $crawler = $client->request('GET', '/all/list');
1192 $form = $crawler->filter('button[id=submit-filter]')->form();
1195 'entry_filter[httpStatus]' => 1024,
1198 $crawler = $client->submit($form, $data);
1200 $this->assertCount(8, $crawler->filter('div[class=entry]'));
1203 public function testSearch()
1205 $this->logInAs('admin');
1206 $this->useTheme('baggy');
1207 $client = $this->getClient();
1209 $entry = new Entry($this->getLoggedInUser());
1210 $entry->setUrl($this->url
);
1211 $entry->setTitle('test');
1212 $this->getEntityManager()->persist($entry);
1213 $this->getEntityManager()->flush();
1215 // Search on unread list
1216 $crawler = $client->request('GET', '/unread/list');
1218 $form = $crawler->filter('form[name=search]')->form();
1220 'search_entry[term]' => 'title',
1223 $crawler = $client->submit($form, $data);
1225 $this->assertCount(4, $crawler->filter('div[class=entry]'));
1227 // Search on starred list
1228 $crawler = $client->request('GET', '/starred/list');
1230 $entry = new Entry($this->getLoggedInUser());
1231 $entry->setUrl('http://localhost/foo/bar');
1232 $entry->setTitle('testeur');
1233 $entry->setStarred(true);
1234 $this->getEntityManager()->persist($entry);
1235 $this->getEntityManager()->flush();
1237 $form = $crawler->filter('form[name=search]')->form();
1239 'search_entry[term]' => 'testeur',
1242 $crawler = $client->submit($form, $data);
1244 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1246 $crawler = $client->request('GET', '/archive/list');
1248 // Added new article to test on archive list
1249 $entry = new Entry($this->getLoggedInUser());
1250 $entry->setUrl('http://0.0.0.0/foo/baz/qux');
1251 $entry->setTitle('Le manège');
1252 $entry->updateArchived(true);
1253 $this->getEntityManager()->persist($entry);
1254 $this->getEntityManager()->flush();
1256 $form = $crawler->filter('form[name=search]')->form();
1258 'search_entry[term]' => 'manège',
1261 $crawler = $client->submit($form, $data);
1263 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1264 $client->request('GET', '/delete/' . $entry->getId());
1266 // test on list of all articles
1267 $crawler = $client->request('GET', '/all/list');
1269 $form = $crawler->filter('form[name=search]')->form();
1271 'search_entry[term]' => 'wxcvbnqsdf', // a string not available in the database
1274 $crawler = $client->submit($form, $data);
1276 $this->assertCount(0, $crawler->filter('div[class=entry]'));
1278 // test url search on list of all articles
1279 $entry = new Entry($this->getLoggedInUser());
1280 $entry->setUrl('http://domain/qux');
1281 $entry->setTitle('Le manège');
1282 $entry->updateArchived(true);
1283 $this->getEntityManager()->persist($entry);
1284 $this->getEntityManager()->flush();
1286 $crawler = $client->request('GET', '/all/list');
1288 $form = $crawler->filter('form[name=search]')->form();
1290 'search_entry[term]' => 'domain', // the search will match an entry with 'domain' in its url
1293 $crawler = $client->submit($form, $data);
1295 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1297 // same as previous test but for case-sensitivity
1298 $crawler = $client->request('GET', '/all/list');
1300 $form = $crawler->filter('form[name=search]')->form();
1302 'search_entry[term]' => 'doMain', // the search will match an entry with 'domain' in its url
1305 $crawler = $client->submit($form, $data);
1307 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1310 public function dataForLanguage()
1314 'https://www.pravda.ru/world/09-06-2017/1337283-qatar-0/',
1318 'https://fr.wikipedia.org/wiki/Wallabag',
1322 'https://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html',
1326 'http://www.ansa.it/sito/notizie/mondo/europa/2017/06/08/voto-gb-seggi-aperti-misure-sicurezza-rafforzate_0cb71f7f-e23b-4d5f-95ca-bc12296419f0.html',
1330 'http://www.hao123.com/shequ?__noscript__-=1',
1334 'https://politica.estadao.com.br/noticias/eleicoes,campanha-catatonica,70002491983',
1337 'fucked_list_of_languages' => [
1338 'http://geocatalog.webservice-energy.org/geonetwork/srv/eng/main.home',
1342 'https://www.20minutos.es/noticia/3360685/0/gobierno-sanchez-primero-historia-mas-mujeres-que-hombres/',
1349 * @dataProvider dataForLanguage
1351 public function testLanguageValidation($url, $expectedLanguage)
1353 $this->logInAs('admin');
1354 $client = $this->getClient();
1356 $crawler = $client->request('GET', '/new');
1358 $this->assertSame(200, $client->getResponse()->getStatusCode());
1360 $form = $crawler->filter('form[name=entry]')->form();
1363 'entry[url]' => $url,
1366 $client->submit($form, $data);
1368 $this->assertSame(302, $client->getResponse()->getStatusCode());
1370 $content = $client->getContainer()
1371 ->get('doctrine.orm.entity_manager')
1372 ->getRepository('WallabagCoreBundle:Entry')
1373 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1375 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1376 $this->assertSame($url, $content->getUrl());
1377 $this->assertSame($expectedLanguage, $content->getLanguage());
1381 * This test will require an internet connection.
1383 public function testRestrictedArticle()
1385 $url = 'https://www.monde-diplomatique.fr/2017/05/BONNET/57475';
1386 $this->logInAs('admin');
1387 $client = $this->getClient();
1388 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
1390 // enable restricted access
1391 $client->getContainer()->get('craue_config')->set('restricted_access', 1);
1393 // create a new site_credential
1394 $user = $client->getContainer()->get('security.token_storage')->getToken()->getUser();
1395 $credential = new SiteCredential($user);
1396 $credential->setHost('monde-diplomatique.fr');
1397 $credential->setUsername($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('foo'));
1398 $credential->setPassword($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('bar'));
1400 $em->persist($credential);
1403 $crawler = $client->request('GET', '/new');
1405 $this->assertSame(200, $client->getResponse()->getStatusCode());
1407 $form = $crawler->filter('form[name=entry]')->form();
1410 'entry[url]' => $url,
1413 $client->submit($form, $data);
1415 $this->assertSame(302, $client->getResponse()->getStatusCode());
1417 $crawler = $client->followRedirect();
1419 $this->assertSame(200, $client->getResponse()->getStatusCode());
1420 $this->assertContains('flashes.entry.notice.entry_saved', $crawler->filter('body')->extract(['_text'])[0]);
1423 ->getRepository('WallabagCoreBundle:Entry')
1424 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1426 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1427 $this->assertSame('Crimes et réformes aux Philippines', $content->getTitle());
1429 $client->getContainer()->get('craue_config')->set('restricted_access', 0);
1432 public function testPostEntryWhenFetchFails()
1434 $url = 'http://example.com/papers/email_tracking.pdf';
1435 $this->logInAs('admin');
1436 $client = $this->getClient();
1438 $container = $client->getContainer();
1439 $contentProxy = $this->getMockBuilder(ContentProxy
::class)
1440 ->disableOriginalConstructor()
1441 ->setMethods(['updateEntry'])
1443 $contentProxy->expects($this->any())
1444 ->method('updateEntry')
1445 ->willThrowException(new \
Exception('Test Fetch content fails'));
1447 $crawler = $client->request('GET', '/new');
1449 $this->assertSame(200, $client->getResponse()->getStatusCode());
1451 $form = $crawler->filter('form[name=entry]')->form();
1454 'entry[url]' => $url,
1458 * We generate a new client to be able to use Mock ContentProxy
1459 * Also we reinject the cookie from the previous client to keep the
1462 $cookie = $client->getCookieJar()->all();
1463 $client = $this->getNewClient();
1464 $client->getCookieJar()->set($cookie[0]);
1465 $client->getContainer()->set('wallabag_core.content_proxy', $contentProxy);
1466 $client->submit($form, $data);
1468 $this->assertSame(302, $client->getResponse()->getStatusCode());
1470 $content = $client->getContainer()
1471 ->get('doctrine.orm.entity_manager')
1472 ->getRepository('WallabagCoreBundle:Entry')
1473 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1475 $authors = $content->getPublishedBy();
1476 $this->assertSame('email_tracking.pdf', $content->getTitle());
1477 $this->assertSame('example.com', $content->getDomainName());
1480 public function testEntryDeleteTagLink()
1482 $this->logInAs('admin');
1483 $client = $this->getClient();
1485 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
1486 $entry = $em->getRepository('WallabagCoreBundle:Entry')->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId());
1487 $tag = $entry->getTags()[0];
1489 $crawler = $client->request('GET', '/view/' . $entry->getId());
1491 // As long as the deletion link of a tag is following
1492 // a link to the tag view, we take the second one to retrieve
1493 // the deletion link of the first tag
1494 $link = $crawler->filter('body div#article div.tools ul.tags li.chip a')->extract('href')[1];
1496 $this->assertSame(sprintf('/remove-tag/%s/%s', $entry->getId(), $tag->getId()), $link);
1499 public function testRandom()
1501 $this->logInAs('admin');
1502 $client = $this->getClient();
1504 $client->request('GET', '/unread/random');
1505 $this->assertSame(302, $client->getResponse()->getStatusCode());
1506 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Unread random');
1508 $client->request('GET', '/starred/random');
1509 $this->assertSame(302, $client->getResponse()->getStatusCode());
1510 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Starred random');
1512 $client->request('GET', '/archive/random');
1513 $this->assertSame(302, $client->getResponse()->getStatusCode());
1514 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Archive random');
1516 $client->request('GET', '/untagged/random');
1517 $this->assertSame(302, $client->getResponse()->getStatusCode());
1518 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Untagged random');
1520 $client->request('GET', '/all/random');
1521 $this->assertSame(302, $client->getResponse()->getStatusCode());
1522 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'All random');