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