3 namespace Tests\Wallabag\CoreBundle\Controller
;
5 use Tests\Wallabag\CoreBundle\WallabagCoreTestCase
;
6 use Wallabag\CoreBundle\Entity\Config
;
7 use Wallabag\CoreBundle\Entity\Entry
;
9 class EntryControllerTest
extends WallabagCoreTestCase
11 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';
13 public function testLogin()
15 $client = $this->getClient();
17 $client->request('GET', '/new');
19 $this->assertEquals(302, $client->getResponse()->getStatusCode());
20 $this->assertContains('login', $client->getResponse()->headers
->get('location'));
23 public function testQuickstart()
25 $this->logInAs('empty');
26 $client = $this->getClient();
28 $client->request('GET', '/unread/list');
29 $crawler = $client->followRedirect();
31 $this->assertEquals(200, $client->getResponse()->getStatusCode());
32 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
33 $this->assertContains('quickstart.intro.title', $body[0]);
35 // Test if quickstart is disabled when user has 1 entry
36 $crawler = $client->request('GET', '/new');
38 $this->assertEquals(200, $client->getResponse()->getStatusCode());
40 $form = $crawler->filter('form[name=entry]')->form();
43 'entry[url]' => $this->url
,
46 $client->submit($form, $data);
47 $this->assertEquals(302, $client->getResponse()->getStatusCode());
48 $client->followRedirect();
50 $crawler = $client->request('GET', '/unread/list');
51 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
52 $this->assertContains('entry.list.number_on_the_page', $body[0]);
55 public function testGetNew()
57 $this->logInAs('admin');
58 $client = $this->getClient();
60 $crawler = $client->request('GET', '/new');
62 $this->assertEquals(200, $client->getResponse()->getStatusCode());
64 $this->assertCount(1, $crawler->filter('input[type=url]'));
65 $this->assertCount(1, $crawler->filter('form[name=entry]'));
68 public function testPostNewViaBookmarklet()
70 $this->logInAs('admin');
71 $client = $this->getClient();
73 $crawler = $client->request('GET', '/');
75 $this->assertCount(4, $crawler->filter('div[class=entry]'));
78 $client->request('GET', '/bookmarklet', ['url' => $this->url
]);
79 $this->assertEquals(302, $client->getResponse()->getStatusCode());
80 $client->followRedirect();
81 $crawler = $client->request('GET', '/');
82 $this->assertCount(5, $crawler->filter('div[class=entry]'));
84 $em = $client->getContainer()
85 ->get('doctrine.orm.entity_manager');
87 ->getRepository('WallabagCoreBundle:Entry')
88 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
93 public function testPostNewEmpty()
95 $this->logInAs('admin');
96 $client = $this->getClient();
98 $crawler = $client->request('GET', '/new');
100 $this->assertEquals(200, $client->getResponse()->getStatusCode());
102 $form = $crawler->filter('form[name=entry]')->form();
104 $crawler = $client->submit($form);
106 $this->assertEquals(200, $client->getResponse()->getStatusCode());
107 $this->assertCount(1, $alert = $crawler->filter('form ul li')->extract(['_text']));
108 $this->assertEquals('This value should not be blank.', $alert[0]);
112 * This test will require an internet connection.
114 public function testPostNewOk()
116 $this->logInAs('admin');
117 $client = $this->getClient();
119 $crawler = $client->request('GET', '/new');
121 $this->assertEquals(200, $client->getResponse()->getStatusCode());
123 $form = $crawler->filter('form[name=entry]')->form();
126 'entry[url]' => $this->url
,
129 $client->submit($form, $data);
131 $this->assertEquals(302, $client->getResponse()->getStatusCode());
133 $content = $client->getContainer()
134 ->get('doctrine.orm.entity_manager')
135 ->getRepository('WallabagCoreBundle:Entry')
136 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
138 $author = $content->getPublishedBy();
140 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
141 $this->assertEquals($this->url
, $content->getUrl());
142 $this->assertContains('Google', $content->getTitle());
143 $this->assertEquals('2015-03-28 15:37:39', $content->getPublishedAt()->format('Y-m-d H:i:s'));
144 $this->assertEquals('Morgane Tual', $author[0]);
147 public function testPostWithMultipleAuthors()
149 $url = 'http://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768';
150 $this->logInAs('admin');
151 $client = $this->getClient();
153 $crawler = $client->request('GET', '/new');
155 $this->assertEquals(200, $client->getResponse()->getStatusCode());
157 $form = $crawler->filter('form[name=entry]')->form();
160 'entry[url]' => $url,
163 $client->submit($form, $data);
165 $this->assertEquals(302, $client->getResponse()->getStatusCode());
167 $content = $client->getContainer()
168 ->get('doctrine.orm.entity_manager')
169 ->getRepository('WallabagCoreBundle:Entry')
170 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
172 $authors = $content->getPublishedBy();
173 $this->assertEquals('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s'));
174 $this->assertEquals('Raphaël Balenieri, correspondant à Pékin', $authors[0]);
175 $this->assertEquals('Frédéric Autran, correspondant à New York', $authors[1]);
178 public function testPostNewOkUrlExist()
180 $this->logInAs('admin');
181 $client = $this->getClient();
183 $crawler = $client->request('GET', '/new');
185 $this->assertEquals(200, $client->getResponse()->getStatusCode());
187 $form = $crawler->filter('form[name=entry]')->form();
190 'entry[url]' => $this->url
,
193 $client->submit($form, $data);
195 $this->assertEquals(302, $client->getResponse()->getStatusCode());
196 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
199 public function testPostNewOkUrlExistWithAccent()
201 $this->logInAs('admin');
202 $client = $this->getClient();
204 $url = 'http://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing';
206 $crawler = $client->request('GET', '/new');
208 $this->assertEquals(200, $client->getResponse()->getStatusCode());
210 $form = $crawler->filter('form[name=entry]')->form();
213 'entry[url]' => $url,
216 $client->submit($form, $data);
218 $crawler = $client->request('GET', '/new');
220 $this->assertEquals(200, $client->getResponse()->getStatusCode());
222 $form = $crawler->filter('form[name=entry]')->form();
225 'entry[url]' => $url,
228 $client->submit($form, $data);
230 $this->assertEquals(302, $client->getResponse()->getStatusCode());
231 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
233 $em = $client->getContainer()
234 ->get('doctrine.orm.entity_manager');
236 ->getRepository('WallabagCoreBundle:Entry')
237 ->findOneByUrl(urldecode($url));
244 * This test will require an internet connection.
246 public function testPostNewThatWillBeTagged()
248 $this->logInAs('admin');
249 $client = $this->getClient();
251 $crawler = $client->request('GET', '/new');
253 $this->assertEquals(200, $client->getResponse()->getStatusCode());
255 $form = $crawler->filter('form[name=entry]')->form();
258 'entry[url]' => $url = 'https://github.com/wallabag/wallabag',
261 $client->submit($form, $data);
263 $this->assertEquals(302, $client->getResponse()->getStatusCode());
264 $this->assertContains('/', $client->getResponse()->getTargetUrl());
266 $em = $client->getContainer()
267 ->get('doctrine.orm.entity_manager');
269 ->getRepository('WallabagCoreBundle:Entry')
270 ->findOneByUrl($url);
271 $tags = $entry->getTags();
273 $this->assertCount(2, $tags);
274 $this->assertEquals('wallabag', $tags[0]->getLabel());
279 // and now re-submit it to test the cascade persistence for tags after entry removal
280 // related https://github.com/wallabag/wallabag/issues/2121
281 $crawler = $client->request('GET', '/new');
283 $this->assertEquals(200, $client->getResponse()->getStatusCode());
285 $form = $crawler->filter('form[name=entry]')->form();
288 'entry[url]' => $url = 'https://github.com/wallabag/wallabag/tree/master',
291 $client->submit($form, $data);
293 $this->assertEquals(302, $client->getResponse()->getStatusCode());
294 $this->assertContains('/', $client->getResponse()->getTargetUrl());
297 ->getRepository('WallabagCoreBundle:Entry')
298 ->findOneByUrl($url);
300 $tags = $entry->getTags();
302 $this->assertCount(2, $tags);
303 $this->assertEquals('wallabag', $tags[1]->getLabel());
309 public function testArchive()
311 $this->logInAs('admin');
312 $client = $this->getClient();
314 $client->request('GET', '/archive/list');
316 $this->assertEquals(200, $client->getResponse()->getStatusCode());
319 public function testUntagged()
321 $this->logInAs('admin');
322 $client = $this->getClient();
324 $client->request('GET', '/untagged/list');
326 $this->assertEquals(200, $client->getResponse()->getStatusCode());
329 public function testStarred()
331 $this->logInAs('admin');
332 $client = $this->getClient();
334 $client->request('GET', '/starred/list');
336 $this->assertEquals(200, $client->getResponse()->getStatusCode());
339 public function testRangeException()
341 $this->logInAs('admin');
342 $client = $this->getClient();
344 $client->request('GET', '/all/list/900');
346 $this->assertEquals(302, $client->getResponse()->getStatusCode());
347 $this->assertEquals('/all/list', $client->getResponse()->getTargetUrl());
351 * @depends testPostNewOk
353 public function testView()
355 $this->logInAs('admin');
356 $client = $this->getClient();
358 $content = $client->getContainer()
359 ->get('doctrine.orm.entity_manager')
360 ->getRepository('WallabagCoreBundle:Entry')
361 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
363 $crawler = $client->request('GET', '/view/'.$content->getId());
365 $this->assertEquals(200, $client->getResponse()->getStatusCode());
366 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
367 $this->assertContains($content->getTitle(), $body[0]);
371 * @depends testPostNewOk
373 * This test will require an internet connection.
375 public function testReload()
377 $this->logInAs('admin');
378 $client = $this->getClient();
380 $em = $client->getContainer()
381 ->get('doctrine.orm.entity_manager');
384 ->getRepository('WallabagCoreBundle:Entry')
385 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
388 $content->setContent('');
389 $em->persist($content);
392 $client->request('GET', '/reload/'.$content->getId());
394 $this->assertEquals(302, $client->getResponse()->getStatusCode());
397 ->getRepository('WallabagCoreBundle:Entry')
398 ->find($content->getId());
400 $this->assertNotEmpty($content->getContent());
404 * @depends testPostNewOk
406 public function testReloadWithFetchingFailed()
408 $this->logInAs('admin');
409 $client = $this->getClient();
411 $em = $client->getContainer()
412 ->get('doctrine.orm.entity_manager');
415 ->getRepository('WallabagCoreBundle:Entry')
416 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
418 // put a known failed url
419 $content->setUrl('http://0.0.0.0/failed.html');
420 $em->persist($content);
423 $client->request('GET', '/reload/'.$content->getId());
425 $this->assertEquals(302, $client->getResponse()->getStatusCode());
427 // force EntityManager to clear previous entity
428 // otherwise, retrieve the same entity will retrieve change from the previous request :0
431 ->getRepository('WallabagCoreBundle:Entry')
432 ->find($content->getId());
434 $newContent->setUrl($this->url
);
435 $em->persist($newContent);
438 $this->assertNotEquals($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent());
441 public function testEdit()
443 $this->logInAs('admin');
444 $client = $this->getClient();
446 $content = $client->getContainer()
447 ->get('doctrine.orm.entity_manager')
448 ->getRepository('WallabagCoreBundle:Entry')
449 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
451 $crawler = $client->request('GET', '/edit/'.$content->getId());
453 $this->assertEquals(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 $content = $client->getContainer()
465 ->get('doctrine.orm.entity_manager')
466 ->getRepository('WallabagCoreBundle:Entry')
467 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
469 $crawler = $client->request('GET', '/edit/'.$content->getId());
471 $this->assertEquals(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->assertEquals(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 $content = $client->getContainer()
495 ->get('doctrine.orm.entity_manager')
496 ->getRepository('WallabagCoreBundle:Entry')
497 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
499 $client->request('GET', '/archive/'.$content->getId());
501 $this->assertEquals(302, $client->getResponse()->getStatusCode());
503 $res = $client->getContainer()
504 ->get('doctrine.orm.entity_manager')
505 ->getRepository('WallabagCoreBundle:Entry')
506 ->find($content->getId());
508 $this->assertEquals($res->isArchived(), true);
511 public function testToggleStar()
513 $this->logInAs('admin');
514 $client = $this->getClient();
516 $content = $client->getContainer()
517 ->get('doctrine.orm.entity_manager')
518 ->getRepository('WallabagCoreBundle:Entry')
519 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
521 $client->request('GET', '/star/'.$content->getId());
523 $this->assertEquals(302, $client->getResponse()->getStatusCode());
525 $res = $client->getContainer()
526 ->get('doctrine.orm.entity_manager')
527 ->getRepository('WallabagCoreBundle:Entry')
528 ->findOneById($content->getId());
530 $this->assertEquals($res->isStarred(), true);
533 public function testDelete()
535 $this->logInAs('admin');
536 $client = $this->getClient();
538 $content = $client->getContainer()
539 ->get('doctrine.orm.entity_manager')
540 ->getRepository('WallabagCoreBundle:Entry')
541 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
543 $client->request('GET', '/delete/'.$content->getId());
545 $this->assertEquals(302, $client->getResponse()->getStatusCode());
547 $client->request('GET', '/delete/'.$content->getId());
549 $this->assertEquals(404, $client->getResponse()->getStatusCode());
553 * It will create a new entry.
557 * And it'll check that user won't be redirected to the view page of the content when it had been removed
559 public function testViewAndDelete()
561 $this->logInAs('admin');
562 $client = $this->getClient();
564 $em = $client->getContainer()
565 ->get('doctrine.orm.entity_manager');
567 // add a new content to be removed later
569 ->getRepository('WallabagUserBundle:User')
570 ->findOneByUserName('admin');
572 $content = new Entry($user);
573 $content->setUrl('http://1.1.1.1/entry');
574 $content->setReadingTime(12);
575 $content->setDomainName('domain.io');
576 $content->setMimetype('text/html');
577 $content->setTitle('test title entry');
578 $content->setContent('This is my content /o/');
579 $content->setArchived(true);
580 $content->setLanguage('fr');
582 $em->persist($content);
585 $client->request('GET', '/view/'.$content->getId());
586 $this->assertEquals(200, $client->getResponse()->getStatusCode());
588 $client->request('GET', '/delete/'.$content->getId());
589 $this->assertEquals(302, $client->getResponse()->getStatusCode());
591 $client->followRedirect();
592 $this->assertEquals(200, $client->getResponse()->getStatusCode());
595 public function testViewOtherUserEntry()
597 $this->logInAs('admin');
598 $client = $this->getClient();
600 $content = $client->getContainer()
601 ->get('doctrine.orm.entity_manager')
602 ->getRepository('WallabagCoreBundle:Entry')
603 ->findOneByUsernameAndNotArchived('bob');
605 $client->request('GET', '/view/'.$content->getId());
607 $this->assertEquals(403, $client->getResponse()->getStatusCode());
610 public function testFilterOnReadingTime()
612 $this->logInAs('admin');
613 $client = $this->getClient();
615 $crawler = $client->request('GET', '/unread/list');
617 $form = $crawler->filter('button[id=submit-filter]')->form();
620 'entry_filter[readingTime][right_number]' => 22,
621 'entry_filter[readingTime][left_number]' => 22,
624 $crawler = $client->submit($form, $data);
626 $this->assertCount(1, $crawler->filter('div[class=entry]'));
629 public function testFilterOnReadingTimeOnlyUpper()
631 $this->logInAs('admin');
632 $client = $this->getClient();
634 $crawler = $client->request('GET', '/unread/list');
636 $form = $crawler->filter('button[id=submit-filter]')->form();
639 'entry_filter[readingTime][right_number]' => 22,
642 $crawler = $client->submit($form, $data);
644 $this->assertCount(3, $crawler->filter('div[class=entry]'));
647 public function testFilterOnReadingTimeOnlyLower()
649 $this->logInAs('admin');
650 $client = $this->getClient();
652 $crawler = $client->request('GET', '/unread/list');
654 $form = $crawler->filter('button[id=submit-filter]')->form();
657 'entry_filter[readingTime][left_number]' => 22,
660 $crawler = $client->submit($form, $data);
662 $this->assertCount(4, $crawler->filter('div[class=entry]'));
665 public function testFilterOnUnreadStatus()
667 $this->logInAs('admin');
668 $client = $this->getClient();
670 $crawler = $client->request('GET', '/all/list');
672 $form = $crawler->filter('button[id=submit-filter]')->form();
675 'entry_filter[isUnread]' => true,
678 $crawler = $client->submit($form, $data);
680 $this->assertCount(5, $crawler->filter('div[class=entry]'));
683 public function testFilterOnCreationDate()
685 $this->logInAs('admin');
686 $client = $this->getClient();
688 $crawler = $client->request('GET', '/unread/list');
690 $form = $crawler->filter('button[id=submit-filter]')->form();
693 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
694 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')),
697 $crawler = $client->submit($form, $data);
699 $this->assertCount(6, $crawler->filter('div[class=entry]'));
702 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
703 'entry_filter[createdAt][right_date]' => date('d/m/Y'),
706 $crawler = $client->submit($form, $data);
708 $this->assertCount(6, $crawler->filter('div[class=entry]'));
711 'entry_filter[createdAt][left_date]' => '01/01/1970',
712 'entry_filter[createdAt][right_date]' => '01/01/1970',
715 $crawler = $client->submit($form, $data);
717 $this->assertCount(0, $crawler->filter('div[class=entry]'));
720 public function testPaginationWithFilter()
722 $this->logInAs('admin');
723 $client = $this->getClient();
724 $crawler = $client->request('GET', '/config');
726 $form = $crawler->filter('button[id=config_save]')->form();
729 'config[items_per_page]' => '1',
732 $client->submit($form, $data);
734 $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D=';
736 $client->request('GET', 'unread/list'.$parameters);
738 $this->assertContains($parameters, $client->getResponse()->getContent());
741 $crawler = $client->request('GET', '/config');
742 $form = $crawler->filter('button[id=config_save]')->form();
744 'config[items_per_page]' => '12',
746 $client->submit($form, $data);
749 public function testFilterOnDomainName()
751 $this->logInAs('admin');
752 $client = $this->getClient();
754 $crawler = $client->request('GET', '/unread/list');
755 $form = $crawler->filter('button[id=submit-filter]')->form();
757 'entry_filter[domainName]' => 'domain',
760 $crawler = $client->submit($form, $data);
761 $this->assertCount(5, $crawler->filter('div[class=entry]'));
763 $crawler = $client->request('GET', '/unread/list');
764 $form = $crawler->filter('button[id=submit-filter]')->form();
766 'entry_filter[domainName]' => 'dOmain',
769 $crawler = $client->submit($form, $data);
770 $this->assertCount(5, $crawler->filter('div[class=entry]'));
772 $form = $crawler->filter('button[id=submit-filter]')->form();
774 'entry_filter[domainName]' => 'wallabag',
777 $crawler = $client->submit($form, $data);
778 $this->assertCount(0, $crawler->filter('div[class=entry]'));
781 public function testFilterOnStatus()
783 $this->logInAs('admin');
784 $client = $this->getClient();
786 $crawler = $client->request('GET', '/unread/list');
787 $form = $crawler->filter('button[id=submit-filter]')->form();
788 $form['entry_filter[isArchived]']->tick();
789 $form['entry_filter[isStarred]']->untick();
791 $crawler = $client->submit($form);
792 $this->assertCount(1, $crawler->filter('div[class=entry]'));
794 $form = $crawler->filter('button[id=submit-filter]')->form();
795 $form['entry_filter[isArchived]']->untick();
796 $form['entry_filter[isStarred]']->tick();
798 $crawler = $client->submit($form);
799 $this->assertCount(1, $crawler->filter('div[class=entry]'));
802 public function testPreviewPictureFilter()
804 $this->logInAs('admin');
805 $client = $this->getClient();
807 $crawler = $client->request('GET', '/unread/list');
808 $form = $crawler->filter('button[id=submit-filter]')->form();
809 $form['entry_filter[previewPicture]']->tick();
811 $crawler = $client->submit($form);
812 $this->assertCount(2, $crawler->filter('div[class=entry]'));
815 public function testFilterOnLanguage()
817 $this->logInAs('admin');
818 $client = $this->getClient();
820 $crawler = $client->request('GET', '/unread/list');
821 $form = $crawler->filter('button[id=submit-filter]')->form();
823 'entry_filter[language]' => 'fr',
826 $crawler = $client->submit($form, $data);
827 $this->assertCount(3, $crawler->filter('div[class=entry]'));
829 $form = $crawler->filter('button[id=submit-filter]')->form();
831 'entry_filter[language]' => 'en',
834 $crawler = $client->submit($form, $data);
835 $this->assertCount(2, $crawler->filter('div[class=entry]'));
838 public function testShareEntryPublicly()
840 $this->logInAs('admin');
841 $client = $this->getClient();
843 $content = $client->getContainer()
844 ->get('doctrine.orm.entity_manager')
845 ->getRepository('WallabagCoreBundle:Entry')
846 ->findOneByUser($this->getLoggedInUserId());
849 $client->request('GET', '/share/'.$content->getUid());
850 $this->assertEquals(404, $client->getResponse()->getStatusCode());
852 // generating the uid
853 $client->request('GET', '/share/'.$content->getId());
854 $this->assertEquals(302, $client->getResponse()->getStatusCode());
856 // follow link with uid
857 $crawler = $client->followRedirect();
858 $this->assertEquals(200, $client->getResponse()->getStatusCode());
859 $this->assertContains('max-age=25200', $client->getResponse()->headers
->get('cache-control'));
860 $this->assertContains('public', $client->getResponse()->headers
->get('cache-control'));
861 $this->assertContains('s-maxage=25200', $client->getResponse()->headers
->get('cache-control'));
862 $this->assertNotContains('no-cache', $client->getResponse()->headers
->get('cache-control'));
863 $this->assertContains('og:title', $client->getResponse()->getContent());
864 $this->assertContains('og:type', $client->getResponse()->getContent());
865 $this->assertContains('og:url', $client->getResponse()->getContent());
866 $this->assertContains('og:image', $client->getResponse()->getContent());
868 // sharing is now disabled
869 $client->getContainer()->get('craue_config')->set('share_public', 0);
870 $client->request('GET', '/share/'.$content->getUid());
871 $this->assertEquals(404, $client->getResponse()->getStatusCode());
873 $client->request('GET', '/view/'.$content->getId());
874 $this->assertContains('no-cache', $client->getResponse()->headers
->get('cache-control'));
876 // removing the share
877 $client->request('GET', '/share/delete/'.$content->getId());
878 $this->assertEquals(302, $client->getResponse()->getStatusCode());
880 // share is now disable
881 $client->request('GET', '/share/'.$content->getUid());
882 $this->assertEquals(404, $client->getResponse()->getStatusCode());
885 public function testNewEntryWithDownloadImagesEnabled()
887 $this->logInAs('admin');
888 $client = $this->getClient();
890 $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route';
891 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
893 $crawler = $client->request('GET', '/new');
895 $this->assertEquals(200, $client->getResponse()->getStatusCode());
897 $form = $crawler->filter('form[name=entry]')->form();
900 'entry[url]' => $url,
903 $client->submit($form, $data);
905 $this->assertEquals(302, $client->getResponse()->getStatusCode());
907 $em = $client->getContainer()
908 ->get('doctrine.orm.entity_manager');
911 ->getRepository('WallabagCoreBundle:Entry')
912 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
914 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry);
915 $this->assertEquals($url, $entry->getUrl());
916 $this->assertContains('Perpignan', $entry->getTitle());
917 $this->assertContains('/d9bc0fcd.jpeg', $entry->getContent());
919 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
923 * @depends testNewEntryWithDownloadImagesEnabled
925 public function testRemoveEntryWithDownloadImagesEnabled()
927 $this->logInAs('admin');
928 $client = $this->getClient();
930 $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route';
931 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
933 $content = $client->getContainer()
934 ->get('doctrine.orm.entity_manager')
935 ->getRepository('WallabagCoreBundle:Entry')
936 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
938 $client->request('GET', '/delete/'.$content->getId());
940 $this->assertEquals(302, $client->getResponse()->getStatusCode());
942 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
945 public function testRedirectToHomepage()
947 $this->logInAs('empty');
948 $client = $this->getClient();
950 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
952 ->getRepository('WallabagUserBundle:User')
953 ->find($this->getLoggedInUserId());
956 $this->markTestSkipped('No user found in db.');
959 // Redirect to homepage
960 $config = $user->getConfig();
961 $config->setActionMarkAsRead(Config
::REDIRECT_TO_HOMEPAGE
);
962 $em->persist($config);
965 $content = $client->getContainer()
966 ->get('doctrine.orm.entity_manager')
967 ->getRepository('WallabagCoreBundle:Entry')
968 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
970 $client->request('GET', '/view/'.$content->getId());
971 $client->request('GET', '/archive/'.$content->getId());
973 $this->assertEquals(302, $client->getResponse()->getStatusCode());
974 $this->assertEquals('/', $client->getResponse()->headers
->get('location'));
977 public function testRedirectToCurrentPage()
979 $this->logInAs('empty');
980 $client = $this->getClient();
982 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
984 ->getRepository('WallabagUserBundle:User')
985 ->find($this->getLoggedInUserId());
988 $this->markTestSkipped('No user found in db.');
991 // Redirect to current page
992 $config = $user->getConfig();
993 $config->setActionMarkAsRead(Config
::REDIRECT_TO_CURRENT_PAGE
);
994 $em->persist($config);
997 $content = $client->getContainer()
998 ->get('doctrine.orm.entity_manager')
999 ->getRepository('WallabagCoreBundle:Entry')
1000 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
1002 $client->request('GET', '/view/'.$content->getId());
1003 $client->request('GET', '/archive/'.$content->getId());
1005 $this->assertEquals(302, $client->getResponse()->getStatusCode());
1006 $this->assertContains('/view/'.$content->getId(), $client->getResponse()->headers
->get('location'));
1009 public function testFilterOnHttpStatus()
1011 $this->logInAs('admin');
1012 $client = $this->getClient();
1014 $crawler = $client->request('GET', '/new');
1015 $form = $crawler->filter('form[name=entry]')->form();
1018 'entry[url]' => 'http://www.lemonde.fr/incorrect-url/',
1021 $client->submit($form, $data);
1023 $crawler = $client->request('GET', '/all/list');
1024 $form = $crawler->filter('button[id=submit-filter]')->form();
1027 'entry_filter[httpStatus]' => 404,
1030 $crawler = $client->submit($form, $data);
1032 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1034 $crawler = $client->request('GET', '/new');
1035 $form = $crawler->filter('form[name=entry]')->form();
1038 'entry[url]' => 'http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm',
1041 $client->submit($form, $data);
1043 $crawler = $client->request('GET', '/all/list');
1044 $form = $crawler->filter('button[id=submit-filter]')->form();
1047 'entry_filter[httpStatus]' => 200,
1050 $crawler = $client->submit($form, $data);
1052 $this->assertCount(2, $crawler->filter('div[class=entry]'));
1054 $crawler = $client->request('GET', '/all/list');
1055 $form = $crawler->filter('button[id=submit-filter]')->form();
1058 'entry_filter[httpStatus]' => 1024,
1061 $crawler = $client->submit($form, $data);
1063 $this->assertCount(8, $crawler->filter('div[class=entry]'));
1066 public function testSearch()
1068 $this->logInAs('admin');
1069 $client = $this->getClient();
1071 // Search on unread list
1072 $crawler = $client->request('GET', '/unread/list');
1074 $form = $crawler->filter('form[name=search]')->form();
1076 'search_entry[term]' => 'title',
1079 $crawler = $client->submit($form, $data);
1081 $this->assertCount(5, $crawler->filter('div[class=entry]'));
1083 // Search on starred list
1084 $crawler = $client->request('GET', '/starred/list');
1086 $form = $crawler->filter('form[name=search]')->form();
1088 'search_entry[term]' => 'title',
1091 $crawler = $client->submit($form, $data);
1093 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1095 // Added new article to test on archive list
1096 $crawler = $client->request('GET', '/new');
1097 $form = $crawler->filter('form[name=entry]')->form();
1099 'entry[url]' => $this->url
,
1101 $client->submit($form, $data);
1102 $content = $client->getContainer()
1103 ->get('doctrine.orm.entity_manager')
1104 ->getRepository('WallabagCoreBundle:Entry')
1105 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
1106 $client->request('GET', '/archive/'.$content->getId());
1108 $crawler = $client->request('GET', '/archive/list');
1110 $form = $crawler->filter('form[name=search]')->form();
1112 'search_entry[term]' => 'manège',
1115 $crawler = $client->submit($form, $data);
1117 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1118 $client->request('GET', '/delete/'.$content->getId());
1120 // test on list of all articles
1121 $crawler = $client->request('GET', '/all/list');
1123 $form = $crawler->filter('form[name=search]')->form();
1125 'search_entry[term]' => 'wxcvbnqsdf', // a string not available in the database
1128 $crawler = $client->submit($form, $data);
1130 $this->assertCount(0, $crawler->filter('div[class=entry]'));
1132 // test url search on list of all articles
1133 $crawler = $client->request('GET', '/all/list');
1135 $form = $crawler->filter('form[name=search]')->form();
1137 'search_entry[term]' => 'domain', // the search will match an entry with 'domain' in its url
1140 $crawler = $client->submit($form, $data);
1142 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1144 // same as previous test but for case-sensitivity
1145 $crawler = $client->request('GET', '/all/list');
1147 $form = $crawler->filter('form[name=search]')->form();
1149 'search_entry[term]' => 'doMain', // the search will match an entry with 'domain' in its url
1152 $crawler = $client->submit($form, $data);
1154 $this->assertCount(1, $crawler->filter('div[class=entry]'));