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