3 namespace Tests\Wallabag\CoreBundle\Controller
;
5 use Tests\Wallabag\CoreBundle\WallabagCoreTestCase
;
6 use Wallabag\CoreBundle\Entity\Config
;
7 use Wallabag\CoreBundle\Entity\Entry
;
8 use Wallabag\CoreBundle\Entity\SiteCredential
;
10 class EntryControllerTest
extends WallabagCoreTestCase
12 const An_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE
= 'http://www.lemonde.fr/judo/article/2017/11/11/judo-la-decima-de-teddy-riner_5213605_1556020.html';
13 public $downloadImagesEnabled = false;
14 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';
19 * Ensure download_images_enabled is disabled after each script
21 public function tearDownImagesEnabled()
23 if ($this->downloadImagesEnabled
) {
24 $client = static::createClient();
25 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
27 $this->downloadImagesEnabled
= false;
31 public function testLogin()
33 $client = $this->getClient();
35 $client->request('GET', '/new');
37 $this->assertSame(302, $client->getResponse()->getStatusCode());
38 $this->assertContains('login', $client->getResponse()->headers
->get('location'));
41 public function testQuickstart()
43 $this->logInAs('empty');
44 $client = $this->getClient();
46 $client->request('GET', '/unread/list');
47 $this->assertSame(302, $client->getResponse()->getStatusCode());
48 $crawler = $client->followRedirect();
50 $this->assertSame(200, $client->getResponse()->getStatusCode());
51 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
52 $this->assertContains('quickstart.intro.title', $body[0]);
54 // Test if quickstart is disabled when user has 1 entry
55 $crawler = $client->request('GET', '/new');
57 $this->assertSame(200, $client->getResponse()->getStatusCode());
59 $form = $crawler->filter('form[name=entry]')->form();
62 'entry[url]' => $this->url
,
65 $client->submit($form, $data);
66 $this->assertSame(302, $client->getResponse()->getStatusCode());
67 $client->followRedirect();
69 $crawler = $client->request('GET', '/unread/list');
70 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
71 $this->assertContains('entry.list.number_on_the_page', $body[0]);
74 public function testGetNew()
76 $this->logInAs('admin');
77 $this->useTheme('baggy');
78 $client = $this->getClient();
80 $crawler = $client->request('GET', '/new');
82 $this->assertSame(200, $client->getResponse()->getStatusCode());
84 $this->assertCount(1, $crawler->filter('input[type=url]'));
85 $this->assertCount(1, $crawler->filter('form[name=entry]'));
88 public function testPostNewViaBookmarklet()
90 $this->logInAs('admin');
91 $this->useTheme('baggy');
92 $client = $this->getClient();
94 $crawler = $client->request('GET', '/');
96 $this->assertCount(4, $crawler->filter('div[class=entry]'));
99 $client->request('GET', '/bookmarklet', ['url' => $this->url
]);
100 $this->assertSame(302, $client->getResponse()->getStatusCode());
101 $client->followRedirect();
102 $crawler = $client->request('GET', '/');
103 $this->assertCount(5, $crawler->filter('div[class=entry]'));
105 $em = $client->getContainer()
106 ->get('doctrine.orm.entity_manager');
108 ->getRepository('WallabagCoreBundle:Entry')
109 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
114 public function testPostNewEmpty()
116 $this->logInAs('admin');
117 $client = $this->getClient();
119 $crawler = $client->request('GET', '/new');
121 $this->assertSame(200, $client->getResponse()->getStatusCode());
123 $form = $crawler->filter('form[name=entry]')->form();
125 $crawler = $client->submit($form);
127 $this->assertSame(200, $client->getResponse()->getStatusCode());
128 $this->assertCount(1, $alert = $crawler->filter('form ul li')->extract(['_text']));
129 $this->assertSame('This value should not be blank.', $alert[0]);
133 * This test will require an internet connection.
135 public function testPostNewOk()
137 $this->logInAs('admin');
138 $client = $this->getClient();
140 $client->getContainer()->get('craue_config')->set('store_article_headers', 1);
142 $crawler = $client->request('GET', '/new');
144 $this->assertSame(200, $client->getResponse()->getStatusCode());
146 $form = $crawler->filter('form[name=entry]')->form();
149 'entry[url]' => $this->url
,
152 $client->submit($form, $data);
154 $this->assertSame(302, $client->getResponse()->getStatusCode());
156 $content = $client->getContainer()
157 ->get('doctrine.orm.entity_manager')
158 ->getRepository('WallabagCoreBundle:Entry')
159 ->findByUrlAndUserId($this->url
, $this->getLoggedInUserId());
161 $author = $content->getPublishedBy();
163 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
164 $this->assertSame($this->url
, $content->getUrl());
165 $this->assertContains('Google', $content->getTitle());
166 $this->assertSame('fr', $content->getLanguage());
167 $this->assertSame('2015-03-28 11:43:19', $content->getPublishedAt()->format('Y-m-d H:i:s'));
168 $this->assertSame('Morgane Tual', $author[0]);
169 $this->assertArrayHasKey('x-varnish1', $content->getHeaders());
170 $client->getContainer()->get('craue_config')->set('store_article_headers', 0);
173 public function testPostWithMultipleAuthors()
175 $url = 'http://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768';
176 $this->logInAs('admin');
177 $client = $this->getClient();
179 $crawler = $client->request('GET', '/new');
181 $this->assertSame(200, $client->getResponse()->getStatusCode());
183 $form = $crawler->filter('form[name=entry]')->form();
186 'entry[url]' => $url,
189 $client->submit($form, $data);
191 $this->assertSame(302, $client->getResponse()->getStatusCode());
193 $content = $client->getContainer()
194 ->get('doctrine.orm.entity_manager')
195 ->getRepository('WallabagCoreBundle:Entry')
196 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
198 $authors = $content->getPublishedBy();
199 $this->assertSame('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s'));
200 $this->assertSame('fr', $content->getLanguage());
201 $this->assertSame('Raphaël Balenieri, correspondant à Pékin', $authors[0]);
202 $this->assertSame('Frédéric Autran, correspondant à New York', $authors[1]);
205 public function testPostNewOkUrlExist()
207 $this->logInAs('admin');
209 $entry = new Entry($this->getLoggedInUser());
210 $entry->setUrl($this->url
);
211 $this->getEntityManager()->persist($entry);
212 $this->getEntityManager()->flush();
214 $client = $this->getClient();
216 $crawler = $client->request('GET', '/new');
218 $this->assertSame(200, $client->getResponse()->getStatusCode());
220 $form = $crawler->filter('form[name=entry]')->form();
223 'entry[url]' => $this->url
,
226 $client->submit($form, $data);
228 $this->assertSame(302, $client->getResponse()->getStatusCode());
229 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
232 public function testPostNewOkUrlExistWithAccent()
234 $this->logInAs('admin');
235 $client = $this->getClient();
237 $url = 'http://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing';
239 $crawler = $client->request('GET', '/new');
241 $this->assertSame(200, $client->getResponse()->getStatusCode());
243 $form = $crawler->filter('form[name=entry]')->form();
246 'entry[url]' => $url,
249 $client->submit($form, $data);
251 $crawler = $client->request('GET', '/new');
253 $this->assertSame(200, $client->getResponse()->getStatusCode());
255 $form = $crawler->filter('form[name=entry]')->form();
258 'entry[url]' => $url,
261 $client->submit($form, $data);
263 $this->assertSame(302, $client->getResponse()->getStatusCode());
264 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
268 * This test will require an internet connection.
270 public function testPostNewThatWillBeTagged()
272 $this->logInAs('admin');
273 $client = $this->getClient();
275 $crawler = $client->request('GET', '/new');
277 $this->assertSame(200, $client->getResponse()->getStatusCode());
279 $form = $crawler->filter('form[name=entry]')->form();
282 'entry[url]' => $url = 'https://github.com/wallabag/wallabag',
285 $client->submit($form, $data);
287 $this->assertSame(302, $client->getResponse()->getStatusCode());
288 $this->assertContains('/', $client->getResponse()->getTargetUrl());
290 $em = $client->getContainer()
291 ->get('doctrine.orm.entity_manager');
293 ->getRepository('WallabagCoreBundle:Entry')
294 ->findOneByUrl($url);
295 $tags = $entry->getTags();
297 $this->assertCount(2, $tags);
298 $this->assertContains('wallabag', $tags);
299 $this->assertSame('en', $entry->getLanguage());
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->assertSame(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->assertSame(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->assertSame(200, $client->getResponse()->getStatusCode());
344 public function testUntagged()
346 $this->logInAs('admin');
347 $client = $this->getClient();
349 $client->request('GET', '/untagged/list');
351 $this->assertSame(200, $client->getResponse()->getStatusCode());
354 public function testStarred()
356 $this->logInAs('admin');
357 $client = $this->getClient();
359 $client->request('GET', '/starred/list');
361 $this->assertSame(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->assertSame(302, $client->getResponse()->getStatusCode());
372 $this->assertSame('/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->assertSame(200, $client->getResponse()->getStatusCode());
390 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
391 $this->assertContains($entry->getTitle(), $body[0]);
395 * This test will require an internet connection.
397 public function testReload()
399 $this->logInAs('admin');
400 $client = $this->getClient();
402 $entry = new Entry($this->getLoggedInUser());
403 $entry->setUrl($this->url
);
404 $entry->setTitle('title foo');
405 $entry->setContent('');
406 $this->getEntityManager()->persist($entry);
407 $this->getEntityManager()->flush();
408 $this->getEntityManager()->clear();
410 $client->request('GET', '/reload/' . $entry->getId());
412 $this->assertSame(302, $client->getResponse()->getStatusCode());
414 $entry = $this->getEntityManager()
415 ->getRepository('WallabagCoreBundle:Entry')
416 ->find($entry->getId());
418 $this->assertNotEmpty($entry->getContent());
421 public function testReloadWithFetchingFailed()
423 $this->logInAs('admin');
424 $client = $this->getClient();
426 $entry = new Entry($this->getLoggedInUser());
427 $entry->setUrl('http://0.0.0.0/failed.html');
428 $this->getEntityManager()->persist($entry);
429 $this->getEntityManager()->flush();
431 $client->request('GET', '/reload/' . $entry->getId());
433 $this->assertSame(302, $client->getResponse()->getStatusCode());
435 // force EntityManager to clear previous entity
436 // otherwise, retrieve the same entity will retrieve change from the previous request :0
437 $this->getEntityManager()->clear();
438 $newContent = $this->getEntityManager()
439 ->getRepository('WallabagCoreBundle:Entry')
440 ->find($entry->getId());
442 $this->assertNotSame($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent());
445 public function testEdit()
447 $this->logInAs('admin');
448 $client = $this->getClient();
450 $entry = new Entry($this->getLoggedInUser());
451 $entry->setUrl($this->url
);
452 $this->getEntityManager()->persist($entry);
453 $this->getEntityManager()->flush();
455 $crawler = $client->request('GET', '/edit/' . $entry->getId());
457 $this->assertSame(200, $client->getResponse()->getStatusCode());
459 $this->assertCount(1, $crawler->filter('input[id=entry_title]'));
460 $this->assertCount(1, $crawler->filter('button[id=entry_save]'));
463 public function testEditUpdate()
465 $this->logInAs('admin');
466 $client = $this->getClient();
468 $entry = new Entry($this->getLoggedInUser());
469 $entry->setUrl($this->url
);
470 $this->getEntityManager()->persist($entry);
471 $this->getEntityManager()->flush();
473 $crawler = $client->request('GET', '/edit/' . $entry->getId());
475 $this->assertSame(200, $client->getResponse()->getStatusCode());
477 $form = $crawler->filter('button[type=submit]')->form();
480 'entry[title]' => 'My updated title hehe :)',
483 $client->submit($form, $data);
485 $this->assertSame(302, $client->getResponse()->getStatusCode());
487 $crawler = $client->followRedirect();
489 $this->assertGreaterThan(1, $alert = $crawler->filter('div[id=article] h1')->extract(['_text']));
490 $this->assertContains('My updated title hehe :)', $alert[0]);
493 public function testToggleArchive()
495 $this->logInAs('admin');
496 $client = $this->getClient();
498 $entry = new Entry($this->getLoggedInUser());
499 $entry->setUrl($this->url
);
500 $this->getEntityManager()->persist($entry);
501 $this->getEntityManager()->flush();
502 $this->getEntityManager()->clear();
504 $client->request('GET', '/archive/' . $entry->getId());
506 $this->assertSame(302, $client->getResponse()->getStatusCode());
508 $res = $client->getContainer()
509 ->get('doctrine.orm.entity_manager')
510 ->getRepository('WallabagCoreBundle:Entry')
511 ->find($entry->getId());
513 $this->assertSame(1, $res->isArchived());
516 public function testToggleStar()
518 $this->logInAs('admin');
519 $client = $this->getClient();
521 $entry = new Entry($this->getLoggedInUser());
522 $entry->setUrl($this->url
);
523 $this->getEntityManager()->persist($entry);
524 $this->getEntityManager()->flush();
525 $this->getEntityManager()->clear();
527 $client->request('GET', '/star/' . $entry->getId());
529 $this->assertSame(302, $client->getResponse()->getStatusCode());
531 $res = $client->getContainer()
532 ->get('doctrine.orm.entity_manager')
533 ->getRepository('WallabagCoreBundle:Entry')
534 ->findOneById($entry->getId());
536 $this->assertSame(1, $res->isStarred());
539 public function testDelete()
541 $this->logInAs('admin');
542 $client = $this->getClient();
544 $entry = new Entry($this->getLoggedInUser());
545 $entry->setUrl($this->url
);
546 $this->getEntityManager()->persist($entry);
547 $this->getEntityManager()->flush();
549 $client->request('GET', '/delete/' . $entry->getId());
551 $this->assertSame(302, $client->getResponse()->getStatusCode());
553 $client->request('GET', '/delete/' . $entry->getId());
555 $this->assertSame(404, $client->getResponse()->getStatusCode());
559 * It will create a new entry.
563 * And it'll check that user won't be redirected to the view page of the content when it had been removed
565 public function testViewAndDelete()
567 $this->logInAs('admin');
568 $client = $this->getClient();
570 $em = $client->getContainer()
571 ->get('doctrine.orm.entity_manager');
573 // add a new content to be removed later
575 ->getRepository('WallabagUserBundle:User')
576 ->findOneByUserName('admin');
578 $content = new Entry($user);
579 $content->setUrl('http://1.1.1.1/entry');
580 $content->setReadingTime(12);
581 $content->setDomainName('domain.io');
582 $content->setMimetype('text/html');
583 $content->setTitle('test title entry');
584 $content->setContent('This is my content /o/');
585 $content->setArchived(true);
586 $content->setLanguage('fr');
588 $em->persist($content);
591 $client->request('GET', '/view/' . $content->getId());
592 $this->assertSame(200, $client->getResponse()->getStatusCode());
594 $client->request('GET', '/delete/' . $content->getId());
595 $this->assertSame(302, $client->getResponse()->getStatusCode());
597 $client->followRedirect();
598 $this->assertSame(200, $client->getResponse()->getStatusCode());
601 public function testViewOtherUserEntry()
603 $this->logInAs('admin');
604 $client = $this->getClient();
606 $content = $client->getContainer()
607 ->get('doctrine.orm.entity_manager')
608 ->getRepository('WallabagCoreBundle:Entry')
609 ->findOneByUsernameAndNotArchived('bob');
611 $client->request('GET', '/view/' . $content->getId());
613 $this->assertSame(403, $client->getResponse()->getStatusCode());
616 public function testFilterOnReadingTime()
618 $this->logInAs('admin');
619 $this->useTheme('baggy');
620 $client = $this->getClient();
621 $entry = new Entry($this->getLoggedInUser());
622 $entry->setUrl($this->url
);
623 $entry->setReadingTime(22);
624 $this->getEntityManager()->persist($entry);
625 $this->getEntityManager()->flush();
627 $crawler = $client->request('GET', '/unread/list');
629 $form = $crawler->filter('button[id=submit-filter]')->form();
632 'entry_filter[readingTime][right_number]' => 22,
633 'entry_filter[readingTime][left_number]' => 22,
636 $crawler = $client->submit($form, $data);
638 $this->assertCount(1, $crawler->filter('div[class=entry]'));
641 public function testFilterOnReadingTimeWithNegativeValue()
643 $this->logInAs('admin');
644 $client = $this->getClient();
646 $crawler = $client->request('GET', '/unread/list');
648 $form = $crawler->filter('button[id=submit-filter]')->form();
651 'entry_filter[readingTime][right_number]' => -22,
652 'entry_filter[readingTime][left_number]' => -22,
655 $crawler = $client->submit($form, $data);
657 // forcing negative value results in no entry displayed
658 $this->assertCount(0, $crawler->filter('div[class=entry]'));
661 public function testFilterOnReadingTimeOnlyUpper()
663 $this->logInAs('admin');
664 $this->useTheme('baggy');
665 $client = $this->getClient();
667 $crawler = $client->request('GET', '/all/list');
668 $this->assertCount(5, $crawler->filter('div[class=entry]'));
670 $entry = new Entry($this->getLoggedInUser());
671 $entry->setUrl($this->url
);
672 $entry->setReadingTime(23);
673 $this->getEntityManager()->persist($entry);
674 $this->getEntityManager()->flush();
676 $crawler = $client->request('GET', '/all/list');
677 $this->assertCount(6, $crawler->filter('div[class=entry]'));
679 $form = $crawler->filter('button[id=submit-filter]')->form();
682 'entry_filter[readingTime][right_number]' => 22,
685 $crawler = $client->submit($form, $data);
687 $this->assertCount(5, $crawler->filter('div[class=entry]'));
690 public function testFilterOnReadingTimeOnlyLower()
692 $this->logInAs('admin');
693 $this->useTheme('baggy');
694 $client = $this->getClient();
696 $crawler = $client->request('GET', '/unread/list');
698 $form = $crawler->filter('button[id=submit-filter]')->form();
701 'entry_filter[readingTime][left_number]' => 22,
704 $crawler = $client->submit($form, $data);
706 $this->assertCount(0, $crawler->filter('div[class=entry]'));
708 $entry = new Entry($this->getLoggedInUser());
709 $entry->setUrl($this->url
);
710 $entry->setReadingTime(23);
711 $this->getEntityManager()->persist($entry);
712 $this->getEntityManager()->flush();
714 $crawler = $client->submit($form, $data);
715 $this->assertCount(1, $crawler->filter('div[class=entry]'));
718 public function testFilterOnUnreadStatus()
720 $this->logInAs('admin');
721 $this->useTheme('baggy');
722 $client = $this->getClient();
724 $crawler = $client->request('GET', '/all/list');
726 $form = $crawler->filter('button[id=submit-filter]')->form();
729 'entry_filter[isUnread]' => true,
732 $crawler = $client->submit($form, $data);
734 $this->assertCount(4, $crawler->filter('div[class=entry]'));
736 $entry = new Entry($this->getLoggedInUser());
737 $entry->setUrl($this->url
);
738 $entry->setArchived(false);
739 $this->getEntityManager()->persist($entry);
740 $this->getEntityManager()->flush();
742 $crawler = $client->submit($form, $data);
744 $this->assertCount(5, $crawler->filter('div[class=entry]'));
747 public function testFilterOnCreationDate()
749 $this->logInAs('admin');
750 $this->useTheme('baggy');
751 $client = $this->getClient();
753 $crawler = $client->request('GET', '/unread/list');
755 $form = $crawler->filter('button[id=submit-filter]')->form();
758 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
759 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')),
762 $crawler = $client->submit($form, $data);
764 $this->assertCount(5, $crawler->filter('div[class=entry]'));
767 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
768 'entry_filter[createdAt][right_date]' => date('d/m/Y'),
771 $crawler = $client->submit($form, $data);
773 $this->assertCount(5, $crawler->filter('div[class=entry]'));
776 'entry_filter[createdAt][left_date]' => '01/01/1970',
777 'entry_filter[createdAt][right_date]' => '01/01/1970',
780 $crawler = $client->submit($form, $data);
782 $this->assertCount(0, $crawler->filter('div[class=entry]'));
785 public function testPaginationWithFilter()
787 $this->logInAs('admin');
788 $client = $this->getClient();
789 $crawler = $client->request('GET', '/config');
791 $form = $crawler->filter('button[id=config_save]')->form();
794 'config[items_per_page]' => '1',
797 $client->submit($form, $data);
799 $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D=';
801 $client->request('GET', 'unread/list' . $parameters);
803 $this->assertContains($parameters, $client->getResponse()->getContent());
806 $crawler = $client->request('GET', '/config');
807 $form = $crawler->filter('button[id=config_save]')->form();
809 'config[items_per_page]' => '12',
811 $client->submit($form, $data);
814 public function testFilterOnDomainName()
816 $this->logInAs('admin');
817 $this->useTheme('baggy');
818 $client = $this->getClient();
820 $crawler = $client->request('GET', '/unread/list');
821 $form = $crawler->filter('button[id=submit-filter]')->form();
823 'entry_filter[domainName]' => 'domain',
826 $crawler = $client->submit($form, $data);
827 $this->assertCount(5, $crawler->filter('div[class=entry]'));
829 $crawler = $client->request('GET', '/unread/list');
830 $form = $crawler->filter('button[id=submit-filter]')->form();
832 'entry_filter[domainName]' => 'dOmain',
835 $crawler = $client->submit($form, $data);
836 $this->assertCount(5, $crawler->filter('div[class=entry]'));
838 $form = $crawler->filter('button[id=submit-filter]')->form();
840 'entry_filter[domainName]' => 'wallabag',
843 $crawler = $client->submit($form, $data);
844 $this->assertCount(0, $crawler->filter('div[class=entry]'));
847 public function testFilterOnStatus()
849 $this->logInAs('admin');
850 $this->useTheme('baggy');
851 $client = $this->getClient();
853 $crawler = $client->request('GET', '/unread/list');
854 $form = $crawler->filter('button[id=submit-filter]')->form();
855 $form['entry_filter[isArchived]']->tick();
856 $form['entry_filter[isStarred]']->untick();
858 $crawler = $client->submit($form);
859 $this->assertCount(1, $crawler->filter('div[class=entry]'));
861 $form = $crawler->filter('button[id=submit-filter]')->form();
862 $form['entry_filter[isArchived]']->untick();
863 $form['entry_filter[isStarred]']->tick();
865 $crawler = $client->submit($form);
866 $this->assertCount(1, $crawler->filter('div[class=entry]'));
869 public function testFilterOnIsPublic()
871 $this->logInAs('admin');
872 $this->useTheme('baggy');
873 $client = $this->getClient();
875 $crawler = $client->request('GET', '/unread/list');
876 $form = $crawler->filter('button[id=submit-filter]')->form();
877 $form['entry_filter[isPublic]']->tick();
879 $crawler = $client->submit($form);
880 $this->assertCount(0, $crawler->filter('div[class=entry]'));
883 public function testPreviewPictureFilter()
885 $this->logInAs('admin');
886 $this->useTheme('baggy');
887 $client = $this->getClient();
889 $crawler = $client->request('GET', '/unread/list');
890 $form = $crawler->filter('button[id=submit-filter]')->form();
891 $form['entry_filter[previewPicture]']->tick();
893 $crawler = $client->submit($form);
894 $this->assertCount(1, $crawler->filter('div[class=entry]'));
897 public function testFilterOnLanguage()
899 $this->logInAs('admin');
900 $this->useTheme('baggy');
901 $client = $this->getClient();
903 $entry = new Entry($this->getLoggedInUser());
904 $entry->setUrl($this->url
);
905 $entry->setLanguage('fr');
906 $this->getEntityManager()->persist($entry);
907 $this->getEntityManager()->flush();
909 $crawler = $client->request('GET', '/unread/list');
910 $form = $crawler->filter('button[id=submit-filter]')->form();
912 'entry_filter[language]' => 'fr',
915 $crawler = $client->submit($form, $data);
916 $this->assertCount(3, $crawler->filter('div[class=entry]'));
918 $form = $crawler->filter('button[id=submit-filter]')->form();
920 'entry_filter[language]' => 'en',
923 $crawler = $client->submit($form, $data);
924 $this->assertCount(2, $crawler->filter('div[class=entry]'));
927 public function testShareEntryPublicly()
929 $this->logInAs('admin');
930 $client = $this->getClient();
932 // sharing is enabled
933 $client->getContainer()->get('craue_config')->set('share_public', 1);
935 $content = new Entry($this->getLoggedInUser());
936 $content->setUrl($this->url
);
937 $this->getEntityManager()->persist($content);
938 $this->getEntityManager()->flush();
939 $this->getEntityManager()->clear();
942 $client->request('GET', '/share/' . $content->getUid());
943 $this->assertSame(404, $client->getResponse()->getStatusCode());
945 // generating the uid
946 $client->request('GET', '/share/' . $content->getId());
947 $this->assertSame(302, $client->getResponse()->getStatusCode());
949 // follow link with uid
950 $crawler = $client->followRedirect();
951 $this->assertSame(200, $client->getResponse()->getStatusCode());
952 $this->assertContains('max-age=25200', $client->getResponse()->headers
->get('cache-control'));
953 $this->assertContains('public', $client->getResponse()->headers
->get('cache-control'));
954 $this->assertContains('s-maxage=25200', $client->getResponse()->headers
->get('cache-control'));
955 $this->assertNotContains('no-cache', $client->getResponse()->headers
->get('cache-control'));
956 $this->assertContains('og:title', $client->getResponse()->getContent());
957 $this->assertContains('og:type', $client->getResponse()->getContent());
958 $this->assertContains('og:url', $client->getResponse()->getContent());
959 $this->assertContains('og:image', $client->getResponse()->getContent());
961 // sharing is now disabled
962 $client->getContainer()->get('craue_config')->set('share_public', 0);
963 $client->request('GET', '/share/' . $content->getUid());
964 $this->assertSame(404, $client->getResponse()->getStatusCode());
966 $client->request('GET', '/view/' . $content->getId());
967 $this->assertContains('no-cache', $client->getResponse()->headers
->get('cache-control'));
969 // removing the share
970 $client->request('GET', '/share/delete/' . $content->getId());
971 $this->assertSame(302, $client->getResponse()->getStatusCode());
973 // share is now disable
974 $client->request('GET', '/share/' . $content->getUid());
975 $this->assertSame(404, $client->getResponse()->getStatusCode());
978 public function testNewEntryWithDownloadImagesEnabled()
980 $this->downloadImagesEnabled
= true;
981 $this->logInAs('admin');
982 $client = $this->getClient();
984 $url = self
::An_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE
;
985 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
987 $crawler = $client->request('GET', '/new');
989 $this->assertSame(200, $client->getResponse()->getStatusCode());
991 $form = $crawler->filter('form[name=entry]')->form();
994 'entry[url]' => $url,
997 $client->submit($form, $data);
999 $this->assertSame(302, $client->getResponse()->getStatusCode());
1001 $em = $client->getContainer()
1002 ->get('doctrine.orm.entity_manager');
1005 ->getRepository('WallabagCoreBundle:Entry')
1006 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1008 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry);
1009 $this->assertSame($url, $entry->getUrl());
1010 $this->assertContains('Judo', $entry->getTitle());
1011 // instead of checking for the filename (which might change) check that the image is now local
1012 $this->assertContains(rtrim($client->getContainer()->getParameter('domain_name'), '/') . '/assets/images/', $entry->getContent());
1014 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1018 * @depends testNewEntryWithDownloadImagesEnabled
1020 public function testRemoveEntryWithDownloadImagesEnabled()
1022 $this->downloadImagesEnabled
= true;
1023 $this->logInAs('admin');
1024 $client = $this->getClient();
1026 $url = self
::An_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE
;
1027 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
1029 $crawler = $client->request('GET', '/new');
1031 $this->assertSame(200, $client->getResponse()->getStatusCode());
1033 $form = $crawler->filter('form[name=entry]')->form();
1036 'entry[url]' => $url,
1039 $client->submit($form, $data);
1041 $this->assertSame(302, $client->getResponse()->getStatusCode());
1043 $content = $client->getContainer()
1044 ->get('doctrine.orm.entity_manager')
1045 ->getRepository('WallabagCoreBundle:Entry')
1046 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1048 $client->request('GET', '/delete/' . $content->getId());
1050 $this->assertSame(302, $client->getResponse()->getStatusCode());
1052 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1055 public function testRedirectToHomepage()
1057 $this->logInAs('empty');
1058 $client = $this->getClient();
1060 // Redirect to homepage
1061 $config = $this->getLoggedInUser()->getConfig();
1062 $config->setActionMarkAsRead(Config
::REDIRECT_TO_HOMEPAGE
);
1063 $this->getEntityManager()->persist($config);
1065 $entry = new Entry($this->getLoggedInUser());
1066 $entry->setUrl($this->url
);
1067 $this->getEntityManager()->persist($entry);
1069 $this->getEntityManager()->flush();
1071 $client->request('GET', '/view/' . $entry->getId());
1072 $client->request('GET', '/archive/' . $entry->getId());
1074 $this->assertSame(302, $client->getResponse()->getStatusCode());
1075 $this->assertSame('/', $client->getResponse()->headers
->get('location'));
1078 public function testRedirectToCurrentPage()
1080 $this->logInAs('empty');
1081 $client = $this->getClient();
1083 // Redirect to current page
1084 $config = $this->getLoggedInUser()->getConfig();
1085 $config->setActionMarkAsRead(Config
::REDIRECT_TO_CURRENT_PAGE
);
1086 $this->getEntityManager()->persist($config);
1088 $entry = new Entry($this->getLoggedInUser());
1089 $entry->setUrl($this->url
);
1090 $this->getEntityManager()->persist($entry);
1092 $this->getEntityManager()->flush();
1094 $client->request('GET', '/view/' . $entry->getId());
1095 $client->request('GET', '/archive/' . $entry->getId());
1097 $this->assertSame(302, $client->getResponse()->getStatusCode());
1098 $this->assertContains('/view/' . $entry->getId(), $client->getResponse()->headers
->get('location'));
1101 public function testFilterOnHttpStatus()
1103 $this->logInAs('admin');
1104 $this->useTheme('baggy');
1105 $client = $this->getClient();
1107 $entry = new Entry($this->getLoggedInUser());
1108 $entry->setUrl('http://www.lemonde.fr/incorrect-url/');
1109 $entry->setHttpStatus(404);
1110 $this->getEntityManager()->persist($entry);
1112 $this->getEntityManager()->flush();
1114 $crawler = $client->request('GET', '/all/list');
1115 $form = $crawler->filter('button[id=submit-filter]')->form();
1118 'entry_filter[httpStatus]' => 404,
1121 $crawler = $client->submit($form, $data);
1123 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1125 $entry = new Entry($this->getLoggedInUser());
1126 $entry->setUrl($this->url
);
1127 $entry->setHttpStatus(200);
1128 $this->getEntityManager()->persist($entry);
1130 $entry = new Entry($this->getLoggedInUser());
1131 $entry->setUrl('http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm');
1132 $entry->setHttpStatus(200);
1133 $this->getEntityManager()->persist($entry);
1135 $this->getEntityManager()->flush();
1137 $crawler = $client->request('GET', '/all/list');
1138 $form = $crawler->filter('button[id=submit-filter]')->form();
1141 'entry_filter[httpStatus]' => 200,
1144 $crawler = $client->submit($form, $data);
1146 $this->assertCount(2, $crawler->filter('div[class=entry]'));
1148 $crawler = $client->request('GET', '/all/list');
1149 $form = $crawler->filter('button[id=submit-filter]')->form();
1152 'entry_filter[httpStatus]' => 1024,
1155 $crawler = $client->submit($form, $data);
1157 $this->assertCount(8, $crawler->filter('div[class=entry]'));
1160 public function testSearch()
1162 $this->logInAs('admin');
1163 $this->useTheme('baggy');
1164 $client = $this->getClient();
1166 $entry = new Entry($this->getLoggedInUser());
1167 $entry->setUrl($this->url
);
1168 $entry->setTitle('test');
1169 $this->getEntityManager()->persist($entry);
1170 $this->getEntityManager()->flush();
1172 // Search on unread list
1173 $crawler = $client->request('GET', '/unread/list');
1175 $form = $crawler->filter('form[name=search]')->form();
1177 'search_entry[term]' => 'title',
1180 $crawler = $client->submit($form, $data);
1182 $this->assertCount(4, $crawler->filter('div[class=entry]'));
1184 // Search on starred list
1185 $crawler = $client->request('GET', '/starred/list');
1187 $entry = new Entry($this->getLoggedInUser());
1188 $entry->setUrl('http://localhost/foo/bar');
1189 $entry->setTitle('testeur');
1190 $entry->setStarred(true);
1191 $this->getEntityManager()->persist($entry);
1192 $this->getEntityManager()->flush();
1194 $form = $crawler->filter('form[name=search]')->form();
1196 'search_entry[term]' => 'testeur',
1199 $crawler = $client->submit($form, $data);
1201 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1203 $crawler = $client->request('GET', '/archive/list');
1205 // Added new article to test on archive list
1206 $entry = new Entry($this->getLoggedInUser());
1207 $entry->setUrl('http://0.0.0.0/foo/baz/qux');
1208 $entry->setTitle('Le manège');
1209 $entry->setArchived(true);
1210 $this->getEntityManager()->persist($entry);
1211 $this->getEntityManager()->flush();
1213 $form = $crawler->filter('form[name=search]')->form();
1215 'search_entry[term]' => 'manège',
1218 $crawler = $client->submit($form, $data);
1220 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1221 $client->request('GET', '/delete/' . $entry->getId());
1223 // test on list of all articles
1224 $crawler = $client->request('GET', '/all/list');
1226 $form = $crawler->filter('form[name=search]')->form();
1228 'search_entry[term]' => 'wxcvbnqsdf', // a string not available in the database
1231 $crawler = $client->submit($form, $data);
1233 $this->assertCount(0, $crawler->filter('div[class=entry]'));
1235 // test url search on list of all articles
1236 $entry = new Entry($this->getLoggedInUser());
1237 $entry->setUrl('http://domain/qux');
1238 $entry->setTitle('Le manège');
1239 $entry->setArchived(true);
1240 $this->getEntityManager()->persist($entry);
1241 $this->getEntityManager()->flush();
1243 $crawler = $client->request('GET', '/all/list');
1245 $form = $crawler->filter('form[name=search]')->form();
1247 'search_entry[term]' => 'domain', // the search will match an entry with 'domain' in its url
1250 $crawler = $client->submit($form, $data);
1252 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1254 // same as previous test but for case-sensitivity
1255 $crawler = $client->request('GET', '/all/list');
1257 $form = $crawler->filter('form[name=search]')->form();
1259 'search_entry[term]' => 'doMain', // the search will match an entry with 'domain' in its url
1262 $crawler = $client->submit($form, $data);
1264 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1267 public function dataForLanguage()
1271 'https://www.pravda.ru/world/09-06-2017/1337283-qatar-0/',
1275 'https://www.zataz.com/90-des-dossiers-medicaux-des-coreens-du-sud-vendus-a-des-entreprises-privees/',
1279 'http://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html',
1283 'http://www.ansa.it/sito/notizie/mondo/europa/2017/06/08/voto-gb-seggi-aperti-misure-sicurezza-rafforzate_0cb71f7f-e23b-4d5f-95ca-bc12296419f0.html',
1287 'http://www.hao123.com/shequ?__noscript__-=1',
1291 'https://buy.garmin.com/de-AT/AT/catalog/product/compareResult.ep?compareProduct=112885&compareProduct=36728',
1295 'http://netler.ru/ikt/windows-error-reporting.htm',
1299 'http://precodoscombustiveis.com.br/postos/cidade/4121/pr/maringa',
1302 'fucked_list_of_languages' => [
1303 'http://geocatalog.webservice-energy.org/geonetwork/srv/eng/main.home',
1307 'https://www.muylinux.com/2015/04/17/odf-reino-unido-microsoft-google/',
1314 * @dataProvider dataForLanguage
1316 public function testLanguageValidation($url, $expectedLanguage)
1318 $this->logInAs('admin');
1319 $client = $this->getClient();
1321 $crawler = $client->request('GET', '/new');
1323 $this->assertSame(200, $client->getResponse()->getStatusCode());
1325 $form = $crawler->filter('form[name=entry]')->form();
1328 'entry[url]' => $url,
1331 $client->submit($form, $data);
1333 $this->assertSame(302, $client->getResponse()->getStatusCode());
1335 $content = $client->getContainer()
1336 ->get('doctrine.orm.entity_manager')
1337 ->getRepository('WallabagCoreBundle:Entry')
1338 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1340 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1341 $this->assertSame($url, $content->getUrl());
1342 $this->assertSame($expectedLanguage, $content->getLanguage());
1346 * This test will require an internet connection.
1348 public function testRestrictedArticle()
1350 $url = 'https://www.monde-diplomatique.fr/2017/05/BONNET/57475';
1351 $this->logInAs('admin');
1352 $client = $this->getClient();
1353 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
1355 // enable restricted access
1356 $client->getContainer()->get('craue_config')->set('restricted_access', 1);
1358 // create a new site_credential
1359 $user = $client->getContainer()->get('security.token_storage')->getToken()->getUser();
1360 $credential = new SiteCredential($user);
1361 $credential->setHost('monde-diplomatique.fr');
1362 $credential->setUsername($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('foo'));
1363 $credential->setPassword($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('bar'));
1365 $em->persist($credential);
1368 $crawler = $client->request('GET', '/new');
1370 $this->assertSame(200, $client->getResponse()->getStatusCode());
1372 $form = $crawler->filter('form[name=entry]')->form();
1375 'entry[url]' => $url,
1378 $client->submit($form, $data);
1380 $this->assertSame(302, $client->getResponse()->getStatusCode());
1382 $crawler = $client->followRedirect();
1384 $this->assertSame(200, $client->getResponse()->getStatusCode());
1385 $this->assertContains('flashes.entry.notice.entry_saved', $crawler->filter('body')->extract(['_text'])[0]);
1388 ->getRepository('WallabagCoreBundle:Entry')
1389 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1391 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1392 $this->assertSame('Crimes et réformes aux Philippines', $content->getTitle());
1394 $client->getContainer()->get('craue_config')->set('restricted_access', 0);