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 $crawler = $client->request('GET', '/new');
142 $this->assertSame(200, $client->getResponse()->getStatusCode());
144 $form = $crawler->filter('form[name=entry]')->form();
147 'entry[url]' => $this->url
,
150 $client->submit($form, $data);
152 $this->assertSame(302, $client->getResponse()->getStatusCode());
154 $content = $client->getContainer()
155 ->get('doctrine.orm.entity_manager')
156 ->getRepository('WallabagCoreBundle:Entry')
157 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
159 $author = $content->getPublishedBy();
161 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
162 $this->assertSame($this->url
, $content->getUrl());
163 $this->assertContains('Google', $content->getTitle());
164 $this->assertSame('fr', $content->getLanguage());
165 $this->assertSame('2015-03-28 11:43:19', $content->getPublishedAt()->format('Y-m-d H:i:s'));
166 $this->assertSame('Morgane Tual', $author[0]);
167 $this->assertArrayHasKey('x-varnish1', $content->getHeaders());
170 public function testPostWithMultipleAuthors()
172 $url = 'http://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768';
173 $this->logInAs('admin');
174 $client = $this->getClient();
176 $crawler = $client->request('GET', '/new');
178 $this->assertSame(200, $client->getResponse()->getStatusCode());
180 $form = $crawler->filter('form[name=entry]')->form();
183 'entry[url]' => $url,
186 $client->submit($form, $data);
188 $this->assertSame(302, $client->getResponse()->getStatusCode());
190 $content = $client->getContainer()
191 ->get('doctrine.orm.entity_manager')
192 ->getRepository('WallabagCoreBundle:Entry')
193 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
195 $authors = $content->getPublishedBy();
196 $this->assertSame('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s'));
197 $this->assertSame('fr', $content->getLanguage());
198 $this->assertSame('Raphaël Balenieri, correspondant à Pékin', $authors[0]);
199 $this->assertSame('Frédéric Autran, correspondant à New York', $authors[1]);
202 public function testPostNewOkUrlExist()
204 $this->logInAs('admin');
206 $entry = new Entry($this->getLoggedInUser());
207 $entry->setUrl($this->url
);
208 $this->getEntityManager()->persist($entry);
209 $this->getEntityManager()->flush();
211 $client = $this->getClient();
213 $crawler = $client->request('GET', '/new');
215 $this->assertSame(200, $client->getResponse()->getStatusCode());
217 $form = $crawler->filter('form[name=entry]')->form();
220 'entry[url]' => $this->url
,
223 $client->submit($form, $data);
225 $this->assertSame(302, $client->getResponse()->getStatusCode());
226 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
229 public function testPostNewOkUrlExistWithAccent()
231 $this->logInAs('admin');
232 $client = $this->getClient();
234 $url = 'http://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing';
236 $crawler = $client->request('GET', '/new');
238 $this->assertSame(200, $client->getResponse()->getStatusCode());
240 $form = $crawler->filter('form[name=entry]')->form();
243 'entry[url]' => $url,
246 $client->submit($form, $data);
248 $crawler = $client->request('GET', '/new');
250 $this->assertSame(200, $client->getResponse()->getStatusCode());
252 $form = $crawler->filter('form[name=entry]')->form();
255 'entry[url]' => $url,
258 $client->submit($form, $data);
260 $this->assertSame(302, $client->getResponse()->getStatusCode());
261 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
265 * This test will require an internet connection.
267 public function testPostNewThatWillBeTagged()
269 $this->logInAs('admin');
270 $client = $this->getClient();
272 $crawler = $client->request('GET', '/new');
274 $this->assertSame(200, $client->getResponse()->getStatusCode());
276 $form = $crawler->filter('form[name=entry]')->form();
279 'entry[url]' => $url = 'https://github.com/wallabag/wallabag',
282 $client->submit($form, $data);
284 $this->assertSame(302, $client->getResponse()->getStatusCode());
285 $this->assertContains('/', $client->getResponse()->getTargetUrl());
287 $em = $client->getContainer()
288 ->get('doctrine.orm.entity_manager');
290 ->getRepository('WallabagCoreBundle:Entry')
291 ->findOneByUrl($url);
292 $tags = $entry->getTags();
294 $this->assertCount(2, $tags);
295 $this->assertContains('wallabag', $tags);
296 $this->assertSame('en', $entry->getLanguage());
301 // and now re-submit it to test the cascade persistence for tags after entry removal
302 // related https://github.com/wallabag/wallabag/issues/2121
303 $crawler = $client->request('GET', '/new');
305 $this->assertSame(200, $client->getResponse()->getStatusCode());
307 $form = $crawler->filter('form[name=entry]')->form();
310 'entry[url]' => $url = 'https://github.com/wallabag/wallabag/tree/master',
313 $client->submit($form, $data);
315 $this->assertSame(302, $client->getResponse()->getStatusCode());
316 $this->assertContains('/', $client->getResponse()->getTargetUrl());
319 ->getRepository('WallabagCoreBundle:Entry')
320 ->findOneByUrl($url);
322 $tags = $entry->getTags();
324 $this->assertCount(2, $tags);
325 $this->assertContains('wallabag', $tags);
331 public function testArchive()
333 $this->logInAs('admin');
334 $client = $this->getClient();
336 $client->request('GET', '/archive/list');
338 $this->assertSame(200, $client->getResponse()->getStatusCode());
341 public function testUntagged()
343 $this->logInAs('admin');
344 $client = $this->getClient();
346 $client->request('GET', '/untagged/list');
348 $this->assertSame(200, $client->getResponse()->getStatusCode());
351 public function testStarred()
353 $this->logInAs('admin');
354 $client = $this->getClient();
356 $client->request('GET', '/starred/list');
358 $this->assertSame(200, $client->getResponse()->getStatusCode());
361 public function testRangeException()
363 $this->logInAs('admin');
364 $client = $this->getClient();
366 $client->request('GET', '/all/list/900');
368 $this->assertSame(302, $client->getResponse()->getStatusCode());
369 $this->assertSame('/all/list', $client->getResponse()->getTargetUrl());
372 public function testView()
374 $this->logInAs('admin');
375 $client = $this->getClient();
377 $entry = new Entry($this->getLoggedInUser());
378 $entry->setUrl('http://example.com/foo');
379 $entry->setTitle('title foo');
380 $entry->setContent('foo bar baz');
381 $this->getEntityManager()->persist($entry);
382 $this->getEntityManager()->flush();
384 $crawler = $client->request('GET', '/view/' . $entry->getId());
386 $this->assertSame(200, $client->getResponse()->getStatusCode());
387 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
388 $this->assertContains($entry->getTitle(), $body[0]);
392 * This test will require an internet connection.
394 public function testReload()
396 $this->logInAs('admin');
397 $client = $this->getClient();
399 $entry = new Entry($this->getLoggedInUser());
400 $entry->setUrl($this->url
);
401 $entry->setTitle('title foo');
402 $entry->setContent('');
403 $this->getEntityManager()->persist($entry);
404 $this->getEntityManager()->flush();
405 $this->getEntityManager()->clear();
407 $client->request('GET', '/reload/' . $entry->getId());
409 $this->assertSame(302, $client->getResponse()->getStatusCode());
411 $entry = $this->getEntityManager()
412 ->getRepository('WallabagCoreBundle:Entry')
413 ->find($entry->getId());
415 $this->assertNotEmpty($entry->getContent());
418 public function testReloadWithFetchingFailed()
420 $this->logInAs('admin');
421 $client = $this->getClient();
423 $entry = new Entry($this->getLoggedInUser());
424 $entry->setUrl('http://0.0.0.0/failed.html');
425 $this->getEntityManager()->persist($entry);
426 $this->getEntityManager()->flush();
428 $client->request('GET', '/reload/' . $entry->getId());
430 $this->assertSame(302, $client->getResponse()->getStatusCode());
432 // force EntityManager to clear previous entity
433 // otherwise, retrieve the same entity will retrieve change from the previous request :0
434 $this->getEntityManager()->clear();
435 $newContent = $this->getEntityManager()
436 ->getRepository('WallabagCoreBundle:Entry')
437 ->find($entry->getId());
439 $this->assertNotSame($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent());
442 public function testEdit()
444 $this->logInAs('admin');
445 $client = $this->getClient();
447 $entry = new Entry($this->getLoggedInUser());
448 $entry->setUrl($this->url
);
449 $this->getEntityManager()->persist($entry);
450 $this->getEntityManager()->flush();
452 $crawler = $client->request('GET', '/edit/' . $entry->getId());
454 $this->assertSame(200, $client->getResponse()->getStatusCode());
456 $this->assertCount(1, $crawler->filter('input[id=entry_title]'));
457 $this->assertCount(1, $crawler->filter('button[id=entry_save]'));
460 public function testEditUpdate()
462 $this->logInAs('admin');
463 $client = $this->getClient();
465 $entry = new Entry($this->getLoggedInUser());
466 $entry->setUrl($this->url
);
467 $this->getEntityManager()->persist($entry);
468 $this->getEntityManager()->flush();
470 $crawler = $client->request('GET', '/edit/' . $entry->getId());
472 $this->assertSame(200, $client->getResponse()->getStatusCode());
474 $form = $crawler->filter('button[type=submit]')->form();
477 'entry[title]' => 'My updated title hehe :)',
480 $client->submit($form, $data);
482 $this->assertSame(302, $client->getResponse()->getStatusCode());
484 $crawler = $client->followRedirect();
486 $this->assertGreaterThan(1, $alert = $crawler->filter('div[id=article] h1')->extract(['_text']));
487 $this->assertContains('My updated title hehe :)', $alert[0]);
490 public function testToggleArchive()
492 $this->logInAs('admin');
493 $client = $this->getClient();
495 $entry = new Entry($this->getLoggedInUser());
496 $entry->setUrl($this->url
);
497 $this->getEntityManager()->persist($entry);
498 $this->getEntityManager()->flush();
499 $this->getEntityManager()->clear();
501 $client->request('GET', '/archive/' . $entry->getId());
503 $this->assertSame(302, $client->getResponse()->getStatusCode());
505 $res = $client->getContainer()
506 ->get('doctrine.orm.entity_manager')
507 ->getRepository('WallabagCoreBundle:Entry')
508 ->find($entry->getId());
510 $this->assertSame(1, $res->isArchived());
513 public function testToggleStar()
515 $this->logInAs('admin');
516 $client = $this->getClient();
518 $entry = new Entry($this->getLoggedInUser());
519 $entry->setUrl($this->url
);
520 $this->getEntityManager()->persist($entry);
521 $this->getEntityManager()->flush();
522 $this->getEntityManager()->clear();
524 $client->request('GET', '/star/' . $entry->getId());
526 $this->assertSame(302, $client->getResponse()->getStatusCode());
528 $res = $client->getContainer()
529 ->get('doctrine.orm.entity_manager')
530 ->getRepository('WallabagCoreBundle:Entry')
531 ->findOneById($entry->getId());
533 $this->assertSame(1, $res->isStarred());
536 public function testDelete()
538 $this->logInAs('admin');
539 $client = $this->getClient();
541 $entry = new Entry($this->getLoggedInUser());
542 $entry->setUrl($this->url
);
543 $this->getEntityManager()->persist($entry);
544 $this->getEntityManager()->flush();
546 $client->request('GET', '/delete/' . $entry->getId());
548 $this->assertSame(302, $client->getResponse()->getStatusCode());
550 $client->request('GET', '/delete/' . $entry->getId());
552 $this->assertSame(404, $client->getResponse()->getStatusCode());
556 * It will create a new entry.
560 * And it'll check that user won't be redirected to the view page of the content when it had been removed
562 public function testViewAndDelete()
564 $this->logInAs('admin');
565 $client = $this->getClient();
567 $em = $client->getContainer()
568 ->get('doctrine.orm.entity_manager');
570 // add a new content to be removed later
572 ->getRepository('WallabagUserBundle:User')
573 ->findOneByUserName('admin');
575 $content = new Entry($user);
576 $content->setUrl('http://1.1.1.1/entry');
577 $content->setReadingTime(12);
578 $content->setDomainName('domain.io');
579 $content->setMimetype('text/html');
580 $content->setTitle('test title entry');
581 $content->setContent('This is my content /o/');
582 $content->setArchived(true);
583 $content->setLanguage('fr');
585 $em->persist($content);
588 $client->request('GET', '/view/' . $content->getId());
589 $this->assertSame(200, $client->getResponse()->getStatusCode());
591 $client->request('GET', '/delete/' . $content->getId());
592 $this->assertSame(302, $client->getResponse()->getStatusCode());
594 $client->followRedirect();
595 $this->assertSame(200, $client->getResponse()->getStatusCode());
598 public function testViewOtherUserEntry()
600 $this->logInAs('admin');
601 $client = $this->getClient();
603 $content = $client->getContainer()
604 ->get('doctrine.orm.entity_manager')
605 ->getRepository('WallabagCoreBundle:Entry')
606 ->findOneByUsernameAndNotArchived('bob');
608 $client->request('GET', '/view/' . $content->getId());
610 $this->assertSame(403, $client->getResponse()->getStatusCode());
613 public function testFilterOnReadingTime()
615 $this->logInAs('admin');
616 $this->useTheme('baggy');
617 $client = $this->getClient();
618 $entry = new Entry($this->getLoggedInUser());
619 $entry->setUrl($this->url
);
620 $entry->setReadingTime(22);
621 $this->getEntityManager()->persist($entry);
622 $this->getEntityManager()->flush();
624 $crawler = $client->request('GET', '/unread/list');
626 $form = $crawler->filter('button[id=submit-filter]')->form();
629 'entry_filter[readingTime][right_number]' => 22,
630 'entry_filter[readingTime][left_number]' => 22,
633 $crawler = $client->submit($form, $data);
635 $this->assertCount(1, $crawler->filter('div[class=entry]'));
638 public function testFilterOnReadingTimeWithNegativeValue()
640 $this->logInAs('admin');
641 $client = $this->getClient();
643 $crawler = $client->request('GET', '/unread/list');
645 $form = $crawler->filter('button[id=submit-filter]')->form();
648 'entry_filter[readingTime][right_number]' => -22,
649 'entry_filter[readingTime][left_number]' => -22,
652 $crawler = $client->submit($form, $data);
654 // forcing negative value results in no entry displayed
655 $this->assertCount(0, $crawler->filter('div[class=entry]'));
658 public function testFilterOnReadingTimeOnlyUpper()
660 $this->logInAs('admin');
661 $this->useTheme('baggy');
662 $client = $this->getClient();
664 $crawler = $client->request('GET', '/all/list');
665 $this->assertCount(5, $crawler->filter('div[class=entry]'));
667 $entry = new Entry($this->getLoggedInUser());
668 $entry->setUrl($this->url
);
669 $entry->setReadingTime(23);
670 $this->getEntityManager()->persist($entry);
671 $this->getEntityManager()->flush();
673 $crawler = $client->request('GET', '/all/list');
674 $this->assertCount(6, $crawler->filter('div[class=entry]'));
676 $form = $crawler->filter('button[id=submit-filter]')->form();
679 'entry_filter[readingTime][right_number]' => 22,
682 $crawler = $client->submit($form, $data);
684 $this->assertCount(5, $crawler->filter('div[class=entry]'));
687 public function testFilterOnReadingTimeOnlyLower()
689 $this->logInAs('admin');
690 $this->useTheme('baggy');
691 $client = $this->getClient();
693 $crawler = $client->request('GET', '/unread/list');
695 $form = $crawler->filter('button[id=submit-filter]')->form();
698 'entry_filter[readingTime][left_number]' => 22,
701 $crawler = $client->submit($form, $data);
703 $this->assertCount(0, $crawler->filter('div[class=entry]'));
705 $entry = new Entry($this->getLoggedInUser());
706 $entry->setUrl($this->url
);
707 $entry->setReadingTime(23);
708 $this->getEntityManager()->persist($entry);
709 $this->getEntityManager()->flush();
711 $crawler = $client->submit($form, $data);
712 $this->assertCount(1, $crawler->filter('div[class=entry]'));
715 public function testFilterOnUnreadStatus()
717 $this->logInAs('admin');
718 $this->useTheme('baggy');
719 $client = $this->getClient();
721 $crawler = $client->request('GET', '/all/list');
723 $form = $crawler->filter('button[id=submit-filter]')->form();
726 'entry_filter[isUnread]' => true,
729 $crawler = $client->submit($form, $data);
731 $this->assertCount(4, $crawler->filter('div[class=entry]'));
733 $entry = new Entry($this->getLoggedInUser());
734 $entry->setUrl($this->url
);
735 $entry->setArchived(false);
736 $this->getEntityManager()->persist($entry);
737 $this->getEntityManager()->flush();
739 $crawler = $client->submit($form, $data);
741 $this->assertCount(5, $crawler->filter('div[class=entry]'));
744 public function testFilterOnCreationDate()
746 $this->logInAs('admin');
747 $this->useTheme('baggy');
748 $client = $this->getClient();
750 $crawler = $client->request('GET', '/unread/list');
752 $form = $crawler->filter('button[id=submit-filter]')->form();
755 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
756 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')),
759 $crawler = $client->submit($form, $data);
761 $this->assertCount(5, $crawler->filter('div[class=entry]'));
764 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
765 'entry_filter[createdAt][right_date]' => date('d/m/Y'),
768 $crawler = $client->submit($form, $data);
770 $this->assertCount(5, $crawler->filter('div[class=entry]'));
773 'entry_filter[createdAt][left_date]' => '01/01/1970',
774 'entry_filter[createdAt][right_date]' => '01/01/1970',
777 $crawler = $client->submit($form, $data);
779 $this->assertCount(0, $crawler->filter('div[class=entry]'));
782 public function testPaginationWithFilter()
784 $this->logInAs('admin');
785 $client = $this->getClient();
786 $crawler = $client->request('GET', '/config');
788 $form = $crawler->filter('button[id=config_save]')->form();
791 'config[items_per_page]' => '1',
794 $client->submit($form, $data);
796 $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D=';
798 $client->request('GET', 'unread/list' . $parameters);
800 $this->assertContains($parameters, $client->getResponse()->getContent());
803 $crawler = $client->request('GET', '/config');
804 $form = $crawler->filter('button[id=config_save]')->form();
806 'config[items_per_page]' => '12',
808 $client->submit($form, $data);
811 public function testFilterOnDomainName()
813 $this->logInAs('admin');
814 $this->useTheme('baggy');
815 $client = $this->getClient();
817 $crawler = $client->request('GET', '/unread/list');
818 $form = $crawler->filter('button[id=submit-filter]')->form();
820 'entry_filter[domainName]' => 'domain',
823 $crawler = $client->submit($form, $data);
824 $this->assertCount(5, $crawler->filter('div[class=entry]'));
826 $crawler = $client->request('GET', '/unread/list');
827 $form = $crawler->filter('button[id=submit-filter]')->form();
829 'entry_filter[domainName]' => 'dOmain',
832 $crawler = $client->submit($form, $data);
833 $this->assertCount(5, $crawler->filter('div[class=entry]'));
835 $form = $crawler->filter('button[id=submit-filter]')->form();
837 'entry_filter[domainName]' => 'wallabag',
840 $crawler = $client->submit($form, $data);
841 $this->assertCount(0, $crawler->filter('div[class=entry]'));
844 public function testFilterOnStatus()
846 $this->logInAs('admin');
847 $this->useTheme('baggy');
848 $client = $this->getClient();
850 $crawler = $client->request('GET', '/unread/list');
851 $form = $crawler->filter('button[id=submit-filter]')->form();
852 $form['entry_filter[isArchived]']->tick();
853 $form['entry_filter[isStarred]']->untick();
855 $crawler = $client->submit($form);
856 $this->assertCount(1, $crawler->filter('div[class=entry]'));
858 $form = $crawler->filter('button[id=submit-filter]')->form();
859 $form['entry_filter[isArchived]']->untick();
860 $form['entry_filter[isStarred]']->tick();
862 $crawler = $client->submit($form);
863 $this->assertCount(1, $crawler->filter('div[class=entry]'));
866 public function testFilterOnIsPublic()
868 $this->logInAs('admin');
869 $this->useTheme('baggy');
870 $client = $this->getClient();
872 $crawler = $client->request('GET', '/unread/list');
873 $form = $crawler->filter('button[id=submit-filter]')->form();
874 $form['entry_filter[isPublic]']->tick();
876 $crawler = $client->submit($form);
877 $this->assertCount(0, $crawler->filter('div[class=entry]'));
880 public function testPreviewPictureFilter()
882 $this->logInAs('admin');
883 $this->useTheme('baggy');
884 $client = $this->getClient();
886 $crawler = $client->request('GET', '/unread/list');
887 $form = $crawler->filter('button[id=submit-filter]')->form();
888 $form['entry_filter[previewPicture]']->tick();
890 $crawler = $client->submit($form);
891 $this->assertCount(1, $crawler->filter('div[class=entry]'));
894 public function testFilterOnLanguage()
896 $this->logInAs('admin');
897 $this->useTheme('baggy');
898 $client = $this->getClient();
900 $entry = new Entry($this->getLoggedInUser());
901 $entry->setUrl($this->url
);
902 $entry->setLanguage('fr');
903 $this->getEntityManager()->persist($entry);
904 $this->getEntityManager()->flush();
906 $crawler = $client->request('GET', '/unread/list');
907 $form = $crawler->filter('button[id=submit-filter]')->form();
909 'entry_filter[language]' => 'fr',
912 $crawler = $client->submit($form, $data);
913 $this->assertCount(3, $crawler->filter('div[class=entry]'));
915 $form = $crawler->filter('button[id=submit-filter]')->form();
917 'entry_filter[language]' => 'en',
920 $crawler = $client->submit($form, $data);
921 $this->assertCount(2, $crawler->filter('div[class=entry]'));
924 public function testShareEntryPublicly()
926 $this->logInAs('admin');
927 $client = $this->getClient();
929 // sharing is enabled
930 $client->getContainer()->get('craue_config')->set('share_public', 1);
932 $content = new Entry($this->getLoggedInUser());
933 $content->setUrl($this->url
);
934 $this->getEntityManager()->persist($content);
935 $this->getEntityManager()->flush();
936 $this->getEntityManager()->clear();
939 $client->request('GET', '/share/' . $content->getUid());
940 $this->assertSame(404, $client->getResponse()->getStatusCode());
942 // generating the uid
943 $client->request('GET', '/share/' . $content->getId());
944 $this->assertSame(302, $client->getResponse()->getStatusCode());
946 // follow link with uid
947 $crawler = $client->followRedirect();
948 $this->assertSame(200, $client->getResponse()->getStatusCode());
949 $this->assertContains('max-age=25200', $client->getResponse()->headers
->get('cache-control'));
950 $this->assertContains('public', $client->getResponse()->headers
->get('cache-control'));
951 $this->assertContains('s-maxage=25200', $client->getResponse()->headers
->get('cache-control'));
952 $this->assertNotContains('no-cache', $client->getResponse()->headers
->get('cache-control'));
953 $this->assertContains('og:title', $client->getResponse()->getContent());
954 $this->assertContains('og:type', $client->getResponse()->getContent());
955 $this->assertContains('og:url', $client->getResponse()->getContent());
956 $this->assertContains('og:image', $client->getResponse()->getContent());
958 // sharing is now disabled
959 $client->getContainer()->get('craue_config')->set('share_public', 0);
960 $client->request('GET', '/share/' . $content->getUid());
961 $this->assertSame(404, $client->getResponse()->getStatusCode());
963 $client->request('GET', '/view/' . $content->getId());
964 $this->assertContains('no-cache', $client->getResponse()->headers
->get('cache-control'));
966 // removing the share
967 $client->request('GET', '/share/delete/' . $content->getId());
968 $this->assertSame(302, $client->getResponse()->getStatusCode());
970 // share is now disable
971 $client->request('GET', '/share/' . $content->getUid());
972 $this->assertSame(404, $client->getResponse()->getStatusCode());
975 public function testNewEntryWithDownloadImagesEnabled()
977 $this->downloadImagesEnabled
= true;
978 $this->logInAs('admin');
979 $client = $this->getClient();
981 $url = self
::An_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE
;
982 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
984 $crawler = $client->request('GET', '/new');
986 $this->assertSame(200, $client->getResponse()->getStatusCode());
988 $form = $crawler->filter('form[name=entry]')->form();
991 'entry[url]' => $url,
994 $client->submit($form, $data);
996 $this->assertSame(302, $client->getResponse()->getStatusCode());
998 $em = $client->getContainer()
999 ->get('doctrine.orm.entity_manager');
1002 ->getRepository('WallabagCoreBundle:Entry')
1003 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1005 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry);
1006 $this->assertSame($url, $entry->getUrl());
1007 $this->assertContains('Judo', $entry->getTitle());
1008 // instead of checking for the filename (which might change) check that the image is now local
1009 $this->assertContains(rtrim($client->getContainer()->getParameter('domain_name'), '/') . '/assets/images/', $entry->getContent());
1011 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1015 * @depends testNewEntryWithDownloadImagesEnabled
1017 public function testRemoveEntryWithDownloadImagesEnabled()
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 $content = $client->getContainer()
1041 ->get('doctrine.orm.entity_manager')
1042 ->getRepository('WallabagCoreBundle:Entry')
1043 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1045 $client->request('GET', '/delete/' . $content->getId());
1047 $this->assertSame(302, $client->getResponse()->getStatusCode());
1049 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1052 public function testRedirectToHomepage()
1054 $this->logInAs('empty');
1055 $client = $this->getClient();
1057 // Redirect to homepage
1058 $config = $this->getLoggedInUser()->getConfig();
1059 $config->setActionMarkAsRead(Config
::REDIRECT_TO_HOMEPAGE
);
1060 $this->getEntityManager()->persist($config);
1062 $entry = new Entry($this->getLoggedInUser());
1063 $entry->setUrl($this->url
);
1064 $this->getEntityManager()->persist($entry);
1066 $this->getEntityManager()->flush();
1068 $client->request('GET', '/view/' . $entry->getId());
1069 $client->request('GET', '/archive/' . $entry->getId());
1071 $this->assertSame(302, $client->getResponse()->getStatusCode());
1072 $this->assertSame('/', $client->getResponse()->headers
->get('location'));
1075 public function testRedirectToCurrentPage()
1077 $this->logInAs('empty');
1078 $client = $this->getClient();
1080 // Redirect to current page
1081 $config = $this->getLoggedInUser()->getConfig();
1082 $config->setActionMarkAsRead(Config
::REDIRECT_TO_CURRENT_PAGE
);
1083 $this->getEntityManager()->persist($config);
1085 $entry = new Entry($this->getLoggedInUser());
1086 $entry->setUrl($this->url
);
1087 $this->getEntityManager()->persist($entry);
1089 $this->getEntityManager()->flush();
1091 $client->request('GET', '/view/' . $entry->getId());
1092 $client->request('GET', '/archive/' . $entry->getId());
1094 $this->assertSame(302, $client->getResponse()->getStatusCode());
1095 $this->assertContains('/view/' . $entry->getId(), $client->getResponse()->headers
->get('location'));
1098 public function testFilterOnHttpStatus()
1100 $this->logInAs('admin');
1101 $this->useTheme('baggy');
1102 $client = $this->getClient();
1104 $entry = new Entry($this->getLoggedInUser());
1105 $entry->setUrl('http://www.lemonde.fr/incorrect-url/');
1106 $entry->setHttpStatus(404);
1107 $this->getEntityManager()->persist($entry);
1109 $this->getEntityManager()->flush();
1111 $crawler = $client->request('GET', '/all/list');
1112 $form = $crawler->filter('button[id=submit-filter]')->form();
1115 'entry_filter[httpStatus]' => 404,
1118 $crawler = $client->submit($form, $data);
1120 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1122 $entry = new Entry($this->getLoggedInUser());
1123 $entry->setUrl($this->url
);
1124 $entry->setHttpStatus(200);
1125 $this->getEntityManager()->persist($entry);
1127 $entry = new Entry($this->getLoggedInUser());
1128 $entry->setUrl('http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm');
1129 $entry->setHttpStatus(200);
1130 $this->getEntityManager()->persist($entry);
1132 $this->getEntityManager()->flush();
1134 $crawler = $client->request('GET', '/all/list');
1135 $form = $crawler->filter('button[id=submit-filter]')->form();
1138 'entry_filter[httpStatus]' => 200,
1141 $crawler = $client->submit($form, $data);
1143 $this->assertCount(2, $crawler->filter('div[class=entry]'));
1145 $crawler = $client->request('GET', '/all/list');
1146 $form = $crawler->filter('button[id=submit-filter]')->form();
1149 'entry_filter[httpStatus]' => 1024,
1152 $crawler = $client->submit($form, $data);
1154 $this->assertCount(8, $crawler->filter('div[class=entry]'));
1157 public function testSearch()
1159 $this->logInAs('admin');
1160 $this->useTheme('baggy');
1161 $client = $this->getClient();
1163 $entry = new Entry($this->getLoggedInUser());
1164 $entry->setUrl($this->url
);
1165 $entry->setTitle('test');
1166 $this->getEntityManager()->persist($entry);
1167 $this->getEntityManager()->flush();
1169 // Search on unread list
1170 $crawler = $client->request('GET', '/unread/list');
1172 $form = $crawler->filter('form[name=search]')->form();
1174 'search_entry[term]' => 'title',
1177 $crawler = $client->submit($form, $data);
1179 $this->assertCount(4, $crawler->filter('div[class=entry]'));
1181 // Search on starred list
1182 $crawler = $client->request('GET', '/starred/list');
1184 $entry = new Entry($this->getLoggedInUser());
1185 $entry->setUrl('http://localhost/foo/bar');
1186 $entry->setTitle('testeur');
1187 $entry->setStarred(true);
1188 $this->getEntityManager()->persist($entry);
1189 $this->getEntityManager()->flush();
1191 $form = $crawler->filter('form[name=search]')->form();
1193 'search_entry[term]' => 'testeur',
1196 $crawler = $client->submit($form, $data);
1198 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1200 $crawler = $client->request('GET', '/archive/list');
1202 // Added new article to test on archive list
1203 $entry = new Entry($this->getLoggedInUser());
1204 $entry->setUrl('http://0.0.0.0/foo/baz/qux');
1205 $entry->setTitle('Le manège');
1206 $entry->setArchived(true);
1207 $this->getEntityManager()->persist($entry);
1208 $this->getEntityManager()->flush();
1210 $form = $crawler->filter('form[name=search]')->form();
1212 'search_entry[term]' => 'manège',
1215 $crawler = $client->submit($form, $data);
1217 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1218 $client->request('GET', '/delete/' . $entry->getId());
1220 // test on list of all articles
1221 $crawler = $client->request('GET', '/all/list');
1223 $form = $crawler->filter('form[name=search]')->form();
1225 'search_entry[term]' => 'wxcvbnqsdf', // a string not available in the database
1228 $crawler = $client->submit($form, $data);
1230 $this->assertCount(0, $crawler->filter('div[class=entry]'));
1232 // test url search on list of all articles
1233 $entry = new Entry($this->getLoggedInUser());
1234 $entry->setUrl('http://domain/qux');
1235 $entry->setTitle('Le manège');
1236 $entry->setArchived(true);
1237 $this->getEntityManager()->persist($entry);
1238 $this->getEntityManager()->flush();
1240 $crawler = $client->request('GET', '/all/list');
1242 $form = $crawler->filter('form[name=search]')->form();
1244 'search_entry[term]' => 'domain', // the search will match an entry with 'domain' in its url
1247 $crawler = $client->submit($form, $data);
1249 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1251 // same as previous test but for case-sensitivity
1252 $crawler = $client->request('GET', '/all/list');
1254 $form = $crawler->filter('form[name=search]')->form();
1256 'search_entry[term]' => 'doMain', // the search will match an entry with 'domain' in its url
1259 $crawler = $client->submit($form, $data);
1261 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1264 public function dataForLanguage()
1268 'https://www.pravda.ru/world/09-06-2017/1337283-qatar-0/',
1272 'https://www.zataz.com/90-des-dossiers-medicaux-des-coreens-du-sud-vendus-a-des-entreprises-privees/',
1276 'http://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html',
1280 'http://www.ansa.it/sito/notizie/mondo/europa/2017/06/08/voto-gb-seggi-aperti-misure-sicurezza-rafforzate_0cb71f7f-e23b-4d5f-95ca-bc12296419f0.html',
1284 'http://www.hao123.com/shequ?__noscript__-=1',
1288 'https://buy.garmin.com/de-AT/AT/catalog/product/compareResult.ep?compareProduct=112885&compareProduct=36728',
1292 'http://netler.ru/ikt/windows-error-reporting.htm',
1296 'http://precodoscombustiveis.com.br/postos/cidade/4121/pr/maringa',
1299 'fucked_list_of_languages' => [
1300 'http://geocatalog.webservice-energy.org/geonetwork/srv/eng/main.home',
1304 'https://www.muylinux.com/2015/04/17/odf-reino-unido-microsoft-google/',
1311 * @dataProvider dataForLanguage
1313 public function testLanguageValidation($url, $expectedLanguage)
1315 $this->logInAs('admin');
1316 $client = $this->getClient();
1318 $crawler = $client->request('GET', '/new');
1320 $this->assertSame(200, $client->getResponse()->getStatusCode());
1322 $form = $crawler->filter('form[name=entry]')->form();
1325 'entry[url]' => $url,
1328 $client->submit($form, $data);
1330 $this->assertSame(302, $client->getResponse()->getStatusCode());
1332 $content = $client->getContainer()
1333 ->get('doctrine.orm.entity_manager')
1334 ->getRepository('WallabagCoreBundle:Entry')
1335 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1337 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1338 $this->assertSame($url, $content->getUrl());
1339 $this->assertSame($expectedLanguage, $content->getLanguage());
1343 * This test will require an internet connection.
1345 public function testRestrictedArticle()
1347 $url = 'https://www.monde-diplomatique.fr/2017/05/BONNET/57475';
1348 $this->logInAs('admin');
1349 $client = $this->getClient();
1350 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
1352 // enable restricted access
1353 $client->getContainer()->get('craue_config')->set('restricted_access', 1);
1355 // create a new site_credential
1356 $user = $client->getContainer()->get('security.token_storage')->getToken()->getUser();
1357 $credential = new SiteCredential($user);
1358 $credential->setHost('monde-diplomatique.fr');
1359 $credential->setUsername($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('foo'));
1360 $credential->setPassword($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('bar'));
1362 $em->persist($credential);
1365 $crawler = $client->request('GET', '/new');
1367 $this->assertSame(200, $client->getResponse()->getStatusCode());
1369 $form = $crawler->filter('form[name=entry]')->form();
1372 'entry[url]' => $url,
1375 $client->submit($form, $data);
1377 $this->assertSame(302, $client->getResponse()->getStatusCode());
1379 $crawler = $client->followRedirect();
1381 $this->assertSame(200, $client->getResponse()->getStatusCode());
1382 $this->assertContains('flashes.entry.notice.entry_saved', $crawler->filter('body')->extract(['_text'])[0]);
1385 ->getRepository('WallabagCoreBundle:Entry')
1386 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1388 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1389 $this->assertSame('Crimes et réformes aux Philippines', $content->getTitle());
1391 $client->getContainer()->get('craue_config')->set('restricted_access', 0);