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