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