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 public $downloadImagesEnabled = false;
13 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';
18 * Ensure download_images_enabled is disabled after each script
20 public function tearDownImagesEnabled()
22 if ($this->downloadImagesEnabled
) {
23 $client = static::createClient();
24 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
26 $this->downloadImagesEnabled
= false;
30 public function testLogin()
32 $client = $this->getClient();
34 $client->request('GET', '/new');
36 $this->assertSame(302, $client->getResponse()->getStatusCode());
37 $this->assertContains('login', $client->getResponse()->headers
->get('location'));
40 public function testQuickstart()
42 $this->logInAs('empty');
43 $client = $this->getClient();
45 $client->request('GET', '/unread/list');
46 $this->assertSame(302, $client->getResponse()->getStatusCode());
47 $crawler = $client->followRedirect();
49 $this->assertSame(200, $client->getResponse()->getStatusCode());
50 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
51 $this->assertContains('quickstart.intro.title', $body[0]);
53 // Test if quickstart is disabled when user has 1 entry
54 $crawler = $client->request('GET', '/new');
56 $this->assertSame(200, $client->getResponse()->getStatusCode());
58 $form = $crawler->filter('form[name=entry]')->form();
61 'entry[url]' => $this->url
,
64 $client->submit($form, $data);
65 $this->assertSame(302, $client->getResponse()->getStatusCode());
66 $client->followRedirect();
68 $crawler = $client->request('GET', '/unread/list');
69 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
70 $this->assertContains('entry.list.number_on_the_page', $body[0]);
73 public function testGetNew()
75 $this->logInAs('admin');
76 $this->useTheme('baggy');
77 $client = $this->getClient();
79 $crawler = $client->request('GET', '/new');
81 $this->assertSame(200, $client->getResponse()->getStatusCode());
83 $this->assertCount(1, $crawler->filter('input[type=url]'));
84 $this->assertCount(1, $crawler->filter('form[name=entry]'));
87 public function testPostNewViaBookmarklet()
89 $this->logInAs('admin');
90 $this->useTheme('baggy');
91 $client = $this->getClient();
93 $crawler = $client->request('GET', '/');
95 $this->assertCount(4, $crawler->filter('div[class=entry]'));
98 $client->request('GET', '/bookmarklet', ['url' => $this->url
]);
99 $this->assertSame(302, $client->getResponse()->getStatusCode());
100 $client->followRedirect();
101 $crawler = $client->request('GET', '/');
102 $this->assertCount(5, $crawler->filter('div[class=entry]'));
104 $em = $client->getContainer()
105 ->get('doctrine.orm.entity_manager');
107 ->getRepository('WallabagCoreBundle:Entry')
108 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
113 public function testPostNewEmpty()
115 $this->logInAs('admin');
116 $client = $this->getClient();
118 $crawler = $client->request('GET', '/new');
120 $this->assertSame(200, $client->getResponse()->getStatusCode());
122 $form = $crawler->filter('form[name=entry]')->form();
124 $crawler = $client->submit($form);
126 $this->assertSame(200, $client->getResponse()->getStatusCode());
127 $this->assertCount(1, $alert = $crawler->filter('form ul li')->extract(['_text']));
128 $this->assertSame('This value should not be blank.', $alert[0]);
132 * This test will require an internet connection.
134 public function testPostNewOk()
136 $this->logInAs('admin');
137 $client = $this->getClient();
139 $crawler = $client->request('GET', '/new');
141 $this->assertSame(200, $client->getResponse()->getStatusCode());
143 $form = $crawler->filter('form[name=entry]')->form();
146 'entry[url]' => $this->url
,
149 $client->submit($form, $data);
151 $this->assertSame(302, $client->getResponse()->getStatusCode());
153 $content = $client->getContainer()
154 ->get('doctrine.orm.entity_manager')
155 ->getRepository('WallabagCoreBundle:Entry')
156 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
158 $author = $content->getPublishedBy();
160 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
161 $this->assertSame($this->url
, $content->getUrl());
162 $this->assertContains('Google', $content->getTitle());
163 $this->assertSame('fr', $content->getLanguage());
164 $this->assertSame('2015-03-28 15:37:39', $content->getPublishedAt()->format('Y-m-d H:i:s'));
165 $this->assertSame('Morgane Tual', $author[0]);
166 $this->assertArrayHasKey('x-varnish1', $content->getHeaders());
169 public function testPostWithMultipleAuthors()
171 $url = 'http://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768';
172 $this->logInAs('admin');
173 $client = $this->getClient();
175 $crawler = $client->request('GET', '/new');
177 $this->assertSame(200, $client->getResponse()->getStatusCode());
179 $form = $crawler->filter('form[name=entry]')->form();
182 'entry[url]' => $url,
185 $client->submit($form, $data);
187 $this->assertSame(302, $client->getResponse()->getStatusCode());
189 $content = $client->getContainer()
190 ->get('doctrine.orm.entity_manager')
191 ->getRepository('WallabagCoreBundle:Entry')
192 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
194 $authors = $content->getPublishedBy();
195 $this->assertSame('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s'));
196 $this->assertSame('fr', $content->getLanguage());
197 $this->assertSame('Raphaël Balenieri, correspondant à Pékin', $authors[0]);
198 $this->assertSame('Frédéric Autran, correspondant à New York', $authors[1]);
201 public function testPostNewOkUrlExist()
203 $this->logInAs('admin');
205 $entry = new Entry($this->getLoggedInUser());
206 $entry->setUrl($this->url
);
207 $this->getEntityManager()->persist($entry);
208 $this->getEntityManager()->flush();
210 $client = $this->getClient();
212 $crawler = $client->request('GET', '/new');
214 $this->assertSame(200, $client->getResponse()->getStatusCode());
216 $form = $crawler->filter('form[name=entry]')->form();
219 'entry[url]' => $this->url
,
222 $client->submit($form, $data);
224 $this->assertSame(302, $client->getResponse()->getStatusCode());
225 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
228 public function testPostNewOkUrlExistWithAccent()
230 $this->logInAs('admin');
231 $client = $this->getClient();
233 $url = 'http://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing';
235 $crawler = $client->request('GET', '/new');
237 $this->assertSame(200, $client->getResponse()->getStatusCode());
239 $form = $crawler->filter('form[name=entry]')->form();
242 'entry[url]' => $url,
245 $client->submit($form, $data);
247 $crawler = $client->request('GET', '/new');
249 $this->assertSame(200, $client->getResponse()->getStatusCode());
251 $form = $crawler->filter('form[name=entry]')->form();
254 'entry[url]' => $url,
257 $client->submit($form, $data);
259 $this->assertSame(302, $client->getResponse()->getStatusCode());
260 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
264 * This test will require an internet connection.
266 public function testPostNewThatWillBeTagged()
268 $this->logInAs('admin');
269 $client = $this->getClient();
271 $crawler = $client->request('GET', '/new');
273 $this->assertSame(200, $client->getResponse()->getStatusCode());
275 $form = $crawler->filter('form[name=entry]')->form();
278 'entry[url]' => $url = 'https://github.com/wallabag/wallabag',
281 $client->submit($form, $data);
283 $this->assertSame(302, $client->getResponse()->getStatusCode());
284 $this->assertContains('/', $client->getResponse()->getTargetUrl());
286 $em = $client->getContainer()
287 ->get('doctrine.orm.entity_manager');
289 ->getRepository('WallabagCoreBundle:Entry')
290 ->findOneByUrl($url);
291 $tags = $entry->getTags();
293 $this->assertCount(2, $tags);
294 $this->assertContains('wallabag', $tags);
295 $this->assertSame('en', $entry->getLanguage());
300 // and now re-submit it to test the cascade persistence for tags after entry removal
301 // related https://github.com/wallabag/wallabag/issues/2121
302 $crawler = $client->request('GET', '/new');
304 $this->assertSame(200, $client->getResponse()->getStatusCode());
306 $form = $crawler->filter('form[name=entry]')->form();
309 'entry[url]' => $url = 'https://github.com/wallabag/wallabag/tree/master',
312 $client->submit($form, $data);
314 $this->assertSame(302, $client->getResponse()->getStatusCode());
315 $this->assertContains('/', $client->getResponse()->getTargetUrl());
318 ->getRepository('WallabagCoreBundle:Entry')
319 ->findOneByUrl($url);
321 $tags = $entry->getTags();
323 $this->assertCount(2, $tags);
324 $this->assertContains('wallabag', $tags);
330 public function testArchive()
332 $this->logInAs('admin');
333 $client = $this->getClient();
335 $client->request('GET', '/archive/list');
337 $this->assertSame(200, $client->getResponse()->getStatusCode());
340 public function testUntagged()
342 $this->logInAs('admin');
343 $client = $this->getClient();
345 $client->request('GET', '/untagged/list');
347 $this->assertSame(200, $client->getResponse()->getStatusCode());
350 public function testStarred()
352 $this->logInAs('admin');
353 $client = $this->getClient();
355 $client->request('GET', '/starred/list');
357 $this->assertSame(200, $client->getResponse()->getStatusCode());
360 public function testRangeException()
362 $this->logInAs('admin');
363 $client = $this->getClient();
365 $client->request('GET', '/all/list/900');
367 $this->assertSame(302, $client->getResponse()->getStatusCode());
368 $this->assertSame('/all/list', $client->getResponse()->getTargetUrl());
371 public function testView()
373 $this->logInAs('admin');
374 $client = $this->getClient();
376 $entry = new Entry($this->getLoggedInUser());
377 $entry->setUrl('http://example.com/foo');
378 $entry->setTitle('title foo');
379 $entry->setContent('foo bar baz');
380 $this->getEntityManager()->persist($entry);
381 $this->getEntityManager()->flush();
383 $crawler = $client->request('GET', '/view/' . $entry->getId());
385 $this->assertSame(200, $client->getResponse()->getStatusCode());
386 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
387 $this->assertContains($entry->getTitle(), $body[0]);
391 * This test will require an internet connection.
393 public function testReload()
395 $this->logInAs('admin');
396 $client = $this->getClient();
398 $entry = new Entry($this->getLoggedInUser());
399 $entry->setUrl($this->url
);
400 $entry->setTitle('title foo');
401 $entry->setContent('');
402 $this->getEntityManager()->persist($entry);
403 $this->getEntityManager()->flush();
404 $this->getEntityManager()->clear();
406 $client->request('GET', '/reload/' . $entry->getId());
408 $this->assertSame(302, $client->getResponse()->getStatusCode());
410 $entry = $this->getEntityManager()
411 ->getRepository('WallabagCoreBundle:Entry')
412 ->find($entry->getId());
414 $this->assertNotEmpty($entry->getContent());
417 public function testReloadWithFetchingFailed()
419 $this->logInAs('admin');
420 $client = $this->getClient();
422 $entry = new Entry($this->getLoggedInUser());
423 $entry->setUrl('http://0.0.0.0/failed.html');
424 $this->getEntityManager()->persist($entry);
425 $this->getEntityManager()->flush();
427 $client->request('GET', '/reload/' . $entry->getId());
429 $this->assertSame(302, $client->getResponse()->getStatusCode());
431 // force EntityManager to clear previous entity
432 // otherwise, retrieve the same entity will retrieve change from the previous request :0
433 $this->getEntityManager()->clear();
434 $newContent = $this->getEntityManager()
435 ->getRepository('WallabagCoreBundle:Entry')
436 ->find($entry->getId());
438 $this->assertNotSame($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent());
441 public function testEdit()
443 $this->logInAs('admin');
444 $client = $this->getClient();
446 $entry = new Entry($this->getLoggedInUser());
447 $entry->setUrl($this->url
);
448 $this->getEntityManager()->persist($entry);
449 $this->getEntityManager()->flush();
451 $crawler = $client->request('GET', '/edit/' . $entry->getId());
453 $this->assertSame(200, $client->getResponse()->getStatusCode());
455 $this->assertCount(1, $crawler->filter('input[id=entry_title]'));
456 $this->assertCount(1, $crawler->filter('button[id=entry_save]'));
459 public function testEditUpdate()
461 $this->logInAs('admin');
462 $client = $this->getClient();
464 $entry = new Entry($this->getLoggedInUser());
465 $entry->setUrl($this->url
);
466 $this->getEntityManager()->persist($entry);
467 $this->getEntityManager()->flush();
469 $crawler = $client->request('GET', '/edit/' . $entry->getId());
471 $this->assertSame(200, $client->getResponse()->getStatusCode());
473 $form = $crawler->filter('button[type=submit]')->form();
476 'entry[title]' => 'My updated title hehe :)',
479 $client->submit($form, $data);
481 $this->assertSame(302, $client->getResponse()->getStatusCode());
483 $crawler = $client->followRedirect();
485 $this->assertGreaterThan(1, $alert = $crawler->filter('div[id=article] h1')->extract(['_text']));
486 $this->assertContains('My updated title hehe :)', $alert[0]);
489 public function testToggleArchive()
491 $this->logInAs('admin');
492 $client = $this->getClient();
494 $entry = new Entry($this->getLoggedInUser());
495 $entry->setUrl($this->url
);
496 $this->getEntityManager()->persist($entry);
497 $this->getEntityManager()->flush();
498 $this->getEntityManager()->clear();
500 $client->request('GET', '/archive/' . $entry->getId());
502 $this->assertSame(302, $client->getResponse()->getStatusCode());
504 $res = $client->getContainer()
505 ->get('doctrine.orm.entity_manager')
506 ->getRepository('WallabagCoreBundle:Entry')
507 ->find($entry->getId());
509 $this->assertSame(1, $res->isArchived());
512 public function testToggleStar()
514 $this->logInAs('admin');
515 $client = $this->getClient();
517 $entry = new Entry($this->getLoggedInUser());
518 $entry->setUrl($this->url
);
519 $this->getEntityManager()->persist($entry);
520 $this->getEntityManager()->flush();
521 $this->getEntityManager()->clear();
523 $client->request('GET', '/star/' . $entry->getId());
525 $this->assertSame(302, $client->getResponse()->getStatusCode());
527 $res = $client->getContainer()
528 ->get('doctrine.orm.entity_manager')
529 ->getRepository('WallabagCoreBundle:Entry')
530 ->findOneById($entry->getId());
532 $this->assertSame(1, $res->isStarred());
535 public function testDelete()
537 $this->logInAs('admin');
538 $client = $this->getClient();
540 $entry = new Entry($this->getLoggedInUser());
541 $entry->setUrl($this->url
);
542 $this->getEntityManager()->persist($entry);
543 $this->getEntityManager()->flush();
545 $client->request('GET', '/delete/' . $entry->getId());
547 $this->assertSame(302, $client->getResponse()->getStatusCode());
549 $client->request('GET', '/delete/' . $entry->getId());
551 $this->assertSame(404, $client->getResponse()->getStatusCode());
555 * It will create a new entry.
559 * And it'll check that user won't be redirected to the view page of the content when it had been removed
561 public function testViewAndDelete()
563 $this->logInAs('admin');
564 $client = $this->getClient();
566 $em = $client->getContainer()
567 ->get('doctrine.orm.entity_manager');
569 // add a new content to be removed later
571 ->getRepository('WallabagUserBundle:User')
572 ->findOneByUserName('admin');
574 $content = new Entry($user);
575 $content->setUrl('http://1.1.1.1/entry');
576 $content->setReadingTime(12);
577 $content->setDomainName('domain.io');
578 $content->setMimetype('text/html');
579 $content->setTitle('test title entry');
580 $content->setContent('This is my content /o/');
581 $content->setArchived(true);
582 $content->setLanguage('fr');
584 $em->persist($content);
587 $client->request('GET', '/view/' . $content->getId());
588 $this->assertSame(200, $client->getResponse()->getStatusCode());
590 $client->request('GET', '/delete/' . $content->getId());
591 $this->assertSame(302, $client->getResponse()->getStatusCode());
593 $client->followRedirect();
594 $this->assertSame(200, $client->getResponse()->getStatusCode());
597 public function testViewOtherUserEntry()
599 $this->logInAs('admin');
600 $client = $this->getClient();
602 $content = $client->getContainer()
603 ->get('doctrine.orm.entity_manager')
604 ->getRepository('WallabagCoreBundle:Entry')
605 ->findOneByUsernameAndNotArchived('bob');
607 $client->request('GET', '/view/' . $content->getId());
609 $this->assertSame(403, $client->getResponse()->getStatusCode());
612 public function testFilterOnReadingTime()
614 $this->logInAs('admin');
615 $this->useTheme('baggy');
616 $client = $this->getClient();
617 $entry = new Entry($this->getLoggedInUser());
618 $entry->setUrl($this->url
);
619 $entry->setReadingTime(22);
620 $this->getEntityManager()->persist($entry);
621 $this->getEntityManager()->flush();
623 $crawler = $client->request('GET', '/unread/list');
625 $form = $crawler->filter('button[id=submit-filter]')->form();
628 'entry_filter[readingTime][right_number]' => 22,
629 'entry_filter[readingTime][left_number]' => 22,
632 $crawler = $client->submit($form, $data);
634 $this->assertCount(1, $crawler->filter('div[class=entry]'));
637 public function testFilterOnReadingTimeWithNegativeValue()
639 $this->logInAs('admin');
640 $client = $this->getClient();
642 $crawler = $client->request('GET', '/unread/list');
644 $form = $crawler->filter('button[id=submit-filter]')->form();
647 'entry_filter[readingTime][right_number]' => -22,
648 'entry_filter[readingTime][left_number]' => -22,
651 $crawler = $client->submit($form, $data);
653 // forcing negative value results in no entry displayed
654 $this->assertCount(0, $crawler->filter('div[class=entry]'));
657 public function testFilterOnReadingTimeOnlyUpper()
659 $this->logInAs('admin');
660 $this->useTheme('baggy');
661 $client = $this->getClient();
663 $crawler = $client->request('GET', '/all/list');
664 $this->assertCount(5, $crawler->filter('div[class=entry]'));
666 $entry = new Entry($this->getLoggedInUser());
667 $entry->setUrl($this->url
);
668 $entry->setReadingTime(23);
669 $this->getEntityManager()->persist($entry);
670 $this->getEntityManager()->flush();
672 $crawler = $client->request('GET', '/all/list');
673 $this->assertCount(6, $crawler->filter('div[class=entry]'));
675 $form = $crawler->filter('button[id=submit-filter]')->form();
678 'entry_filter[readingTime][right_number]' => 22,
681 $crawler = $client->submit($form, $data);
683 $this->assertCount(5, $crawler->filter('div[class=entry]'));
686 public function testFilterOnReadingTimeOnlyLower()
688 $this->logInAs('admin');
689 $this->useTheme('baggy');
690 $client = $this->getClient();
692 $crawler = $client->request('GET', '/unread/list');
694 $form = $crawler->filter('button[id=submit-filter]')->form();
697 'entry_filter[readingTime][left_number]' => 22,
700 $crawler = $client->submit($form, $data);
702 $this->assertCount(0, $crawler->filter('div[class=entry]'));
704 $entry = new Entry($this->getLoggedInUser());
705 $entry->setUrl($this->url
);
706 $entry->setReadingTime(23);
707 $this->getEntityManager()->persist($entry);
708 $this->getEntityManager()->flush();
710 $crawler = $client->submit($form, $data);
711 $this->assertCount(1, $crawler->filter('div[class=entry]'));
714 public function testFilterOnUnreadStatus()
716 $this->logInAs('admin');
717 $this->useTheme('baggy');
718 $client = $this->getClient();
720 $crawler = $client->request('GET', '/all/list');
722 $form = $crawler->filter('button[id=submit-filter]')->form();
725 'entry_filter[isUnread]' => true,
728 $crawler = $client->submit($form, $data);
730 $this->assertCount(4, $crawler->filter('div[class=entry]'));
732 $entry = new Entry($this->getLoggedInUser());
733 $entry->setUrl($this->url
);
734 $entry->setArchived(false);
735 $this->getEntityManager()->persist($entry);
736 $this->getEntityManager()->flush();
738 $crawler = $client->submit($form, $data);
740 $this->assertCount(5, $crawler->filter('div[class=entry]'));
743 public function testFilterOnCreationDate()
745 $this->logInAs('admin');
746 $this->useTheme('baggy');
747 $client = $this->getClient();
749 $crawler = $client->request('GET', '/unread/list');
751 $form = $crawler->filter('button[id=submit-filter]')->form();
754 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
755 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')),
758 $crawler = $client->submit($form, $data);
760 $this->assertCount(5, $crawler->filter('div[class=entry]'));
763 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
764 'entry_filter[createdAt][right_date]' => date('d/m/Y'),
767 $crawler = $client->submit($form, $data);
769 $this->assertCount(5, $crawler->filter('div[class=entry]'));
772 'entry_filter[createdAt][left_date]' => '01/01/1970',
773 'entry_filter[createdAt][right_date]' => '01/01/1970',
776 $crawler = $client->submit($form, $data);
778 $this->assertCount(0, $crawler->filter('div[class=entry]'));
781 public function testPaginationWithFilter()
783 $this->logInAs('admin');
784 $client = $this->getClient();
785 $crawler = $client->request('GET', '/config');
787 $form = $crawler->filter('button[id=config_save]')->form();
790 'config[items_per_page]' => '1',
793 $client->submit($form, $data);
795 $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D=';
797 $client->request('GET', 'unread/list' . $parameters);
799 $this->assertContains($parameters, $client->getResponse()->getContent());
802 $crawler = $client->request('GET', '/config');
803 $form = $crawler->filter('button[id=config_save]')->form();
805 'config[items_per_page]' => '12',
807 $client->submit($form, $data);
810 public function testFilterOnDomainName()
812 $this->logInAs('admin');
813 $this->useTheme('baggy');
814 $client = $this->getClient();
816 $crawler = $client->request('GET', '/unread/list');
817 $form = $crawler->filter('button[id=submit-filter]')->form();
819 'entry_filter[domainName]' => 'domain',
822 $crawler = $client->submit($form, $data);
823 $this->assertCount(5, $crawler->filter('div[class=entry]'));
825 $crawler = $client->request('GET', '/unread/list');
826 $form = $crawler->filter('button[id=submit-filter]')->form();
828 'entry_filter[domainName]' => 'dOmain',
831 $crawler = $client->submit($form, $data);
832 $this->assertCount(5, $crawler->filter('div[class=entry]'));
834 $form = $crawler->filter('button[id=submit-filter]')->form();
836 'entry_filter[domainName]' => 'wallabag',
839 $crawler = $client->submit($form, $data);
840 $this->assertCount(0, $crawler->filter('div[class=entry]'));
843 public function testFilterOnStatus()
845 $this->logInAs('admin');
846 $this->useTheme('baggy');
847 $client = $this->getClient();
849 $crawler = $client->request('GET', '/unread/list');
850 $form = $crawler->filter('button[id=submit-filter]')->form();
851 $form['entry_filter[isArchived]']->tick();
852 $form['entry_filter[isStarred]']->untick();
854 $crawler = $client->submit($form);
855 $this->assertCount(1, $crawler->filter('div[class=entry]'));
857 $form = $crawler->filter('button[id=submit-filter]')->form();
858 $form['entry_filter[isArchived]']->untick();
859 $form['entry_filter[isStarred]']->tick();
861 $crawler = $client->submit($form);
862 $this->assertCount(1, $crawler->filter('div[class=entry]'));
865 public function testFilterOnIsPublic()
867 $this->logInAs('admin');
868 $this->useTheme('baggy');
869 $client = $this->getClient();
871 $crawler = $client->request('GET', '/unread/list');
872 $form = $crawler->filter('button[id=submit-filter]')->form();
873 $form['entry_filter[isPublic]']->tick();
875 $crawler = $client->submit($form);
876 $this->assertCount(0, $crawler->filter('div[class=entry]'));
879 public function testPreviewPictureFilter()
881 $this->logInAs('admin');
882 $this->useTheme('baggy');
883 $client = $this->getClient();
885 $crawler = $client->request('GET', '/unread/list');
886 $form = $crawler->filter('button[id=submit-filter]')->form();
887 $form['entry_filter[previewPicture]']->tick();
889 $crawler = $client->submit($form);
890 $this->assertCount(1, $crawler->filter('div[class=entry]'));
893 public function testFilterOnLanguage()
895 $this->logInAs('admin');
896 $this->useTheme('baggy');
897 $client = $this->getClient();
899 $entry = new Entry($this->getLoggedInUser());
900 $entry->setUrl($this->url
);
901 $entry->setLanguage('fr');
902 $this->getEntityManager()->persist($entry);
903 $this->getEntityManager()->flush();
905 $crawler = $client->request('GET', '/unread/list');
906 $form = $crawler->filter('button[id=submit-filter]')->form();
908 'entry_filter[language]' => 'fr',
911 $crawler = $client->submit($form, $data);
912 $this->assertCount(3, $crawler->filter('div[class=entry]'));
914 $form = $crawler->filter('button[id=submit-filter]')->form();
916 'entry_filter[language]' => 'en',
919 $crawler = $client->submit($form, $data);
920 $this->assertCount(2, $crawler->filter('div[class=entry]'));
923 public function testShareEntryPublicly()
925 $this->logInAs('admin');
926 $client = $this->getClient();
928 // sharing is enabled
929 $client->getContainer()->get('craue_config')->set('share_public', 1);
931 $content = new Entry($this->getLoggedInUser());
932 $content->setUrl($this->url
);
933 $this->getEntityManager()->persist($content);
934 $this->getEntityManager()->flush();
935 $this->getEntityManager()->clear();
938 $client->request('GET', '/share/' . $content->getUid());
939 $this->assertSame(404, $client->getResponse()->getStatusCode());
941 // generating the uid
942 $client->request('GET', '/share/' . $content->getId());
943 $this->assertSame(302, $client->getResponse()->getStatusCode());
945 // follow link with uid
946 $crawler = $client->followRedirect();
947 $this->assertSame(200, $client->getResponse()->getStatusCode());
948 $this->assertContains('max-age=25200', $client->getResponse()->headers
->get('cache-control'));
949 $this->assertContains('public', $client->getResponse()->headers
->get('cache-control'));
950 $this->assertContains('s-maxage=25200', $client->getResponse()->headers
->get('cache-control'));
951 $this->assertNotContains('no-cache', $client->getResponse()->headers
->get('cache-control'));
952 $this->assertContains('og:title', $client->getResponse()->getContent());
953 $this->assertContains('og:type', $client->getResponse()->getContent());
954 $this->assertContains('og:url', $client->getResponse()->getContent());
955 $this->assertContains('og:image', $client->getResponse()->getContent());
957 // sharing is now disabled
958 $client->getContainer()->get('craue_config')->set('share_public', 0);
959 $client->request('GET', '/share/' . $content->getUid());
960 $this->assertSame(404, $client->getResponse()->getStatusCode());
962 $client->request('GET', '/view/' . $content->getId());
963 $this->assertContains('no-cache', $client->getResponse()->headers
->get('cache-control'));
965 // removing the share
966 $client->request('GET', '/share/delete/' . $content->getId());
967 $this->assertSame(302, $client->getResponse()->getStatusCode());
969 // share is now disable
970 $client->request('GET', '/share/' . $content->getUid());
971 $this->assertSame(404, $client->getResponse()->getStatusCode());
974 public function testNewEntryWithDownloadImagesEnabled()
976 $this->downloadImagesEnabled
= true;
977 $this->logInAs('admin');
978 $client = $this->getClient();
980 $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route';
981 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
983 $crawler = $client->request('GET', '/new');
985 $this->assertSame(200, $client->getResponse()->getStatusCode());
987 $form = $crawler->filter('form[name=entry]')->form();
990 'entry[url]' => $url,
993 $client->submit($form, $data);
995 $this->assertSame(302, $client->getResponse()->getStatusCode());
997 $em = $client->getContainer()
998 ->get('doctrine.orm.entity_manager');
1001 ->getRepository('WallabagCoreBundle:Entry')
1002 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1004 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry);
1005 $this->assertSame($url, $entry->getUrl());
1006 $this->assertContains('Perpignan', $entry->getTitle());
1007 // instead of checking for the filename (which might change) check that the image is now local
1008 $this->assertContains($client->getContainer()->getParameter('domain_name') . '/assets/images/', $entry->getContent());
1010 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1014 * @depends testNewEntryWithDownloadImagesEnabled
1016 public function testRemoveEntryWithDownloadImagesEnabled()
1018 $this->downloadImagesEnabled
= true;
1019 $this->logInAs('admin');
1020 $client = $this->getClient();
1022 $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route';
1023 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
1025 $crawler = $client->request('GET', '/new');
1027 $this->assertSame(200, $client->getResponse()->getStatusCode());
1029 $form = $crawler->filter('form[name=entry]')->form();
1032 'entry[url]' => $url,
1035 $client->submit($form, $data);
1037 $this->assertSame(302, $client->getResponse()->getStatusCode());
1039 $content = $client->getContainer()
1040 ->get('doctrine.orm.entity_manager')
1041 ->getRepository('WallabagCoreBundle:Entry')
1042 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1044 $client->request('GET', '/delete/' . $content->getId());
1046 $this->assertSame(302, $client->getResponse()->getStatusCode());
1048 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1051 public function testRedirectToHomepage()
1053 $this->logInAs('empty');
1054 $client = $this->getClient();
1056 // Redirect to homepage
1057 $config = $this->getLoggedInUser()->getConfig();
1058 $config->setActionMarkAsRead(Config
::REDIRECT_TO_HOMEPAGE
);
1059 $this->getEntityManager()->persist($config);
1061 $entry = new Entry($this->getLoggedInUser());
1062 $entry->setUrl($this->url
);
1063 $this->getEntityManager()->persist($entry);
1065 $this->getEntityManager()->flush();
1067 $client->request('GET', '/view/' . $entry->getId());
1068 $client->request('GET', '/archive/' . $entry->getId());
1070 $this->assertSame(302, $client->getResponse()->getStatusCode());
1071 $this->assertSame('/', $client->getResponse()->headers
->get('location'));
1074 public function testRedirectToCurrentPage()
1076 $this->logInAs('empty');
1077 $client = $this->getClient();
1079 // Redirect to current page
1080 $config = $this->getLoggedInUser()->getConfig();
1081 $config->setActionMarkAsRead(Config
::REDIRECT_TO_CURRENT_PAGE
);
1082 $this->getEntityManager()->persist($config);
1084 $entry = new Entry($this->getLoggedInUser());
1085 $entry->setUrl($this->url
);
1086 $this->getEntityManager()->persist($entry);
1088 $this->getEntityManager()->flush();
1090 $client->request('GET', '/view/' . $entry->getId());
1091 $client->request('GET', '/archive/' . $entry->getId());
1093 $this->assertSame(302, $client->getResponse()->getStatusCode());
1094 $this->assertContains('/view/' . $entry->getId(), $client->getResponse()->headers
->get('location'));
1097 public function testFilterOnHttpStatus()
1099 $this->logInAs('admin');
1100 $this->useTheme('baggy');
1101 $client = $this->getClient();
1103 $entry = new Entry($this->getLoggedInUser());
1104 $entry->setUrl('http://www.lemonde.fr/incorrect-url/');
1105 $entry->setHttpStatus(404);
1106 $this->getEntityManager()->persist($entry);
1108 $this->getEntityManager()->flush();
1110 $crawler = $client->request('GET', '/all/list');
1111 $form = $crawler->filter('button[id=submit-filter]')->form();
1114 'entry_filter[httpStatus]' => 404,
1117 $crawler = $client->submit($form, $data);
1119 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1121 $entry = new Entry($this->getLoggedInUser());
1122 $entry->setUrl($this->url
);
1123 $entry->setHttpStatus(200);
1124 $this->getEntityManager()->persist($entry);
1126 $entry = new Entry($this->getLoggedInUser());
1127 $entry->setUrl('http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm');
1128 $entry->setHttpStatus(200);
1129 $this->getEntityManager()->persist($entry);
1131 $this->getEntityManager()->flush();
1133 $crawler = $client->request('GET', '/all/list');
1134 $form = $crawler->filter('button[id=submit-filter]')->form();
1137 'entry_filter[httpStatus]' => 200,
1140 $crawler = $client->submit($form, $data);
1142 $this->assertCount(2, $crawler->filter('div[class=entry]'));
1144 $crawler = $client->request('GET', '/all/list');
1145 $form = $crawler->filter('button[id=submit-filter]')->form();
1148 'entry_filter[httpStatus]' => 1024,
1151 $crawler = $client->submit($form, $data);
1153 $this->assertCount(8, $crawler->filter('div[class=entry]'));
1156 public function testSearch()
1158 $this->logInAs('admin');
1159 $this->useTheme('baggy');
1160 $client = $this->getClient();
1162 $entry = new Entry($this->getLoggedInUser());
1163 $entry->setUrl($this->url
);
1164 $entry->setTitle('test');
1165 $this->getEntityManager()->persist($entry);
1166 $this->getEntityManager()->flush();
1168 // Search on unread list
1169 $crawler = $client->request('GET', '/unread/list');
1171 $form = $crawler->filter('form[name=search]')->form();
1173 'search_entry[term]' => 'title',
1176 $crawler = $client->submit($form, $data);
1178 $this->assertCount(4, $crawler->filter('div[class=entry]'));
1180 // Search on starred list
1181 $crawler = $client->request('GET', '/starred/list');
1183 $entry = new Entry($this->getLoggedInUser());
1184 $entry->setUrl('http://localhost/foo/bar');
1185 $entry->setTitle('testeur');
1186 $entry->setStarred(true);
1187 $this->getEntityManager()->persist($entry);
1188 $this->getEntityManager()->flush();
1190 $form = $crawler->filter('form[name=search]')->form();
1192 'search_entry[term]' => 'testeur',
1195 $crawler = $client->submit($form, $data);
1197 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1199 $crawler = $client->request('GET', '/archive/list');
1201 // Added new article to test on archive list
1202 $entry = new Entry($this->getLoggedInUser());
1203 $entry->setUrl('http://0.0.0.0/foo/baz/qux');
1204 $entry->setTitle('Le manège');
1205 $entry->setArchived(true);
1206 $this->getEntityManager()->persist($entry);
1207 $this->getEntityManager()->flush();
1209 $form = $crawler->filter('form[name=search]')->form();
1211 'search_entry[term]' => 'manège',
1214 $crawler = $client->submit($form, $data);
1216 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1217 $client->request('GET', '/delete/' . $entry->getId());
1219 // test on list of all articles
1220 $crawler = $client->request('GET', '/all/list');
1222 $form = $crawler->filter('form[name=search]')->form();
1224 'search_entry[term]' => 'wxcvbnqsdf', // a string not available in the database
1227 $crawler = $client->submit($form, $data);
1229 $this->assertCount(0, $crawler->filter('div[class=entry]'));
1231 // test url search on list of all articles
1232 $entry = new Entry($this->getLoggedInUser());
1233 $entry->setUrl('http://domain/qux');
1234 $entry->setTitle('Le manège');
1235 $entry->setArchived(true);
1236 $this->getEntityManager()->persist($entry);
1237 $this->getEntityManager()->flush();
1239 $crawler = $client->request('GET', '/all/list');
1241 $form = $crawler->filter('form[name=search]')->form();
1243 'search_entry[term]' => 'domain', // the search will match an entry with 'domain' in its url
1246 $crawler = $client->submit($form, $data);
1248 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1250 // same as previous test but for case-sensitivity
1251 $crawler = $client->request('GET', '/all/list');
1253 $form = $crawler->filter('form[name=search]')->form();
1255 'search_entry[term]' => 'doMain', // the search will match an entry with 'domain' in its url
1258 $crawler = $client->submit($form, $data);
1260 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1263 public function dataForLanguage()
1267 'https://www.pravda.ru/world/09-06-2017/1337283-qatar-0/',
1271 'https://www.zataz.com/90-des-dossiers-medicaux-des-coreens-du-sud-vendus-a-des-entreprises-privees/',
1275 'http://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html',
1279 'http://www.ansa.it/sito/notizie/mondo/europa/2017/06/08/voto-gb-seggi-aperti-misure-sicurezza-rafforzate_0cb71f7f-e23b-4d5f-95ca-bc12296419f0.html',
1283 'http://www.hao123.com/shequ?__noscript__-=1',
1287 'https://buy.garmin.com/de-AT/AT/catalog/product/compareResult.ep?compareProduct=112885&compareProduct=36728',
1291 'http://netler.ru/ikt/windows-error-reporting.htm',
1295 'http://precodoscombustiveis.com.br/postos/cidade/4121/pr/maringa',
1298 'fucked_list_of_languages' => [
1299 'http://geocatalog.webservice-energy.org/geonetwork/srv/eng/main.home',
1303 'https://www.muylinux.com/2015/04/17/odf-reino-unido-microsoft-google/',
1310 * @dataProvider dataForLanguage
1312 public function testLanguageValidation($url, $expectedLanguage)
1314 $this->logInAs('admin');
1315 $client = $this->getClient();
1317 $crawler = $client->request('GET', '/new');
1319 $this->assertSame(200, $client->getResponse()->getStatusCode());
1321 $form = $crawler->filter('form[name=entry]')->form();
1324 'entry[url]' => $url,
1327 $client->submit($form, $data);
1329 $this->assertSame(302, $client->getResponse()->getStatusCode());
1331 $content = $client->getContainer()
1332 ->get('doctrine.orm.entity_manager')
1333 ->getRepository('WallabagCoreBundle:Entry')
1334 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1336 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1337 $this->assertSame($url, $content->getUrl());
1338 $this->assertSame($expectedLanguage, $content->getLanguage());
1342 * This test will require an internet connection.
1344 public function testRestrictedArticle()
1346 $url = 'https://www.monde-diplomatique.fr/2017/05/BONNET/57475';
1347 $this->logInAs('admin');
1348 $client = $this->getClient();
1349 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
1351 // enable restricted access
1352 $client->getContainer()->get('craue_config')->set('restricted_access', 1);
1354 // create a new site_credential
1355 $user = $client->getContainer()->get('security.token_storage')->getToken()->getUser();
1356 $credential = new SiteCredential($user);
1357 $credential->setHost('monde-diplomatique.fr');
1358 $credential->setUsername($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('foo'));
1359 $credential->setPassword($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('bar'));
1361 $em->persist($credential);
1364 $crawler = $client->request('GET', '/new');
1366 $this->assertSame(200, $client->getResponse()->getStatusCode());
1368 $form = $crawler->filter('form[name=entry]')->form();
1371 'entry[url]' => $url,
1374 $client->submit($form, $data);
1376 $this->assertSame(302, $client->getResponse()->getStatusCode());
1378 $crawler = $client->followRedirect();
1380 $this->assertSame(200, $client->getResponse()->getStatusCode());
1381 $this->assertContains('flashes.entry.notice.entry_saved', $crawler->filter('body')->extract(['_text'])[0]);
1384 ->getRepository('WallabagCoreBundle:Entry')
1385 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1387 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1388 $this->assertSame('Crimes et réformes aux Philippines', $content->getTitle());
1390 $client->getContainer()->get('craue_config')->set('restricted_access', 0);