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 $downloadImagesEnabled = false;
12 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';
17 * Ensure download_images_enabled is disabled after each script
19 public function tearDownImagesEnabled()
21 if ($this->downloadImagesEnabled
) {
22 $client = static::createClient();
23 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
25 $this->downloadImagesEnabled
= false;
29 public function testLogin()
31 $client = $this->getClient();
33 $client->request('GET', '/new');
35 $this->assertEquals(302, $client->getResponse()->getStatusCode());
36 $this->assertContains('login', $client->getResponse()->headers
->get('location'));
39 public function testQuickstart()
41 $this->logInAs('empty');
42 $client = $this->getClient();
44 $client->request('GET', '/unread/list');
45 $crawler = $client->followRedirect();
47 $this->assertEquals(200, $client->getResponse()->getStatusCode());
48 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
49 $this->assertContains('quickstart.intro.title', $body[0]);
51 // Test if quickstart is disabled when user has 1 entry
52 $crawler = $client->request('GET', '/new');
54 $this->assertEquals(200, $client->getResponse()->getStatusCode());
56 $form = $crawler->filter('form[name=entry]')->form();
59 'entry[url]' => $this->url
,
62 $client->submit($form, $data);
63 $this->assertEquals(302, $client->getResponse()->getStatusCode());
64 $client->followRedirect();
66 $crawler = $client->request('GET', '/unread/list');
67 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
68 $this->assertContains('entry.list.number_on_the_page', $body[0]);
71 public function testGetNew()
73 $this->logInAs('admin');
74 $this->useTheme('baggy');
75 $client = $this->getClient();
77 $crawler = $client->request('GET', '/new');
79 $this->assertEquals(200, $client->getResponse()->getStatusCode());
81 $this->assertCount(1, $crawler->filter('input[type=url]'));
82 $this->assertCount(1, $crawler->filter('form[name=entry]'));
85 public function testPostNewViaBookmarklet()
87 $this->logInAs('admin');
88 $this->useTheme('baggy');
89 $client = $this->getClient();
91 $crawler = $client->request('GET', '/');
93 $this->assertCount(4, $crawler->filter('div[class=entry]'));
96 $client->request('GET', '/bookmarklet', ['url' => $this->url
]);
97 $this->assertEquals(302, $client->getResponse()->getStatusCode());
98 $client->followRedirect();
99 $crawler = $client->request('GET', '/');
100 $this->assertCount(5, $crawler->filter('div[class=entry]'));
102 $em = $client->getContainer()
103 ->get('doctrine.orm.entity_manager');
105 ->getRepository('WallabagCoreBundle:Entry')
106 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
111 public function testPostNewEmpty()
113 $this->logInAs('admin');
114 $client = $this->getClient();
116 $crawler = $client->request('GET', '/new');
118 $this->assertEquals(200, $client->getResponse()->getStatusCode());
120 $form = $crawler->filter('form[name=entry]')->form();
122 $crawler = $client->submit($form);
124 $this->assertEquals(200, $client->getResponse()->getStatusCode());
125 $this->assertCount(1, $alert = $crawler->filter('form ul li')->extract(['_text']));
126 $this->assertEquals('This value should not be blank.', $alert[0]);
130 * This test will require an internet connection.
132 public function testPostNewOk()
134 $this->logInAs('admin');
135 $client = $this->getClient();
137 $crawler = $client->request('GET', '/new');
139 $this->assertEquals(200, $client->getResponse()->getStatusCode());
141 $form = $crawler->filter('form[name=entry]')->form();
144 'entry[url]' => $this->url
,
147 $client->submit($form, $data);
149 $this->assertEquals(302, $client->getResponse()->getStatusCode());
151 $content = $client->getContainer()
152 ->get('doctrine.orm.entity_manager')
153 ->getRepository('WallabagCoreBundle:Entry')
154 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
156 $author = $content->getPublishedBy();
158 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
159 $this->assertEquals($this->url
, $content->getUrl());
160 $this->assertContains('Google', $content->getTitle());
161 $this->assertEquals('2015-03-28 15:37:39', $content->getPublishedAt()->format('Y-m-d H:i:s'));
162 $this->assertEquals('Morgane Tual', $author[0]);
163 $this->assertArrayHasKey('x-varnish1', $content->getHeaders());
166 public function testPostWithMultipleAuthors()
168 $url = 'http://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768';
169 $this->logInAs('admin');
170 $client = $this->getClient();
172 $crawler = $client->request('GET', '/new');
174 $this->assertEquals(200, $client->getResponse()->getStatusCode());
176 $form = $crawler->filter('form[name=entry]')->form();
179 'entry[url]' => $url,
182 $client->submit($form, $data);
184 $this->assertEquals(302, $client->getResponse()->getStatusCode());
186 $content = $client->getContainer()
187 ->get('doctrine.orm.entity_manager')
188 ->getRepository('WallabagCoreBundle:Entry')
189 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
191 $authors = $content->getPublishedBy();
192 $this->assertEquals('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s'));
193 $this->assertEquals('Raphaël Balenieri, correspondant à Pékin', $authors[0]);
194 $this->assertEquals('Frédéric Autran, correspondant à New York', $authors[1]);
197 public function testPostNewOkUrlExist()
199 $this->logInAs('admin');
201 $entry = new Entry($this->getLoggedInUser());
202 $entry->setUrl($this->url
);
203 $this->getEntityManager()->persist($entry);
204 $this->getEntityManager()->flush();
206 $client = $this->getClient();
208 $crawler = $client->request('GET', '/new');
210 $this->assertEquals(200, $client->getResponse()->getStatusCode());
212 $form = $crawler->filter('form[name=entry]')->form();
215 'entry[url]' => $this->url
,
218 $client->submit($form, $data);
220 $this->assertEquals(302, $client->getResponse()->getStatusCode());
221 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
224 public function testPostNewOkUrlExistWithAccent()
226 $this->logInAs('admin');
227 $client = $this->getClient();
229 $url = 'http://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing';
231 $crawler = $client->request('GET', '/new');
233 $this->assertEquals(200, $client->getResponse()->getStatusCode());
235 $form = $crawler->filter('form[name=entry]')->form();
238 'entry[url]' => $url,
241 $client->submit($form, $data);
243 $crawler = $client->request('GET', '/new');
245 $this->assertEquals(200, $client->getResponse()->getStatusCode());
247 $form = $crawler->filter('form[name=entry]')->form();
250 'entry[url]' => $url,
253 $client->submit($form, $data);
255 $this->assertEquals(302, $client->getResponse()->getStatusCode());
256 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
258 $em = $client->getContainer()
259 ->get('doctrine.orm.entity_manager');
261 ->getRepository('WallabagCoreBundle:Entry')
262 ->findOneByUrl(urldecode($url));
269 * This test will require an internet connection.
271 public function testPostNewThatWillBeTagged()
273 $this->logInAs('admin');
274 $client = $this->getClient();
276 $crawler = $client->request('GET', '/new');
278 $this->assertEquals(200, $client->getResponse()->getStatusCode());
280 $form = $crawler->filter('form[name=entry]')->form();
283 'entry[url]' => $url = 'https://github.com/wallabag/wallabag',
286 $client->submit($form, $data);
288 $this->assertEquals(302, $client->getResponse()->getStatusCode());
289 $this->assertContains('/', $client->getResponse()->getTargetUrl());
291 $em = $client->getContainer()
292 ->get('doctrine.orm.entity_manager');
294 ->getRepository('WallabagCoreBundle:Entry')
295 ->findOneByUrl($url);
296 $tags = $entry->getTags();
298 $this->assertCount(2, $tags);
299 $this->assertContains('wallabag', $tags);
304 // and now re-submit it to test the cascade persistence for tags after entry removal
305 // related https://github.com/wallabag/wallabag/issues/2121
306 $crawler = $client->request('GET', '/new');
308 $this->assertEquals(200, $client->getResponse()->getStatusCode());
310 $form = $crawler->filter('form[name=entry]')->form();
313 'entry[url]' => $url = 'https://github.com/wallabag/wallabag/tree/master',
316 $client->submit($form, $data);
318 $this->assertEquals(302, $client->getResponse()->getStatusCode());
319 $this->assertContains('/', $client->getResponse()->getTargetUrl());
322 ->getRepository('WallabagCoreBundle:Entry')
323 ->findOneByUrl($url);
325 $tags = $entry->getTags();
327 $this->assertCount(2, $tags);
328 $this->assertContains('wallabag', $tags);
334 public function testArchive()
336 $this->logInAs('admin');
337 $client = $this->getClient();
339 $client->request('GET', '/archive/list');
341 $this->assertEquals(200, $client->getResponse()->getStatusCode());
344 public function testUntagged()
346 $this->logInAs('admin');
347 $client = $this->getClient();
349 $client->request('GET', '/untagged/list');
351 $this->assertEquals(200, $client->getResponse()->getStatusCode());
354 public function testStarred()
356 $this->logInAs('admin');
357 $client = $this->getClient();
359 $client->request('GET', '/starred/list');
361 $this->assertEquals(200, $client->getResponse()->getStatusCode());
364 public function testRangeException()
366 $this->logInAs('admin');
367 $client = $this->getClient();
369 $client->request('GET', '/all/list/900');
371 $this->assertEquals(302, $client->getResponse()->getStatusCode());
372 $this->assertEquals('/all/list', $client->getResponse()->getTargetUrl());
375 public function testView()
377 $this->logInAs('admin');
378 $client = $this->getClient();
380 $entry = new Entry($this->getLoggedInUser());
381 $entry->setUrl('http://example.com/foo');
382 $entry->setTitle('title foo');
383 $entry->setContent('foo bar baz');
384 $this->getEntityManager()->persist($entry);
385 $this->getEntityManager()->flush();
387 $crawler = $client->request('GET', '/view/'.$entry->getId());
389 $this->assertEquals(200, $client->getResponse()->getStatusCode());
390 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
391 $this->assertContains($entry->getTitle(), $body[0]);
395 * @depends testPostNewOk
397 * This test will require an internet connection.
399 public function testReload()
401 $this->logInAs('admin');
402 $client = $this->getClient();
404 $entry = new Entry($this->getLoggedInUser());
405 $entry->setUrl($this->url
);
406 $entry->setTitle('title foo');
407 $entry->setContent('');
408 $this->getEntityManager()->persist($entry);
409 $this->getEntityManager()->flush();
410 $this->getEntityManager()->clear();
412 $client->request('GET', '/reload/'.$entry->getId());
414 $this->assertEquals(302, $client->getResponse()->getStatusCode());
416 $entry = $this->getEntityManager()
417 ->getRepository('WallabagCoreBundle:Entry')
418 ->find($entry->getId());
420 $this->assertNotEmpty($entry->getContent());
424 * @depends testPostNewOk
426 public function testReloadWithFetchingFailed()
428 $this->logInAs('admin');
429 $client = $this->getClient();
431 $entry = new Entry($this->getLoggedInUser());
432 $entry->setUrl('http://0.0.0.0/failed.html');
433 $this->getEntityManager()->persist($entry);
434 $this->getEntityManager()->flush();
436 $client->request('GET', '/reload/'.$entry->getId());
438 $this->assertEquals(302, $client->getResponse()->getStatusCode());
440 // force EntityManager to clear previous entity
441 // otherwise, retrieve the same entity will retrieve change from the previous request :0
442 $this->getEntityManager()->clear();
443 $newContent = $this->getEntityManager()
444 ->getRepository('WallabagCoreBundle:Entry')
445 ->find($entry->getId());
447 $this->assertNotEquals($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent());
450 public function testEdit()
452 $this->logInAs('admin');
453 $client = $this->getClient();
455 $entry = new Entry($this->getLoggedInUser());
456 $entry->setUrl($this->url
);
457 $this->getEntityManager()->persist($entry);
458 $this->getEntityManager()->flush();
460 $crawler = $client->request('GET', '/edit/'.$entry->getId());
462 $this->assertEquals(200, $client->getResponse()->getStatusCode());
464 $this->assertCount(1, $crawler->filter('input[id=entry_title]'));
465 $this->assertCount(1, $crawler->filter('button[id=entry_save]'));
468 public function testEditUpdate()
470 $this->logInAs('admin');
471 $client = $this->getClient();
473 $entry = new Entry($this->getLoggedInUser());
474 $entry->setUrl($this->url
);
475 $this->getEntityManager()->persist($entry);
476 $this->getEntityManager()->flush();
478 $crawler = $client->request('GET', '/edit/'.$entry->getId());
480 $this->assertEquals(200, $client->getResponse()->getStatusCode());
482 $form = $crawler->filter('button[type=submit]')->form();
485 'entry[title]' => 'My updated title hehe :)',
488 $client->submit($form, $data);
490 $this->assertEquals(302, $client->getResponse()->getStatusCode());
492 $crawler = $client->followRedirect();
494 $this->assertGreaterThan(1, $alert = $crawler->filter('div[id=article] h1')->extract(['_text']));
495 $this->assertContains('My updated title hehe :)', $alert[0]);
498 public function testToggleArchive()
500 $this->logInAs('admin');
501 $client = $this->getClient();
503 $entry = new Entry($this->getLoggedInUser());
504 $entry->setUrl($this->url
);
505 $this->getEntityManager()->persist($entry);
506 $this->getEntityManager()->flush();
507 $this->getEntityManager()->clear();
509 $client->request('GET', '/archive/'.$entry->getId());
511 $this->assertEquals(302, $client->getResponse()->getStatusCode());
513 $res = $client->getContainer()
514 ->get('doctrine.orm.entity_manager')
515 ->getRepository('WallabagCoreBundle:Entry')
516 ->find($entry->getId());
518 $this->assertEquals($res->isArchived(), true);
521 public function testToggleStar()
523 $this->logInAs('admin');
524 $client = $this->getClient();
526 $entry = new Entry($this->getLoggedInUser());
527 $entry->setUrl($this->url
);
528 $this->getEntityManager()->persist($entry);
529 $this->getEntityManager()->flush();
530 $this->getEntityManager()->clear();
532 $client->request('GET', '/star/'.$entry->getId());
534 $this->assertEquals(302, $client->getResponse()->getStatusCode());
536 $res = $client->getContainer()
537 ->get('doctrine.orm.entity_manager')
538 ->getRepository('WallabagCoreBundle:Entry')
539 ->findOneById($entry->getId());
541 $this->assertEquals($res->isStarred(), true);
544 public function testDelete()
546 $this->logInAs('admin');
547 $client = $this->getClient();
549 $entry = new Entry($this->getLoggedInUser());
550 $entry->setUrl($this->url
);
551 $this->getEntityManager()->persist($entry);
552 $this->getEntityManager()->flush();
554 $client->request('GET', '/delete/'.$entry->getId());
556 $this->assertEquals(302, $client->getResponse()->getStatusCode());
558 $client->request('GET', '/delete/'.$entry->getId());
560 $this->assertEquals(404, $client->getResponse()->getStatusCode());
564 * It will create a new entry.
568 * And it'll check that user won't be redirected to the view page of the content when it had been removed
570 public function testViewAndDelete()
572 $this->logInAs('admin');
573 $client = $this->getClient();
575 $em = $client->getContainer()
576 ->get('doctrine.orm.entity_manager');
578 // add a new content to be removed later
580 ->getRepository('WallabagUserBundle:User')
581 ->findOneByUserName('admin');
583 $content = new Entry($user);
584 $content->setUrl('http://1.1.1.1/entry');
585 $content->setReadingTime(12);
586 $content->setDomainName('domain.io');
587 $content->setMimetype('text/html');
588 $content->setTitle('test title entry');
589 $content->setContent('This is my content /o/');
590 $content->setArchived(true);
591 $content->setLanguage('fr');
593 $em->persist($content);
596 $client->request('GET', '/view/'.$content->getId());
597 $this->assertEquals(200, $client->getResponse()->getStatusCode());
599 $client->request('GET', '/delete/'.$content->getId());
600 $this->assertEquals(302, $client->getResponse()->getStatusCode());
602 $client->followRedirect();
603 $this->assertEquals(200, $client->getResponse()->getStatusCode());
606 public function testViewOtherUserEntry()
608 $this->logInAs('admin');
609 $client = $this->getClient();
611 $content = $client->getContainer()
612 ->get('doctrine.orm.entity_manager')
613 ->getRepository('WallabagCoreBundle:Entry')
614 ->findOneByUsernameAndNotArchived('bob');
616 $client->request('GET', '/view/'.$content->getId());
618 $this->assertEquals(403, $client->getResponse()->getStatusCode());
621 public function testFilterOnReadingTime()
623 $this->logInAs('admin');
624 $this->useTheme('baggy');
625 $client = $this->getClient();
626 $entry = new Entry($this->getLoggedInUser());
627 $entry->setUrl($this->url
);
628 $entry->setReadingTime(22);
629 $this->getEntityManager()->persist($entry);
630 $this->getEntityManager()->flush();
632 $crawler = $client->request('GET', '/unread/list');
634 $form = $crawler->filter('button[id=submit-filter]')->form();
637 'entry_filter[readingTime][right_number]' => 22,
638 'entry_filter[readingTime][left_number]' => 22,
641 $crawler = $client->submit($form, $data);
643 $this->assertCount(1, $crawler->filter('div[class=entry]'));
646 public function testFilterOnReadingTimeWithNegativeValue()
648 $this->logInAs('admin');
649 $client = $this->getClient();
651 $crawler = $client->request('GET', '/unread/list');
653 $form = $crawler->filter('button[id=submit-filter]')->form();
656 'entry_filter[readingTime][right_number]' => -22,
657 'entry_filter[readingTime][left_number]' => -22,
660 $crawler = $client->submit($form, $data);
662 // forcing negative value results in no entry displayed
663 $this->assertCount(0, $crawler->filter('div[class=entry]'));
666 public function testFilterOnReadingTimeOnlyUpper()
668 $this->logInAs('admin');
669 $this->useTheme('baggy');
670 $client = $this->getClient();
672 $crawler = $client->request('GET', '/all/list');
673 $this->assertCount(5, $crawler->filter('div[class=entry]'));
675 $entry = new Entry($this->getLoggedInUser());
676 $entry->setUrl($this->url
);
677 $entry->setReadingTime(23);
678 $this->getEntityManager()->persist($entry);
679 $this->getEntityManager()->flush();
681 $crawler = $client->request('GET', '/all/list');
682 $this->assertCount(6, $crawler->filter('div[class=entry]'));
684 $form = $crawler->filter('button[id=submit-filter]')->form();
687 'entry_filter[readingTime][right_number]' => 22,
690 $crawler = $client->submit($form, $data);
692 $this->assertCount(5, $crawler->filter('div[class=entry]'));
695 public function testFilterOnReadingTimeOnlyLower()
697 $this->logInAs('admin');
698 $this->useTheme('baggy');
699 $client = $this->getClient();
701 $crawler = $client->request('GET', '/unread/list');
703 $form = $crawler->filter('button[id=submit-filter]')->form();
706 'entry_filter[readingTime][left_number]' => 22,
709 $crawler = $client->submit($form, $data);
711 $this->assertCount(0, $crawler->filter('div[class=entry]'));
713 $entry = new Entry($this->getLoggedInUser());
714 $entry->setUrl($this->url
);
715 $entry->setReadingTime(23);
716 $this->getEntityManager()->persist($entry);
717 $this->getEntityManager()->flush();
719 $crawler = $client->submit($form, $data);
720 $this->assertCount(1, $crawler->filter('div[class=entry]'));
723 public function testFilterOnUnreadStatus()
725 $this->logInAs('admin');
726 $this->useTheme('baggy');
727 $client = $this->getClient();
729 $crawler = $client->request('GET', '/all/list');
731 $form = $crawler->filter('button[id=submit-filter]')->form();
734 'entry_filter[isUnread]' => true,
737 $crawler = $client->submit($form, $data);
739 $this->assertCount(4, $crawler->filter('div[class=entry]'));
741 $entry = new Entry($this->getLoggedInUser());
742 $entry->setUrl($this->url
);
743 $entry->setArchived(false);
744 $this->getEntityManager()->persist($entry);
745 $this->getEntityManager()->flush();
747 $crawler = $client->submit($form, $data);
749 $this->assertCount(5, $crawler->filter('div[class=entry]'));
752 public function testFilterOnCreationDate()
754 $this->logInAs('admin');
755 $this->useTheme('baggy');
756 $client = $this->getClient();
758 $crawler = $client->request('GET', '/unread/list');
760 $form = $crawler->filter('button[id=submit-filter]')->form();
763 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
764 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')),
767 $crawler = $client->submit($form, $data);
769 $this->assertCount(5, $crawler->filter('div[class=entry]'));
772 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
773 'entry_filter[createdAt][right_date]' => date('d/m/Y'),
776 $crawler = $client->submit($form, $data);
778 $this->assertCount(5, $crawler->filter('div[class=entry]'));
781 'entry_filter[createdAt][left_date]' => '01/01/1970',
782 'entry_filter[createdAt][right_date]' => '01/01/1970',
785 $crawler = $client->submit($form, $data);
787 $this->assertCount(0, $crawler->filter('div[class=entry]'));
790 public function testPaginationWithFilter()
792 $this->logInAs('admin');
793 $client = $this->getClient();
794 $crawler = $client->request('GET', '/config');
796 $form = $crawler->filter('button[id=config_save]')->form();
799 'config[items_per_page]' => '1',
802 $client->submit($form, $data);
804 $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D=';
806 $client->request('GET', 'unread/list'.$parameters);
808 $this->assertContains($parameters, $client->getResponse()->getContent());
811 $crawler = $client->request('GET', '/config');
812 $form = $crawler->filter('button[id=config_save]')->form();
814 'config[items_per_page]' => '12',
816 $client->submit($form, $data);
819 public function testFilterOnDomainName()
821 $this->logInAs('admin');
822 $this->useTheme('baggy');
823 $client = $this->getClient();
825 $crawler = $client->request('GET', '/unread/list');
826 $form = $crawler->filter('button[id=submit-filter]')->form();
828 'entry_filter[domainName]' => 'domain',
831 $crawler = $client->submit($form, $data);
832 $this->assertCount(5, $crawler->filter('div[class=entry]'));
834 $crawler = $client->request('GET', '/unread/list');
835 $form = $crawler->filter('button[id=submit-filter]')->form();
837 'entry_filter[domainName]' => 'dOmain',
840 $crawler = $client->submit($form, $data);
841 $this->assertCount(5, $crawler->filter('div[class=entry]'));
843 $form = $crawler->filter('button[id=submit-filter]')->form();
845 'entry_filter[domainName]' => 'wallabag',
848 $crawler = $client->submit($form, $data);
849 $this->assertCount(0, $crawler->filter('div[class=entry]'));
852 public function testFilterOnStatus()
854 $this->logInAs('admin');
855 $this->useTheme('baggy');
856 $client = $this->getClient();
858 $crawler = $client->request('GET', '/unread/list');
859 $form = $crawler->filter('button[id=submit-filter]')->form();
860 $form['entry_filter[isArchived]']->tick();
861 $form['entry_filter[isStarred]']->untick();
863 $crawler = $client->submit($form);
864 $this->assertCount(1, $crawler->filter('div[class=entry]'));
866 $form = $crawler->filter('button[id=submit-filter]')->form();
867 $form['entry_filter[isArchived]']->untick();
868 $form['entry_filter[isStarred]']->tick();
870 $crawler = $client->submit($form);
871 $this->assertCount(1, $crawler->filter('div[class=entry]'));
874 public function testPreviewPictureFilter()
876 $this->logInAs('admin');
877 $this->useTheme('baggy');
878 $client = $this->getClient();
880 $crawler = $client->request('GET', '/unread/list');
881 $form = $crawler->filter('button[id=submit-filter]')->form();
882 $form['entry_filter[previewPicture]']->tick();
884 $crawler = $client->submit($form);
885 $this->assertCount(1, $crawler->filter('div[class=entry]'));
888 public function testFilterOnLanguage()
890 $this->logInAs('admin');
891 $this->useTheme('baggy');
892 $client = $this->getClient();
894 $entry = new Entry($this->getLoggedInUser());
895 $entry->setUrl($this->url
);
896 $entry->setLanguage('fr');
897 $this->getEntityManager()->persist($entry);
898 $this->getEntityManager()->flush();
900 $crawler = $client->request('GET', '/unread/list');
901 $form = $crawler->filter('button[id=submit-filter]')->form();
903 'entry_filter[language]' => 'fr',
906 $crawler = $client->submit($form, $data);
907 $this->assertCount(3, $crawler->filter('div[class=entry]'));
909 $form = $crawler->filter('button[id=submit-filter]')->form();
911 'entry_filter[language]' => 'en',
914 $crawler = $client->submit($form, $data);
915 $this->assertCount(2, $crawler->filter('div[class=entry]'));
918 public function testShareEntryPublicly()
920 $this->logInAs('admin');
921 $client = $this->getClient();
923 // sharing is enabled
924 $client->getContainer()->get('craue_config')->set('share_public', 1);
926 $content = new Entry($this->getLoggedInUser());
927 $content->setUrl($this->url
);
928 $this->getEntityManager()->persist($content);
929 $this->getEntityManager()->flush();
930 $this->getEntityManager()->clear();
933 $client->request('GET', '/share/'.$content->getUid());
934 $this->assertEquals(404, $client->getResponse()->getStatusCode());
936 // generating the uid
937 $client->request('GET', '/share/'.$content->getId());
938 $this->assertEquals(302, $client->getResponse()->getStatusCode());
940 // follow link with uid
941 $crawler = $client->followRedirect();
942 $this->assertEquals(200, $client->getResponse()->getStatusCode());
943 $this->assertContains('max-age=25200', $client->getResponse()->headers
->get('cache-control'));
944 $this->assertContains('public', $client->getResponse()->headers
->get('cache-control'));
945 $this->assertContains('s-maxage=25200', $client->getResponse()->headers
->get('cache-control'));
946 $this->assertNotContains('no-cache', $client->getResponse()->headers
->get('cache-control'));
947 $this->assertContains('og:title', $client->getResponse()->getContent());
948 $this->assertContains('og:type', $client->getResponse()->getContent());
949 $this->assertContains('og:url', $client->getResponse()->getContent());
950 $this->assertContains('og:image', $client->getResponse()->getContent());
952 // sharing is now disabled
953 $client->getContainer()->get('craue_config')->set('share_public', 0);
954 $client->request('GET', '/share/'.$content->getUid());
955 $this->assertEquals(404, $client->getResponse()->getStatusCode());
957 $client->request('GET', '/view/'.$content->getId());
958 $this->assertContains('no-cache', $client->getResponse()->headers
->get('cache-control'));
960 // removing the share
961 $client->request('GET', '/share/delete/'.$content->getId());
962 $this->assertEquals(302, $client->getResponse()->getStatusCode());
964 // share is now disable
965 $client->request('GET', '/share/'.$content->getUid());
966 $this->assertEquals(404, $client->getResponse()->getStatusCode());
969 public function testNewEntryWithDownloadImagesEnabled()
971 $this->downloadImagesEnabled
= true;
972 $this->logInAs('admin');
973 $client = $this->getClient();
975 $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route';
976 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
978 $crawler = $client->request('GET', '/new');
980 $this->assertEquals(200, $client->getResponse()->getStatusCode());
982 $form = $crawler->filter('form[name=entry]')->form();
985 'entry[url]' => $url,
988 $client->submit($form, $data);
990 $this->assertEquals(302, $client->getResponse()->getStatusCode());
992 $em = $client->getContainer()
993 ->get('doctrine.orm.entity_manager');
996 ->getRepository('WallabagCoreBundle:Entry')
997 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
999 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry);
1000 $this->assertEquals($url, $entry->getUrl());
1001 $this->assertContains('Perpignan', $entry->getTitle());
1002 // instead of checking for the filename (which might change) check that the image is now local
1003 $this->assertContains('http://v2.wallabag.org/assets/images/', $entry->getContent());
1005 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1009 * @depends testNewEntryWithDownloadImagesEnabled
1011 public function testRemoveEntryWithDownloadImagesEnabled()
1013 $this->downloadImagesEnabled
= true;
1014 $this->logInAs('admin');
1015 $client = $this->getClient();
1017 $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route';
1018 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
1020 $crawler = $client->request('GET', '/new');
1022 $this->assertEquals(200, $client->getResponse()->getStatusCode());
1024 $form = $crawler->filter('form[name=entry]')->form();
1027 'entry[url]' => $url,
1030 $client->submit($form, $data);
1032 $this->assertEquals(302, $client->getResponse()->getStatusCode());
1034 $content = $client->getContainer()
1035 ->get('doctrine.orm.entity_manager')
1036 ->getRepository('WallabagCoreBundle:Entry')
1037 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1039 $client->request('GET', '/delete/'.$content->getId());
1041 $this->assertEquals(302, $client->getResponse()->getStatusCode());
1043 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1046 public function testRedirectToHomepage()
1048 $this->logInAs('empty');
1049 $client = $this->getClient();
1051 // Redirect to homepage
1052 $config = $this->getLoggedInUser()->getConfig();
1053 $config->setActionMarkAsRead(Config
::REDIRECT_TO_HOMEPAGE
);
1054 $this->getEntityManager()->persist($config);
1056 $entry = new Entry($this->getLoggedInUser());
1057 $entry->setUrl($this->url
);
1058 $this->getEntityManager()->persist($entry);
1060 $this->getEntityManager()->flush();
1062 $client->request('GET', '/view/'.$entry->getId());
1063 $client->request('GET', '/archive/'.$entry->getId());
1065 $this->assertEquals(302, $client->getResponse()->getStatusCode());
1066 $this->assertEquals('/', $client->getResponse()->headers
->get('location'));
1069 public function testRedirectToCurrentPage()
1071 $this->logInAs('empty');
1072 $client = $this->getClient();
1074 // Redirect to current page
1075 $config = $this->getLoggedInUser()->getConfig();
1076 $config->setActionMarkAsRead(Config
::REDIRECT_TO_CURRENT_PAGE
);
1077 $this->getEntityManager()->persist($config);
1079 $entry = new Entry($this->getLoggedInUser());
1080 $entry->setUrl($this->url
);
1081 $this->getEntityManager()->persist($entry);
1083 $this->getEntityManager()->flush();
1085 $client->request('GET', '/view/'.$entry->getId());
1086 $client->request('GET', '/archive/'.$entry->getId());
1088 $this->assertEquals(302, $client->getResponse()->getStatusCode());
1089 $this->assertContains('/view/'.$entry->getId(), $client->getResponse()->headers
->get('location'));
1092 public function testFilterOnHttpStatus()
1094 $this->logInAs('admin');
1095 $this->useTheme('baggy');
1096 $client = $this->getClient();
1098 $entry = new Entry($this->getLoggedInUser());
1099 $entry->setUrl('http://www.lemonde.fr/incorrect-url/');
1100 $entry->setHttpStatus(404);
1101 $this->getEntityManager()->persist($entry);
1103 $this->getEntityManager()->flush();
1105 $crawler = $client->request('GET', '/all/list');
1106 $form = $crawler->filter('button[id=submit-filter]')->form();
1109 'entry_filter[httpStatus]' => 404,
1112 $crawler = $client->submit($form, $data);
1114 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1116 $entry = new Entry($this->getLoggedInUser());
1117 $entry->setUrl($this->url
);
1118 $entry->setHttpStatus(200);
1119 $this->getEntityManager()->persist($entry);
1121 $entry = new Entry($this->getLoggedInUser());
1122 $entry->setUrl('http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm');
1123 $entry->setHttpStatus(200);
1124 $this->getEntityManager()->persist($entry);
1126 $this->getEntityManager()->flush();
1128 $crawler = $client->request('GET', '/all/list');
1129 $form = $crawler->filter('button[id=submit-filter]')->form();
1132 'entry_filter[httpStatus]' => 200,
1135 $crawler = $client->submit($form, $data);
1137 $this->assertCount(2, $crawler->filter('div[class=entry]'));
1139 $crawler = $client->request('GET', '/all/list');
1140 $form = $crawler->filter('button[id=submit-filter]')->form();
1143 'entry_filter[httpStatus]' => 1024,
1146 $crawler = $client->submit($form, $data);
1148 $this->assertCount(8, $crawler->filter('div[class=entry]'));
1151 public function testSearch()
1153 $this->logInAs('admin');
1154 $this->useTheme('baggy');
1155 $client = $this->getClient();
1157 $entry = new Entry($this->getLoggedInUser());
1158 $entry->setUrl($this->url
);
1159 $entry->setTitle('test');
1160 $this->getEntityManager()->persist($entry);
1161 $this->getEntityManager()->flush();
1163 // Search on unread list
1164 $crawler = $client->request('GET', '/unread/list');
1166 $form = $crawler->filter('form[name=search]')->form();
1168 'search_entry[term]' => 'title',
1171 $crawler = $client->submit($form, $data);
1173 $this->assertCount(4, $crawler->filter('div[class=entry]'));
1175 // Search on starred list
1176 $crawler = $client->request('GET', '/starred/list');
1178 $entry = new Entry($this->getLoggedInUser());
1179 $entry->setUrl('http://localhost/foo/bar');
1180 $entry->setTitle('testeur');
1181 $entry->setStarred(true);
1182 $this->getEntityManager()->persist($entry);
1183 $this->getEntityManager()->flush();
1185 $form = $crawler->filter('form[name=search]')->form();
1187 'search_entry[term]' => 'testeur',
1190 $crawler = $client->submit($form, $data);
1192 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1194 $crawler = $client->request('GET', '/archive/list');
1196 // Added new article to test on archive list
1197 $entry = new Entry($this->getLoggedInUser());
1198 $entry->setUrl('http://0.0.0.0/foo/baz/qux');
1199 $entry->setTitle('Le manège');
1200 $entry->setArchived(true);
1201 $this->getEntityManager()->persist($entry);
1202 $this->getEntityManager()->flush();
1204 $form = $crawler->filter('form[name=search]')->form();
1206 'search_entry[term]' => 'manège',
1209 $crawler = $client->submit($form, $data);
1211 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1212 $client->request('GET', '/delete/'.$entry->getId());
1214 // test on list of all articles
1215 $crawler = $client->request('GET', '/all/list');
1217 $form = $crawler->filter('form[name=search]')->form();
1219 'search_entry[term]' => 'wxcvbnqsdf', // a string not available in the database
1222 $crawler = $client->submit($form, $data);
1224 $this->assertCount(0, $crawler->filter('div[class=entry]'));
1226 // test url search on list of all articles
1227 $entry = new Entry($this->getLoggedInUser());
1228 $entry->setUrl('http://domain/qux');
1229 $entry->setTitle('Le manège');
1230 $entry->setArchived(true);
1231 $this->getEntityManager()->persist($entry);
1232 $this->getEntityManager()->flush();
1234 $crawler = $client->request('GET', '/all/list');
1236 $form = $crawler->filter('form[name=search]')->form();
1238 'search_entry[term]' => 'domain', // the search will match an entry with 'domain' in its url
1241 $crawler = $client->submit($form, $data);
1243 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1245 // same as previous test but for case-sensitivity
1246 $crawler = $client->request('GET', '/all/list');
1248 $form = $crawler->filter('form[name=search]')->form();
1250 'search_entry[term]' => 'doMain', // the search will match an entry with 'domain' in its url
1253 $crawler = $client->submit($form, $data);
1255 $this->assertCount(1, $crawler->filter('div[class=entry]'));