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('2015-03-28 11:43:19', $content->getPublishedAt()->format('Y-m-d H:i:s'));
170 $this->assertSame('Morgane Tual', $author[0]);
171 $this->assertArrayHasKey('x-varnish1', $content->getHeaders());
172 $client->getContainer()->get('craue_config')->set('store_article_headers', 0);
175 public function testPostWithMultipleAuthors()
177 $url = 'https://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768';
178 $this->logInAs('admin');
179 $client = $this->getClient();
181 $crawler = $client->request('GET', '/new');
183 $this->assertSame(200, $client->getResponse()->getStatusCode());
185 $form = $crawler->filter('form[name=entry]')->form();
188 'entry[url]' => $url,
191 $client->submit($form, $data);
193 $this->assertSame(302, $client->getResponse()->getStatusCode());
195 $content = $client->getContainer()
196 ->get('doctrine.orm.entity_manager')
197 ->getRepository('WallabagCoreBundle:Entry')
198 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
200 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
201 $authors = $content->getPublishedBy();
202 $this->assertSame('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s'));
203 $this->assertSame('fr', $content->getLanguage());
204 $this->assertSame('Raphaël Balenieri, correspondant à Pékin', $authors[0]);
205 $this->assertSame('Frédéric Autran, correspondant à New York', $authors[1]);
208 public function testPostNewOkUrlExist()
210 $this->logInAs('admin');
212 $entry = new Entry($this->getLoggedInUser());
213 $entry->setUrl($this->url
);
214 $this->getEntityManager()->persist($entry);
215 $this->getEntityManager()->flush();
217 $client = $this->getClient();
219 $crawler = $client->request('GET', '/new');
221 $this->assertSame(200, $client->getResponse()->getStatusCode());
223 $form = $crawler->filter('form[name=entry]')->form();
226 'entry[url]' => $this->url
,
229 $client->submit($form, $data);
231 $this->assertSame(302, $client->getResponse()->getStatusCode());
232 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
235 public function testPostNewOkUrlExistWithAccent()
237 $this->logInAs('admin');
238 $client = $this->getClient();
240 $url = 'http://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing';
242 $crawler = $client->request('GET', '/new');
244 $this->assertSame(200, $client->getResponse()->getStatusCode());
246 $form = $crawler->filter('form[name=entry]')->form();
249 'entry[url]' => $url,
252 $client->submit($form, $data);
254 $crawler = $client->request('GET', '/new');
256 $this->assertSame(200, $client->getResponse()->getStatusCode());
258 $form = $crawler->filter('form[name=entry]')->form();
261 'entry[url]' => $url,
264 $client->submit($form, $data);
266 $this->assertSame(302, $client->getResponse()->getStatusCode());
267 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
271 * This test will require an internet connection.
273 public function testPostNewThatWillBeTagged()
275 $this->logInAs('admin');
276 $client = $this->getClient();
278 $crawler = $client->request('GET', '/new');
280 $this->assertSame(200, $client->getResponse()->getStatusCode());
282 $form = $crawler->filter('form[name=entry]')->form();
285 'entry[url]' => $url = 'https://github.com/wallabag/wallabag',
288 $client->submit($form, $data);
290 $this->assertSame(302, $client->getResponse()->getStatusCode());
291 $this->assertContains('/', $client->getResponse()->getTargetUrl());
293 $em = $client->getContainer()
294 ->get('doctrine.orm.entity_manager');
296 ->getRepository('WallabagCoreBundle:Entry')
297 ->findOneByUrl($url);
298 $tags = $entry->getTags();
300 $this->assertCount(2, $tags);
301 $this->assertContains('wallabag', $tags);
302 $this->assertSame('en', $entry->getLanguage());
307 // and now re-submit it to test the cascade persistence for tags after entry removal
308 // related https://github.com/wallabag/wallabag/issues/2121
309 $crawler = $client->request('GET', '/new');
311 $this->assertSame(200, $client->getResponse()->getStatusCode());
313 $form = $crawler->filter('form[name=entry]')->form();
316 'entry[url]' => $url = 'https://github.com/wallabag/wallabag/tree/master',
319 $client->submit($form, $data);
321 $this->assertSame(302, $client->getResponse()->getStatusCode());
322 $this->assertContains('/', $client->getResponse()->getTargetUrl());
325 ->getRepository('WallabagCoreBundle:Entry')
326 ->findOneByUrl($url);
328 $tags = $entry->getTags();
330 $this->assertCount(2, $tags);
331 $this->assertContains('wallabag', $tags);
337 public function testArchive()
339 $this->logInAs('admin');
340 $client = $this->getClient();
342 $client->request('GET', '/archive/list');
344 $this->assertSame(200, $client->getResponse()->getStatusCode());
347 public function testUntagged()
349 $this->logInAs('admin');
350 $client = $this->getClient();
352 $client->request('GET', '/untagged/list');
354 $this->assertSame(200, $client->getResponse()->getStatusCode());
357 public function testStarred()
359 $this->logInAs('admin');
360 $client = $this->getClient();
362 $client->request('GET', '/starred/list');
364 $this->assertSame(200, $client->getResponse()->getStatusCode());
367 public function testRangeException()
369 $this->logInAs('admin');
370 $client = $this->getClient();
372 $client->request('GET', '/all/list/900');
374 $this->assertSame(302, $client->getResponse()->getStatusCode());
375 $this->assertSame('/all/list', $client->getResponse()->getTargetUrl());
378 public function testView()
380 $this->logInAs('admin');
381 $client = $this->getClient();
383 $entry = new Entry($this->getLoggedInUser());
384 $entry->setUrl('http://example.com/foo');
385 $entry->setTitle('title foo');
386 $entry->setContent('foo bar baz');
387 $this->getEntityManager()->persist($entry);
388 $this->getEntityManager()->flush();
390 $crawler = $client->request('GET', '/view/' . $entry->getId());
392 $this->assertSame(200, $client->getResponse()->getStatusCode());
393 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
394 $this->assertContains($entry->getTitle(), $body[0]);
398 * This test will require an internet connection.
400 public function testReload()
402 $this->logInAs('admin');
403 $client = $this->getClient();
405 $entry = new Entry($this->getLoggedInUser());
406 $entry->setUrl($this->url
);
407 $entry->setTitle('title foo');
408 $entry->setContent('');
409 $this->getEntityManager()->persist($entry);
410 $this->getEntityManager()->flush();
411 $this->getEntityManager()->clear();
413 $client->request('GET', '/reload/' . $entry->getId());
415 $this->assertSame(302, $client->getResponse()->getStatusCode());
417 $entry = $this->getEntityManager()
418 ->getRepository('WallabagCoreBundle:Entry')
419 ->find($entry->getId());
421 $this->assertNotEmpty($entry->getContent());
424 public function testReloadWithFetchingFailed()
426 $this->logInAs('admin');
427 $client = $this->getClient();
429 $entry = new Entry($this->getLoggedInUser());
430 $entry->setUrl('http://0.0.0.0/failed.html');
431 $this->getEntityManager()->persist($entry);
432 $this->getEntityManager()->flush();
434 $client->request('GET', '/reload/' . $entry->getId());
436 $this->assertSame(302, $client->getResponse()->getStatusCode());
438 // force EntityManager to clear previous entity
439 // otherwise, retrieve the same entity will retrieve change from the previous request :0
440 $this->getEntityManager()->clear();
441 $newContent = $this->getEntityManager()
442 ->getRepository('WallabagCoreBundle:Entry')
443 ->find($entry->getId());
445 $this->assertNotSame($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent());
448 public function testEdit()
450 $this->logInAs('admin');
451 $client = $this->getClient();
453 $entry = new Entry($this->getLoggedInUser());
454 $entry->setUrl($this->url
);
455 $this->getEntityManager()->persist($entry);
456 $this->getEntityManager()->flush();
458 $crawler = $client->request('GET', '/edit/' . $entry->getId());
460 $this->assertSame(200, $client->getResponse()->getStatusCode());
462 $this->assertCount(1, $crawler->filter('input[id=entry_title]'));
463 $this->assertCount(1, $crawler->filter('button[id=entry_save]'));
466 public function testEditUpdate()
468 $this->logInAs('admin');
469 $client = $this->getClient();
471 $entry = new Entry($this->getLoggedInUser());
472 $entry->setUrl($this->url
);
473 $this->getEntityManager()->persist($entry);
474 $this->getEntityManager()->flush();
476 $crawler = $client->request('GET', '/edit/' . $entry->getId());
478 $this->assertSame(200, $client->getResponse()->getStatusCode());
480 $form = $crawler->filter('button[id=entry_save]')->form();
483 'entry[title]' => 'My updated title hehe :)',
484 'entry[origin_url]' => 'https://example.io',
487 $client->submit($form, $data);
489 $this->assertSame(302, $client->getResponse()->getStatusCode());
491 $crawler = $client->followRedirect();
493 $this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text']));
494 $this->assertContains('My updated title hehe :)', $title[0]);
495 $this->assertGreaterThan(1, $stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']));
496 $this->assertContains('example.io', trim($stats[1]));
499 public function testEditRemoveOriginUrl()
501 $this->logInAs('admin');
502 $client = $this->getClient();
504 $entry = new Entry($this->getLoggedInUser());
505 $entry->setUrl($this->url
);
506 $this->getEntityManager()->persist($entry);
507 $this->getEntityManager()->flush();
509 $crawler = $client->request('GET', '/edit/' . $entry->getId());
511 $this->assertSame(200, $client->getResponse()->getStatusCode());
513 $form = $crawler->filter('button[id=entry_save]')->form();
516 'entry[title]' => 'My updated title hehe :)',
517 'entry[origin_url]' => '',
520 $client->submit($form, $data);
522 $this->assertSame(302, $client->getResponse()->getStatusCode());
524 $crawler = $client->followRedirect();
526 $this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text']));
527 $this->assertContains('My updated title hehe :)', $title[0]);
528 $this->assertSame(1, \
count($stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text'])));
529 $this->assertNotContains('example.io', trim($stats[0]));
532 public function testToggleArchive()
534 $this->logInAs('admin');
535 $client = $this->getClient();
537 $entry = new Entry($this->getLoggedInUser());
538 $entry->setUrl($this->url
);
539 $this->getEntityManager()->persist($entry);
540 $this->getEntityManager()->flush();
541 $this->getEntityManager()->clear();
543 $client->request('GET', '/archive/' . $entry->getId());
545 $this->assertSame(302, $client->getResponse()->getStatusCode());
547 $res = $client->getContainer()
548 ->get('doctrine.orm.entity_manager')
549 ->getRepository('WallabagCoreBundle:Entry')
550 ->find($entry->getId());
552 $this->assertSame(1, $res->isArchived());
555 public function testToggleStar()
557 $this->logInAs('admin');
558 $client = $this->getClient();
560 $entry = new Entry($this->getLoggedInUser());
561 $entry->setUrl($this->url
);
562 $this->getEntityManager()->persist($entry);
563 $this->getEntityManager()->flush();
564 $this->getEntityManager()->clear();
566 $client->request('GET', '/star/' . $entry->getId());
568 $this->assertSame(302, $client->getResponse()->getStatusCode());
570 $res = $client->getContainer()
571 ->get('doctrine.orm.entity_manager')
572 ->getRepository('WallabagCoreBundle:Entry')
573 ->findOneById($entry->getId());
575 $this->assertSame(1, $res->isStarred());
578 public function testDelete()
580 $this->logInAs('admin');
581 $client = $this->getClient();
583 $entry = new Entry($this->getLoggedInUser());
584 $entry->setUrl($this->url
);
585 $this->getEntityManager()->persist($entry);
586 $this->getEntityManager()->flush();
588 $client->request('GET', '/delete/' . $entry->getId());
590 $this->assertSame(302, $client->getResponse()->getStatusCode());
592 $client->request('GET', '/delete/' . $entry->getId());
594 $this->assertSame(404, $client->getResponse()->getStatusCode());
598 * It will create a new entry.
602 * And it'll check that user won't be redirected to the view page of the content when it had been removed
604 public function testViewAndDelete()
606 $this->logInAs('admin');
607 $client = $this->getClient();
609 $em = $client->getContainer()
610 ->get('doctrine.orm.entity_manager');
612 // add a new content to be removed later
614 ->getRepository('WallabagUserBundle:User')
615 ->findOneByUserName('admin');
617 $content = new Entry($user);
618 $content->setUrl('http://1.1.1.1/entry');
619 $content->setReadingTime(12);
620 $content->setDomainName('domain.io');
621 $content->setMimetype('text/html');
622 $content->setTitle('test title entry');
623 $content->setContent('This is my content /o/');
624 $content->setArchived(true);
625 $content->setLanguage('fr');
627 $em->persist($content);
630 $client->request('GET', '/view/' . $content->getId());
631 $this->assertSame(200, $client->getResponse()->getStatusCode());
633 $client->request('GET', '/delete/' . $content->getId());
634 $this->assertSame(302, $client->getResponse()->getStatusCode());
636 $client->followRedirect();
637 $this->assertSame(200, $client->getResponse()->getStatusCode());
640 public function testViewOtherUserEntry()
642 $this->logInAs('admin');
643 $client = $this->getClient();
645 $content = $client->getContainer()
646 ->get('doctrine.orm.entity_manager')
647 ->getRepository('WallabagCoreBundle:Entry')
648 ->findOneByUsernameAndNotArchived('bob');
650 $client->request('GET', '/view/' . $content->getId());
652 $this->assertSame(403, $client->getResponse()->getStatusCode());
655 public function testFilterOnReadingTime()
657 $this->logInAs('admin');
658 $this->useTheme('baggy');
659 $client = $this->getClient();
660 $entry = new Entry($this->getLoggedInUser());
661 $entry->setUrl($this->url
);
662 $entry->setReadingTime(22);
663 $this->getEntityManager()->persist($entry);
664 $this->getEntityManager()->flush();
666 $crawler = $client->request('GET', '/unread/list');
668 $form = $crawler->filter('button[id=submit-filter]')->form();
671 'entry_filter[readingTime][right_number]' => 22,
672 'entry_filter[readingTime][left_number]' => 22,
675 $crawler = $client->submit($form, $data);
677 $this->assertCount(1, $crawler->filter('div[class=entry]'));
680 public function testFilterOnReadingTimeWithNegativeValue()
682 $this->logInAs('admin');
683 $client = $this->getClient();
685 $crawler = $client->request('GET', '/unread/list');
687 $form = $crawler->filter('button[id=submit-filter]')->form();
690 'entry_filter[readingTime][right_number]' => -22,
691 'entry_filter[readingTime][left_number]' => -22,
694 $crawler = $client->submit($form, $data);
696 // forcing negative value results in no entry displayed
697 $this->assertCount(0, $crawler->filter('div[class=entry]'));
700 public function testFilterOnReadingTimeOnlyUpper()
702 $this->logInAs('admin');
703 $this->useTheme('baggy');
704 $client = $this->getClient();
706 $crawler = $client->request('GET', '/all/list');
707 $this->assertCount(5, $crawler->filter('div[class=entry]'));
709 $entry = new Entry($this->getLoggedInUser());
710 $entry->setUrl($this->url
);
711 $entry->setReadingTime(23);
712 $this->getEntityManager()->persist($entry);
713 $this->getEntityManager()->flush();
715 $crawler = $client->request('GET', '/all/list');
716 $this->assertCount(6, $crawler->filter('div[class=entry]'));
718 $form = $crawler->filter('button[id=submit-filter]')->form();
721 'entry_filter[readingTime][right_number]' => 22,
724 $crawler = $client->submit($form, $data);
726 $this->assertCount(5, $crawler->filter('div[class=entry]'));
729 public function testFilterOnReadingTimeOnlyLower()
731 $this->logInAs('admin');
732 $this->useTheme('baggy');
733 $client = $this->getClient();
735 $crawler = $client->request('GET', '/unread/list');
737 $form = $crawler->filter('button[id=submit-filter]')->form();
740 'entry_filter[readingTime][left_number]' => 22,
743 $crawler = $client->submit($form, $data);
745 $this->assertCount(0, $crawler->filter('div[class=entry]'));
747 $entry = new Entry($this->getLoggedInUser());
748 $entry->setUrl($this->url
);
749 $entry->setReadingTime(23);
750 $this->getEntityManager()->persist($entry);
751 $this->getEntityManager()->flush();
753 $crawler = $client->submit($form, $data);
754 $this->assertCount(1, $crawler->filter('div[class=entry]'));
757 public function testFilterOnUnreadStatus()
759 $this->logInAs('admin');
760 $this->useTheme('baggy');
761 $client = $this->getClient();
763 $crawler = $client->request('GET', '/all/list');
765 $form = $crawler->filter('button[id=submit-filter]')->form();
768 'entry_filter[isUnread]' => true,
771 $crawler = $client->submit($form, $data);
773 $this->assertCount(4, $crawler->filter('div[class=entry]'));
775 $entry = new Entry($this->getLoggedInUser());
776 $entry->setUrl($this->url
);
777 $entry->setArchived(false);
778 $this->getEntityManager()->persist($entry);
779 $this->getEntityManager()->flush();
781 $crawler = $client->submit($form, $data);
783 $this->assertCount(5, $crawler->filter('div[class=entry]'));
786 public function testFilterOnCreationDate()
788 $this->logInAs('admin');
789 $this->useTheme('baggy');
790 $client = $this->getClient();
792 $crawler = $client->request('GET', '/unread/list');
794 $form = $crawler->filter('button[id=submit-filter]')->form();
797 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
798 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')),
801 $crawler = $client->submit($form, $data);
803 $this->assertCount(5, $crawler->filter('div[class=entry]'));
806 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
807 'entry_filter[createdAt][right_date]' => date('d/m/Y'),
810 $crawler = $client->submit($form, $data);
812 $this->assertCount(5, $crawler->filter('div[class=entry]'));
815 'entry_filter[createdAt][left_date]' => '01/01/1970',
816 'entry_filter[createdAt][right_date]' => '01/01/1970',
819 $crawler = $client->submit($form, $data);
821 $this->assertCount(0, $crawler->filter('div[class=entry]'));
824 public function testPaginationWithFilter()
826 $this->logInAs('admin');
827 $client = $this->getClient();
828 $crawler = $client->request('GET', '/config');
830 $form = $crawler->filter('button[id=config_save]')->form();
833 'config[items_per_page]' => '1',
836 $client->submit($form, $data);
838 $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D=';
840 $client->request('GET', 'unread/list' . $parameters);
842 $this->assertContains($parameters, $client->getResponse()->getContent());
845 $crawler = $client->request('GET', '/config');
846 $form = $crawler->filter('button[id=config_save]')->form();
848 'config[items_per_page]' => '12',
850 $client->submit($form, $data);
853 public function testFilterOnDomainName()
855 $this->logInAs('admin');
856 $this->useTheme('baggy');
857 $client = $this->getClient();
859 $crawler = $client->request('GET', '/unread/list');
860 $form = $crawler->filter('button[id=submit-filter]')->form();
862 'entry_filter[domainName]' => 'domain',
865 $crawler = $client->submit($form, $data);
866 $this->assertCount(5, $crawler->filter('div[class=entry]'));
868 $crawler = $client->request('GET', '/unread/list');
869 $form = $crawler->filter('button[id=submit-filter]')->form();
871 'entry_filter[domainName]' => 'dOmain',
874 $crawler = $client->submit($form, $data);
875 $this->assertCount(5, $crawler->filter('div[class=entry]'));
877 $form = $crawler->filter('button[id=submit-filter]')->form();
879 'entry_filter[domainName]' => 'wallabag',
882 $crawler = $client->submit($form, $data);
883 $this->assertCount(0, $crawler->filter('div[class=entry]'));
886 public function testFilterOnStatus()
888 $this->logInAs('admin');
889 $this->useTheme('baggy');
890 $client = $this->getClient();
892 $crawler = $client->request('GET', '/unread/list');
893 $form = $crawler->filter('button[id=submit-filter]')->form();
894 $form['entry_filter[isArchived]']->tick();
895 $form['entry_filter[isStarred]']->untick();
897 $crawler = $client->submit($form);
898 $this->assertCount(1, $crawler->filter('div[class=entry]'));
900 $form = $crawler->filter('button[id=submit-filter]')->form();
901 $form['entry_filter[isArchived]']->untick();
902 $form['entry_filter[isStarred]']->tick();
904 $crawler = $client->submit($form);
905 $this->assertCount(1, $crawler->filter('div[class=entry]'));
908 public function testFilterOnIsPublic()
910 $this->logInAs('admin');
911 $this->useTheme('baggy');
912 $client = $this->getClient();
914 $crawler = $client->request('GET', '/unread/list');
915 $form = $crawler->filter('button[id=submit-filter]')->form();
916 $form['entry_filter[isPublic]']->tick();
918 $crawler = $client->submit($form);
919 $this->assertCount(0, $crawler->filter('div[class=entry]'));
922 public function testPreviewPictureFilter()
924 $this->logInAs('admin');
925 $this->useTheme('baggy');
926 $client = $this->getClient();
928 $crawler = $client->request('GET', '/unread/list');
929 $form = $crawler->filter('button[id=submit-filter]')->form();
930 $form['entry_filter[previewPicture]']->tick();
932 $crawler = $client->submit($form);
933 $this->assertCount(1, $crawler->filter('div[class=entry]'));
936 public function testFilterOnLanguage()
938 $this->logInAs('admin');
939 $this->useTheme('baggy');
940 $client = $this->getClient();
942 $entry = new Entry($this->getLoggedInUser());
943 $entry->setUrl($this->url
);
944 $entry->setLanguage('fr');
945 $this->getEntityManager()->persist($entry);
946 $this->getEntityManager()->flush();
948 $crawler = $client->request('GET', '/unread/list');
949 $form = $crawler->filter('button[id=submit-filter]')->form();
951 'entry_filter[language]' => 'fr',
954 $crawler = $client->submit($form, $data);
955 $this->assertCount(3, $crawler->filter('div[class=entry]'));
957 $form = $crawler->filter('button[id=submit-filter]')->form();
959 'entry_filter[language]' => 'en',
962 $crawler = $client->submit($form, $data);
963 $this->assertCount(2, $crawler->filter('div[class=entry]'));
966 public function testShareEntryPublicly()
968 $this->logInAs('admin');
969 $client = $this->getClient();
971 // sharing is enabled
972 $client->getContainer()->get('craue_config')->set('share_public', 1);
974 $content = new Entry($this->getLoggedInUser());
975 $content->setUrl($this->url
);
976 $this->getEntityManager()->persist($content);
977 $this->getEntityManager()->flush();
978 $this->getEntityManager()->clear();
981 $client->request('GET', '/share/' . $content->getUid());
982 $this->assertSame(404, $client->getResponse()->getStatusCode());
984 // generating the uid
985 $client->request('GET', '/share/' . $content->getId());
986 $this->assertSame(302, $client->getResponse()->getStatusCode());
988 // follow link with uid
989 $crawler = $client->followRedirect();
990 $this->assertSame(200, $client->getResponse()->getStatusCode());
991 $this->assertContains('max-age=25200', $client->getResponse()->headers
->get('cache-control'));
992 $this->assertContains('public', $client->getResponse()->headers
->get('cache-control'));
993 $this->assertContains('s-maxage=25200', $client->getResponse()->headers
->get('cache-control'));
994 $this->assertNotContains('no-cache', $client->getResponse()->headers
->get('cache-control'));
995 $this->assertContains('og:title', $client->getResponse()->getContent());
996 $this->assertContains('og:type', $client->getResponse()->getContent());
997 $this->assertContains('og:url', $client->getResponse()->getContent());
998 $this->assertContains('og:image', $client->getResponse()->getContent());
1000 // sharing is now disabled
1001 $client->getContainer()->get('craue_config')->set('share_public', 0);
1002 $client->request('GET', '/share/' . $content->getUid());
1003 $this->assertSame(404, $client->getResponse()->getStatusCode());
1005 $client->request('GET', '/view/' . $content->getId());
1006 $this->assertContains('no-cache', $client->getResponse()->headers
->get('cache-control'));
1008 // removing the share
1009 $client->request('GET', '/share/delete/' . $content->getId());
1010 $this->assertSame(302, $client->getResponse()->getStatusCode());
1012 // share is now disable
1013 $client->request('GET', '/share/' . $content->getUid());
1014 $this->assertSame(404, $client->getResponse()->getStatusCode());
1017 public function testNewEntryWithDownloadImagesEnabled()
1019 $this->downloadImagesEnabled
= true;
1020 $this->logInAs('admin');
1021 $client = $this->getClient();
1023 $url = self
::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE
;
1024 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
1026 $crawler = $client->request('GET', '/new');
1028 $this->assertSame(200, $client->getResponse()->getStatusCode());
1030 $form = $crawler->filter('form[name=entry]')->form();
1033 'entry[url]' => $url,
1036 $client->submit($form, $data);
1038 $this->assertSame(302, $client->getResponse()->getStatusCode());
1040 $em = $client->getContainer()
1041 ->get('doctrine.orm.entity_manager');
1044 ->getRepository('WallabagCoreBundle:Entry')
1045 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1047 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry);
1048 $this->assertSame($url, $entry->getUrl());
1049 $this->assertContains('Judo', $entry->getTitle());
1050 // instead of checking for the filename (which might change) check that the image is now local
1051 $this->assertContains(rtrim($client->getContainer()->getParameter('domain_name'), '/') . '/assets/images/', $entry->getContent());
1053 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1057 * @depends testNewEntryWithDownloadImagesEnabled
1059 public function testRemoveEntryWithDownloadImagesEnabled()
1061 $this->downloadImagesEnabled
= true;
1062 $this->logInAs('admin');
1063 $client = $this->getClient();
1065 $url = self
::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE
;
1066 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
1068 $crawler = $client->request('GET', '/new');
1070 $this->assertSame(200, $client->getResponse()->getStatusCode());
1072 $form = $crawler->filter('form[name=entry]')->form();
1075 'entry[url]' => $url,
1078 $client->submit($form, $data);
1080 $this->assertSame(302, $client->getResponse()->getStatusCode());
1082 $content = $client->getContainer()
1083 ->get('doctrine.orm.entity_manager')
1084 ->getRepository('WallabagCoreBundle:Entry')
1085 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1087 $client->request('GET', '/delete/' . $content->getId());
1089 $this->assertSame(302, $client->getResponse()->getStatusCode());
1091 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1094 public function testRedirectToHomepage()
1096 $this->logInAs('empty');
1097 $client = $this->getClient();
1099 // Redirect to homepage
1100 $config = $this->getLoggedInUser()->getConfig();
1101 $config->setActionMarkAsRead(Config
::REDIRECT_TO_HOMEPAGE
);
1102 $this->getEntityManager()->persist($config);
1104 $entry = new Entry($this->getLoggedInUser());
1105 $entry->setUrl($this->url
);
1106 $this->getEntityManager()->persist($entry);
1108 $this->getEntityManager()->flush();
1110 $client->request('GET', '/view/' . $entry->getId());
1111 $client->request('GET', '/archive/' . $entry->getId());
1113 $this->assertSame(302, $client->getResponse()->getStatusCode());
1114 $this->assertSame('/', $client->getResponse()->headers
->get('location'));
1117 public function testRedirectToCurrentPage()
1119 $this->logInAs('empty');
1120 $client = $this->getClient();
1122 // Redirect to current page
1123 $config = $this->getLoggedInUser()->getConfig();
1124 $config->setActionMarkAsRead(Config
::REDIRECT_TO_CURRENT_PAGE
);
1125 $this->getEntityManager()->persist($config);
1127 $entry = new Entry($this->getLoggedInUser());
1128 $entry->setUrl($this->url
);
1129 $this->getEntityManager()->persist($entry);
1131 $this->getEntityManager()->flush();
1133 $client->request('GET', '/view/' . $entry->getId());
1134 $client->request('GET', '/archive/' . $entry->getId());
1136 $this->assertSame(302, $client->getResponse()->getStatusCode());
1137 $this->assertContains('/view/' . $entry->getId(), $client->getResponse()->headers
->get('location'));
1140 public function testFilterOnHttpStatus()
1142 $this->logInAs('admin');
1143 $this->useTheme('baggy');
1144 $client = $this->getClient();
1146 $entry = new Entry($this->getLoggedInUser());
1147 $entry->setUrl('https://www.lemonde.fr/incorrect-url/');
1148 $entry->setHttpStatus(404);
1149 $this->getEntityManager()->persist($entry);
1151 $this->getEntityManager()->flush();
1153 $crawler = $client->request('GET', '/all/list');
1154 $form = $crawler->filter('button[id=submit-filter]')->form();
1157 'entry_filter[httpStatus]' => 404,
1160 $crawler = $client->submit($form, $data);
1162 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1164 $entry = new Entry($this->getLoggedInUser());
1165 $entry->setUrl($this->url
);
1166 $entry->setHttpStatus(200);
1167 $this->getEntityManager()->persist($entry);
1169 $entry = new Entry($this->getLoggedInUser());
1170 $entry->setUrl('http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm');
1171 $entry->setHttpStatus(200);
1172 $this->getEntityManager()->persist($entry);
1174 $this->getEntityManager()->flush();
1176 $crawler = $client->request('GET', '/all/list');
1177 $form = $crawler->filter('button[id=submit-filter]')->form();
1180 'entry_filter[httpStatus]' => 200,
1183 $crawler = $client->submit($form, $data);
1185 $this->assertCount(2, $crawler->filter('div[class=entry]'));
1187 $crawler = $client->request('GET', '/all/list');
1188 $form = $crawler->filter('button[id=submit-filter]')->form();
1191 'entry_filter[httpStatus]' => 1024,
1194 $crawler = $client->submit($form, $data);
1196 $this->assertCount(8, $crawler->filter('div[class=entry]'));
1199 public function testSearch()
1201 $this->logInAs('admin');
1202 $this->useTheme('baggy');
1203 $client = $this->getClient();
1205 $entry = new Entry($this->getLoggedInUser());
1206 $entry->setUrl($this->url
);
1207 $entry->setTitle('test');
1208 $this->getEntityManager()->persist($entry);
1209 $this->getEntityManager()->flush();
1211 // Search on unread list
1212 $crawler = $client->request('GET', '/unread/list');
1214 $form = $crawler->filter('form[name=search]')->form();
1216 'search_entry[term]' => 'title',
1219 $crawler = $client->submit($form, $data);
1221 $this->assertCount(4, $crawler->filter('div[class=entry]'));
1223 // Search on starred list
1224 $crawler = $client->request('GET', '/starred/list');
1226 $entry = new Entry($this->getLoggedInUser());
1227 $entry->setUrl('http://localhost/foo/bar');
1228 $entry->setTitle('testeur');
1229 $entry->setStarred(true);
1230 $this->getEntityManager()->persist($entry);
1231 $this->getEntityManager()->flush();
1233 $form = $crawler->filter('form[name=search]')->form();
1235 'search_entry[term]' => 'testeur',
1238 $crawler = $client->submit($form, $data);
1240 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1242 $crawler = $client->request('GET', '/archive/list');
1244 // Added new article to test on archive list
1245 $entry = new Entry($this->getLoggedInUser());
1246 $entry->setUrl('http://0.0.0.0/foo/baz/qux');
1247 $entry->setTitle('Le manège');
1248 $entry->setArchived(true);
1249 $this->getEntityManager()->persist($entry);
1250 $this->getEntityManager()->flush();
1252 $form = $crawler->filter('form[name=search]')->form();
1254 'search_entry[term]' => 'manège',
1257 $crawler = $client->submit($form, $data);
1259 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1260 $client->request('GET', '/delete/' . $entry->getId());
1262 // test on list of all articles
1263 $crawler = $client->request('GET', '/all/list');
1265 $form = $crawler->filter('form[name=search]')->form();
1267 'search_entry[term]' => 'wxcvbnqsdf', // a string not available in the database
1270 $crawler = $client->submit($form, $data);
1272 $this->assertCount(0, $crawler->filter('div[class=entry]'));
1274 // test url search on list of all articles
1275 $entry = new Entry($this->getLoggedInUser());
1276 $entry->setUrl('http://domain/qux');
1277 $entry->setTitle('Le manège');
1278 $entry->setArchived(true);
1279 $this->getEntityManager()->persist($entry);
1280 $this->getEntityManager()->flush();
1282 $crawler = $client->request('GET', '/all/list');
1284 $form = $crawler->filter('form[name=search]')->form();
1286 'search_entry[term]' => 'domain', // the search will match an entry with 'domain' in its url
1289 $crawler = $client->submit($form, $data);
1291 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1293 // same as previous test but for case-sensitivity
1294 $crawler = $client->request('GET', '/all/list');
1296 $form = $crawler->filter('form[name=search]')->form();
1298 'search_entry[term]' => 'doMain', // the search will match an entry with 'domain' in its url
1301 $crawler = $client->submit($form, $data);
1303 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1306 public function dataForLanguage()
1310 'https://www.pravda.ru/world/09-06-2017/1337283-qatar-0/',
1314 'https://fr.wikipedia.org/wiki/Wallabag',
1318 'https://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html',
1322 'http://www.ansa.it/sito/notizie/mondo/europa/2017/06/08/voto-gb-seggi-aperti-misure-sicurezza-rafforzate_0cb71f7f-e23b-4d5f-95ca-bc12296419f0.html',
1326 'http://www.hao123.com/shequ?__noscript__-=1',
1330 'https://www.kp.ru/daily/26879.7/3921982/',
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);