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