]> git.immae.eu Git - github/wallabag/wallabag.git/blob - tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
tests: replace baggy theme used in EntryController tests
[github/wallabag/wallabag.git] / tests / Wallabag / CoreBundle / Controller / EntryControllerTest.php
1 <?php
2
3 namespace Tests\Wallabag\CoreBundle\Controller;
4
5 use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6 use Wallabag\CoreBundle\Entity\Config;
7 use Wallabag\CoreBundle\Entity\Entry;
8 use Wallabag\CoreBundle\Entity\SiteCredential;
9 use Wallabag\CoreBundle\Entity\Tag;
10 use Wallabag\CoreBundle\Helper\ContentProxy;
11
12 class EntryControllerTest extends WallabagCoreTestCase
13 {
14 const AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE = 'https://www.lemonde.fr/judo/article/2017/11/11/judo-la-decima-de-teddy-riner_5213605_1556020.html';
15 public $downloadImagesEnabled = false;
16 public $url = 'https://www.lemonde.fr/pixels/article/2019/06/18/ce-qu-il-faut-savoir-sur-le-libra-la-cryptomonnaie-de-facebook_5477887_4408996.html';
17
18 /**
19 * @after
20 *
21 * Ensure download_images_enabled is disabled after each script
22 */
23 public function tearDownImagesEnabled()
24 {
25 if ($this->downloadImagesEnabled) {
26 $client = static::createClient();
27 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
28
29 $this->downloadImagesEnabled = false;
30 }
31 }
32
33 public function testLogin()
34 {
35 $client = $this->getClient();
36
37 $client->request('GET', '/new');
38
39 $this->assertSame(302, $client->getResponse()->getStatusCode());
40 $this->assertContains('login', $client->getResponse()->headers->get('location'));
41 }
42
43 public function testQuickstart()
44 {
45 $this->logInAs('empty');
46 $client = $this->getClient();
47
48 $client->request('GET', '/unread/list');
49 $this->assertSame(302, $client->getResponse()->getStatusCode());
50 $crawler = $client->followRedirect();
51
52 $this->assertSame(200, $client->getResponse()->getStatusCode());
53 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
54 $this->assertContains('quickstart.intro.title', $body[0]);
55
56 // Test if quickstart is disabled when user has 1 entry
57 $crawler = $client->request('GET', '/new');
58
59 $this->assertSame(200, $client->getResponse()->getStatusCode());
60
61 $form = $crawler->filter('form[name=entry]')->form();
62
63 $data = [
64 'entry[url]' => $this->url,
65 ];
66
67 $client->submit($form, $data);
68 $this->assertSame(302, $client->getResponse()->getStatusCode());
69 $client->followRedirect();
70
71 $crawler = $client->request('GET', '/unread/list');
72 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
73 $this->assertContains('entry.list.number_on_the_page', $body[0]);
74 }
75
76 public function testGetNew()
77 {
78 $this->logInAs('admin');
79 $this->useTheme('baggy');
80 $client = $this->getClient();
81
82 $crawler = $client->request('GET', '/new');
83
84 $this->assertSame(200, $client->getResponse()->getStatusCode());
85
86 $this->assertCount(1, $crawler->filter('input[type=url]'));
87 $this->assertCount(1, $crawler->filter('form[name=entry]'));
88 }
89
90 public function testPostNewViaBookmarklet()
91 {
92 $this->logInAs('admin');
93 $client = $this->getClient();
94
95 $crawler = $client->request('GET', '/');
96
97 $this->assertCount(4, $crawler->filter('li.entry'));
98
99 // Good URL
100 $client->request('GET', '/bookmarklet', ['url' => $this->url]);
101 $this->assertSame(302, $client->getResponse()->getStatusCode());
102 $client->followRedirect();
103 $crawler = $client->request('GET', '/');
104 $this->assertCount(5, $crawler->filter('li.entry'));
105
106 $em = $client->getContainer()
107 ->get('doctrine.orm.entity_manager');
108 $entry = $em
109 ->getRepository('WallabagCoreBundle:Entry')
110 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
111 $em->remove($entry);
112 $em->flush();
113 }
114
115 public function testPostNewEmpty()
116 {
117 $this->logInAs('admin');
118 $client = $this->getClient();
119
120 $crawler = $client->request('GET', '/new');
121
122 $this->assertSame(200, $client->getResponse()->getStatusCode());
123
124 $form = $crawler->filter('form[name=entry]')->form();
125
126 $crawler = $client->submit($form);
127
128 $this->assertSame(200, $client->getResponse()->getStatusCode());
129 $this->assertCount(1, $alert = $crawler->filter('form ul li')->extract(['_text']));
130 $this->assertSame('This value should not be blank.', $alert[0]);
131 }
132
133 /**
134 * This test will require an internet connection.
135 */
136 public function testPostNewOk()
137 {
138 $this->logInAs('admin');
139 $client = $this->getClient();
140
141 $client->getContainer()->get('craue_config')->set('store_article_headers', 1);
142
143 $crawler = $client->request('GET', '/new');
144
145 $this->assertSame(200, $client->getResponse()->getStatusCode());
146
147 $form = $crawler->filter('form[name=entry]')->form();
148
149 $data = [
150 'entry[url]' => $this->url,
151 ];
152
153 $client->submit($form, $data);
154
155 $this->assertSame(302, $client->getResponse()->getStatusCode());
156
157 $content = $client->getContainer()
158 ->get('doctrine.orm.entity_manager')
159 ->getRepository('WallabagCoreBundle:Entry')
160 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
161
162 $author = $content->getPublishedBy();
163
164 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
165 $this->assertSame($this->url, $content->getUrl());
166 $this->assertContains('la cryptomonnaie de Facebook', $content->getTitle());
167 $this->assertSame('fr', $content->getLanguage());
168 $this->assertArrayHasKey('x-frame-options', $content->getHeaders());
169 $client->getContainer()->get('craue_config')->set('store_article_headers', 0);
170 }
171
172 public function testPostWithMultipleAuthors()
173 {
174 $url = 'https://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768';
175 $this->logInAs('admin');
176 $client = $this->getClient();
177
178 $crawler = $client->request('GET', '/new');
179
180 $this->assertSame(200, $client->getResponse()->getStatusCode());
181
182 $form = $crawler->filter('form[name=entry]')->form();
183
184 $data = [
185 'entry[url]' => $url,
186 ];
187
188 $client->submit($form, $data);
189
190 $this->assertSame(302, $client->getResponse()->getStatusCode());
191
192 $content = $client->getContainer()
193 ->get('doctrine.orm.entity_manager')
194 ->getRepository('WallabagCoreBundle:Entry')
195 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
196
197 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
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', $authors[0]);
202 $this->assertSame('Frédéric Autran', $authors[1]);
203 }
204
205 public function testPostNewOkUrlExist()
206 {
207 $this->logInAs('admin');
208
209 $entry = new Entry($this->getLoggedInUser());
210 $entry->setUrl($this->url);
211 $this->getEntityManager()->persist($entry);
212 $this->getEntityManager()->flush();
213
214 $client = $this->getClient();
215
216 $crawler = $client->request('GET', '/new');
217
218 $this->assertSame(200, $client->getResponse()->getStatusCode());
219
220 $form = $crawler->filter('form[name=entry]')->form();
221
222 $data = [
223 'entry[url]' => $this->url,
224 ];
225
226 $client->submit($form, $data);
227
228 $this->assertSame(302, $client->getResponse()->getStatusCode());
229 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
230 }
231
232 public function testPostNewOkUrlExistWithAccent()
233 {
234 $this->logInAs('admin');
235 $client = $this->getClient();
236
237 $url = 'https://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing';
238
239 $crawler = $client->request('GET', '/new');
240
241 $this->assertSame(200, $client->getResponse()->getStatusCode());
242
243 $form = $crawler->filter('form[name=entry]')->form();
244
245 $data = [
246 'entry[url]' => $url,
247 ];
248
249 $client->submit($form, $data);
250
251 $crawler = $client->request('GET', '/new');
252
253 $this->assertSame(200, $client->getResponse()->getStatusCode());
254
255 $form = $crawler->filter('form[name=entry]')->form();
256
257 $data = [
258 'entry[url]' => $url,
259 ];
260
261 $client->submit($form, $data);
262
263 $this->assertSame(302, $client->getResponse()->getStatusCode());
264 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
265 }
266
267 /**
268 * This test will require an internet connection.
269 */
270 public function testPostNewOkUrlExistWithRedirection()
271 {
272 $this->logInAs('admin');
273 $client = $this->getClient();
274
275 $url = 'https://wllbg.org/test-redirect/c51c';
276
277 $crawler = $client->request('GET', '/new');
278
279 $this->assertSame(200, $client->getResponse()->getStatusCode());
280
281 $form = $crawler->filter('form[name=entry]')->form();
282
283 $data = [
284 'entry[url]' => $url,
285 ];
286
287 $client->submit($form, $data);
288
289 $crawler = $client->request('GET', '/new');
290
291 $this->assertSame(200, $client->getResponse()->getStatusCode());
292
293 $form = $crawler->filter('form[name=entry]')->form();
294
295 $data = [
296 'entry[url]' => $url,
297 ];
298
299 $client->submit($form, $data);
300
301 $this->assertSame(302, $client->getResponse()->getStatusCode());
302 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
303 }
304
305 /**
306 * This test will require an internet connection.
307 */
308 public function testPostNewThatWillBeTagged()
309 {
310 $this->logInAs('admin');
311 $client = $this->getClient();
312
313 $crawler = $client->request('GET', '/new');
314
315 $this->assertSame(200, $client->getResponse()->getStatusCode());
316
317 $form = $crawler->filter('form[name=entry]')->form();
318
319 $data = [
320 'entry[url]' => $url = 'https://github.com/wallabag/wallabag',
321 ];
322
323 $client->submit($form, $data);
324
325 $this->assertSame(302, $client->getResponse()->getStatusCode());
326 $this->assertContains('/', $client->getResponse()->getTargetUrl());
327
328 $em = $client->getContainer()
329 ->get('doctrine.orm.entity_manager');
330 $entry = $em
331 ->getRepository('WallabagCoreBundle:Entry')
332 ->findOneByUrl($url);
333 $tags = $entry->getTags();
334
335 $this->assertCount(2, $tags);
336 $this->assertContains('wallabag', $tags);
337 $this->assertSame('en', $entry->getLanguage());
338
339 $em->remove($entry);
340 $em->flush();
341
342 // and now re-submit it to test the cascade persistence for tags after entry removal
343 // related https://github.com/wallabag/wallabag/issues/2121
344 $crawler = $client->request('GET', '/new');
345
346 $this->assertSame(200, $client->getResponse()->getStatusCode());
347
348 $form = $crawler->filter('form[name=entry]')->form();
349
350 $data = [
351 'entry[url]' => $url = 'https://github.com/wallabag/wallabag/tree/master',
352 ];
353
354 $client->submit($form, $data);
355
356 $this->assertSame(302, $client->getResponse()->getStatusCode());
357 $this->assertContains('/', $client->getResponse()->getTargetUrl());
358
359 $entry = $em
360 ->getRepository('WallabagCoreBundle:Entry')
361 ->findOneByUrl($url);
362
363 $tags = $entry->getTags();
364
365 $this->assertCount(2, $tags);
366 $this->assertContains('wallabag', $tags);
367
368 $em->remove($entry);
369 $em->flush();
370 }
371
372 public function testArchive()
373 {
374 $this->logInAs('admin');
375 $client = $this->getClient();
376
377 $client->request('GET', '/archive/list');
378
379 $this->assertSame(200, $client->getResponse()->getStatusCode());
380 }
381
382 public function testUntagged()
383 {
384 $this->logInAs('admin');
385 $client = $this->getClient();
386
387 $client->request('GET', '/untagged/list');
388
389 $this->assertSame(200, $client->getResponse()->getStatusCode());
390 }
391
392 public function testStarred()
393 {
394 $this->logInAs('admin');
395 $client = $this->getClient();
396
397 $client->request('GET', '/starred/list');
398
399 $this->assertSame(200, $client->getResponse()->getStatusCode());
400 }
401
402 public function testRangeException()
403 {
404 $this->logInAs('admin');
405 $client = $this->getClient();
406
407 $client->request('GET', '/all/list/900');
408
409 $this->assertSame(302, $client->getResponse()->getStatusCode());
410 $this->assertSame('/all/list', $client->getResponse()->getTargetUrl());
411 }
412
413 public function testView()
414 {
415 $this->logInAs('admin');
416 $client = $this->getClient();
417
418 $entry = new Entry($this->getLoggedInUser());
419 $entry->setUrl('http://example.com/foo');
420 $entry->setTitle('title foo');
421 $entry->setContent('foo bar baz');
422 $this->getEntityManager()->persist($entry);
423 $this->getEntityManager()->flush();
424
425 $crawler = $client->request('GET', '/view/' . $entry->getId());
426
427 $this->assertSame(200, $client->getResponse()->getStatusCode());
428 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
429 $this->assertContains($entry->getTitle(), $body[0]);
430 }
431
432 /**
433 * This test will require an internet connection.
434 */
435 public function testReload()
436 {
437 $this->logInAs('admin');
438 $client = $this->getClient();
439
440 $entry = new Entry($this->getLoggedInUser());
441 $entry->setUrl($this->url);
442 $entry->setTitle('title foo');
443 $entry->setContent('');
444 $this->getEntityManager()->persist($entry);
445 $this->getEntityManager()->flush();
446 $this->getEntityManager()->clear();
447
448 $client->request('GET', '/reload/' . $entry->getId());
449
450 $this->assertSame(302, $client->getResponse()->getStatusCode());
451
452 $entry = $this->getEntityManager()
453 ->getRepository('WallabagCoreBundle:Entry')
454 ->find($entry->getId());
455
456 $this->assertNotEmpty($entry->getContent());
457 }
458
459 public function testReloadWithFetchingFailed()
460 {
461 $this->logInAs('admin');
462 $client = $this->getClient();
463
464 $entry = new Entry($this->getLoggedInUser());
465 $entry->setUrl('http://0.0.0.0/failed.html');
466 $this->getEntityManager()->persist($entry);
467 $this->getEntityManager()->flush();
468
469 $client->request('GET', '/reload/' . $entry->getId());
470
471 $this->assertSame(302, $client->getResponse()->getStatusCode());
472
473 // force EntityManager to clear previous entity
474 // otherwise, retrieve the same entity will retrieve change from the previous request :0
475 $this->getEntityManager()->clear();
476 $newContent = $this->getEntityManager()
477 ->getRepository('WallabagCoreBundle:Entry')
478 ->find($entry->getId());
479
480 $this->assertNotSame($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent());
481 }
482
483 public function testEdit()
484 {
485 $this->logInAs('admin');
486 $client = $this->getClient();
487
488 $entry = new Entry($this->getLoggedInUser());
489 $entry->setUrl($this->url);
490 $this->getEntityManager()->persist($entry);
491 $this->getEntityManager()->flush();
492
493 $crawler = $client->request('GET', '/edit/' . $entry->getId());
494
495 $this->assertSame(200, $client->getResponse()->getStatusCode());
496
497 $this->assertCount(1, $crawler->filter('input[id=entry_title]'));
498 $this->assertCount(1, $crawler->filter('button[id=entry_save]'));
499 }
500
501 public function testEditUpdate()
502 {
503 $this->logInAs('admin');
504 $client = $this->getClient();
505
506 $entry = new Entry($this->getLoggedInUser());
507 $entry->setUrl($this->url);
508 $this->getEntityManager()->persist($entry);
509 $this->getEntityManager()->flush();
510
511 $crawler = $client->request('GET', '/edit/' . $entry->getId());
512
513 $this->assertSame(200, $client->getResponse()->getStatusCode());
514
515 $form = $crawler->filter('button[id=entry_save]')->form();
516
517 $data = [
518 'entry[title]' => 'My updated title hehe :)',
519 'entry[origin_url]' => 'https://example.io',
520 ];
521
522 $client->submit($form, $data);
523
524 $this->assertSame(302, $client->getResponse()->getStatusCode());
525
526 $crawler = $client->followRedirect();
527
528 $this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text']));
529 $this->assertContains('My updated title hehe :)', $title[0]);
530 $this->assertGreaterThan(1, $stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']));
531 $this->assertContains('example.io', trim($stats[1]));
532 }
533
534 public function testEditRemoveOriginUrl()
535 {
536 $this->logInAs('admin');
537 $client = $this->getClient();
538
539 $entry = new Entry($this->getLoggedInUser());
540 $entry->setUrl($this->url);
541 $this->getEntityManager()->persist($entry);
542 $this->getEntityManager()->flush();
543
544 $crawler = $client->request('GET', '/edit/' . $entry->getId());
545
546 $this->assertSame(200, $client->getResponse()->getStatusCode());
547
548 $form = $crawler->filter('button[id=entry_save]')->form();
549
550 $data = [
551 'entry[title]' => 'My updated title hehe :)',
552 'entry[origin_url]' => '',
553 ];
554
555 $client->submit($form, $data);
556
557 $this->assertSame(302, $client->getResponse()->getStatusCode());
558
559 $crawler = $client->followRedirect();
560
561 $title = $crawler->filter('div[id=article] h1')->extract(['_text']);
562 $this->assertGreaterThan(1, $title);
563 $this->assertContains('My updated title hehe :)', $title[0]);
564
565 $stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']);
566 $this->assertCount(1, $stats);
567 $this->assertNotContains('example.io', trim($stats[0]));
568 }
569
570 public function testToggleArchive()
571 {
572 $this->logInAs('admin');
573 $client = $this->getClient();
574
575 $entry = new Entry($this->getLoggedInUser());
576 $entry->setUrl($this->url);
577 $this->getEntityManager()->persist($entry);
578 $this->getEntityManager()->flush();
579 $this->getEntityManager()->clear();
580
581 $client->request('GET', '/archive/' . $entry->getId());
582
583 $this->assertSame(302, $client->getResponse()->getStatusCode());
584
585 $res = $client->getContainer()
586 ->get('doctrine.orm.entity_manager')
587 ->getRepository('WallabagCoreBundle:Entry')
588 ->find($entry->getId());
589
590 $this->assertSame(1, $res->isArchived());
591 }
592
593 public function testToggleStar()
594 {
595 $this->logInAs('admin');
596 $client = $this->getClient();
597
598 $entry = new Entry($this->getLoggedInUser());
599 $entry->setUrl($this->url);
600 $this->getEntityManager()->persist($entry);
601 $this->getEntityManager()->flush();
602 $this->getEntityManager()->clear();
603
604 $client->request('GET', '/star/' . $entry->getId());
605
606 $this->assertSame(302, $client->getResponse()->getStatusCode());
607
608 $res = $client->getContainer()
609 ->get('doctrine.orm.entity_manager')
610 ->getRepository('WallabagCoreBundle:Entry')
611 ->findOneById($entry->getId());
612
613 $this->assertSame(1, $res->isStarred());
614 }
615
616 public function testDelete()
617 {
618 $this->logInAs('admin');
619 $client = $this->getClient();
620
621 $entry = new Entry($this->getLoggedInUser());
622 $entry->setUrl($this->url);
623 $this->getEntityManager()->persist($entry);
624 $this->getEntityManager()->flush();
625
626 $client->request('GET', '/delete/' . $entry->getId());
627
628 $this->assertSame(302, $client->getResponse()->getStatusCode());
629
630 $client->request('GET', '/delete/' . $entry->getId());
631
632 $this->assertSame(404, $client->getResponse()->getStatusCode());
633 }
634
635 /**
636 * It will create a new entry.
637 * Browse to it.
638 * Then remove it.
639 *
640 * And it'll check that user won't be redirected to the view page of the content when it had been removed
641 */
642 public function testViewAndDelete()
643 {
644 $this->logInAs('admin');
645 $client = $this->getClient();
646
647 $em = $client->getContainer()
648 ->get('doctrine.orm.entity_manager');
649
650 // add a new content to be removed later
651 $user = $em
652 ->getRepository('WallabagUserBundle:User')
653 ->findOneByUserName('admin');
654
655 $content = new Entry($user);
656 $content->setUrl('http://1.1.1.1/entry');
657 $content->setReadingTime(12);
658 $content->setDomainName('domain.io');
659 $content->setMimetype('text/html');
660 $content->setTitle('test title entry');
661 $content->setContent('This is my content /o/');
662 $content->updateArchived(true);
663 $content->setLanguage('fr');
664
665 $em->persist($content);
666 $em->flush();
667
668 $client->request('GET', '/view/' . $content->getId());
669 $this->assertSame(200, $client->getResponse()->getStatusCode());
670
671 $client->request('GET', '/delete/' . $content->getId());
672 $this->assertSame(302, $client->getResponse()->getStatusCode());
673
674 $client->followRedirect();
675 $this->assertSame(200, $client->getResponse()->getStatusCode());
676 }
677
678 public function testViewOtherUserEntry()
679 {
680 $this->logInAs('admin');
681 $client = $this->getClient();
682
683 $content = $client->getContainer()
684 ->get('doctrine.orm.entity_manager')
685 ->getRepository('WallabagCoreBundle:Entry')
686 ->findOneByUsernameAndNotArchived('bob');
687
688 $client->request('GET', '/view/' . $content->getId());
689
690 $this->assertSame(403, $client->getResponse()->getStatusCode());
691 }
692
693 public function testFilterOnReadingTime()
694 {
695 $this->logInAs('admin');
696 $client = $this->getClient();
697 $entry = new Entry($this->getLoggedInUser());
698 $entry->setUrl($this->url);
699 $entry->setReadingTime(22);
700 $this->getEntityManager()->persist($entry);
701 $this->getEntityManager()->flush();
702
703 $crawler = $client->request('GET', '/unread/list');
704
705 $form = $crawler->filter('button[id=submit-filter]')->form();
706
707 $data = [
708 'entry_filter[readingTime][right_number]' => 22,
709 'entry_filter[readingTime][left_number]' => 22,
710 ];
711
712 $crawler = $client->submit($form, $data);
713
714 $this->assertCount(1, $crawler->filter('li.entry'));
715 }
716
717 public function testFilterOnReadingTimeWithNegativeValue()
718 {
719 $this->logInAs('admin');
720 $client = $this->getClient();
721
722 $crawler = $client->request('GET', '/unread/list');
723
724 $form = $crawler->filter('button[id=submit-filter]')->form();
725
726 $data = [
727 'entry_filter[readingTime][right_number]' => -22,
728 'entry_filter[readingTime][left_number]' => -22,
729 ];
730
731 $crawler = $client->submit($form, $data);
732
733 // forcing negative value results in no entry displayed
734 $this->assertCount(0, $crawler->filter('li.entry'));
735 }
736
737 public function testFilterOnReadingTimeOnlyUpper()
738 {
739 $this->logInAs('admin');
740 $client = $this->getClient();
741
742 $crawler = $client->request('GET', '/all/list');
743 $this->assertCount(5, $crawler->filter('li.entry'));
744
745 $entry = new Entry($this->getLoggedInUser());
746 $entry->setUrl($this->url);
747 $entry->setReadingTime(23);
748 $this->getEntityManager()->persist($entry);
749 $this->getEntityManager()->flush();
750
751 $crawler = $client->request('GET', '/all/list');
752 $this->assertCount(6, $crawler->filter('li.entry'));
753
754 $form = $crawler->filter('button[id=submit-filter]')->form();
755
756 $data = [
757 'entry_filter[readingTime][right_number]' => 22,
758 ];
759
760 $crawler = $client->submit($form, $data);
761
762 $this->assertCount(5, $crawler->filter('li.entry'));
763 }
764
765 public function testFilterOnReadingTimeOnlyLower()
766 {
767 $this->logInAs('admin');
768 $client = $this->getClient();
769
770 $crawler = $client->request('GET', '/unread/list');
771
772 $form = $crawler->filter('button[id=submit-filter]')->form();
773
774 $data = [
775 'entry_filter[readingTime][left_number]' => 22,
776 ];
777
778 $crawler = $client->submit($form, $data);
779
780 $this->assertCount(0, $crawler->filter('li.entry'));
781
782 $entry = new Entry($this->getLoggedInUser());
783 $entry->setUrl($this->url);
784 $entry->setReadingTime(23);
785 $this->getEntityManager()->persist($entry);
786 $this->getEntityManager()->flush();
787
788 $crawler = $client->submit($form, $data);
789 $this->assertCount(1, $crawler->filter('li.entry'));
790 }
791
792 public function testFilterOnUnreadStatus()
793 {
794 $this->logInAs('admin');
795 $client = $this->getClient();
796
797 $crawler = $client->request('GET', '/all/list');
798
799 $form = $crawler->filter('button[id=submit-filter]')->form();
800
801 $data = [
802 'entry_filter[isUnread]' => true,
803 ];
804
805 $crawler = $client->submit($form, $data);
806
807 $this->assertCount(4, $crawler->filter('li.entry'));
808
809 $entry = new Entry($this->getLoggedInUser());
810 $entry->setUrl($this->url);
811 $entry->updateArchived(false);
812 $this->getEntityManager()->persist($entry);
813 $this->getEntityManager()->flush();
814
815 $crawler = $client->submit($form, $data);
816
817 $this->assertCount(5, $crawler->filter('li.entry'));
818 }
819
820 public function testFilterOnCreationDate()
821 {
822 $this->logInAs('admin');
823 $client = $this->getClient();
824
825 $crawler = $client->request('GET', '/unread/list');
826
827 $form = $crawler->filter('button[id=submit-filter]')->form();
828
829 $data = [
830 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
831 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')),
832 ];
833
834 $crawler = $client->submit($form, $data);
835
836 $this->assertCount(5, $crawler->filter('li.entry'));
837
838 $data = [
839 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
840 'entry_filter[createdAt][right_date]' => date('d/m/Y'),
841 ];
842
843 $crawler = $client->submit($form, $data);
844
845 $this->assertCount(5, $crawler->filter('li.entry'));
846
847 $data = [
848 'entry_filter[createdAt][left_date]' => '01/01/1970',
849 'entry_filter[createdAt][right_date]' => '01/01/1970',
850 ];
851
852 $crawler = $client->submit($form, $data);
853
854 $this->assertCount(0, $crawler->filter('li.entry'));
855 }
856
857 public function testPaginationWithFilter()
858 {
859 $this->logInAs('admin');
860 $client = $this->getClient();
861 $crawler = $client->request('GET', '/config');
862
863 $form = $crawler->filter('button[id=config_save]')->form();
864
865 $data = [
866 'config[items_per_page]' => '1',
867 ];
868
869 $client->submit($form, $data);
870
871 $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D=';
872
873 $client->request('GET', 'unread/list' . $parameters);
874
875 $this->assertContains($parameters, $client->getResponse()->getContent());
876
877 // reset pagination
878 $crawler = $client->request('GET', '/config');
879 $form = $crawler->filter('button[id=config_save]')->form();
880 $data = [
881 'config[items_per_page]' => '12',
882 ];
883 $client->submit($form, $data);
884 }
885
886 public function testFilterOnDomainName()
887 {
888 $this->logInAs('admin');
889 $client = $this->getClient();
890
891 $crawler = $client->request('GET', '/unread/list');
892 $form = $crawler->filter('button[id=submit-filter]')->form();
893 $data = [
894 'entry_filter[domainName]' => 'domain',
895 ];
896
897 $crawler = $client->submit($form, $data);
898 $this->assertCount(5, $crawler->filter('li.entry'));
899
900 $crawler = $client->request('GET', '/unread/list');
901 $form = $crawler->filter('button[id=submit-filter]')->form();
902 $data = [
903 'entry_filter[domainName]' => 'dOmain',
904 ];
905
906 $crawler = $client->submit($form, $data);
907 $this->assertCount(5, $crawler->filter('li.entry'));
908
909 $form = $crawler->filter('button[id=submit-filter]')->form();
910 $data = [
911 'entry_filter[domainName]' => 'wallabag',
912 ];
913
914 $crawler = $client->submit($form, $data);
915 $this->assertCount(0, $crawler->filter('li.entry'));
916 }
917
918 public function testFilterOnStatus()
919 {
920 $this->logInAs('admin');
921 $client = $this->getClient();
922
923 $crawler = $client->request('GET', '/unread/list');
924 $form = $crawler->filter('button[id=submit-filter]')->form();
925 $form['entry_filter[isArchived]']->tick();
926 $form['entry_filter[isStarred]']->untick();
927
928 $crawler = $client->submit($form);
929 $this->assertCount(1, $crawler->filter('li.entry'));
930
931 $form = $crawler->filter('button[id=submit-filter]')->form();
932 $form['entry_filter[isArchived]']->untick();
933 $form['entry_filter[isStarred]']->tick();
934
935 $crawler = $client->submit($form);
936 $this->assertCount(1, $crawler->filter('li.entry'));
937 }
938
939 public function testFilterOnIsPublic()
940 {
941 $this->logInAs('admin');
942 $client = $this->getClient();
943
944 $crawler = $client->request('GET', '/unread/list');
945 $form = $crawler->filter('button[id=submit-filter]')->form();
946 $form['entry_filter[isPublic]']->tick();
947
948 $crawler = $client->submit($form);
949 $this->assertCount(0, $crawler->filter('li.entry'));
950 }
951
952 public function testPreviewPictureFilter()
953 {
954 $this->logInAs('admin');
955 $client = $this->getClient();
956
957 $crawler = $client->request('GET', '/unread/list');
958 $form = $crawler->filter('button[id=submit-filter]')->form();
959 $form['entry_filter[previewPicture]']->tick();
960
961 $crawler = $client->submit($form);
962 $this->assertCount(1, $crawler->filter('li.entry'));
963 }
964
965 public function testFilterOnLanguage()
966 {
967 $this->logInAs('admin');
968 $client = $this->getClient();
969
970 $entry = new Entry($this->getLoggedInUser());
971 $entry->setUrl($this->url);
972 $entry->setLanguage('fr');
973 $this->getEntityManager()->persist($entry);
974 $this->getEntityManager()->flush();
975
976 $crawler = $client->request('GET', '/unread/list');
977 $form = $crawler->filter('button[id=submit-filter]')->form();
978 $data = [
979 'entry_filter[language]' => 'fr',
980 ];
981
982 $crawler = $client->submit($form, $data);
983 $this->assertCount(3, $crawler->filter('li.entry'));
984
985 $form = $crawler->filter('button[id=submit-filter]')->form();
986 $data = [
987 'entry_filter[language]' => 'en',
988 ];
989
990 $crawler = $client->submit($form, $data);
991 $this->assertCount(2, $crawler->filter('li.entry'));
992 }
993
994 public function testShareEntryPublicly()
995 {
996 $this->logInAs('admin');
997 $client = $this->getClient();
998
999 // sharing is enabled
1000 $client->getContainer()->get('craue_config')->set('share_public', 1);
1001
1002 $content = new Entry($this->getLoggedInUser());
1003 $content->setUrl($this->url);
1004 $this->getEntityManager()->persist($content);
1005 $this->getEntityManager()->flush();
1006 $this->getEntityManager()->clear();
1007
1008 // no uid
1009 $client->request('GET', '/share/' . $content->getUid());
1010 $this->assertSame(404, $client->getResponse()->getStatusCode());
1011
1012 // generating the uid
1013 $client->request('GET', '/share/' . $content->getId());
1014 $this->assertSame(302, $client->getResponse()->getStatusCode());
1015
1016 $shareUrl = $client->getResponse()->getTargetUrl();
1017
1018 // use a new client to have a fresh empty session (instead of a logged one from the previous client)
1019 $client->restart();
1020
1021 $client->request('GET', $shareUrl);
1022
1023 $this->assertSame(200, $client->getResponse()->getStatusCode());
1024 $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control'));
1025 $this->assertContains('public', $client->getResponse()->headers->get('cache-control'));
1026 $this->assertContains('s-maxage=25200', $client->getResponse()->headers->get('cache-control'));
1027 $this->assertNotContains('no-cache', $client->getResponse()->headers->get('cache-control'));
1028 $this->assertContains('og:title', $client->getResponse()->getContent());
1029 $this->assertContains('og:type', $client->getResponse()->getContent());
1030 $this->assertContains('og:url', $client->getResponse()->getContent());
1031 $this->assertContains('og:image', $client->getResponse()->getContent());
1032
1033 // sharing is now disabled
1034 $client->getContainer()->get('craue_config')->set('share_public', 0);
1035 $client->request('GET', '/share/' . $content->getUid());
1036 $this->assertSame(404, $client->getResponse()->getStatusCode());
1037
1038 // removing the share
1039 $client->request('GET', '/share/delete/' . $content->getId());
1040 $this->assertSame(302, $client->getResponse()->getStatusCode());
1041
1042 // share is now disable
1043 $client->request('GET', '/share/' . $content->getUid());
1044 $this->assertSame(404, $client->getResponse()->getStatusCode());
1045 }
1046
1047 public function testNewEntryWithDownloadImagesEnabled()
1048 {
1049 $this->downloadImagesEnabled = true;
1050 $this->logInAs('admin');
1051 $client = $this->getClient();
1052
1053 $url = self::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE;
1054 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
1055
1056 $crawler = $client->request('GET', '/new');
1057
1058 $this->assertSame(200, $client->getResponse()->getStatusCode());
1059
1060 $form = $crawler->filter('form[name=entry]')->form();
1061
1062 $data = [
1063 'entry[url]' => $url,
1064 ];
1065
1066 $client->submit($form, $data);
1067
1068 $this->assertSame(302, $client->getResponse()->getStatusCode());
1069
1070 $em = $client->getContainer()
1071 ->get('doctrine.orm.entity_manager');
1072
1073 $entry = $em
1074 ->getRepository('WallabagCoreBundle:Entry')
1075 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1076
1077 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry);
1078 $this->assertSame($url, $entry->getUrl());
1079 $this->assertContains('Judo', $entry->getTitle());
1080 // instead of checking for the filename (which might change) check that the image is now local
1081 $this->assertContains(rtrim($client->getContainer()->getParameter('domain_name'), '/') . '/assets/images/', $entry->getContent());
1082
1083 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1084 }
1085
1086 /**
1087 * @depends testNewEntryWithDownloadImagesEnabled
1088 */
1089 public function testRemoveEntryWithDownloadImagesEnabled()
1090 {
1091 $this->downloadImagesEnabled = true;
1092 $this->logInAs('admin');
1093 $client = $this->getClient();
1094
1095 $url = self::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE;
1096 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
1097
1098 $crawler = $client->request('GET', '/new');
1099
1100 $this->assertSame(200, $client->getResponse()->getStatusCode());
1101
1102 $form = $crawler->filter('form[name=entry]')->form();
1103
1104 $data = [
1105 'entry[url]' => $url,
1106 ];
1107
1108 $client->submit($form, $data);
1109
1110 $this->assertSame(302, $client->getResponse()->getStatusCode());
1111
1112 $content = $client->getContainer()
1113 ->get('doctrine.orm.entity_manager')
1114 ->getRepository('WallabagCoreBundle:Entry')
1115 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1116
1117 $client->request('GET', '/delete/' . $content->getId());
1118
1119 $this->assertSame(302, $client->getResponse()->getStatusCode());
1120
1121 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
1122 }
1123
1124 public function testRedirectToHomepage()
1125 {
1126 $this->logInAs('empty');
1127 $client = $this->getClient();
1128
1129 // Redirect to homepage
1130 $config = $this->getLoggedInUser()->getConfig();
1131 $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE);
1132 $this->getEntityManager()->persist($config);
1133
1134 $entry = new Entry($this->getLoggedInUser());
1135 $entry->setUrl($this->url);
1136 $this->getEntityManager()->persist($entry);
1137
1138 $this->getEntityManager()->flush();
1139
1140 $client->request('GET', '/view/' . $entry->getId());
1141 $client->request('GET', '/archive/' . $entry->getId());
1142
1143 $this->assertSame(302, $client->getResponse()->getStatusCode());
1144 $this->assertSame('/', $client->getResponse()->headers->get('location'));
1145 }
1146
1147 public function testRedirectToCurrentPage()
1148 {
1149 $this->logInAs('empty');
1150 $client = $this->getClient();
1151
1152 // Redirect to current page
1153 $config = $this->getLoggedInUser()->getConfig();
1154 $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE);
1155 $this->getEntityManager()->persist($config);
1156
1157 $entry = new Entry($this->getLoggedInUser());
1158 $entry->setUrl($this->url);
1159 $this->getEntityManager()->persist($entry);
1160
1161 $this->getEntityManager()->flush();
1162
1163 $client->request('GET', '/view/' . $entry->getId());
1164 $client->request('GET', '/archive/' . $entry->getId());
1165
1166 $this->assertSame(302, $client->getResponse()->getStatusCode());
1167 $this->assertContains('/view/' . $entry->getId(), $client->getResponse()->headers->get('location'));
1168 }
1169
1170 public function testFilterOnHttpStatus()
1171 {
1172 $this->logInAs('admin');
1173 $client = $this->getClient();
1174
1175 $entry = new Entry($this->getLoggedInUser());
1176 $entry->setUrl('https://www.lemonde.fr/incorrect-url/');
1177 $entry->setHttpStatus(404);
1178 $this->getEntityManager()->persist($entry);
1179
1180 $this->getEntityManager()->flush();
1181
1182 $crawler = $client->request('GET', '/all/list');
1183 $form = $crawler->filter('button[id=submit-filter]')->form();
1184
1185 $data = [
1186 'entry_filter[httpStatus]' => 404,
1187 ];
1188
1189 $crawler = $client->submit($form, $data);
1190
1191 $this->assertCount(1, $crawler->filter('li.entry'));
1192
1193 $entry = new Entry($this->getLoggedInUser());
1194 $entry->setUrl($this->url);
1195 $entry->setHttpStatus(200);
1196 $this->getEntityManager()->persist($entry);
1197
1198 $entry = new Entry($this->getLoggedInUser());
1199 $entry->setUrl('http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm');
1200 $entry->setHttpStatus(200);
1201 $this->getEntityManager()->persist($entry);
1202
1203 $this->getEntityManager()->flush();
1204
1205 $crawler = $client->request('GET', '/all/list');
1206 $form = $crawler->filter('button[id=submit-filter]')->form();
1207
1208 $data = [
1209 'entry_filter[httpStatus]' => 200,
1210 ];
1211
1212 $crawler = $client->submit($form, $data);
1213
1214 $this->assertCount(2, $crawler->filter('li.entry'));
1215
1216 $crawler = $client->request('GET', '/all/list');
1217 $form = $crawler->filter('button[id=submit-filter]')->form();
1218
1219 $data = [
1220 'entry_filter[httpStatus]' => 1024,
1221 ];
1222
1223 $crawler = $client->submit($form, $data);
1224
1225 $this->assertCount(8, $crawler->filter('li.entry'));
1226 }
1227
1228 public function testSearch()
1229 {
1230 $this->logInAs('admin');
1231 $client = $this->getClient();
1232
1233 $entry = new Entry($this->getLoggedInUser());
1234 $entry->setUrl($this->url);
1235 $entry->setTitle('test');
1236 $this->getEntityManager()->persist($entry);
1237 $this->getEntityManager()->flush();
1238
1239 // Search on unread list
1240 $crawler = $client->request('GET', '/unread/list');
1241
1242 $form = $crawler->filter('form[name=search]')->form();
1243 $data = [
1244 'search_entry[term]' => 'title',
1245 ];
1246
1247 $crawler = $client->submit($form, $data);
1248
1249 $this->assertCount(4, $crawler->filter('li.entry'));
1250
1251 // Search on starred list
1252 $crawler = $client->request('GET', '/starred/list');
1253
1254 $entry = new Entry($this->getLoggedInUser());
1255 $entry->setUrl('http://localhost/foo/bar');
1256 $entry->setTitle('testeur');
1257 $entry->setStarred(true);
1258 $this->getEntityManager()->persist($entry);
1259 $this->getEntityManager()->flush();
1260
1261 $form = $crawler->filter('form[name=search]')->form();
1262 $data = [
1263 'search_entry[term]' => 'testeur',
1264 ];
1265
1266 $crawler = $client->submit($form, $data);
1267
1268 $this->assertCount(1, $crawler->filter('li.entry'));
1269
1270 $crawler = $client->request('GET', '/archive/list');
1271
1272 // Added new article to test on archive list
1273 $entry = new Entry($this->getLoggedInUser());
1274 $entry->setUrl('http://0.0.0.0/foo/baz/qux');
1275 $entry->setTitle('Le manège');
1276 $entry->updateArchived(true);
1277 $this->getEntityManager()->persist($entry);
1278 $this->getEntityManager()->flush();
1279
1280 $form = $crawler->filter('form[name=search]')->form();
1281 $data = [
1282 'search_entry[term]' => 'manège',
1283 ];
1284
1285 $crawler = $client->submit($form, $data);
1286
1287 $this->assertCount(1, $crawler->filter('li.entry'));
1288 $client->request('GET', '/delete/' . $entry->getId());
1289
1290 // test on list of all articles
1291 $crawler = $client->request('GET', '/all/list');
1292
1293 $form = $crawler->filter('form[name=search]')->form();
1294 $data = [
1295 'search_entry[term]' => 'wxcvbnqsdf', // a string not available in the database
1296 ];
1297
1298 $crawler = $client->submit($form, $data);
1299
1300 $this->assertCount(0, $crawler->filter('li.entry'));
1301
1302 // test url search on list of all articles
1303 $entry = new Entry($this->getLoggedInUser());
1304 $entry->setUrl('http://domain/qux');
1305 $entry->setTitle('Le manège');
1306 $entry->updateArchived(true);
1307 $this->getEntityManager()->persist($entry);
1308 $this->getEntityManager()->flush();
1309
1310 $crawler = $client->request('GET', '/all/list');
1311
1312 $form = $crawler->filter('form[name=search]')->form();
1313 $data = [
1314 'search_entry[term]' => 'domain', // the search will match an entry with 'domain' in its url
1315 ];
1316
1317 $crawler = $client->submit($form, $data);
1318
1319 $this->assertCount(1, $crawler->filter('li.entry'));
1320
1321 // same as previous test but for case-sensitivity
1322 $crawler = $client->request('GET', '/all/list');
1323
1324 $form = $crawler->filter('form[name=search]')->form();
1325 $data = [
1326 'search_entry[term]' => 'doMain', // the search will match an entry with 'domain' in its url
1327 ];
1328
1329 $crawler = $client->submit($form, $data);
1330
1331 $this->assertCount(1, $crawler->filter('li.entry'));
1332 }
1333
1334 public function dataForLanguage()
1335 {
1336 return [
1337 'ru' => [
1338 'https://www.pravda.ru/world/09-06-2017/1337283-qatar-0/',
1339 'ru',
1340 ],
1341 'fr' => [
1342 'https://fr.wikipedia.org/wiki/Wallabag',
1343 'fr',
1344 ],
1345 'de' => [
1346 'https://www.bild.de/politik/ausland/theresa-may/wahlbeben-grossbritannien-analyse-52108924.bild.html',
1347 'de',
1348 ],
1349 'it' => [
1350 'http://www.ansa.it/sito/notizie/mondo/europa/2017/06/08/voto-gb-seggi-aperti-misure-sicurezza-rafforzate_0cb71f7f-e23b-4d5f-95ca-bc12296419f0.html',
1351 'it',
1352 ],
1353 'zh_CN' => [
1354 'http://www.hao123.com/shequ?__noscript__-=1',
1355 'zh_CN',
1356 ],
1357 'pt_BR' => [
1358 'https://politica.estadao.com.br/noticias/eleicoes,campanha-catatonica,70002491983',
1359 'pt_BR',
1360 ],
1361 'fucked_list_of_languages' => [
1362 'http://geocatalog.webservice-energy.org/geonetwork/srv/eng/main.home',
1363 null,
1364 ],
1365 'es-ES' => [
1366 'https://www.20minutos.es/noticia/3360685/0/gobierno-sanchez-primero-historia-mas-mujeres-que-hombres/',
1367 'es_ES',
1368 ],
1369 ];
1370 }
1371
1372 /**
1373 * @dataProvider dataForLanguage
1374 */
1375 public function testLanguageValidation($url, $expectedLanguage)
1376 {
1377 $this->logInAs('admin');
1378 $client = $this->getClient();
1379
1380 $crawler = $client->request('GET', '/new');
1381
1382 $this->assertSame(200, $client->getResponse()->getStatusCode());
1383
1384 $form = $crawler->filter('form[name=entry]')->form();
1385
1386 $data = [
1387 'entry[url]' => $url,
1388 ];
1389
1390 $client->submit($form, $data);
1391
1392 $this->assertSame(302, $client->getResponse()->getStatusCode());
1393
1394 $content = $client->getContainer()
1395 ->get('doctrine.orm.entity_manager')
1396 ->getRepository('WallabagCoreBundle:Entry')
1397 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1398
1399 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1400 $this->assertSame($url, $content->getUrl());
1401 $this->assertSame($expectedLanguage, $content->getLanguage());
1402 }
1403
1404 /**
1405 * This test will require an internet connection.
1406 */
1407 public function testRestrictedArticle()
1408 {
1409 $url = 'https://www.monde-diplomatique.fr/2017/05/BONNET/57475';
1410 $this->logInAs('admin');
1411 $client = $this->getClient();
1412 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
1413
1414 // enable restricted access
1415 $client->getContainer()->get('craue_config')->set('restricted_access', 1);
1416
1417 // create a new site_credential
1418 $user = $client->getContainer()->get('security.token_storage')->getToken()->getUser();
1419 $credential = new SiteCredential($user);
1420 $credential->setHost('monde-diplomatique.fr');
1421 $credential->setUsername($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('foo'));
1422 $credential->setPassword($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('bar'));
1423
1424 $em->persist($credential);
1425 $em->flush();
1426
1427 $crawler = $client->request('GET', '/new');
1428
1429 $this->assertSame(200, $client->getResponse()->getStatusCode());
1430
1431 $form = $crawler->filter('form[name=entry]')->form();
1432
1433 $data = [
1434 'entry[url]' => $url,
1435 ];
1436
1437 $client->submit($form, $data);
1438
1439 $this->assertSame(302, $client->getResponse()->getStatusCode());
1440
1441 $crawler = $client->followRedirect();
1442
1443 $this->assertSame(200, $client->getResponse()->getStatusCode());
1444 $this->assertContains('flashes.entry.notice.entry_saved', $crawler->filter('body')->extract(['_text'])[0]);
1445
1446 $content = $em
1447 ->getRepository('WallabagCoreBundle:Entry')
1448 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1449
1450 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
1451 $this->assertSame('Crimes et réformes aux Philippines', $content->getTitle());
1452
1453 $client->getContainer()->get('craue_config')->set('restricted_access', 0);
1454 }
1455
1456 public function testPostEntryWhenFetchFails()
1457 {
1458 $url = 'http://example.com/papers/email_tracking.pdf';
1459 $this->logInAs('admin');
1460 $client = $this->getClient();
1461
1462 $container = $client->getContainer();
1463 $contentProxy = $this->getMockBuilder(ContentProxy::class)
1464 ->disableOriginalConstructor()
1465 ->setMethods(['updateEntry'])
1466 ->getMock();
1467 $contentProxy->expects($this->any())
1468 ->method('updateEntry')
1469 ->willThrowException(new \Exception('Test Fetch content fails'));
1470
1471 $crawler = $client->request('GET', '/new');
1472
1473 $this->assertSame(200, $client->getResponse()->getStatusCode());
1474
1475 $form = $crawler->filter('form[name=entry]')->form();
1476
1477 $data = [
1478 'entry[url]' => $url,
1479 ];
1480
1481 /**
1482 * We generate a new client to be able to use Mock ContentProxy
1483 * Also we reinject the cookie from the previous client to keep the
1484 * session.
1485 */
1486 $cookie = $client->getCookieJar()->all();
1487 $client = $this->getNewClient();
1488 $client->getCookieJar()->set($cookie[0]);
1489 $client->getContainer()->set('wallabag_core.content_proxy', $contentProxy);
1490 $client->submit($form, $data);
1491
1492 $this->assertSame(302, $client->getResponse()->getStatusCode());
1493
1494 $content = $client->getContainer()
1495 ->get('doctrine.orm.entity_manager')
1496 ->getRepository('WallabagCoreBundle:Entry')
1497 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
1498
1499 $authors = $content->getPublishedBy();
1500 $this->assertSame('email_tracking.pdf', $content->getTitle());
1501 $this->assertSame('example.com', $content->getDomainName());
1502 }
1503
1504 public function testEntryDeleteTagLink()
1505 {
1506 $this->logInAs('admin');
1507 $client = $this->getClient();
1508
1509 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
1510 $entry = $em->getRepository('WallabagCoreBundle:Entry')->findByUrlAndUserId('http://0.0.0.0/entry1', $this->getLoggedInUserId());
1511 $tag = $entry->getTags()[0];
1512
1513 $crawler = $client->request('GET', '/view/' . $entry->getId());
1514
1515 // As long as the deletion link of a tag is following
1516 // a link to the tag view, we take the second one to retrieve
1517 // the deletion link of the first tag
1518 $link = $crawler->filter('body div#article div.tools ul.tags li.chip a')->extract('href')[1];
1519
1520 $this->assertSame(sprintf('/remove-tag/%s/%s', $entry->getId(), $tag->getId()), $link);
1521 }
1522
1523 public function testRandom()
1524 {
1525 $this->logInAs('admin');
1526 $client = $this->getClient();
1527
1528 $client->request('GET', '/unread/random');
1529 $this->assertSame(302, $client->getResponse()->getStatusCode());
1530 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Unread random');
1531
1532 $client->request('GET', '/starred/random');
1533 $this->assertSame(302, $client->getResponse()->getStatusCode());
1534 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Starred random');
1535
1536 $client->request('GET', '/archive/random');
1537 $this->assertSame(302, $client->getResponse()->getStatusCode());
1538 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Archive random');
1539
1540 $client->request('GET', '/untagged/random');
1541 $this->assertSame(302, $client->getResponse()->getStatusCode());
1542 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'Untagged random');
1543
1544 $client->request('GET', '/all/random');
1545 $this->assertSame(302, $client->getResponse()->getStatusCode());
1546 $this->assertContains('/view/', $client->getResponse()->getTargetUrl(), 'All random');
1547 }
1548 }