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
;
10 class EntryControllerTest
extends WallabagCoreTestCase
12 const An_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE
= 'http://www.lemonde.fr/judo/article/2017/11/11/judo-la-decima-de-teddy-riner_5213605_1556020.html';
13 public $downloadImagesEnabled = false;
14 public $url = 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html';
19 * Ensure download_images_enabled is disabled after each script
21 public function tearDownImagesEnabled()
23 if ($this->downloadImagesEnabled
) {
24 $client = static::createClient();
25 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
27 $this->downloadImagesEnabled
= false;
31 public function testLogin()
33 $client = $this->getClient();
35 $client->request('GET', '/new');
37 $this->assertSame(302, $client->getResponse()->getStatusCode());
38 $this->assertContains('login', $client->getResponse()->headers
->get('location'));
41 public function testQuickstart()
43 $this->logInAs('empty');
44 $client = $this->getClient();
46 $client->request('GET', '/unread/list');
47 $this->assertSame(302, $client->getResponse()->getStatusCode());
48 $crawler = $client->followRedirect();
50 $this->assertSame(200, $client->getResponse()->getStatusCode());
51 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
52 $this->assertContains('quickstart.intro.title', $body[0]);
54 // Test if quickstart is disabled when user has 1 entry
55 $crawler = $client->request('GET', '/new');
57 $this->assertSame(200, $client->getResponse()->getStatusCode());
59 $form = $crawler->filter('form[name=entry]')->form();
62 'entry[url]' => $this->url
,
65 $client->submit($form, $data);
66 $this->assertSame(302, $client->getResponse()->getStatusCode());
67 $client->followRedirect();
69 $crawler = $client->request('GET', '/unread/list');
70 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
71 $this->assertContains('entry.list.number_on_the_page', $body[0]);
74 public function testGetNew()
76 $this->logInAs('admin');
77 $this->useTheme('baggy');
78 $client = $this->getClient();
80 $crawler = $client->request('GET', '/new');
82 $this->assertSame(200, $client->getResponse()->getStatusCode());
84 $this->assertCount(1, $crawler->filter('input[type=url]'));
85 $this->assertCount(1, $crawler->filter('form[name=entry]'));
88 public function testPostNewViaBookmarklet()
90 $this->logInAs('admin');
91 $this->useTheme('baggy');
92 $client = $this->getClient();
94 $crawler = $client->request('GET', '/');
96 $this->assertCount(4, $crawler->filter('div[class=entry]'));
99 $client->request('GET', '/bookmarklet', ['url' => $this->url
]);
100 $this->assertSame(302, $client->getResponse()->getStatusCode());
101 $client->followRedirect();
102 $crawler = $client->request('GET', '/');
103 $this->assertCount(5, $crawler->filter('div[class=entry]'));
105 $em = $client->getContainer()
106 ->get('doctrine.orm.entity_manager');
108 ->getRepository('WallabagCoreBundle:Entry')
109 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
114 public function testPostNewEmpty()
116 $this->logInAs('admin');
117 $client = $this->getClient();
119 $crawler = $client->request('GET', '/new');
121 $this->assertSame(200, $client->getResponse()->getStatusCode());
123 $form = $crawler->filter('form[name=entry]')->form();
125 $crawler = $client->submit($form);
127 $this->assertSame(200, $client->getResponse()->getStatusCode());
128 $this->assertCount(1, $alert = $crawler->filter('form ul li')->extract(['_text']));
129 $this->assertSame('This value should not be blank.', $alert[0]);
133 * This test will require an internet connection.
135 public function testPostNewOk()
137 $this->logInAs('admin');
138 $client = $this->getClient();
140 $client->getContainer()->get('craue_config')->set('store_article_headers', 1);
142 $crawler = $client->request('GET', '/new');
144 $this->assertSame(200, $client->getResponse()->getStatusCode());
146 $form = $crawler->filter('form[name=entry]')->form();
149 'entry[url]' => $this->url
,
152 $client->submit($form, $data);
154 $this->assertSame(302, $client->getResponse()->getStatusCode());
156 $content = $client->getContainer()
157 ->get('doctrine.orm.entity_manager')
158 ->getRepository('WallabagCoreBundle:Entry')
159 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
161 $author = $content->getPublishedBy();
163 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
164 $this->assertSame($this->url
, $content->getUrl());
165 $this->assertContains('Google', $content->getTitle());
166 $this->assertSame('fr', $content->getLanguage());
167 $this->assertSame('2015-03-28 11:43:19', $content->getPublishedAt()->format('Y-m-d H:i:s'));
168 $this->assertSame('Morgane Tual', $author[0]);
169 $this->assertArrayHasKey('x-varnish1', $content->getHeaders());
170 $client->getContainer()->get('craue_config')->set('store_article_headers', 0);
173 public function testPostWithMultipleAuthors()
175 $url = 'http://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768';
176 $this->logInAs('admin');
177 $client = $this->getClient();
179 $crawler = $client->request('GET', '/new');
181 $this->assertSame(200, $client->getResponse()->getStatusCode());
183 $form = $crawler->filter('form[name=entry]')->form();
186 'entry[url]' => $url,
189 $client->submit($form, $data);
191 $this->assertSame(302, $client->getResponse()->getStatusCode());
193 $content = $client->getContainer()
194 ->get('doctrine.orm.entity_manager')
195 ->getRepository('WallabagCoreBundle:Entry')
196 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
198 $authors = $content->getPublishedBy();
199 $this->assertSame('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s'));
200 $this->assertSame('fr', $content->getLanguage());
201 $this->assertSame('Raphaël Balenieri, correspondant à Pékin', $authors[0]);
202 $this->assertSame('Frédéric Autran, correspondant à New York', $authors[1]);
205 public function testPostNewOkUrlExist()
207 $this->logInAs('admin');
209 $entry = new Entry($this->getLoggedInUser());
210 $entry->setUrl($this->url
);
211 $this->getEntityManager()->persist($entry);
212 $this->getEntityManager()->flush();
214 $client = $this->getClient();
216 $crawler = $client->request('GET', '/new');
218 $this->assertSame(200, $client->getResponse()->getStatusCode());
220 $form = $crawler->filter('form[name=entry]')->form();
223 'entry[url]' => $this->url
,
226 $client->submit($form, $data);
228 $this->assertSame(302, $client->getResponse()->getStatusCode());
229 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
232 public function testPostNewOkUrlExistWithAccent()
234 $this->logInAs('admin');
235 $client = $this->getClient();
237 $url = 'http://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing';
239 $crawler = $client->request('GET', '/new');
241 $this->assertSame(200, $client->getResponse()->getStatusCode());
243 $form = $crawler->filter('form[name=entry]')->form();
246 'entry[url]' => $url,
249 $client->submit($form, $data);
251 $crawler = $client->request('GET', '/new');
253 $this->assertSame(200, $client->getResponse()->getStatusCode());
255 $form = $crawler->filter('form[name=entry]')->form();
258 'entry[url]' => $url,
261 $client->submit($form, $data);
263 $this->assertSame(302, $client->getResponse()->getStatusCode());
264 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
268 * This test will require an internet connection.
270 public function testPostNewThatWillBeTagged()
272 $this->logInAs('admin');
273 $client = $this->getClient();
275 $crawler = $client->request('GET', '/new');
277 $this->assertSame(200, $client->getResponse()->getStatusCode());
279 $form = $crawler->filter('form[name=entry]')->form();
282 'entry[url]' => $url = 'https://github.com/wallabag/wallabag',
285 $client->submit($form, $data);
287 $this->assertSame(302, $client->getResponse()->getStatusCode());
288 $this->assertContains('/', $client->getResponse()->getTargetUrl());
290 $em = $client->getContainer()
291 ->get('doctrine.orm.entity_manager');
293 ->getRepository('WallabagCoreBundle:Entry')
294 ->findOneByUrl($url);
295 $tags = $entry->getTags();
297 $this->assertCount(2, $tags);
298 $this->assertContains('wallabag', $tags);
299 $this->assertSame('en', $entry->getLanguage());
304 // and now re-submit it to test the cascade persistence for tags after entry removal
305 // related https://github.com/wallabag/wallabag/issues/2121
306 $crawler = $client->request('GET', '/new');
308 $this->assertSame(200, $client->getResponse()->getStatusCode());
310 $form = $crawler->filter('form[name=entry]')->form();
313 'entry[url]' => $url = 'https://github.com/wallabag/wallabag/tree/master',
316 $client->submit($form, $data);
318 $this->assertSame(302, $client->getResponse()->getStatusCode());
319 $this->assertContains('/', $client->getResponse()->getTargetUrl());
322 ->getRepository('WallabagCoreBundle:Entry')
323 ->findOneByUrl($url);
325 $tags = $entry->getTags();
327 $this->assertCount(2, $tags);
328 $this->assertContains('wallabag', $tags);
334 public function testArchive()
336 $this->logInAs('admin');
337 $client = $this->getClient();
339 $client->request('GET', '/archive/list');
341 $this->assertSame(200, $client->getResponse()->getStatusCode());
344 public function testUntagged()
346 $this->logInAs('admin');
347 $client = $this->getClient();
349 $client->request('GET', '/untagged/list');
351 $this->assertSame(200, $client->getResponse()->getStatusCode());
354 public function testStarred()
356 $this->logInAs('admin');
357 $client = $this->getClient();
359 $client->request('GET', '/starred/list');
361 $this->assertSame(200, $client->getResponse()->getStatusCode());
364 public function testRangeException()
366 $this->logInAs('admin');
367 $client = $this->getClient();
369 $client->request('GET', '/all/list/900');
371 $this->assertSame(302, $client->getResponse()->getStatusCode());
372 $this->assertSame('/all/list', $client->getResponse()->getTargetUrl());
375 public function testView()
377 $this->logInAs('admin');
378 $client = $this->getClient();
380 $entry = new Entry($this->getLoggedInUser());
381 $entry->setUrl('http://example.com/foo');
382 $entry->setTitle('title foo');
383 $entry->setContent('foo bar baz');
384 $this->getEntityManager()->persist($entry);
385 $this->getEntityManager()->flush();
387 $crawler = $client->request('GET', '/view/' . $entry->getId());
389 $this->assertSame(200, $client->getResponse()->getStatusCode());
390 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
391 $this->assertContains($entry->getTitle(), $body[0]);
395 * This test will require an internet connection.
397 public function testReload()
399 $this->logInAs('admin');
400 $client = $this->getClient();
402 $entry = new Entry($this->getLoggedInUser());
403 $entry->setUrl($this->url
);
404 $entry->setTitle('title foo');
405 $entry->setContent('');
406 $this->getEntityManager()->persist($entry);
407 $this->getEntityManager()->flush();
408 $this->getEntityManager()->clear();
410 $client->request('GET', '/reload/' . $entry->getId());
412 $this->assertSame(302, $client->getResponse()->getStatusCode());
414 $entry = $this->getEntityManager()
415 ->getRepository('WallabagCoreBundle:Entry')
416 ->find($entry->getId());
418 $this->assertNotEmpty($entry->getContent());
421 public function testReloadWithFetchingFailed()
423 $this->logInAs('admin');
424 $client = $this->getClient();
426 $entry = new Entry($this->getLoggedInUser());
427 $entry->setUrl('http://0.0.0.0/failed.html');
428 $this->getEntityManager()->persist($entry);
429 $this->getEntityManager()->flush();
431 $client->request('GET', '/reload/' . $entry->getId());
433 $this->assertSame(302, $client->getResponse()->getStatusCode());
435 // force EntityManager to clear previous entity
436 // otherwise, retrieve the same entity will retrieve change from the previous request :0
437 $this->getEntityManager()->clear();
438 $newContent = $this->getEntityManager()
439 ->getRepository('WallabagCoreBundle:Entry')
440 ->find($entry->getId());
442 $this->assertNotSame($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent());
445 public function testEdit()
447 $this->logInAs('admin');
448 $client = $this->getClient();
450 $entry = new Entry($this->getLoggedInUser());
451 $entry->setUrl($this->url
);
452 $this->getEntityManager()->persist($entry);
453 $this->getEntityManager()->flush();
455 $crawler = $client->request('GET', '/edit/' . $entry->getId());
457 $this->assertSame(200, $client->getResponse()->getStatusCode());
459 $this->assertCount(1, $crawler->filter('input[id=entry_title]'));
460 $this->assertCount(1, $crawler->filter('button[id=entry_save]'));
463 public function testEditUpdate()
465 $this->logInAs('admin');
466 $client = $this->getClient();
468 $entry = new Entry($this->getLoggedInUser());
469 $entry->setUrl($this->url
);
470 $this->getEntityManager()->persist($entry);
471 $this->getEntityManager()->flush();
473 $crawler = $client->request('GET', '/edit/' . $entry->getId());
475 $this->assertSame(200, $client->getResponse()->getStatusCode());
477 $form = $crawler->filter('button[type=submit]')->form();
480 'entry[title]' => 'My updated title hehe :)',
481 'entry[origin_url]' => 'https://example.io',
484 $client->submit($form, $data);
486 $this->assertSame(302, $client->getResponse()->getStatusCode());
488 $crawler = $client->followRedirect();
490 $this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text']));
491 $this->assertContains('My updated title hehe :)', $title[0]);
492 $this->assertGreaterThan(1, $stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']));
493 $this->assertContains('example.io', trim($stats[1]));
496 public function testEditRemoveOriginUrl()
498 $this->logInAs('admin');
499 $client = $this->getClient();
501 $entry = new Entry($this->getLoggedInUser());
502 $entry->setUrl($this->url
);
503 $this->getEntityManager()->persist($entry);
504 $this->getEntityManager()->flush();
506 $crawler = $client->request('GET', '/edit/' . $entry->getId());
508 $this->assertSame(200, $client->getResponse()->getStatusCode());
510 $form = $crawler->filter('button[type=submit]')->form();
513 'entry[title]' => 'My updated title hehe :)',
514 'entry[origin_url]' => '',
517 $client->submit($form, $data);
519 $this->assertSame(302, $client->getResponse()->getStatusCode());
521 $crawler = $client->followRedirect();
523 $this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text']));
524 $this->assertContains('My updated title hehe :)', $title[0]);
525 $this->assertSame(1, count($stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text'])));
526 $this->assertNotContains('example.io', trim($stats[0]));
529 public function testToggleArchive()
531 $this->logInAs('admin');
532 $client = $this->getClient();
534 $entry = new Entry($this->getLoggedInUser());
535 $entry->setUrl($this->url
);
536 $this->getEntityManager()->persist($entry);
537 $this->getEntityManager()->flush();
538 $this->getEntityManager()->clear();
540 $client->request('GET', '/archive/' . $entry->getId());
542 $this->assertSame(302, $client->getResponse()->getStatusCode());
544 $res = $client->getContainer()
545 ->get('doctrine.orm.entity_manager')
546 ->getRepository('WallabagCoreBundle:Entry')
547 ->find($entry->getId());
549 $this->assertSame(1, $res->isArchived());
552 public function testToggleStar()
554 $this->logInAs('admin');
555 $client = $this->getClient();
557 $entry = new Entry($this->getLoggedInUser());
558 $entry->setUrl($this->url
);
559 $this->getEntityManager()->persist($entry);
560 $this->getEntityManager()->flush();
561 $this->getEntityManager()->clear();
563 $client->request('GET', '/star/' . $entry->getId());
565 $this->assertSame(302, $client->getResponse()->getStatusCode());
567 $res = $client->getContainer()
568 ->get('doctrine.orm.entity_manager')
569 ->getRepository('WallabagCoreBundle:Entry')
570 ->findOneById($entry->getId());
572 $this->assertSame(1, $res->isStarred());
575 public function testDelete()
577 $this->logInAs('admin');
578 $client = $this->getClient();
580 $entry = new Entry($this->getLoggedInUser());
581 $entry->setUrl($this->url
);
582 $this->getEntityManager()->persist($entry);
583 $this->getEntityManager()->flush();
585 $client->request('GET', '/delete/' . $entry->getId());
587 $this->assertSame(302, $client->getResponse()->getStatusCode());
589 $client->request('GET', '/delete/' . $entry->getId());
591 $this->assertSame(404, $client->getResponse()->getStatusCode());
595 * It will create a new entry.
599 * And it'll check that user won't be redirected to the view page of the content when it had been removed
601 public function testViewAndDelete()
603 $this->logInAs('admin');
604 $client = $this->getClient();
606 $em = $client->getContainer()
607 ->get('doctrine.orm.entity_manager');
609 // add a new content to be removed later
611 ->getRepository('WallabagUserBundle:User')
612 ->findOneByUserName('admin');
614 $content = new Entry($user);
615 $content->setUrl('http://1.1.1.1/entry');
616 $content->setReadingTime(12);
617 $content->setDomainName('domain.io');
618 $content->setMimetype('text/html');
619 $content->setTitle('test title entry');
620 $content->setContent('This is my content /o/');
621 $content->setArchived(true);
622 $content->setLanguage('fr');
624 $em->persist($content);
627 $client->request('GET', '/view/' . $content->getId());
628 $this->assertSame(200, $client->getResponse()->getStatusCode());
630 $client->request('GET', '/delete/' . $content->getId());
631 $this->assertSame(302, $client->getResponse()->getStatusCode());
633 $client->followRedirect();
634 $this->assertSame(200, $client->getResponse()->getStatusCode());
637 public function testViewOtherUserEntry()
639 $this->logInAs('admin');
640 $client = $this->getClient();
642 $content = $client->getContainer()
643 ->get('doctrine.orm.entity_manager')
644 ->getRepository('WallabagCoreBundle:Entry')
645 ->findOneByUsernameAndNotArchived('bob');
647 $client->request('GET', '/view/' . $content->getId());
649 $this->assertSame(403, $client->getResponse()->getStatusCode());
652 public function testFilterOnReadingTime()
654 $this->logInAs('admin');
655 $this->useTheme('baggy');
656 $client = $this->getClient();
657 $entry = new Entry($this->getLoggedInUser());
658 $entry->setUrl($this->url
);
659 $entry->setReadingTime(22);
660 $this->getEntityManager()->persist($entry);
661 $this->getEntityManager()->flush();
663 $crawler = $client->request('GET', '/unread/list');
665 $form = $crawler->filter('button[id=submit-filter]')->form();
668 'entry_filter[readingTime][right_number]' => 22,
669 'entry_filter[readingTime][left_number]' => 22,
672 $crawler = $client->submit($form, $data);
674 $this->assertCount(1, $crawler->filter('div[class=entry]'));
677 public function testFilterOnReadingTimeWithNegativeValue()
679 $this->logInAs('admin');
680 $client = $this->getClient();
682 $crawler = $client->request('GET', '/unread/list');
684 $form = $crawler->filter('button[id=submit-filter]')->form();
687 'entry_filter[readingTime][right_number]' => -22,
688 'entry_filter[readingTime][left_number]' => -22,
691 $crawler = $client->submit($form, $data);
693 // forcing negative value results in no entry displayed
694 $this->assertCount(0, $crawler->filter('div[class=entry]'));
697 public function testFilterOnReadingTimeOnlyUpper()
699 $this->logInAs('admin');
700 $this->useTheme('baggy');
701 $client = $this->getClient();
703 $crawler = $client->request('GET', '/all/list');
704 $this->assertCount(5, $crawler->filter('div[class=entry]'));
706 $entry = new Entry($this->getLoggedInUser());
707 $entry->setUrl($this->url
);
708 $entry->setReadingTime(23);
709 $this->getEntityManager()->persist($entry);
710 $this->getEntityManager()->flush();
712 $crawler = $client->request('GET', '/all/list');
713 $this->assertCount(6, $crawler->filter('div[class=entry]'));
715 $form = $crawler->filter('button[id=submit-filter]')->form();
718 'entry_filter[readingTime][right_number]' => 22,
721 $crawler = $client->submit($form, $data);
723 $this->assertCount(5, $crawler->filter('div[class=entry]'));
726 public function testFilterOnReadingTimeOnlyLower()
728 $this->logInAs('admin');
729 $this->useTheme('baggy');
730 $client = $this->getClient();
732 $crawler = $client->request('GET', '/unread/list');
734 $form = $crawler->filter('button[id=submit-filter]')->form();
737 'entry_filter[readingTime][left_number]' => 22,
740 $crawler = $client->submit($form, $data);
742 $this->assertCount(0, $crawler->filter('div[class=entry]'));
744 $entry = new Entry($this->getLoggedInUser());
745 $entry->setUrl($this->url
);
746 $entry->setReadingTime(23);
747 $this->getEntityManager()->persist($entry);
748 $this->getEntityManager()->flush();
750 $crawler = $client->submit($form, $data);
751 $this->assertCount(1, $crawler->filter('div[class=entry]'));
754 public function testFilterOnUnreadStatus()
756 $this->logInAs('admin');
757 $this->useTheme('baggy');
758 $client = $this->getClient();
760 $crawler = $client->request('GET', '/all/list');
762 $form = $crawler->filter('button[id=submit-filter]')->form();
765 'entry_filter[isUnread]' => true,
768 $crawler = $client->submit($form, $data);
770 $this->assertCount(4, $crawler->filter('div[class=entry]'));
772 $entry = new Entry($this->getLoggedInUser());
773 $entry->setUrl($this->url
);
774 $entry->setArchived(false);
775 $this->getEntityManager()->persist($entry);
776 $this->getEntityManager()->flush();
778 $crawler = $client->submit($form, $data);
780 $this->assertCount(5, $crawler->filter('div[class=entry]'));
783 public function testFilterOnCreationDate()
785 $this->logInAs('admin');
786 $this->useTheme('baggy');
787 $client = $this->getClient();
789 $crawler = $client->request('GET', '/unread/list');
791 $form = $crawler->filter('button[id=submit-filter]')->form();
794 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
795 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')),
798 $crawler = $client->submit($form, $data);
800 $this->assertCount(5, $crawler->filter('div[class=entry]'));
803 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
804 'entry_filter[createdAt][right_date]' => date('d/m/Y'),
807 $crawler = $client->submit($form, $data);
809 $this->assertCount(5, $crawler->filter('div[class=entry]'));
812 'entry_filter[createdAt][left_date]' => '01/01/1970',
813 'entry_filter[createdAt][right_date]' => '01/01/1970',
816 $crawler = $client->submit($form, $data);
818 $this->assertCount(0, $crawler->filter('div[class=entry]'));
821 public function testPaginationWithFilter()
823 $this->logInAs('admin');
824 $client = $this->getClient();
825 $crawler = $client->request('GET', '/config');
827 $form = $crawler->filter('button[id=config_save]')->form();
830 'config[items_per_page]' => '1',
833 $client->submit($form, $data);
835 $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D=';
837 $client->request('GET', 'unread/list' . $parameters);
839 $this->assertContains($parameters, $client->getResponse()->getContent());
842 $crawler = $client->request('GET', '/config');
843 $form = $crawler->filter('button[id=config_save]')->form();
845 'config[items_per_page]' => '12',
847 $client->submit($form, $data);
850 public function testFilterOnDomainName()
852 $this->logInAs('admin');
853 $this->useTheme('baggy');
854 $client = $this->getClient();
856 $crawler = $client->request('GET', '/unread/list');
857 $form = $crawler->filter('button[id=submit-filter]')->form();
859 'entry_filter[domainName]' => 'domain',
862 $crawler = $client->submit($form, $data);
863 $this->assertCount(5, $crawler->filter('div[class=entry]'));
865 $crawler = $client->request('GET', '/unread/list');
866 $form = $crawler->filter('button[id=submit-filter]')->form();
868 'entry_filter[domainName]' => 'dOmain',
871 $crawler = $client->submit($form, $data);
872 $this->assertCount(5, $crawler->filter('div[class=entry]'));
874 $form = $crawler->filter('button[id=submit-filter]')->form();
876 'entry_filter[domainName]' => 'wallabag',
879 $crawler = $client->submit($form, $data);
880 $this->assertCount(0, $crawler->filter('div[class=entry]'));
883 public function testFilterOnStatus()
885 $this->logInAs('admin');
886 $this->useTheme('baggy');
887 $client = $this->getClient();
889 $crawler = $client->request('GET', '/unread/list');
890 $form = $crawler->filter('button[id=submit-filter]')->form();
891 $form['entry_filter[isArchived]']->tick();
892 $form['entry_filter[isStarred]']->untick();
894 $crawler = $client->submit($form);
895 $this->assertCount(1, $crawler->filter('div[class=entry]'));
897 $form = $crawler->filter('button[id=submit-filter]')->form();
898 $form['entry_filter[isArchived]']->untick();
899 $form['entry_filter[isStarred]']->tick();
901 $crawler = $client->submit($form);
902 $this->assertCount(1, $crawler->filter('div[class=entry]'));
905 public function testFilterOnIsPublic()
907 $this->logInAs('admin');
908 $this->useTheme('baggy');
909 $client = $this->getClient();
911 $crawler = $client->request('GET', '/unread/list');
912 $form = $crawler->filter('button[id=submit-filter]')->form();
913 $form['entry_filter[isPublic]']->tick();
915 $crawler = $client->submit($form);
916 $this->assertCount(0, $crawler->filter('div[class=entry]'));
919 public function testPreviewPictureFilter()
921 $this->logInAs('admin');
922 $this->useTheme('baggy');
923 $client = $this->getClient();
925 $crawler = $client->request('GET', '/unread/list');
926 $form = $crawler->filter('button[id=submit-filter]')->form();
927 $form['entry_filter[previewPicture]']->tick();
929 $crawler = $client->submit($form);
930 $this->assertCount(1, $crawler->filter('div[class=entry]'));
933 public function testFilterOnLanguage()
935 $this->logInAs('admin');
936 $this->useTheme('baggy');
937 $client = $this->getClient();
939 $entry = new Entry($this->getLoggedInUser());
940 $entry->setUrl($this->url
);
941 $entry->setLanguage('fr');
942 $this->getEntityManager()->persist($entry);
943 $this->getEntityManager()->flush();
945 $crawler = $client->request('GET', '/unread/list');
946 $form = $crawler->filter('button[id=submit-filter]')->form();
948 'entry_filter[language]' => 'fr',
951 $crawler = $client->submit($form, $data);
952 $this->assertCount(3, $crawler->filter('div[class=entry]'));
954 $form = $crawler->filter('button[id=submit-filter]')->form();
956 'entry_filter[language]' => 'en',
959 $crawler = $client->submit($form, $data);
960 $this->assertCount(2, $crawler->filter('div[class=entry]'));
963 public function testShareEntryPublicly()
965 $this->logInAs('admin');
966 $client = $this->getClient();
968 // sharing is enabled
969 $client->getContainer()->get('craue_config')->set('share_public', 1);
971 $content = new Entry($this->getLoggedInUser());
972 $content->setUrl($this->url
);
973 $this->getEntityManager()->persist($content);
974 $this->getEntityManager()->flush();
975 $this->getEntityManager()->clear();
978 $client->request('GET', '/share/' . $content->getUid());
979 $this->assertSame(404, $client->getResponse()->getStatusCode());
981 // generating the uid
982 $client->request('GET', '/share/' . $content->getId());
983 $this->assertSame(302, $client->getResponse()->getStatusCode());
985 // follow link with uid
986 $crawler = $client->followRedirect();
987 $this->assertSame(200, $client->getResponse()->getStatusCode());
988 $this->assertContains('max-age=25200', $client->getResponse()->headers
->get('cache-control'));
989 $this->assertContains('public', $client->getResponse()->headers
->get('cache-control'));
990 $this->assertContains('s-maxage=25200', $client->getResponse()->headers
->get('cache-control'));
991 $this->assertNotContains('no-cache', $client->getResponse()->headers
->get('cache-control'));
992 $this->assertContains('og:title', $client->getResponse()->getContent());
993 $this->assertContains('og:type', $client->getResponse()->getContent());
994 $this->assertContains('og:url', $client->getResponse()->getContent());
995 $this->assertContains('og:image', $client->getResponse()->getContent());
997 // sharing is now disabled
998 $client->getContainer()->get('craue_config')->set('share_public', 0);
999 $client->request('GET', '/share/' . $content->getUid());
1000 $this->assertSame(404, $client->getResponse()->getStatusCode());
1002 $client->request('GET', '/view/' . $content->getId());
1003 $this->assertContains('no-cache', $client->getResponse()->headers
->get('cache-control'));
1005 // removing the share
1006 $client->request('GET', '/share/delete/' . $content->getId());
1007 $this->assertSame(302, $client->getResponse()->getStatusCode());
1009 // share is now disable
1010 $client->request('GET', '/share/' . $content->getUid());
1011 $this->assertSame(404, $client->getResponse()->getStatusCode());
1014 public function testNewEntryWithDownloadImagesEnabled()
1016 $this->downloadImagesEnabled
= true;
1017 $this->logInAs('admin');
1018 $client = $this->getClient();
1020 $url = self
::An_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE
;
1021 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
1023 $crawler = $client->request('GET', '/new');
1025 $this->assertSame(200, $client->getResponse()->getStatusCode());
1027 $form = $crawler->filter('form[name=entry]')->form();
1030 'entry[url]' => $url,
1033 $client->submit($form, $data);
1035 $this->assertSame(302, $client->getResponse()->getStatusCode());
1037 $em = $client->getContainer()
1038 ->get('doctrine.orm.entity_manager');
1041 ->getRepository('WallabagCoreBundle:Entry')
1042 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1044 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry);
1045 $this->assertSame($url, $entry->getUrl());
1046 $this->assertContains('Judo', $entry->getTitle());
1047 // instead of checking for the filename (which might change) check that the image is now local
1048 $this->assertContains(rtrim($client->getContainer()->getParameter('domain_name'), '/') . '/assets/images/', $entry->getContent());
1050 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1054 * @depends testNewEntryWithDownloadImagesEnabled
1056 public function testRemoveEntryWithDownloadImagesEnabled()
1058 $this->downloadImagesEnabled
= true;
1059 $this->logInAs('admin');
1060 $client = $this->getClient();
1062 $url = self
::An_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE
;
1063 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
1065 $crawler = $client->request('GET', '/new');
1067 $this->assertSame(200, $client->getResponse()->getStatusCode());
1069 $form = $crawler->filter('form[name=entry]')->form();
1072 'entry[url]' => $url,
1075 $client->submit($form, $data);
1077 $this->assertSame(302, $client->getResponse()->getStatusCode());
1079 $content = $client->getContainer()
1080 ->get('doctrine.orm.entity_manager')
1081 ->getRepository('WallabagCoreBundle:Entry')
1082 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1084 $client->request('GET', '/delete/' . $content->getId());
1086 $this->assertSame(302, $client->getResponse()->getStatusCode());
1088 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1091 public function testRedirectToHomepage()
1093 $this->logInAs('empty');
1094 $client = $this->getClient();
1096 // Redirect to homepage
1097 $config = $this->getLoggedInUser()->getConfig();
1098 $config->setActionMarkAsRead(Config
::REDIRECT_TO_HOMEPAGE
);
1099 $this->getEntityManager()->persist($config);
1101 $entry = new Entry($this->getLoggedInUser());
1102 $entry->setUrl($this->url
);
1103 $this->getEntityManager()->persist($entry);
1105 $this->getEntityManager()->flush();
1107 $client->request('GET', '/view/' . $entry->getId());
1108 $client->request('GET', '/archive/' . $entry->getId());
1110 $this->assertSame(302, $client->getResponse()->getStatusCode());
1111 $this->assertSame('/', $client->getResponse()->headers
->get('location'));
1114 public function testRedirectToCurrentPage()
1116 $this->logInAs('empty');
1117 $client = $this->getClient();
1119 // Redirect to current page
1120 $config = $this->getLoggedInUser()->getConfig();
1121 $config->setActionMarkAsRead(Config
::REDIRECT_TO_CURRENT_PAGE
);
1122 $this->getEntityManager()->persist($config);
1124 $entry = new Entry($this->getLoggedInUser());
1125 $entry->setUrl($this->url
);
1126 $this->getEntityManager()->persist($entry);
1128 $this->getEntityManager()->flush();
1130 $client->request('GET', '/view/' . $entry->getId());
1131 $client->request('GET', '/archive/' . $entry->getId());
1133 $this->assertSame(302, $client->getResponse()->getStatusCode());
1134 $this->assertContains('/view/' . $entry->getId(), $client->getResponse()->headers
->get('location'));
1137 public function testFilterOnHttpStatus()
1139 $this->logInAs('admin');
1140 $this->useTheme('baggy');
1141 $client = $this->getClient();
1143 $entry = new Entry($this->getLoggedInUser());
1144 $entry->setUrl('http://www.lemonde.fr/incorrect-url/');
1145 $entry->setHttpStatus(404);
1146 $this->getEntityManager()->persist($entry);
1148 $this->getEntityManager()->flush();
1150 $crawler = $client->request('GET', '/all/list');
1151 $form = $crawler->filter('button[id=submit-filter]')->form();
1154 'entry_filter[httpStatus]' => 404,
1157 $crawler = $client->submit($form, $data);
1159 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1161 $entry = new Entry($this->getLoggedInUser());
1162 $entry->setUrl($this->url
);
1163 $entry->setHttpStatus(200);
1164 $this->getEntityManager()->persist($entry);
1166 $entry = new Entry($this->getLoggedInUser());
1167 $entry->setUrl('http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm');
1168 $entry->setHttpStatus(200);
1169 $this->getEntityManager()->persist($entry);
1171 $this->getEntityManager()->flush();
1173 $crawler = $client->request('GET', '/all/list');
1174 $form = $crawler->filter('button[id=submit-filter]')->form();
1177 'entry_filter[httpStatus]' => 200,
1180 $crawler = $client->submit($form, $data);
1182 $this->assertCount(2, $crawler->filter('div[class=entry]'));
1184 $crawler = $client->request('GET', '/all/list');
1185 $form = $crawler->filter('button[id=submit-filter]')->form();
1188 'entry_filter[httpStatus]' => 1024,
1191 $crawler = $client->submit($form, $data);
1193 $this->assertCount(8, $crawler->filter('div[class=entry]'));
1196 public function testSearch()
1198 $this->logInAs('admin');
1199 $this->useTheme('baggy');
1200 $client = $this->getClient();
1202 $entry = new Entry($this->getLoggedInUser());
1203 $entry->setUrl($this->url
);
1204 $entry->setTitle('test');
1205 $this->getEntityManager()->persist($entry);
1206 $this->getEntityManager()->flush();
1208 // Search on unread list
1209 $crawler = $client->request('GET', '/unread/list');
1211 $form = $crawler->filter('form[name=search]')->form();
1213 'search_entry[term]' => 'title',
1216 $crawler = $client->submit($form, $data);
1218 $this->assertCount(4, $crawler->filter('div[class=entry]'));
1220 // Search on starred list
1221 $crawler = $client->request('GET', '/starred/list');
1223 $entry = new Entry($this->getLoggedInUser());
1224 $entry->setUrl('http://localhost/foo/bar');
1225 $entry->setTitle('testeur');
1226 $entry->setStarred(true);
1227 $this->getEntityManager()->persist($entry);
1228 $this->getEntityManager()->flush();
1230 $form = $crawler->filter('form[name=search]')->form();
1232 'search_entry[term]' => 'testeur',
1235 $crawler = $client->submit($form, $data);
1237 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1239 $crawler = $client->request('GET', '/archive/list');
1241 // Added new article to test on archive list
1242 $entry = new Entry($this->getLoggedInUser());
1243 $entry->setUrl('http://0.0.0.0/foo/baz/qux');
1244 $entry->setTitle('Le manège');
1245 $entry->setArchived(true);
1246 $this->getEntityManager()->persist($entry);
1247 $this->getEntityManager()->flush();
1249 $form = $crawler->filter('form[name=search]')->form();
1251 'search_entry[term]' => 'manège',
1254 $crawler = $client->submit($form, $data);
1256 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1257 $client->request('GET', '/delete/' . $entry->getId());
1259 // test on list of all articles
1260 $crawler = $client->request('GET', '/all/list');
1262 $form = $crawler->filter('form[name=search]')->form();
1264 'search_entry[term]' => 'wxcvbnqsdf', // a string not available in the database
1267 $crawler = $client->submit($form, $data);
1269 $this->assertCount(0, $crawler->filter('div[class=entry]'));
1271 // test url search on list of all articles
1272 $entry = new Entry($this->getLoggedInUser());
1273 $entry->setUrl('http://domain/qux');
1274 $entry->setTitle('Le manège');
1275 $entry->setArchived(true);
1276 $this->getEntityManager()->persist($entry);
1277 $this->getEntityManager()->flush();
1279 $crawler = $client->request('GET', '/all/list');
1281 $form = $crawler->filter('form[name=search]')->form();
1283 'search_entry[term]' => 'domain', // the search will match an entry with 'domain' in its url
1286 $crawler = $client->submit($form, $data);
1288 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1290 // same as previous test but for case-sensitivity
1291 $crawler = $client->request('GET', '/all/list');
1293 $form = $crawler->filter('form[name=search]')->form();
1295 'search_entry[term]' => 'doMain', // the search will match an entry with 'domain' in its url
1298 $crawler = $client->submit($form, $data);
1300 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1303 public function dataForLanguage()
1307 'https://www.pravda.ru/world/09-06-2017/1337283-qatar-0/',
1311 'https://www.zataz.com/90-des-dossiers-medicaux-des-coreens-du-sud-vendus-a-des-entreprises-privees/',
1315 'http://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html',
1319 'http://www.ansa.it/sito/notizie/mondo/europa/2017/06/08/voto-gb-seggi-aperti-misure-sicurezza-rafforzate_0cb71f7f-e23b-4d5f-95ca-bc12296419f0.html',
1323 'http://www.hao123.com/shequ?__noscript__-=1',
1327 'https://buy.garmin.com/de-AT/AT/catalog/product/compareResult.ep?compareProduct=112885&compareProduct=36728',
1331 'http://netler.ru/ikt/windows-error-reporting.htm',
1335 'http://precodoscombustiveis.com.br/postos/cidade/4121/pr/maringa',
1338 'fucked_list_of_languages' => [
1339 'http://geocatalog.webservice-energy.org/geonetwork/srv/eng/main.home',
1343 'https://www.muylinux.com/2015/04/17/odf-reino-unido-microsoft-google/',
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);