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