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]);
145 $this->assertArrayHasKey('x-varnish1', $content->getHeaders());
148 public function testPostWithMultipleAuthors()
150 $url = 'http://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768';
151 $this->logInAs('admin');
152 $client = $this->getClient();
154 $crawler = $client->request('GET', '/new');
156 $this->assertEquals(200, $client->getResponse()->getStatusCode());
158 $form = $crawler->filter('form[name=entry]')->form();
161 'entry[url]' => $url,
164 $client->submit($form, $data);
166 $this->assertEquals(302, $client->getResponse()->getStatusCode());
168 $content = $client->getContainer()
169 ->get('doctrine.orm.entity_manager')
170 ->getRepository('WallabagCoreBundle:Entry')
171 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
173 $authors = $content->getPublishedBy();
174 $this->assertEquals('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s'));
175 $this->assertEquals('Raphaël Balenieri, correspondant à Pékin', $authors[0]);
176 $this->assertEquals('Frédéric Autran, correspondant à New York', $authors[1]);
179 public function testPostNewOkUrlExist()
181 $this->logInAs('admin');
182 $client = $this->getClient();
184 $crawler = $client->request('GET', '/new');
186 $this->assertEquals(200, $client->getResponse()->getStatusCode());
188 $form = $crawler->filter('form[name=entry]')->form();
191 'entry[url]' => $this->url
,
194 $client->submit($form, $data);
196 $this->assertEquals(302, $client->getResponse()->getStatusCode());
197 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
200 public function testPostNewOkUrlExistWithAccent()
202 $this->logInAs('admin');
203 $client = $this->getClient();
205 $url = 'http://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing';
207 $crawler = $client->request('GET', '/new');
209 $this->assertEquals(200, $client->getResponse()->getStatusCode());
211 $form = $crawler->filter('form[name=entry]')->form();
214 'entry[url]' => $url,
217 $client->submit($form, $data);
219 $crawler = $client->request('GET', '/new');
221 $this->assertEquals(200, $client->getResponse()->getStatusCode());
223 $form = $crawler->filter('form[name=entry]')->form();
226 'entry[url]' => $url,
229 $client->submit($form, $data);
231 $this->assertEquals(302, $client->getResponse()->getStatusCode());
232 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
234 $em = $client->getContainer()
235 ->get('doctrine.orm.entity_manager');
237 ->getRepository('WallabagCoreBundle:Entry')
238 ->findOneByUrl(urldecode($url));
245 * This test will require an internet connection.
247 public function testPostNewThatWillBeTagged()
249 $this->logInAs('admin');
250 $client = $this->getClient();
252 $crawler = $client->request('GET', '/new');
254 $this->assertEquals(200, $client->getResponse()->getStatusCode());
256 $form = $crawler->filter('form[name=entry]')->form();
259 'entry[url]' => $url = 'https://github.com/wallabag/wallabag',
262 $client->submit($form, $data);
264 $this->assertEquals(302, $client->getResponse()->getStatusCode());
265 $this->assertContains('/', $client->getResponse()->getTargetUrl());
267 $em = $client->getContainer()
268 ->get('doctrine.orm.entity_manager');
270 ->getRepository('WallabagCoreBundle:Entry')
271 ->findOneByUrl($url);
272 $tags = $entry->getTags();
274 $this->assertCount(2, $tags);
275 $this->assertEquals('wallabag', $tags[0]->getLabel());
280 // and now re-submit it to test the cascade persistence for tags after entry removal
281 // related https://github.com/wallabag/wallabag/issues/2121
282 $crawler = $client->request('GET', '/new');
284 $this->assertEquals(200, $client->getResponse()->getStatusCode());
286 $form = $crawler->filter('form[name=entry]')->form();
289 'entry[url]' => $url = 'https://github.com/wallabag/wallabag/tree/master',
292 $client->submit($form, $data);
294 $this->assertEquals(302, $client->getResponse()->getStatusCode());
295 $this->assertContains('/', $client->getResponse()->getTargetUrl());
298 ->getRepository('WallabagCoreBundle:Entry')
299 ->findOneByUrl($url);
301 $tags = $entry->getTags();
303 $this->assertCount(2, $tags);
304 $this->assertEquals('wallabag', $tags[1]->getLabel());
310 public function testArchive()
312 $this->logInAs('admin');
313 $client = $this->getClient();
315 $client->request('GET', '/archive/list');
317 $this->assertEquals(200, $client->getResponse()->getStatusCode());
320 public function testUntagged()
322 $this->logInAs('admin');
323 $client = $this->getClient();
325 $client->request('GET', '/untagged/list');
327 $this->assertEquals(200, $client->getResponse()->getStatusCode());
330 public function testStarred()
332 $this->logInAs('admin');
333 $client = $this->getClient();
335 $client->request('GET', '/starred/list');
337 $this->assertEquals(200, $client->getResponse()->getStatusCode());
340 public function testRangeException()
342 $this->logInAs('admin');
343 $client = $this->getClient();
345 $client->request('GET', '/all/list/900');
347 $this->assertEquals(302, $client->getResponse()->getStatusCode());
348 $this->assertEquals('/all/list', $client->getResponse()->getTargetUrl());
352 * @depends testPostNewOk
354 public function testView()
356 $this->logInAs('admin');
357 $client = $this->getClient();
359 $content = $client->getContainer()
360 ->get('doctrine.orm.entity_manager')
361 ->getRepository('WallabagCoreBundle:Entry')
362 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
364 $crawler = $client->request('GET', '/view/'.$content->getId());
366 $this->assertEquals(200, $client->getResponse()->getStatusCode());
367 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
368 $this->assertContains($content->getTitle(), $body[0]);
372 * @depends testPostNewOk
374 * This test will require an internet connection.
376 public function testReload()
378 $this->logInAs('admin');
379 $client = $this->getClient();
381 $em = $client->getContainer()
382 ->get('doctrine.orm.entity_manager');
385 ->getRepository('WallabagCoreBundle:Entry')
386 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
389 $content->setContent('');
390 $em->persist($content);
393 $client->request('GET', '/reload/'.$content->getId());
395 $this->assertEquals(302, $client->getResponse()->getStatusCode());
398 ->getRepository('WallabagCoreBundle:Entry')
399 ->find($content->getId());
401 $this->assertNotEmpty($content->getContent());
405 * @depends testPostNewOk
407 public function testReloadWithFetchingFailed()
409 $this->logInAs('admin');
410 $client = $this->getClient();
412 $em = $client->getContainer()
413 ->get('doctrine.orm.entity_manager');
416 ->getRepository('WallabagCoreBundle:Entry')
417 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
419 // put a known failed url
420 $content->setUrl('http://0.0.0.0/failed.html');
421 $em->persist($content);
424 $client->request('GET', '/reload/'.$content->getId());
426 $this->assertEquals(302, $client->getResponse()->getStatusCode());
428 // force EntityManager to clear previous entity
429 // otherwise, retrieve the same entity will retrieve change from the previous request :0
432 ->getRepository('WallabagCoreBundle:Entry')
433 ->find($content->getId());
435 $newContent->setUrl($this->url
);
436 $em->persist($newContent);
439 $this->assertNotEquals($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent());
442 public function testEdit()
444 $this->logInAs('admin');
445 $client = $this->getClient();
447 $content = $client->getContainer()
448 ->get('doctrine.orm.entity_manager')
449 ->getRepository('WallabagCoreBundle:Entry')
450 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
452 $crawler = $client->request('GET', '/edit/'.$content->getId());
454 $this->assertEquals(200, $client->getResponse()->getStatusCode());
456 $this->assertCount(1, $crawler->filter('input[id=entry_title]'));
457 $this->assertCount(1, $crawler->filter('button[id=entry_save]'));
460 public function testEditUpdate()
462 $this->logInAs('admin');
463 $client = $this->getClient();
465 $content = $client->getContainer()
466 ->get('doctrine.orm.entity_manager')
467 ->getRepository('WallabagCoreBundle:Entry')
468 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
470 $crawler = $client->request('GET', '/edit/'.$content->getId());
472 $this->assertEquals(200, $client->getResponse()->getStatusCode());
474 $form = $crawler->filter('button[type=submit]')->form();
477 'entry[title]' => 'My updated title hehe :)',
480 $client->submit($form, $data);
482 $this->assertEquals(302, $client->getResponse()->getStatusCode());
484 $crawler = $client->followRedirect();
486 $this->assertGreaterThan(1, $alert = $crawler->filter('div[id=article] h1')->extract(['_text']));
487 $this->assertContains('My updated title hehe :)', $alert[0]);
490 public function testToggleArchive()
492 $this->logInAs('admin');
493 $client = $this->getClient();
495 $content = $client->getContainer()
496 ->get('doctrine.orm.entity_manager')
497 ->getRepository('WallabagCoreBundle:Entry')
498 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
500 $client->request('GET', '/archive/'.$content->getId());
502 $this->assertEquals(302, $client->getResponse()->getStatusCode());
504 $res = $client->getContainer()
505 ->get('doctrine.orm.entity_manager')
506 ->getRepository('WallabagCoreBundle:Entry')
507 ->find($content->getId());
509 $this->assertEquals($res->isArchived(), true);
512 public function testToggleStar()
514 $this->logInAs('admin');
515 $client = $this->getClient();
517 $content = $client->getContainer()
518 ->get('doctrine.orm.entity_manager')
519 ->getRepository('WallabagCoreBundle:Entry')
520 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
522 $client->request('GET', '/star/'.$content->getId());
524 $this->assertEquals(302, $client->getResponse()->getStatusCode());
526 $res = $client->getContainer()
527 ->get('doctrine.orm.entity_manager')
528 ->getRepository('WallabagCoreBundle:Entry')
529 ->findOneById($content->getId());
531 $this->assertEquals($res->isStarred(), true);
534 public function testDelete()
536 $this->logInAs('admin');
537 $client = $this->getClient();
539 $content = $client->getContainer()
540 ->get('doctrine.orm.entity_manager')
541 ->getRepository('WallabagCoreBundle:Entry')
542 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
544 $client->request('GET', '/delete/'.$content->getId());
546 $this->assertEquals(302, $client->getResponse()->getStatusCode());
548 $client->request('GET', '/delete/'.$content->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 $client = $this->getClient();
616 $crawler = $client->request('GET', '/unread/list');
618 $form = $crawler->filter('button[id=submit-filter]')->form();
621 'entry_filter[readingTime][right_number]' => 22,
622 'entry_filter[readingTime][left_number]' => 22,
625 $crawler = $client->submit($form, $data);
627 $this->assertCount(1, $crawler->filter('div[class=entry]'));
630 public function testFilterOnReadingTimeWithNegativeValue()
632 $this->logInAs('admin');
633 $client = $this->getClient();
635 $crawler = $client->request('GET', '/unread/list');
637 $form = $crawler->filter('button[id=submit-filter]')->form();
640 'entry_filter[readingTime][right_number]' => -22,
641 'entry_filter[readingTime][left_number]' => -22,
644 $crawler = $client->submit($form, $data);
646 // forcing negative value results in no entry displayed
647 $this->assertCount(0, $crawler->filter('div[class=entry]'));
650 public function testFilterOnReadingTimeOnlyUpper()
652 $this->logInAs('admin');
653 $client = $this->getClient();
655 $crawler = $client->request('GET', '/unread/list');
657 $form = $crawler->filter('button[id=submit-filter]')->form();
660 'entry_filter[readingTime][right_number]' => 22,
663 $crawler = $client->submit($form, $data);
665 $this->assertCount(3, $crawler->filter('div[class=entry]'));
668 public function testFilterOnReadingTimeOnlyLower()
670 $this->logInAs('admin');
671 $client = $this->getClient();
673 $crawler = $client->request('GET', '/unread/list');
675 $form = $crawler->filter('button[id=submit-filter]')->form();
678 'entry_filter[readingTime][left_number]' => 22,
681 $crawler = $client->submit($form, $data);
683 $this->assertCount(4, $crawler->filter('div[class=entry]'));
686 public function testFilterOnUnreadStatus()
688 $this->logInAs('admin');
689 $client = $this->getClient();
691 $crawler = $client->request('GET', '/all/list');
693 $form = $crawler->filter('button[id=submit-filter]')->form();
696 'entry_filter[isUnread]' => true,
699 $crawler = $client->submit($form, $data);
701 $this->assertCount(5, $crawler->filter('div[class=entry]'));
704 public function testFilterOnCreationDate()
706 $this->logInAs('admin');
707 $client = $this->getClient();
709 $crawler = $client->request('GET', '/unread/list');
711 $form = $crawler->filter('button[id=submit-filter]')->form();
714 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
715 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')),
718 $crawler = $client->submit($form, $data);
720 $this->assertCount(6, $crawler->filter('div[class=entry]'));
723 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
724 'entry_filter[createdAt][right_date]' => date('d/m/Y'),
727 $crawler = $client->submit($form, $data);
729 $this->assertCount(6, $crawler->filter('div[class=entry]'));
732 'entry_filter[createdAt][left_date]' => '01/01/1970',
733 'entry_filter[createdAt][right_date]' => '01/01/1970',
736 $crawler = $client->submit($form, $data);
738 $this->assertCount(0, $crawler->filter('div[class=entry]'));
741 public function testPaginationWithFilter()
743 $this->logInAs('admin');
744 $client = $this->getClient();
745 $crawler = $client->request('GET', '/config');
747 $form = $crawler->filter('button[id=config_save]')->form();
750 'config[items_per_page]' => '1',
753 $client->submit($form, $data);
755 $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D=';
757 $client->request('GET', 'unread/list'.$parameters);
759 $this->assertContains($parameters, $client->getResponse()->getContent());
762 $crawler = $client->request('GET', '/config');
763 $form = $crawler->filter('button[id=config_save]')->form();
765 'config[items_per_page]' => '12',
767 $client->submit($form, $data);
770 public function testFilterOnDomainName()
772 $this->logInAs('admin');
773 $client = $this->getClient();
775 $crawler = $client->request('GET', '/unread/list');
776 $form = $crawler->filter('button[id=submit-filter]')->form();
778 'entry_filter[domainName]' => 'domain',
781 $crawler = $client->submit($form, $data);
782 $this->assertCount(5, $crawler->filter('div[class=entry]'));
784 $crawler = $client->request('GET', '/unread/list');
785 $form = $crawler->filter('button[id=submit-filter]')->form();
787 'entry_filter[domainName]' => 'dOmain',
790 $crawler = $client->submit($form, $data);
791 $this->assertCount(5, $crawler->filter('div[class=entry]'));
793 $form = $crawler->filter('button[id=submit-filter]')->form();
795 'entry_filter[domainName]' => 'wallabag',
798 $crawler = $client->submit($form, $data);
799 $this->assertCount(0, $crawler->filter('div[class=entry]'));
802 public function testFilterOnStatus()
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[isArchived]']->tick();
810 $form['entry_filter[isStarred]']->untick();
812 $crawler = $client->submit($form);
813 $this->assertCount(1, $crawler->filter('div[class=entry]'));
815 $form = $crawler->filter('button[id=submit-filter]')->form();
816 $form['entry_filter[isArchived]']->untick();
817 $form['entry_filter[isStarred]']->tick();
819 $crawler = $client->submit($form);
820 $this->assertCount(1, $crawler->filter('div[class=entry]'));
823 public function testPreviewPictureFilter()
825 $this->logInAs('admin');
826 $client = $this->getClient();
828 $crawler = $client->request('GET', '/unread/list');
829 $form = $crawler->filter('button[id=submit-filter]')->form();
830 $form['entry_filter[previewPicture]']->tick();
832 $crawler = $client->submit($form);
833 $this->assertCount(2, $crawler->filter('div[class=entry]'));
836 public function testFilterOnLanguage()
838 $this->logInAs('admin');
839 $client = $this->getClient();
841 $crawler = $client->request('GET', '/unread/list');
842 $form = $crawler->filter('button[id=submit-filter]')->form();
844 'entry_filter[language]' => 'fr',
847 $crawler = $client->submit($form, $data);
848 $this->assertCount(3, $crawler->filter('div[class=entry]'));
850 $form = $crawler->filter('button[id=submit-filter]')->form();
852 'entry_filter[language]' => 'en',
855 $crawler = $client->submit($form, $data);
856 $this->assertCount(2, $crawler->filter('div[class=entry]'));
859 public function testShareEntryPublicly()
861 $this->logInAs('admin');
862 $client = $this->getClient();
864 $content = $client->getContainer()
865 ->get('doctrine.orm.entity_manager')
866 ->getRepository('WallabagCoreBundle:Entry')
867 ->findOneByUser($this->getLoggedInUserId());
870 $client->request('GET', '/share/'.$content->getUid());
871 $this->assertEquals(404, $client->getResponse()->getStatusCode());
873 // generating the uid
874 $client->request('GET', '/share/'.$content->getId());
875 $this->assertEquals(302, $client->getResponse()->getStatusCode());
877 // follow link with uid
878 $crawler = $client->followRedirect();
879 $this->assertEquals(200, $client->getResponse()->getStatusCode());
880 $this->assertContains('max-age=25200', $client->getResponse()->headers
->get('cache-control'));
881 $this->assertContains('public', $client->getResponse()->headers
->get('cache-control'));
882 $this->assertContains('s-maxage=25200', $client->getResponse()->headers
->get('cache-control'));
883 $this->assertNotContains('no-cache', $client->getResponse()->headers
->get('cache-control'));
884 $this->assertContains('og:title', $client->getResponse()->getContent());
885 $this->assertContains('og:type', $client->getResponse()->getContent());
886 $this->assertContains('og:url', $client->getResponse()->getContent());
887 $this->assertContains('og:image', $client->getResponse()->getContent());
889 // sharing is now disabled
890 $client->getContainer()->get('craue_config')->set('share_public', 0);
891 $client->request('GET', '/share/'.$content->getUid());
892 $this->assertEquals(404, $client->getResponse()->getStatusCode());
894 $client->request('GET', '/view/'.$content->getId());
895 $this->assertContains('no-cache', $client->getResponse()->headers
->get('cache-control'));
897 // removing the share
898 $client->request('GET', '/share/delete/'.$content->getId());
899 $this->assertEquals(302, $client->getResponse()->getStatusCode());
901 // share is now disable
902 $client->request('GET', '/share/'.$content->getUid());
903 $this->assertEquals(404, $client->getResponse()->getStatusCode());
906 public function testNewEntryWithDownloadImagesEnabled()
908 $this->logInAs('admin');
909 $client = $this->getClient();
911 $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route';
912 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
914 $crawler = $client->request('GET', '/new');
916 $this->assertEquals(200, $client->getResponse()->getStatusCode());
918 $form = $crawler->filter('form[name=entry]')->form();
921 'entry[url]' => $url,
924 $client->submit($form, $data);
926 $this->assertEquals(302, $client->getResponse()->getStatusCode());
928 $em = $client->getContainer()
929 ->get('doctrine.orm.entity_manager');
932 ->getRepository('WallabagCoreBundle:Entry')
933 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
935 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry);
936 $this->assertEquals($url, $entry->getUrl());
937 $this->assertContains('Perpignan', $entry->getTitle());
938 $this->assertContains('/c4789a7f.jpeg', $entry->getContent());
940 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
944 * @depends testNewEntryWithDownloadImagesEnabled
946 public function testRemoveEntryWithDownloadImagesEnabled()
948 $this->logInAs('admin');
949 $client = $this->getClient();
951 $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route';
952 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
954 $content = $client->getContainer()
955 ->get('doctrine.orm.entity_manager')
956 ->getRepository('WallabagCoreBundle:Entry')
957 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
959 $client->request('GET', '/delete/'.$content->getId());
961 $this->assertEquals(302, $client->getResponse()->getStatusCode());
963 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
966 public function testRedirectToHomepage()
968 $this->logInAs('empty');
969 $client = $this->getClient();
971 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
973 ->getRepository('WallabagUserBundle:User')
974 ->find($this->getLoggedInUserId());
977 $this->markTestSkipped('No user found in db.');
980 // Redirect to homepage
981 $config = $user->getConfig();
982 $config->setActionMarkAsRead(Config
::REDIRECT_TO_HOMEPAGE
);
983 $em->persist($config);
986 $content = $client->getContainer()
987 ->get('doctrine.orm.entity_manager')
988 ->getRepository('WallabagCoreBundle:Entry')
989 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
991 $client->request('GET', '/view/'.$content->getId());
992 $client->request('GET', '/archive/'.$content->getId());
994 $this->assertEquals(302, $client->getResponse()->getStatusCode());
995 $this->assertEquals('/', $client->getResponse()->headers
->get('location'));
998 public function testRedirectToCurrentPage()
1000 $this->logInAs('empty');
1001 $client = $this->getClient();
1003 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
1005 ->getRepository('WallabagUserBundle:User')
1006 ->find($this->getLoggedInUserId());
1009 $this->markTestSkipped('No user found in db.');
1012 // Redirect to current page
1013 $config = $user->getConfig();
1014 $config->setActionMarkAsRead(Config
::REDIRECT_TO_CURRENT_PAGE
);
1015 $em->persist($config);
1018 $content = $client->getContainer()
1019 ->get('doctrine.orm.entity_manager')
1020 ->getRepository('WallabagCoreBundle:Entry')
1021 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
1023 $client->request('GET', '/view/'.$content->getId());
1024 $client->request('GET', '/archive/'.$content->getId());
1026 $this->assertEquals(302, $client->getResponse()->getStatusCode());
1027 $this->assertContains('/view/'.$content->getId(), $client->getResponse()->headers
->get('location'));
1030 public function testFilterOnHttpStatus()
1032 $this->logInAs('admin');
1033 $client = $this->getClient();
1035 $crawler = $client->request('GET', '/new');
1036 $form = $crawler->filter('form[name=entry]')->form();
1039 'entry[url]' => 'http://www.lemonde.fr/incorrect-url/',
1042 $client->submit($form, $data);
1044 $crawler = $client->request('GET', '/all/list');
1045 $form = $crawler->filter('button[id=submit-filter]')->form();
1048 'entry_filter[httpStatus]' => 404,
1051 $crawler = $client->submit($form, $data);
1053 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1055 $crawler = $client->request('GET', '/new');
1056 $form = $crawler->filter('form[name=entry]')->form();
1059 'entry[url]' => 'http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm',
1062 $client->submit($form, $data);
1064 $crawler = $client->request('GET', '/all/list');
1065 $form = $crawler->filter('button[id=submit-filter]')->form();
1068 'entry_filter[httpStatus]' => 200,
1071 $crawler = $client->submit($form, $data);
1073 $this->assertCount(2, $crawler->filter('div[class=entry]'));
1075 $crawler = $client->request('GET', '/all/list');
1076 $form = $crawler->filter('button[id=submit-filter]')->form();
1079 'entry_filter[httpStatus]' => 1024,
1082 $crawler = $client->submit($form, $data);
1084 $this->assertCount(8, $crawler->filter('div[class=entry]'));
1087 public function testSearch()
1089 $this->logInAs('admin');
1090 $client = $this->getClient();
1092 // Search on unread list
1093 $crawler = $client->request('GET', '/unread/list');
1095 $form = $crawler->filter('form[name=search]')->form();
1097 'search_entry[term]' => 'title',
1100 $crawler = $client->submit($form, $data);
1102 $this->assertCount(5, $crawler->filter('div[class=entry]'));
1104 // Search on starred list
1105 $crawler = $client->request('GET', '/starred/list');
1107 $form = $crawler->filter('form[name=search]')->form();
1109 'search_entry[term]' => 'title',
1112 $crawler = $client->submit($form, $data);
1114 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1116 // Added new article to test on archive list
1117 $crawler = $client->request('GET', '/new');
1118 $form = $crawler->filter('form[name=entry]')->form();
1120 'entry[url]' => $this->url
,
1122 $client->submit($form, $data);
1123 $content = $client->getContainer()
1124 ->get('doctrine.orm.entity_manager')
1125 ->getRepository('WallabagCoreBundle:Entry')
1126 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
1127 $client->request('GET', '/archive/'.$content->getId());
1129 $crawler = $client->request('GET', '/archive/list');
1131 $form = $crawler->filter('form[name=search]')->form();
1133 'search_entry[term]' => 'manège',
1136 $crawler = $client->submit($form, $data);
1138 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1139 $client->request('GET', '/delete/'.$content->getId());
1141 // test on list of all articles
1142 $crawler = $client->request('GET', '/all/list');
1144 $form = $crawler->filter('form[name=search]')->form();
1146 'search_entry[term]' => 'wxcvbnqsdf', // a string not available in the database
1149 $crawler = $client->submit($form, $data);
1151 $this->assertCount(0, $crawler->filter('div[class=entry]'));
1153 // test url search on list of all articles
1154 $crawler = $client->request('GET', '/all/list');
1156 $form = $crawler->filter('form[name=search]')->form();
1158 'search_entry[term]' => 'domain', // the search will match an entry with 'domain' in its url
1161 $crawler = $client->submit($form, $data);
1163 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1165 // same as previous test but for case-sensitivity
1166 $crawler = $client->request('GET', '/all/list');
1168 $form = $crawler->filter('form[name=search]')->form();
1170 'search_entry[term]' => 'doMain', // the search will match an entry with 'domain' in its url
1173 $crawler = $client->submit($form, $data);
1175 $this->assertCount(1, $crawler->filter('div[class=entry]'));