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