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