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->assertEquals(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 $crawler = $client->followRedirect();
48 $this->assertEquals(200, $client->getResponse()->getStatusCode());
49 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
50 $this->assertContains('quickstart.intro.title', $body[0]);
52 // Test if quickstart is disabled when user has 1 entry
53 $crawler = $client->request('GET', '/new');
55 $this->assertEquals(200, $client->getResponse()->getStatusCode());
57 $form = $crawler->filter('form[name=entry]')->form();
60 'entry[url]' => $this->url
,
63 $client->submit($form, $data);
64 $this->assertEquals(302, $client->getResponse()->getStatusCode());
65 $client->followRedirect();
67 $crawler = $client->request('GET', '/unread/list');
68 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
69 $this->assertContains('entry.list.number_on_the_page', $body[0]);
72 public function testGetNew()
74 $this->logInAs('admin');
75 $this->useTheme('baggy');
76 $client = $this->getClient();
78 $crawler = $client->request('GET', '/new');
80 $this->assertEquals(200, $client->getResponse()->getStatusCode());
82 $this->assertCount(1, $crawler->filter('input[type=url]'));
83 $this->assertCount(1, $crawler->filter('form[name=entry]'));
86 public function testPostNewViaBookmarklet()
88 $this->logInAs('admin');
89 $this->useTheme('baggy');
90 $client = $this->getClient();
92 $crawler = $client->request('GET', '/');
94 $this->assertCount(4, $crawler->filter('div[class=entry]'));
97 $client->request('GET', '/bookmarklet', ['url' => $this->url
]);
98 $this->assertEquals(302, $client->getResponse()->getStatusCode());
99 $client->followRedirect();
100 $crawler = $client->request('GET', '/');
101 $this->assertCount(5, $crawler->filter('div[class=entry]'));
103 $em = $client->getContainer()
104 ->get('doctrine.orm.entity_manager');
106 ->getRepository('WallabagCoreBundle:Entry')
107 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
112 public function testPostNewEmpty()
114 $this->logInAs('admin');
115 $client = $this->getClient();
117 $crawler = $client->request('GET', '/new');
119 $this->assertEquals(200, $client->getResponse()->getStatusCode());
121 $form = $crawler->filter('form[name=entry]')->form();
123 $crawler = $client->submit($form);
125 $this->assertEquals(200, $client->getResponse()->getStatusCode());
126 $this->assertCount(1, $alert = $crawler->filter('form ul li')->extract(['_text']));
127 $this->assertEquals('This value should not be blank.', $alert[0]);
131 * This test will require an internet connection.
133 public function testPostNewOk()
135 $this->logInAs('admin');
136 $client = $this->getClient();
138 $crawler = $client->request('GET', '/new');
140 $this->assertEquals(200, $client->getResponse()->getStatusCode());
142 $form = $crawler->filter('form[name=entry]')->form();
145 'entry[url]' => $this->url
,
148 $client->submit($form, $data);
150 $this->assertEquals(302, $client->getResponse()->getStatusCode());
152 $content = $client->getContainer()
153 ->get('doctrine.orm.entity_manager')
154 ->getRepository('WallabagCoreBundle:Entry')
155 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
157 $author = $content->getPublishedBy();
159 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
160 $this->assertEquals($this->url
, $content->getUrl());
161 $this->assertContains('Google', $content->getTitle());
162 $this->assertEquals('fr', $content->getLanguage());
163 $this->assertEquals('2015-03-28 15:37:39', $content->getPublishedAt()->format('Y-m-d H:i:s'));
164 $this->assertEquals('Morgane Tual', $author[0]);
165 $this->assertArrayHasKey('x-varnish1', $content->getHeaders());
168 public function testPostWithMultipleAuthors()
170 $url = 'http://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768';
171 $this->logInAs('admin');
172 $client = $this->getClient();
174 $crawler = $client->request('GET', '/new');
176 $this->assertEquals(200, $client->getResponse()->getStatusCode());
178 $form = $crawler->filter('form[name=entry]')->form();
181 'entry[url]' => $url,
184 $client->submit($form, $data);
186 $this->assertEquals(302, $client->getResponse()->getStatusCode());
188 $content = $client->getContainer()
189 ->get('doctrine.orm.entity_manager')
190 ->getRepository('WallabagCoreBundle:Entry')
191 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
193 $authors = $content->getPublishedBy();
194 $this->assertEquals('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s'));
195 $this->assertEquals('fr', $content->getLanguage());
196 $this->assertEquals('Raphaël Balenieri, correspondant à Pékin', $authors[0]);
197 $this->assertEquals('Frédéric Autran, correspondant à New York', $authors[1]);
200 public function testPostNewOkUrlExist()
202 $this->logInAs('admin');
204 $entry = new Entry($this->getLoggedInUser());
205 $entry->setUrl($this->url
);
206 $this->getEntityManager()->persist($entry);
207 $this->getEntityManager()->flush();
209 $client = $this->getClient();
211 $crawler = $client->request('GET', '/new');
213 $this->assertEquals(200, $client->getResponse()->getStatusCode());
215 $form = $crawler->filter('form[name=entry]')->form();
218 'entry[url]' => $this->url
,
221 $client->submit($form, $data);
223 $this->assertEquals(302, $client->getResponse()->getStatusCode());
224 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
227 public function testPostNewOkUrlExistWithAccent()
229 $this->logInAs('admin');
230 $client = $this->getClient();
232 $url = 'http://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing';
234 $crawler = $client->request('GET', '/new');
236 $this->assertEquals(200, $client->getResponse()->getStatusCode());
238 $form = $crawler->filter('form[name=entry]')->form();
241 'entry[url]' => $url,
244 $client->submit($form, $data);
246 $crawler = $client->request('GET', '/new');
248 $this->assertEquals(200, $client->getResponse()->getStatusCode());
250 $form = $crawler->filter('form[name=entry]')->form();
253 'entry[url]' => $url,
256 $client->submit($form, $data);
258 $this->assertEquals(302, $client->getResponse()->getStatusCode());
259 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
263 * This test will require an internet connection.
265 public function testPostNewThatWillBeTagged()
267 $this->logInAs('admin');
268 $client = $this->getClient();
270 $crawler = $client->request('GET', '/new');
272 $this->assertEquals(200, $client->getResponse()->getStatusCode());
274 $form = $crawler->filter('form[name=entry]')->form();
277 'entry[url]' => $url = 'https://github.com/wallabag/wallabag',
280 $client->submit($form, $data);
282 $this->assertEquals(302, $client->getResponse()->getStatusCode());
283 $this->assertContains('/', $client->getResponse()->getTargetUrl());
285 $em = $client->getContainer()
286 ->get('doctrine.orm.entity_manager');
288 ->getRepository('WallabagCoreBundle:Entry')
289 ->findOneByUrl($url);
290 $tags = $entry->getTags();
292 $this->assertCount(2, $tags);
293 $this->assertContains('wallabag', $tags);
294 $this->assertEquals('en', $entry->getLanguage());
299 // and now re-submit it to test the cascade persistence for tags after entry removal
300 // related https://github.com/wallabag/wallabag/issues/2121
301 $crawler = $client->request('GET', '/new');
303 $this->assertEquals(200, $client->getResponse()->getStatusCode());
305 $form = $crawler->filter('form[name=entry]')->form();
308 'entry[url]' => $url = 'https://github.com/wallabag/wallabag/tree/master',
311 $client->submit($form, $data);
313 $this->assertEquals(302, $client->getResponse()->getStatusCode());
314 $this->assertContains('/', $client->getResponse()->getTargetUrl());
317 ->getRepository('WallabagCoreBundle:Entry')
318 ->findOneByUrl($url);
320 $tags = $entry->getTags();
322 $this->assertCount(2, $tags);
323 $this->assertContains('wallabag', $tags);
329 public function testArchive()
331 $this->logInAs('admin');
332 $client = $this->getClient();
334 $client->request('GET', '/archive/list');
336 $this->assertEquals(200, $client->getResponse()->getStatusCode());
339 public function testUntagged()
341 $this->logInAs('admin');
342 $client = $this->getClient();
344 $client->request('GET', '/untagged/list');
346 $this->assertEquals(200, $client->getResponse()->getStatusCode());
349 public function testStarred()
351 $this->logInAs('admin');
352 $client = $this->getClient();
354 $client->request('GET', '/starred/list');
356 $this->assertEquals(200, $client->getResponse()->getStatusCode());
359 public function testRangeException()
361 $this->logInAs('admin');
362 $client = $this->getClient();
364 $client->request('GET', '/all/list/900');
366 $this->assertEquals(302, $client->getResponse()->getStatusCode());
367 $this->assertEquals('/all/list', $client->getResponse()->getTargetUrl());
370 public function testView()
372 $this->logInAs('admin');
373 $client = $this->getClient();
375 $entry = new Entry($this->getLoggedInUser());
376 $entry->setUrl('http://example.com/foo');
377 $entry->setTitle('title foo');
378 $entry->setContent('foo bar baz');
379 $this->getEntityManager()->persist($entry);
380 $this->getEntityManager()->flush();
382 $crawler = $client->request('GET', '/view/'.$entry->getId());
384 $this->assertEquals(200, $client->getResponse()->getStatusCode());
385 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
386 $this->assertContains($entry->getTitle(), $body[0]);
390 * This test will require an internet connection.
392 public function testReload()
394 $this->logInAs('admin');
395 $client = $this->getClient();
397 $entry = new Entry($this->getLoggedInUser());
398 $entry->setUrl($this->url
);
399 $entry->setTitle('title foo');
400 $entry->setContent('');
401 $this->getEntityManager()->persist($entry);
402 $this->getEntityManager()->flush();
403 $this->getEntityManager()->clear();
405 $client->request('GET', '/reload/'.$entry->getId());
407 $this->assertEquals(302, $client->getResponse()->getStatusCode());
409 $entry = $this->getEntityManager()
410 ->getRepository('WallabagCoreBundle:Entry')
411 ->find($entry->getId());
413 $this->assertNotEmpty($entry->getContent());
416 public function testReloadWithFetchingFailed()
418 $this->logInAs('admin');
419 $client = $this->getClient();
421 $entry = new Entry($this->getLoggedInUser());
422 $entry->setUrl('http://0.0.0.0/failed.html');
423 $this->getEntityManager()->persist($entry);
424 $this->getEntityManager()->flush();
426 $client->request('GET', '/reload/'.$entry->getId());
428 $this->assertEquals(302, $client->getResponse()->getStatusCode());
430 // force EntityManager to clear previous entity
431 // otherwise, retrieve the same entity will retrieve change from the previous request :0
432 $this->getEntityManager()->clear();
433 $newContent = $this->getEntityManager()
434 ->getRepository('WallabagCoreBundle:Entry')
435 ->find($entry->getId());
437 $this->assertNotEquals($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent());
440 public function testEdit()
442 $this->logInAs('admin');
443 $client = $this->getClient();
445 $entry = new Entry($this->getLoggedInUser());
446 $entry->setUrl($this->url
);
447 $this->getEntityManager()->persist($entry);
448 $this->getEntityManager()->flush();
450 $crawler = $client->request('GET', '/edit/'.$entry->getId());
452 $this->assertEquals(200, $client->getResponse()->getStatusCode());
454 $this->assertCount(1, $crawler->filter('input[id=entry_title]'));
455 $this->assertCount(1, $crawler->filter('button[id=entry_save]'));
458 public function testEditUpdate()
460 $this->logInAs('admin');
461 $client = $this->getClient();
463 $entry = new Entry($this->getLoggedInUser());
464 $entry->setUrl($this->url
);
465 $this->getEntityManager()->persist($entry);
466 $this->getEntityManager()->flush();
468 $crawler = $client->request('GET', '/edit/'.$entry->getId());
470 $this->assertEquals(200, $client->getResponse()->getStatusCode());
472 $form = $crawler->filter('button[type=submit]')->form();
475 'entry[title]' => 'My updated title hehe :)',
478 $client->submit($form, $data);
480 $this->assertEquals(302, $client->getResponse()->getStatusCode());
482 $crawler = $client->followRedirect();
484 $this->assertGreaterThan(1, $alert = $crawler->filter('div[id=article] h1')->extract(['_text']));
485 $this->assertContains('My updated title hehe :)', $alert[0]);
488 public function testToggleArchive()
490 $this->logInAs('admin');
491 $client = $this->getClient();
493 $entry = new Entry($this->getLoggedInUser());
494 $entry->setUrl($this->url
);
495 $this->getEntityManager()->persist($entry);
496 $this->getEntityManager()->flush();
497 $this->getEntityManager()->clear();
499 $client->request('GET', '/archive/'.$entry->getId());
501 $this->assertEquals(302, $client->getResponse()->getStatusCode());
503 $res = $client->getContainer()
504 ->get('doctrine.orm.entity_manager')
505 ->getRepository('WallabagCoreBundle:Entry')
506 ->find($entry->getId());
508 $this->assertEquals($res->isArchived(), true);
511 public function testToggleStar()
513 $this->logInAs('admin');
514 $client = $this->getClient();
516 $entry = new Entry($this->getLoggedInUser());
517 $entry->setUrl($this->url
);
518 $this->getEntityManager()->persist($entry);
519 $this->getEntityManager()->flush();
520 $this->getEntityManager()->clear();
522 $client->request('GET', '/star/'.$entry->getId());
524 $this->assertEquals(302, $client->getResponse()->getStatusCode());
526 $res = $client->getContainer()
527 ->get('doctrine.orm.entity_manager')
528 ->getRepository('WallabagCoreBundle:Entry')
529 ->findOneById($entry->getId());
531 $this->assertEquals($res->isStarred(), true);
534 public function testDelete()
536 $this->logInAs('admin');
537 $client = $this->getClient();
539 $entry = new Entry($this->getLoggedInUser());
540 $entry->setUrl($this->url
);
541 $this->getEntityManager()->persist($entry);
542 $this->getEntityManager()->flush();
544 $client->request('GET', '/delete/'.$entry->getId());
546 $this->assertEquals(302, $client->getResponse()->getStatusCode());
548 $client->request('GET', '/delete/'.$entry->getId());
550 $this->assertEquals(404, $client->getResponse()->getStatusCode());
554 * It will create a new entry.
558 * And it'll check that user won't be redirected to the view page of the content when it had been removed
560 public function testViewAndDelete()
562 $this->logInAs('admin');
563 $client = $this->getClient();
565 $em = $client->getContainer()
566 ->get('doctrine.orm.entity_manager');
568 // add a new content to be removed later
570 ->getRepository('WallabagUserBundle:User')
571 ->findOneByUserName('admin');
573 $content = new Entry($user);
574 $content->setUrl('http://1.1.1.1/entry');
575 $content->setReadingTime(12);
576 $content->setDomainName('domain.io');
577 $content->setMimetype('text/html');
578 $content->setTitle('test title entry');
579 $content->setContent('This is my content /o/');
580 $content->setArchived(true);
581 $content->setLanguage('fr');
583 $em->persist($content);
586 $client->request('GET', '/view/'.$content->getId());
587 $this->assertEquals(200, $client->getResponse()->getStatusCode());
589 $client->request('GET', '/delete/'.$content->getId());
590 $this->assertEquals(302, $client->getResponse()->getStatusCode());
592 $client->followRedirect();
593 $this->assertEquals(200, $client->getResponse()->getStatusCode());
596 public function testViewOtherUserEntry()
598 $this->logInAs('admin');
599 $client = $this->getClient();
601 $content = $client->getContainer()
602 ->get('doctrine.orm.entity_manager')
603 ->getRepository('WallabagCoreBundle:Entry')
604 ->findOneByUsernameAndNotArchived('bob');
606 $client->request('GET', '/view/'.$content->getId());
608 $this->assertEquals(403, $client->getResponse()->getStatusCode());
611 public function testFilterOnReadingTime()
613 $this->logInAs('admin');
614 $this->useTheme('baggy');
615 $client = $this->getClient();
616 $entry = new Entry($this->getLoggedInUser());
617 $entry->setUrl($this->url
);
618 $entry->setReadingTime(22);
619 $this->getEntityManager()->persist($entry);
620 $this->getEntityManager()->flush();
622 $crawler = $client->request('GET', '/unread/list');
624 $form = $crawler->filter('button[id=submit-filter]')->form();
627 'entry_filter[readingTime][right_number]' => 22,
628 'entry_filter[readingTime][left_number]' => 22,
631 $crawler = $client->submit($form, $data);
633 $this->assertCount(1, $crawler->filter('div[class=entry]'));
636 public function testFilterOnReadingTimeWithNegativeValue()
638 $this->logInAs('admin');
639 $client = $this->getClient();
641 $crawler = $client->request('GET', '/unread/list');
643 $form = $crawler->filter('button[id=submit-filter]')->form();
646 'entry_filter[readingTime][right_number]' => -22,
647 'entry_filter[readingTime][left_number]' => -22,
650 $crawler = $client->submit($form, $data);
652 // forcing negative value results in no entry displayed
653 $this->assertCount(0, $crawler->filter('div[class=entry]'));
656 public function testFilterOnReadingTimeOnlyUpper()
658 $this->logInAs('admin');
659 $this->useTheme('baggy');
660 $client = $this->getClient();
662 $crawler = $client->request('GET', '/all/list');
663 $this->assertCount(5, $crawler->filter('div[class=entry]'));
665 $entry = new Entry($this->getLoggedInUser());
666 $entry->setUrl($this->url
);
667 $entry->setReadingTime(23);
668 $this->getEntityManager()->persist($entry);
669 $this->getEntityManager()->flush();
671 $crawler = $client->request('GET', '/all/list');
672 $this->assertCount(6, $crawler->filter('div[class=entry]'));
674 $form = $crawler->filter('button[id=submit-filter]')->form();
677 'entry_filter[readingTime][right_number]' => 22,
680 $crawler = $client->submit($form, $data);
682 $this->assertCount(5, $crawler->filter('div[class=entry]'));
685 public function testFilterOnReadingTimeOnlyLower()
687 $this->logInAs('admin');
688 $this->useTheme('baggy');
689 $client = $this->getClient();
691 $crawler = $client->request('GET', '/unread/list');
693 $form = $crawler->filter('button[id=submit-filter]')->form();
696 'entry_filter[readingTime][left_number]' => 22,
699 $crawler = $client->submit($form, $data);
701 $this->assertCount(0, $crawler->filter('div[class=entry]'));
703 $entry = new Entry($this->getLoggedInUser());
704 $entry->setUrl($this->url
);
705 $entry->setReadingTime(23);
706 $this->getEntityManager()->persist($entry);
707 $this->getEntityManager()->flush();
709 $crawler = $client->submit($form, $data);
710 $this->assertCount(1, $crawler->filter('div[class=entry]'));
713 public function testFilterOnUnreadStatus()
715 $this->logInAs('admin');
716 $this->useTheme('baggy');
717 $client = $this->getClient();
719 $crawler = $client->request('GET', '/all/list');
721 $form = $crawler->filter('button[id=submit-filter]')->form();
724 'entry_filter[isUnread]' => true,
727 $crawler = $client->submit($form, $data);
729 $this->assertCount(4, $crawler->filter('div[class=entry]'));
731 $entry = new Entry($this->getLoggedInUser());
732 $entry->setUrl($this->url
);
733 $entry->setArchived(false);
734 $this->getEntityManager()->persist($entry);
735 $this->getEntityManager()->flush();
737 $crawler = $client->submit($form, $data);
739 $this->assertCount(5, $crawler->filter('div[class=entry]'));
742 public function testFilterOnCreationDate()
744 $this->logInAs('admin');
745 $this->useTheme('baggy');
746 $client = $this->getClient();
748 $crawler = $client->request('GET', '/unread/list');
750 $form = $crawler->filter('button[id=submit-filter]')->form();
753 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
754 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')),
757 $crawler = $client->submit($form, $data);
759 $this->assertCount(5, $crawler->filter('div[class=entry]'));
762 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
763 'entry_filter[createdAt][right_date]' => date('d/m/Y'),
766 $crawler = $client->submit($form, $data);
768 $this->assertCount(5, $crawler->filter('div[class=entry]'));
771 'entry_filter[createdAt][left_date]' => '01/01/1970',
772 'entry_filter[createdAt][right_date]' => '01/01/1970',
775 $crawler = $client->submit($form, $data);
777 $this->assertCount(0, $crawler->filter('div[class=entry]'));
780 public function testPaginationWithFilter()
782 $this->logInAs('admin');
783 $client = $this->getClient();
784 $crawler = $client->request('GET', '/config');
786 $form = $crawler->filter('button[id=config_save]')->form();
789 'config[items_per_page]' => '1',
792 $client->submit($form, $data);
794 $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D=';
796 $client->request('GET', 'unread/list'.$parameters);
798 $this->assertContains($parameters, $client->getResponse()->getContent());
801 $crawler = $client->request('GET', '/config');
802 $form = $crawler->filter('button[id=config_save]')->form();
804 'config[items_per_page]' => '12',
806 $client->submit($form, $data);
809 public function testFilterOnDomainName()
811 $this->logInAs('admin');
812 $this->useTheme('baggy');
813 $client = $this->getClient();
815 $crawler = $client->request('GET', '/unread/list');
816 $form = $crawler->filter('button[id=submit-filter]')->form();
818 'entry_filter[domainName]' => 'domain',
821 $crawler = $client->submit($form, $data);
822 $this->assertCount(5, $crawler->filter('div[class=entry]'));
824 $crawler = $client->request('GET', '/unread/list');
825 $form = $crawler->filter('button[id=submit-filter]')->form();
827 'entry_filter[domainName]' => 'dOmain',
830 $crawler = $client->submit($form, $data);
831 $this->assertCount(5, $crawler->filter('div[class=entry]'));
833 $form = $crawler->filter('button[id=submit-filter]')->form();
835 'entry_filter[domainName]' => 'wallabag',
838 $crawler = $client->submit($form, $data);
839 $this->assertCount(0, $crawler->filter('div[class=entry]'));
842 public function testFilterOnStatus()
844 $this->logInAs('admin');
845 $this->useTheme('baggy');
846 $client = $this->getClient();
848 $crawler = $client->request('GET', '/unread/list');
849 $form = $crawler->filter('button[id=submit-filter]')->form();
850 $form['entry_filter[isArchived]']->tick();
851 $form['entry_filter[isStarred]']->untick();
853 $crawler = $client->submit($form);
854 $this->assertCount(1, $crawler->filter('div[class=entry]'));
856 $form = $crawler->filter('button[id=submit-filter]')->form();
857 $form['entry_filter[isArchived]']->untick();
858 $form['entry_filter[isStarred]']->tick();
860 $crawler = $client->submit($form);
861 $this->assertCount(1, $crawler->filter('div[class=entry]'));
864 public function testFilterOnIsPublic()
866 $this->logInAs('admin');
867 $this->useTheme('baggy');
868 $client = $this->getClient();
870 $crawler = $client->request('GET', '/unread/list');
871 $form = $crawler->filter('button[id=submit-filter]')->form();
872 $form['entry_filter[isPublic]']->tick();
874 $crawler = $client->submit($form);
875 $this->assertCount(0, $crawler->filter('div[class=entry]'));
878 public function testPreviewPictureFilter()
880 $this->logInAs('admin');
881 $this->useTheme('baggy');
882 $client = $this->getClient();
884 $crawler = $client->request('GET', '/unread/list');
885 $form = $crawler->filter('button[id=submit-filter]')->form();
886 $form['entry_filter[previewPicture]']->tick();
888 $crawler = $client->submit($form);
889 $this->assertCount(1, $crawler->filter('div[class=entry]'));
892 public function testFilterOnLanguage()
894 $this->logInAs('admin');
895 $this->useTheme('baggy');
896 $client = $this->getClient();
898 $entry = new Entry($this->getLoggedInUser());
899 $entry->setUrl($this->url
);
900 $entry->setLanguage('fr');
901 $this->getEntityManager()->persist($entry);
902 $this->getEntityManager()->flush();
904 $crawler = $client->request('GET', '/unread/list');
905 $form = $crawler->filter('button[id=submit-filter]')->form();
907 'entry_filter[language]' => 'fr',
910 $crawler = $client->submit($form, $data);
911 $this->assertCount(3, $crawler->filter('div[class=entry]'));
913 $form = $crawler->filter('button[id=submit-filter]')->form();
915 'entry_filter[language]' => 'en',
918 $crawler = $client->submit($form, $data);
919 $this->assertCount(2, $crawler->filter('div[class=entry]'));
922 public function testShareEntryPublicly()
924 $this->logInAs('admin');
925 $client = $this->getClient();
927 // sharing is enabled
928 $client->getContainer()->get('craue_config')->set('share_public', 1);
930 $content = new Entry($this->getLoggedInUser());
931 $content->setUrl($this->url
);
932 $this->getEntityManager()->persist($content);
933 $this->getEntityManager()->flush();
934 $this->getEntityManager()->clear();
937 $client->request('GET', '/share/'.$content->getUid());
938 $this->assertEquals(404, $client->getResponse()->getStatusCode());
940 // generating the uid
941 $client->request('GET', '/share/'.$content->getId());
942 $this->assertEquals(302, $client->getResponse()->getStatusCode());
944 // follow link with uid
945 $crawler = $client->followRedirect();
946 $this->assertEquals(200, $client->getResponse()->getStatusCode());
947 $this->assertContains('max-age=25200', $client->getResponse()->headers
->get('cache-control'));
948 $this->assertContains('public', $client->getResponse()->headers
->get('cache-control'));
949 $this->assertContains('s-maxage=25200', $client->getResponse()->headers
->get('cache-control'));
950 $this->assertNotContains('no-cache', $client->getResponse()->headers
->get('cache-control'));
951 $this->assertContains('og:title', $client->getResponse()->getContent());
952 $this->assertContains('og:type', $client->getResponse()->getContent());
953 $this->assertContains('og:url', $client->getResponse()->getContent());
954 $this->assertContains('og:image', $client->getResponse()->getContent());
956 // sharing is now disabled
957 $client->getContainer()->get('craue_config')->set('share_public', 0);
958 $client->request('GET', '/share/'.$content->getUid());
959 $this->assertEquals(404, $client->getResponse()->getStatusCode());
961 $client->request('GET', '/view/'.$content->getId());
962 $this->assertContains('no-cache', $client->getResponse()->headers
->get('cache-control'));
964 // removing the share
965 $client->request('GET', '/share/delete/'.$content->getId());
966 $this->assertEquals(302, $client->getResponse()->getStatusCode());
968 // share is now disable
969 $client->request('GET', '/share/'.$content->getUid());
970 $this->assertEquals(404, $client->getResponse()->getStatusCode());
973 public function testNewEntryWithDownloadImagesEnabled()
975 $this->downloadImagesEnabled
= true;
976 $this->logInAs('admin');
977 $client = $this->getClient();
979 $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route';
980 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
982 $crawler = $client->request('GET', '/new');
984 $this->assertEquals(200, $client->getResponse()->getStatusCode());
986 $form = $crawler->filter('form[name=entry]')->form();
989 'entry[url]' => $url,
992 $client->submit($form, $data);
994 $this->assertEquals(302, $client->getResponse()->getStatusCode());
996 $em = $client->getContainer()
997 ->get('doctrine.orm.entity_manager');
1000 ->getRepository('WallabagCoreBundle:Entry')
1001 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1003 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry);
1004 $this->assertEquals($url, $entry->getUrl());
1005 $this->assertContains('Perpignan', $entry->getTitle());
1006 // instead of checking for the filename (which might change) check that the image is now local
1007 $this->assertContains('https://your-wallabag-url-instance.com/assets/images/', $entry->getContent());
1009 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1013 * @depends testNewEntryWithDownloadImagesEnabled
1015 public function testRemoveEntryWithDownloadImagesEnabled()
1017 $this->downloadImagesEnabled
= true;
1018 $this->logInAs('admin');
1019 $client = $this->getClient();
1021 $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route';
1022 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
1024 $crawler = $client->request('GET', '/new');
1026 $this->assertEquals(200, $client->getResponse()->getStatusCode());
1028 $form = $crawler->filter('form[name=entry]')->form();
1031 'entry[url]' => $url,
1034 $client->submit($form, $data);
1036 $this->assertEquals(302, $client->getResponse()->getStatusCode());
1038 $content = $client->getContainer()
1039 ->get('doctrine.orm.entity_manager')
1040 ->getRepository('WallabagCoreBundle:Entry')
1041 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1043 $client->request('GET', '/delete/'.$content->getId());
1045 $this->assertEquals(302, $client->getResponse()->getStatusCode());
1047 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1050 public function testRedirectToHomepage()
1052 $this->logInAs('empty');
1053 $client = $this->getClient();
1055 // Redirect to homepage
1056 $config = $this->getLoggedInUser()->getConfig();
1057 $config->setActionMarkAsRead(Config
::REDIRECT_TO_HOMEPAGE
);
1058 $this->getEntityManager()->persist($config);
1060 $entry = new Entry($this->getLoggedInUser());
1061 $entry->setUrl($this->url
);
1062 $this->getEntityManager()->persist($entry);
1064 $this->getEntityManager()->flush();
1066 $client->request('GET', '/view/'.$entry->getId());
1067 $client->request('GET', '/archive/'.$entry->getId());
1069 $this->assertEquals(302, $client->getResponse()->getStatusCode());
1070 $this->assertEquals('/', $client->getResponse()->headers
->get('location'));
1073 public function testRedirectToCurrentPage()
1075 $this->logInAs('empty');
1076 $client = $this->getClient();
1078 // Redirect to current page
1079 $config = $this->getLoggedInUser()->getConfig();
1080 $config->setActionMarkAsRead(Config
::REDIRECT_TO_CURRENT_PAGE
);
1081 $this->getEntityManager()->persist($config);
1083 $entry = new Entry($this->getLoggedInUser());
1084 $entry->setUrl($this->url
);
1085 $this->getEntityManager()->persist($entry);
1087 $this->getEntityManager()->flush();
1089 $client->request('GET', '/view/'.$entry->getId());
1090 $client->request('GET', '/archive/'.$entry->getId());
1092 $this->assertEquals(302, $client->getResponse()->getStatusCode());
1093 $this->assertContains('/view/'.$entry->getId(), $client->getResponse()->headers
->get('location'));
1096 public function testFilterOnHttpStatus()
1098 $this->logInAs('admin');
1099 $this->useTheme('baggy');
1100 $client = $this->getClient();
1102 $entry = new Entry($this->getLoggedInUser());
1103 $entry->setUrl('http://www.lemonde.fr/incorrect-url/');
1104 $entry->setHttpStatus(404);
1105 $this->getEntityManager()->persist($entry);
1107 $this->getEntityManager()->flush();
1109 $crawler = $client->request('GET', '/all/list');
1110 $form = $crawler->filter('button[id=submit-filter]')->form();
1113 'entry_filter[httpStatus]' => 404,
1116 $crawler = $client->submit($form, $data);
1118 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1120 $entry = new Entry($this->getLoggedInUser());
1121 $entry->setUrl($this->url
);
1122 $entry->setHttpStatus(200);
1123 $this->getEntityManager()->persist($entry);
1125 $entry = new Entry($this->getLoggedInUser());
1126 $entry->setUrl('http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm');
1127 $entry->setHttpStatus(200);
1128 $this->getEntityManager()->persist($entry);
1130 $this->getEntityManager()->flush();
1132 $crawler = $client->request('GET', '/all/list');
1133 $form = $crawler->filter('button[id=submit-filter]')->form();
1136 'entry_filter[httpStatus]' => 200,
1139 $crawler = $client->submit($form, $data);
1141 $this->assertCount(2, $crawler->filter('div[class=entry]'));
1143 $crawler = $client->request('GET', '/all/list');
1144 $form = $crawler->filter('button[id=submit-filter]')->form();
1147 'entry_filter[httpStatus]' => 1024,
1150 $crawler = $client->submit($form, $data);
1152 $this->assertCount(8, $crawler->filter('div[class=entry]'));
1155 public function testSearch()
1157 $this->logInAs('admin');
1158 $this->useTheme('baggy');
1159 $client = $this->getClient();
1161 $entry = new Entry($this->getLoggedInUser());
1162 $entry->setUrl($this->url
);
1163 $entry->setTitle('test');
1164 $this->getEntityManager()->persist($entry);
1165 $this->getEntityManager()->flush();
1167 // Search on unread list
1168 $crawler = $client->request('GET', '/unread/list');
1170 $form = $crawler->filter('form[name=search]')->form();
1172 'search_entry[term]' => 'title',
1175 $crawler = $client->submit($form, $data);
1177 $this->assertCount(4, $crawler->filter('div[class=entry]'));
1179 // Search on starred list
1180 $crawler = $client->request('GET', '/starred/list');
1182 $entry = new Entry($this->getLoggedInUser());
1183 $entry->setUrl('http://localhost/foo/bar');
1184 $entry->setTitle('testeur');
1185 $entry->setStarred(true);
1186 $this->getEntityManager()->persist($entry);
1187 $this->getEntityManager()->flush();
1189 $form = $crawler->filter('form[name=search]')->form();
1191 'search_entry[term]' => 'testeur',
1194 $crawler = $client->submit($form, $data);
1196 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1198 $crawler = $client->request('GET', '/archive/list');
1200 // Added new article to test on archive list
1201 $entry = new Entry($this->getLoggedInUser());
1202 $entry->setUrl('http://0.0.0.0/foo/baz/qux');
1203 $entry->setTitle('Le manège');
1204 $entry->setArchived(true);
1205 $this->getEntityManager()->persist($entry);
1206 $this->getEntityManager()->flush();
1208 $form = $crawler->filter('form[name=search]')->form();
1210 'search_entry[term]' => 'manège',
1213 $crawler = $client->submit($form, $data);
1215 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1216 $client->request('GET', '/delete/'.$entry->getId());
1218 // test on list of all articles
1219 $crawler = $client->request('GET', '/all/list');
1221 $form = $crawler->filter('form[name=search]')->form();
1223 'search_entry[term]' => 'wxcvbnqsdf', // a string not available in the database
1226 $crawler = $client->submit($form, $data);
1228 $this->assertCount(0, $crawler->filter('div[class=entry]'));
1230 // test url search on list of all articles
1231 $entry = new Entry($this->getLoggedInUser());
1232 $entry->setUrl('http://domain/qux');
1233 $entry->setTitle('Le manège');
1234 $entry->setArchived(true);
1235 $this->getEntityManager()->persist($entry);
1236 $this->getEntityManager()->flush();
1238 $crawler = $client->request('GET', '/all/list');
1240 $form = $crawler->filter('form[name=search]')->form();
1242 'search_entry[term]' => 'domain', // the search will match an entry with 'domain' in its url
1245 $crawler = $client->submit($form, $data);
1247 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1249 // same as previous test but for case-sensitivity
1250 $crawler = $client->request('GET', '/all/list');
1252 $form = $crawler->filter('form[name=search]')->form();
1254 'search_entry[term]' => 'doMain', // the search will match an entry with 'domain' in its url
1257 $crawler = $client->submit($form, $data);
1259 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1262 public function dataForLanguage()
1266 'https://www.pravda.ru/world/09-06-2017/1337283-qatar-0/',
1270 'http://www.zataz.com/90-des-dossiers-medicaux-des-coreens-du-sud-vendus-a-des-entreprises-privees/',
1274 'http://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html',
1278 'http://www.ansa.it/sito/notizie/mondo/europa/2017/06/08/voto-gb-seggi-aperti-misure-sicurezza-rafforzate_0cb71f7f-e23b-4d5f-95ca-bc12296419f0.html',
1282 'http://www.hao123.com/shequ?__noscript__-=1',
1286 'https://buy.garmin.com/de-AT/AT/catalog/product/compareResult.ep?compareProduct=112885&compareProduct=36728',
1290 'http://netler.ru/ikt/windows-error-reporting.htm',
1294 'http://precodoscombustiveis.com.br/postos/cidade/4121/pr/maringa',
1297 'fucked_list_of_languages' => [
1298 'http://geocatalog.webservice-energy.org/geonetwork/srv/eng/main.home',
1302 'http://www.muylinux.com/2015/04/17/odf-reino-unido-microsoft-google',
1309 * @dataProvider dataForLanguage
1311 public function testLanguageValidation($url, $expectedLanguage)
1313 $this->logInAs('admin');
1314 $client = $this->getClient();
1316 $crawler = $client->request('GET', '/new');
1318 $this->assertEquals(200, $client->getResponse()->getStatusCode());
1320 $form = $crawler->filter('form[name=entry]')->form();
1323 'entry[url]' => $url,
1326 $client->submit($form, $data);
1328 $this->assertEquals(302, $client->getResponse()->getStatusCode());
1330 $content = $client->getContainer()
1331 ->get('doctrine.orm.entity_manager')
1332 ->getRepository('WallabagCoreBundle:Entry')
1333 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1335 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1336 $this->assertEquals($url, $content->getUrl());
1337 $this->assertEquals($expectedLanguage, $content->getLanguage());
1341 * This test will require an internet connection.
1343 public function testRestrictedArticle()
1345 $url = 'http://www.monde-diplomatique.fr/2017/05/BONNET/57475';
1346 $this->logInAs('admin');
1347 $client = $this->getClient();
1348 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
1350 // enable restricted access
1351 $client->getContainer()->get('craue_config')->set('restricted_access', 1);
1353 // create a new site_credential
1354 $user = $client->getContainer()->get('security.token_storage')->getToken()->getUser();
1355 $credential = new SiteCredential($user);
1356 $credential->setHost('monde-diplomatique.fr');
1357 $credential->setUsername($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('foo'));
1358 $credential->setPassword($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('bar'));
1360 $em->persist($credential);
1363 $crawler = $client->request('GET', '/new');
1365 $this->assertEquals(200, $client->getResponse()->getStatusCode());
1367 $form = $crawler->filter('form[name=entry]')->form();
1370 'entry[url]' => $url,
1373 $client->submit($form, $data);
1375 $this->assertEquals(302, $client->getResponse()->getStatusCode());
1377 $crawler = $client->followRedirect();
1379 $this->assertEquals(200, $client->getResponse()->getStatusCode());
1380 $this->assertContains('flashes.entry.notice.entry_saved', $crawler->filter('body')->extract(['_text'])[0]);
1383 ->getRepository('WallabagCoreBundle:Entry')
1384 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1386 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1387 $this->assertSame('Crimes et réformes aux Philippines', $content->getTitle());
1389 $client->getContainer()->get('craue_config')->set('restricted_access', 0);