]> git.immae.eu Git - github/wallabag/wallabag.git/blob - tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
Merge remote-tracking branch 'origin/master' into 2.3
[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
9 class EntryControllerTest extends WallabagCoreTestCase
10 {
11 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';
12
13 public function testLogin()
14 {
15 $client = $this->getClient();
16
17 $client->request('GET', '/new');
18
19 $this->assertEquals(302, $client->getResponse()->getStatusCode());
20 $this->assertContains('login', $client->getResponse()->headers->get('location'));
21 }
22
23 public function testQuickstart()
24 {
25 $this->logInAs('empty');
26 $client = $this->getClient();
27
28 $client->request('GET', '/unread/list');
29 $crawler = $client->followRedirect();
30
31 $this->assertEquals(200, $client->getResponse()->getStatusCode());
32 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
33 $this->assertContains('quickstart.intro.title', $body[0]);
34
35 // Test if quickstart is disabled when user has 1 entry
36 $crawler = $client->request('GET', '/new');
37
38 $this->assertEquals(200, $client->getResponse()->getStatusCode());
39
40 $form = $crawler->filter('form[name=entry]')->form();
41
42 $data = [
43 'entry[url]' => $this->url,
44 ];
45
46 $client->submit($form, $data);
47 $this->assertEquals(302, $client->getResponse()->getStatusCode());
48 $client->followRedirect();
49
50 $crawler = $client->request('GET', '/unread/list');
51 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
52 $this->assertContains('entry.list.number_on_the_page', $body[0]);
53 }
54
55 public function testGetNew()
56 {
57 $this->logInAs('admin');
58 $client = $this->getClient();
59
60 $crawler = $client->request('GET', '/new');
61
62 $this->assertEquals(200, $client->getResponse()->getStatusCode());
63
64 $this->assertCount(1, $crawler->filter('input[type=url]'));
65 $this->assertCount(1, $crawler->filter('form[name=entry]'));
66 }
67
68 public function testPostNewViaBookmarklet()
69 {
70 $this->logInAs('admin');
71 $client = $this->getClient();
72
73 $crawler = $client->request('GET', '/');
74
75 $this->assertCount(4, $crawler->filter('div[class=entry]'));
76
77 // Good URL
78 $client->request('GET', '/bookmarklet', ['url' => $this->url]);
79 $this->assertEquals(302, $client->getResponse()->getStatusCode());
80 $client->followRedirect();
81 $crawler = $client->request('GET', '/');
82 $this->assertCount(5, $crawler->filter('div[class=entry]'));
83
84 $em = $client->getContainer()
85 ->get('doctrine.orm.entity_manager');
86 $entry = $em
87 ->getRepository('WallabagCoreBundle:Entry')
88 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
89 $em->remove($entry);
90 $em->flush();
91 }
92
93 public function testPostNewEmpty()
94 {
95 $this->logInAs('admin');
96 $client = $this->getClient();
97
98 $crawler = $client->request('GET', '/new');
99
100 $this->assertEquals(200, $client->getResponse()->getStatusCode());
101
102 $form = $crawler->filter('form[name=entry]')->form();
103
104 $crawler = $client->submit($form);
105
106 $this->assertEquals(200, $client->getResponse()->getStatusCode());
107 $this->assertCount(1, $alert = $crawler->filter('form ul li')->extract(['_text']));
108 $this->assertEquals('This value should not be blank.', $alert[0]);
109 }
110
111 /**
112 * This test will require an internet connection.
113 */
114 public function testPostNewOk()
115 {
116 $this->logInAs('admin');
117 $client = $this->getClient();
118
119 $crawler = $client->request('GET', '/new');
120
121 $this->assertEquals(200, $client->getResponse()->getStatusCode());
122
123 $form = $crawler->filter('form[name=entry]')->form();
124
125 $data = [
126 'entry[url]' => $this->url,
127 ];
128
129 $client->submit($form, $data);
130
131 $this->assertEquals(302, $client->getResponse()->getStatusCode());
132
133 $content = $client->getContainer()
134 ->get('doctrine.orm.entity_manager')
135 ->getRepository('WallabagCoreBundle:Entry')
136 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
137
138 $author = $content->getPublishedBy();
139
140 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $content);
141 $this->assertEquals($this->url, $content->getUrl());
142 $this->assertContains('Google', $content->getTitle());
143 $this->assertEquals('2015-03-28 15:37:39', $content->getPublishedAt()->format('Y-m-d H:i:s'));
144 $this->assertEquals('Morgane Tual', $author[0]);
145 $this->assertArrayHasKey('x-varnish1', $content->getHeaders());
146 }
147
148 public function testPostWithMultipleAuthors()
149 {
150 $url = 'http://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768';
151 $this->logInAs('admin');
152 $client = $this->getClient();
153
154 $crawler = $client->request('GET', '/new');
155
156 $this->assertEquals(200, $client->getResponse()->getStatusCode());
157
158 $form = $crawler->filter('form[name=entry]')->form();
159
160 $data = [
161 'entry[url]' => $url,
162 ];
163
164 $client->submit($form, $data);
165
166 $this->assertEquals(302, $client->getResponse()->getStatusCode());
167
168 $content = $client->getContainer()
169 ->get('doctrine.orm.entity_manager')
170 ->getRepository('WallabagCoreBundle:Entry')
171 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
172
173 $authors = $content->getPublishedBy();
174 $this->assertEquals('2017-04-05 19:26:13', $content->getPublishedAt()->format('Y-m-d H:i:s'));
175 $this->assertEquals('Raphaël Balenieri, correspondant à Pékin', $authors[0]);
176 $this->assertEquals('Frédéric Autran, correspondant à New York', $authors[1]);
177 }
178
179 public function testPostNewOkUrlExist()
180 {
181 $this->logInAs('admin');
182 $client = $this->getClient();
183
184 $crawler = $client->request('GET', '/new');
185
186 $this->assertEquals(200, $client->getResponse()->getStatusCode());
187
188 $form = $crawler->filter('form[name=entry]')->form();
189
190 $data = [
191 'entry[url]' => $this->url,
192 ];
193
194 $client->submit($form, $data);
195
196 $this->assertEquals(302, $client->getResponse()->getStatusCode());
197 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
198 }
199
200 public function testPostNewOkUrlExistWithAccent()
201 {
202 $this->logInAs('admin');
203 $client = $this->getClient();
204
205 $url = 'http://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing';
206
207 $crawler = $client->request('GET', '/new');
208
209 $this->assertEquals(200, $client->getResponse()->getStatusCode());
210
211 $form = $crawler->filter('form[name=entry]')->form();
212
213 $data = [
214 'entry[url]' => $url,
215 ];
216
217 $client->submit($form, $data);
218
219 $crawler = $client->request('GET', '/new');
220
221 $this->assertEquals(200, $client->getResponse()->getStatusCode());
222
223 $form = $crawler->filter('form[name=entry]')->form();
224
225 $data = [
226 'entry[url]' => $url,
227 ];
228
229 $client->submit($form, $data);
230
231 $this->assertEquals(302, $client->getResponse()->getStatusCode());
232 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
233
234 $em = $client->getContainer()
235 ->get('doctrine.orm.entity_manager');
236 $entry = $em
237 ->getRepository('WallabagCoreBundle:Entry')
238 ->findOneByUrl(urldecode($url));
239
240 $em->remove($entry);
241 $em->flush();
242 }
243
244 /**
245 * This test will require an internet connection.
246 */
247 public function testPostNewThatWillBeTagged()
248 {
249 $this->logInAs('admin');
250 $client = $this->getClient();
251
252 $crawler = $client->request('GET', '/new');
253
254 $this->assertEquals(200, $client->getResponse()->getStatusCode());
255
256 $form = $crawler->filter('form[name=entry]')->form();
257
258 $data = [
259 'entry[url]' => $url = 'https://github.com/wallabag/wallabag',
260 ];
261
262 $client->submit($form, $data);
263
264 $this->assertEquals(302, $client->getResponse()->getStatusCode());
265 $this->assertContains('/', $client->getResponse()->getTargetUrl());
266
267 $em = $client->getContainer()
268 ->get('doctrine.orm.entity_manager');
269 $entry = $em
270 ->getRepository('WallabagCoreBundle:Entry')
271 ->findOneByUrl($url);
272 $tags = $entry->getTags();
273
274 $this->assertCount(2, $tags);
275 $this->assertEquals('wallabag', $tags[0]->getLabel());
276
277 $em->remove($entry);
278 $em->flush();
279
280 // and now re-submit it to test the cascade persistence for tags after entry removal
281 // related https://github.com/wallabag/wallabag/issues/2121
282 $crawler = $client->request('GET', '/new');
283
284 $this->assertEquals(200, $client->getResponse()->getStatusCode());
285
286 $form = $crawler->filter('form[name=entry]')->form();
287
288 $data = [
289 'entry[url]' => $url = 'https://github.com/wallabag/wallabag/tree/master',
290 ];
291
292 $client->submit($form, $data);
293
294 $this->assertEquals(302, $client->getResponse()->getStatusCode());
295 $this->assertContains('/', $client->getResponse()->getTargetUrl());
296
297 $entry = $em
298 ->getRepository('WallabagCoreBundle:Entry')
299 ->findOneByUrl($url);
300
301 $tags = $entry->getTags();
302
303 $this->assertCount(2, $tags);
304 $this->assertEquals('wallabag', $tags[1]->getLabel());
305
306 $em->remove($entry);
307 $em->flush();
308 }
309
310 public function testArchive()
311 {
312 $this->logInAs('admin');
313 $client = $this->getClient();
314
315 $client->request('GET', '/archive/list');
316
317 $this->assertEquals(200, $client->getResponse()->getStatusCode());
318 }
319
320 public function testUntagged()
321 {
322 $this->logInAs('admin');
323 $client = $this->getClient();
324
325 $client->request('GET', '/untagged/list');
326
327 $this->assertEquals(200, $client->getResponse()->getStatusCode());
328 }
329
330 public function testStarred()
331 {
332 $this->logInAs('admin');
333 $client = $this->getClient();
334
335 $client->request('GET', '/starred/list');
336
337 $this->assertEquals(200, $client->getResponse()->getStatusCode());
338 }
339
340 public function testRangeException()
341 {
342 $this->logInAs('admin');
343 $client = $this->getClient();
344
345 $client->request('GET', '/all/list/900');
346
347 $this->assertEquals(302, $client->getResponse()->getStatusCode());
348 $this->assertEquals('/all/list', $client->getResponse()->getTargetUrl());
349 }
350
351 /**
352 * @depends testPostNewOk
353 */
354 public function testView()
355 {
356 $this->logInAs('admin');
357 $client = $this->getClient();
358
359 $content = $client->getContainer()
360 ->get('doctrine.orm.entity_manager')
361 ->getRepository('WallabagCoreBundle:Entry')
362 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
363
364 $crawler = $client->request('GET', '/view/'.$content->getId());
365
366 $this->assertEquals(200, $client->getResponse()->getStatusCode());
367 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
368 $this->assertContains($content->getTitle(), $body[0]);
369 }
370
371 /**
372 * @depends testPostNewOk
373 *
374 * This test will require an internet connection.
375 */
376 public function testReload()
377 {
378 $this->logInAs('admin');
379 $client = $this->getClient();
380
381 $em = $client->getContainer()
382 ->get('doctrine.orm.entity_manager');
383
384 $content = $em
385 ->getRepository('WallabagCoreBundle:Entry')
386 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
387
388 // empty content
389 $content->setContent('');
390 $em->persist($content);
391 $em->flush();
392
393 $client->request('GET', '/reload/'.$content->getId());
394
395 $this->assertEquals(302, $client->getResponse()->getStatusCode());
396
397 $content = $em
398 ->getRepository('WallabagCoreBundle:Entry')
399 ->find($content->getId());
400
401 $this->assertNotEmpty($content->getContent());
402 }
403
404 /**
405 * @depends testPostNewOk
406 */
407 public function testReloadWithFetchingFailed()
408 {
409 $this->logInAs('admin');
410 $client = $this->getClient();
411
412 $em = $client->getContainer()
413 ->get('doctrine.orm.entity_manager');
414
415 $content = $em
416 ->getRepository('WallabagCoreBundle:Entry')
417 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
418
419 // put a known failed url
420 $content->setUrl('http://0.0.0.0/failed.html');
421 $em->persist($content);
422 $em->flush();
423
424 $client->request('GET', '/reload/'.$content->getId());
425
426 $this->assertEquals(302, $client->getResponse()->getStatusCode());
427
428 // force EntityManager to clear previous entity
429 // otherwise, retrieve the same entity will retrieve change from the previous request :0
430 $em->clear();
431 $newContent = $em
432 ->getRepository('WallabagCoreBundle:Entry')
433 ->find($content->getId());
434
435 $newContent->setUrl($this->url);
436 $em->persist($newContent);
437 $em->flush();
438
439 $this->assertNotEquals($client->getContainer()->getParameter('wallabag_core.fetching_error_message'), $newContent->getContent());
440 }
441
442 public function testEdit()
443 {
444 $this->logInAs('admin');
445 $client = $this->getClient();
446
447 $content = $client->getContainer()
448 ->get('doctrine.orm.entity_manager')
449 ->getRepository('WallabagCoreBundle:Entry')
450 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
451
452 $crawler = $client->request('GET', '/edit/'.$content->getId());
453
454 $this->assertEquals(200, $client->getResponse()->getStatusCode());
455
456 $this->assertCount(1, $crawler->filter('input[id=entry_title]'));
457 $this->assertCount(1, $crawler->filter('button[id=entry_save]'));
458 }
459
460 public function testEditUpdate()
461 {
462 $this->logInAs('admin');
463 $client = $this->getClient();
464
465 $content = $client->getContainer()
466 ->get('doctrine.orm.entity_manager')
467 ->getRepository('WallabagCoreBundle:Entry')
468 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
469
470 $crawler = $client->request('GET', '/edit/'.$content->getId());
471
472 $this->assertEquals(200, $client->getResponse()->getStatusCode());
473
474 $form = $crawler->filter('button[type=submit]')->form();
475
476 $data = [
477 'entry[title]' => 'My updated title hehe :)',
478 ];
479
480 $client->submit($form, $data);
481
482 $this->assertEquals(302, $client->getResponse()->getStatusCode());
483
484 $crawler = $client->followRedirect();
485
486 $this->assertGreaterThan(1, $alert = $crawler->filter('div[id=article] h1')->extract(['_text']));
487 $this->assertContains('My updated title hehe :)', $alert[0]);
488 }
489
490 public function testToggleArchive()
491 {
492 $this->logInAs('admin');
493 $client = $this->getClient();
494
495 $content = $client->getContainer()
496 ->get('doctrine.orm.entity_manager')
497 ->getRepository('WallabagCoreBundle:Entry')
498 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
499
500 $client->request('GET', '/archive/'.$content->getId());
501
502 $this->assertEquals(302, $client->getResponse()->getStatusCode());
503
504 $res = $client->getContainer()
505 ->get('doctrine.orm.entity_manager')
506 ->getRepository('WallabagCoreBundle:Entry')
507 ->find($content->getId());
508
509 $this->assertEquals($res->isArchived(), true);
510 }
511
512 public function testToggleStar()
513 {
514 $this->logInAs('admin');
515 $client = $this->getClient();
516
517 $content = $client->getContainer()
518 ->get('doctrine.orm.entity_manager')
519 ->getRepository('WallabagCoreBundle:Entry')
520 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
521
522 $client->request('GET', '/star/'.$content->getId());
523
524 $this->assertEquals(302, $client->getResponse()->getStatusCode());
525
526 $res = $client->getContainer()
527 ->get('doctrine.orm.entity_manager')
528 ->getRepository('WallabagCoreBundle:Entry')
529 ->findOneById($content->getId());
530
531 $this->assertEquals($res->isStarred(), true);
532 }
533
534 public function testDelete()
535 {
536 $this->logInAs('admin');
537 $client = $this->getClient();
538
539 $content = $client->getContainer()
540 ->get('doctrine.orm.entity_manager')
541 ->getRepository('WallabagCoreBundle:Entry')
542 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
543
544 $client->request('GET', '/delete/'.$content->getId());
545
546 $this->assertEquals(302, $client->getResponse()->getStatusCode());
547
548 $client->request('GET', '/delete/'.$content->getId());
549
550 $this->assertEquals(404, $client->getResponse()->getStatusCode());
551 }
552
553 /**
554 * It will create a new entry.
555 * Browse to it.
556 * Then remove it.
557 *
558 * And it'll check that user won't be redirected to the view page of the content when it had been removed
559 */
560 public function testViewAndDelete()
561 {
562 $this->logInAs('admin');
563 $client = $this->getClient();
564
565 $em = $client->getContainer()
566 ->get('doctrine.orm.entity_manager');
567
568 // add a new content to be removed later
569 $user = $em
570 ->getRepository('WallabagUserBundle:User')
571 ->findOneByUserName('admin');
572
573 $content = new Entry($user);
574 $content->setUrl('http://1.1.1.1/entry');
575 $content->setReadingTime(12);
576 $content->setDomainName('domain.io');
577 $content->setMimetype('text/html');
578 $content->setTitle('test title entry');
579 $content->setContent('This is my content /o/');
580 $content->setArchived(true);
581 $content->setLanguage('fr');
582
583 $em->persist($content);
584 $em->flush();
585
586 $client->request('GET', '/view/'.$content->getId());
587 $this->assertEquals(200, $client->getResponse()->getStatusCode());
588
589 $client->request('GET', '/delete/'.$content->getId());
590 $this->assertEquals(302, $client->getResponse()->getStatusCode());
591
592 $client->followRedirect();
593 $this->assertEquals(200, $client->getResponse()->getStatusCode());
594 }
595
596 public function testViewOtherUserEntry()
597 {
598 $this->logInAs('admin');
599 $client = $this->getClient();
600
601 $content = $client->getContainer()
602 ->get('doctrine.orm.entity_manager')
603 ->getRepository('WallabagCoreBundle:Entry')
604 ->findOneByUsernameAndNotArchived('bob');
605
606 $client->request('GET', '/view/'.$content->getId());
607
608 $this->assertEquals(403, $client->getResponse()->getStatusCode());
609 }
610
611 public function testFilterOnReadingTime()
612 {
613 $this->logInAs('admin');
614 $client = $this->getClient();
615
616 $crawler = $client->request('GET', '/unread/list');
617
618 $form = $crawler->filter('button[id=submit-filter]')->form();
619
620 $data = [
621 'entry_filter[readingTime][right_number]' => 22,
622 'entry_filter[readingTime][left_number]' => 22,
623 ];
624
625 $crawler = $client->submit($form, $data);
626
627 $this->assertCount(1, $crawler->filter('div[class=entry]'));
628 }
629
630 public function testFilterOnReadingTimeWithNegativeValue()
631 {
632 $this->logInAs('admin');
633 $client = $this->getClient();
634
635 $crawler = $client->request('GET', '/unread/list');
636
637 $form = $crawler->filter('button[id=submit-filter]')->form();
638
639 $data = [
640 'entry_filter[readingTime][right_number]' => -22,
641 'entry_filter[readingTime][left_number]' => -22,
642 ];
643
644 $crawler = $client->submit($form, $data);
645
646 // forcing negative value results in no entry displayed
647 $this->assertCount(0, $crawler->filter('div[class=entry]'));
648 }
649
650 public function testFilterOnReadingTimeOnlyUpper()
651 {
652 $this->logInAs('admin');
653 $client = $this->getClient();
654
655 $crawler = $client->request('GET', '/unread/list');
656
657 $form = $crawler->filter('button[id=submit-filter]')->form();
658
659 $data = [
660 'entry_filter[readingTime][right_number]' => 22,
661 ];
662
663 $crawler = $client->submit($form, $data);
664
665 $this->assertCount(3, $crawler->filter('div[class=entry]'));
666 }
667
668 public function testFilterOnReadingTimeOnlyLower()
669 {
670 $this->logInAs('admin');
671 $client = $this->getClient();
672
673 $crawler = $client->request('GET', '/unread/list');
674
675 $form = $crawler->filter('button[id=submit-filter]')->form();
676
677 $data = [
678 'entry_filter[readingTime][left_number]' => 22,
679 ];
680
681 $crawler = $client->submit($form, $data);
682
683 $this->assertCount(4, $crawler->filter('div[class=entry]'));
684 }
685
686 public function testFilterOnUnreadStatus()
687 {
688 $this->logInAs('admin');
689 $client = $this->getClient();
690
691 $crawler = $client->request('GET', '/all/list');
692
693 $form = $crawler->filter('button[id=submit-filter]')->form();
694
695 $data = [
696 'entry_filter[isUnread]' => true,
697 ];
698
699 $crawler = $client->submit($form, $data);
700
701 $this->assertCount(5, $crawler->filter('div[class=entry]'));
702 }
703
704 public function testFilterOnCreationDate()
705 {
706 $this->logInAs('admin');
707 $client = $this->getClient();
708
709 $crawler = $client->request('GET', '/unread/list');
710
711 $form = $crawler->filter('button[id=submit-filter]')->form();
712
713 $data = [
714 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
715 'entry_filter[createdAt][right_date]' => date('d/m/Y', strtotime('+1 day')),
716 ];
717
718 $crawler = $client->submit($form, $data);
719
720 $this->assertCount(6, $crawler->filter('div[class=entry]'));
721
722 $data = [
723 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
724 'entry_filter[createdAt][right_date]' => date('d/m/Y'),
725 ];
726
727 $crawler = $client->submit($form, $data);
728
729 $this->assertCount(6, $crawler->filter('div[class=entry]'));
730
731 $data = [
732 'entry_filter[createdAt][left_date]' => '01/01/1970',
733 'entry_filter[createdAt][right_date]' => '01/01/1970',
734 ];
735
736 $crawler = $client->submit($form, $data);
737
738 $this->assertCount(0, $crawler->filter('div[class=entry]'));
739 }
740
741 public function testPaginationWithFilter()
742 {
743 $this->logInAs('admin');
744 $client = $this->getClient();
745 $crawler = $client->request('GET', '/config');
746
747 $form = $crawler->filter('button[id=config_save]')->form();
748
749 $data = [
750 'config[items_per_page]' => '1',
751 ];
752
753 $client->submit($form, $data);
754
755 $parameters = '?entry_filter%5BreadingTime%5D%5Bleft_number%5D=&entry_filter%5BreadingTime%5D%5Bright_number%5D=';
756
757 $client->request('GET', 'unread/list'.$parameters);
758
759 $this->assertContains($parameters, $client->getResponse()->getContent());
760
761 // reset pagination
762 $crawler = $client->request('GET', '/config');
763 $form = $crawler->filter('button[id=config_save]')->form();
764 $data = [
765 'config[items_per_page]' => '12',
766 ];
767 $client->submit($form, $data);
768 }
769
770 public function testFilterOnDomainName()
771 {
772 $this->logInAs('admin');
773 $client = $this->getClient();
774
775 $crawler = $client->request('GET', '/unread/list');
776 $form = $crawler->filter('button[id=submit-filter]')->form();
777 $data = [
778 'entry_filter[domainName]' => 'domain',
779 ];
780
781 $crawler = $client->submit($form, $data);
782 $this->assertCount(5, $crawler->filter('div[class=entry]'));
783
784 $crawler = $client->request('GET', '/unread/list');
785 $form = $crawler->filter('button[id=submit-filter]')->form();
786 $data = [
787 'entry_filter[domainName]' => 'dOmain',
788 ];
789
790 $crawler = $client->submit($form, $data);
791 $this->assertCount(5, $crawler->filter('div[class=entry]'));
792
793 $form = $crawler->filter('button[id=submit-filter]')->form();
794 $data = [
795 'entry_filter[domainName]' => 'wallabag',
796 ];
797
798 $crawler = $client->submit($form, $data);
799 $this->assertCount(0, $crawler->filter('div[class=entry]'));
800 }
801
802 public function testFilterOnStatus()
803 {
804 $this->logInAs('admin');
805 $client = $this->getClient();
806
807 $crawler = $client->request('GET', '/unread/list');
808 $form = $crawler->filter('button[id=submit-filter]')->form();
809 $form['entry_filter[isArchived]']->tick();
810 $form['entry_filter[isStarred]']->untick();
811
812 $crawler = $client->submit($form);
813 $this->assertCount(1, $crawler->filter('div[class=entry]'));
814
815 $form = $crawler->filter('button[id=submit-filter]')->form();
816 $form['entry_filter[isArchived]']->untick();
817 $form['entry_filter[isStarred]']->tick();
818
819 $crawler = $client->submit($form);
820 $this->assertCount(1, $crawler->filter('div[class=entry]'));
821 }
822
823 public function testPreviewPictureFilter()
824 {
825 $this->logInAs('admin');
826 $client = $this->getClient();
827
828 $crawler = $client->request('GET', '/unread/list');
829 $form = $crawler->filter('button[id=submit-filter]')->form();
830 $form['entry_filter[previewPicture]']->tick();
831
832 $crawler = $client->submit($form);
833 $this->assertCount(2, $crawler->filter('div[class=entry]'));
834 }
835
836 public function testFilterOnLanguage()
837 {
838 $this->logInAs('admin');
839 $client = $this->getClient();
840
841 $crawler = $client->request('GET', '/unread/list');
842 $form = $crawler->filter('button[id=submit-filter]')->form();
843 $data = [
844 'entry_filter[language]' => 'fr',
845 ];
846
847 $crawler = $client->submit($form, $data);
848 $this->assertCount(3, $crawler->filter('div[class=entry]'));
849
850 $form = $crawler->filter('button[id=submit-filter]')->form();
851 $data = [
852 'entry_filter[language]' => 'en',
853 ];
854
855 $crawler = $client->submit($form, $data);
856 $this->assertCount(2, $crawler->filter('div[class=entry]'));
857 }
858
859 public function testShareEntryPublicly()
860 {
861 $this->logInAs('admin');
862 $client = $this->getClient();
863
864 $content = $client->getContainer()
865 ->get('doctrine.orm.entity_manager')
866 ->getRepository('WallabagCoreBundle:Entry')
867 ->findOneByUser($this->getLoggedInUserId());
868
869 // no uid
870 $client->request('GET', '/share/'.$content->getUid());
871 $this->assertEquals(404, $client->getResponse()->getStatusCode());
872
873 // generating the uid
874 $client->request('GET', '/share/'.$content->getId());
875 $this->assertEquals(302, $client->getResponse()->getStatusCode());
876
877 // follow link with uid
878 $crawler = $client->followRedirect();
879 $this->assertEquals(200, $client->getResponse()->getStatusCode());
880 $this->assertContains('max-age=25200', $client->getResponse()->headers->get('cache-control'));
881 $this->assertContains('public', $client->getResponse()->headers->get('cache-control'));
882 $this->assertContains('s-maxage=25200', $client->getResponse()->headers->get('cache-control'));
883 $this->assertNotContains('no-cache', $client->getResponse()->headers->get('cache-control'));
884 $this->assertContains('og:title', $client->getResponse()->getContent());
885 $this->assertContains('og:type', $client->getResponse()->getContent());
886 $this->assertContains('og:url', $client->getResponse()->getContent());
887 $this->assertContains('og:image', $client->getResponse()->getContent());
888
889 // sharing is now disabled
890 $client->getContainer()->get('craue_config')->set('share_public', 0);
891 $client->request('GET', '/share/'.$content->getUid());
892 $this->assertEquals(404, $client->getResponse()->getStatusCode());
893
894 $client->request('GET', '/view/'.$content->getId());
895 $this->assertContains('no-cache', $client->getResponse()->headers->get('cache-control'));
896
897 // removing the share
898 $client->request('GET', '/share/delete/'.$content->getId());
899 $this->assertEquals(302, $client->getResponse()->getStatusCode());
900
901 // share is now disable
902 $client->request('GET', '/share/'.$content->getUid());
903 $this->assertEquals(404, $client->getResponse()->getStatusCode());
904 }
905
906 public function testNewEntryWithDownloadImagesEnabled()
907 {
908 $this->logInAs('admin');
909 $client = $this->getClient();
910
911 $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route';
912 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
913
914 $crawler = $client->request('GET', '/new');
915
916 $this->assertEquals(200, $client->getResponse()->getStatusCode());
917
918 $form = $crawler->filter('form[name=entry]')->form();
919
920 $data = [
921 'entry[url]' => $url,
922 ];
923
924 $client->submit($form, $data);
925
926 $this->assertEquals(302, $client->getResponse()->getStatusCode());
927
928 $em = $client->getContainer()
929 ->get('doctrine.orm.entity_manager');
930
931 $entry = $em
932 ->getRepository('WallabagCoreBundle:Entry')
933 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
934
935 $this->assertInstanceOf('Wallabag\CoreBundle\Entity\Entry', $entry);
936 $this->assertEquals($url, $entry->getUrl());
937 $this->assertContains('Perpignan', $entry->getTitle());
938 $this->assertContains('/c4789a7f.jpeg', $entry->getContent());
939
940 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
941 }
942
943 /**
944 * @depends testNewEntryWithDownloadImagesEnabled
945 */
946 public function testRemoveEntryWithDownloadImagesEnabled()
947 {
948 $this->logInAs('admin');
949 $client = $this->getClient();
950
951 $url = 'http://www.20minutes.fr/montpellier/1952003-20161030-video-car-tombe-panne-rugbymen-perpignan-improvisent-melee-route';
952 $client->getContainer()->get('craue_config')->set('download_images_enabled', 1);
953
954 $content = $client->getContainer()
955 ->get('doctrine.orm.entity_manager')
956 ->getRepository('WallabagCoreBundle:Entry')
957 ->findByUrlAndUserId($url, $this->getLoggedInUserId());
958
959 $client->request('GET', '/delete/'.$content->getId());
960
961 $this->assertEquals(302, $client->getResponse()->getStatusCode());
962
963 $client->getContainer()->get('craue_config')->set('download_images_enabled', 0);
964 }
965
966 public function testRedirectToHomepage()
967 {
968 $this->logInAs('empty');
969 $client = $this->getClient();
970
971 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
972 $user = $em
973 ->getRepository('WallabagUserBundle:User')
974 ->find($this->getLoggedInUserId());
975
976 if (!$user) {
977 $this->markTestSkipped('No user found in db.');
978 }
979
980 // Redirect to homepage
981 $config = $user->getConfig();
982 $config->setActionMarkAsRead(Config::REDIRECT_TO_HOMEPAGE);
983 $em->persist($config);
984 $em->flush();
985
986 $content = $client->getContainer()
987 ->get('doctrine.orm.entity_manager')
988 ->getRepository('WallabagCoreBundle:Entry')
989 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
990
991 $client->request('GET', '/view/'.$content->getId());
992 $client->request('GET', '/archive/'.$content->getId());
993
994 $this->assertEquals(302, $client->getResponse()->getStatusCode());
995 $this->assertEquals('/', $client->getResponse()->headers->get('location'));
996 }
997
998 public function testRedirectToCurrentPage()
999 {
1000 $this->logInAs('empty');
1001 $client = $this->getClient();
1002
1003 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
1004 $user = $em
1005 ->getRepository('WallabagUserBundle:User')
1006 ->find($this->getLoggedInUserId());
1007
1008 if (!$user) {
1009 $this->markTestSkipped('No user found in db.');
1010 }
1011
1012 // Redirect to current page
1013 $config = $user->getConfig();
1014 $config->setActionMarkAsRead(Config::REDIRECT_TO_CURRENT_PAGE);
1015 $em->persist($config);
1016 $em->flush();
1017
1018 $content = $client->getContainer()
1019 ->get('doctrine.orm.entity_manager')
1020 ->getRepository('WallabagCoreBundle:Entry')
1021 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
1022
1023 $client->request('GET', '/view/'.$content->getId());
1024 $client->request('GET', '/archive/'.$content->getId());
1025
1026 $this->assertEquals(302, $client->getResponse()->getStatusCode());
1027 $this->assertContains('/view/'.$content->getId(), $client->getResponse()->headers->get('location'));
1028 }
1029
1030 public function testFilterOnHttpStatus()
1031 {
1032 $this->logInAs('admin');
1033 $client = $this->getClient();
1034
1035 $crawler = $client->request('GET', '/new');
1036 $form = $crawler->filter('form[name=entry]')->form();
1037
1038 $data = [
1039 'entry[url]' => 'http://www.lemonde.fr/incorrect-url/',
1040 ];
1041
1042 $client->submit($form, $data);
1043
1044 $crawler = $client->request('GET', '/all/list');
1045 $form = $crawler->filter('button[id=submit-filter]')->form();
1046
1047 $data = [
1048 'entry_filter[httpStatus]' => 404,
1049 ];
1050
1051 $crawler = $client->submit($form, $data);
1052
1053 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1054
1055 $crawler = $client->request('GET', '/new');
1056 $form = $crawler->filter('form[name=entry]')->form();
1057
1058 $data = [
1059 'entry[url]' => 'http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm',
1060 ];
1061
1062 $client->submit($form, $data);
1063
1064 $crawler = $client->request('GET', '/all/list');
1065 $form = $crawler->filter('button[id=submit-filter]')->form();
1066
1067 $data = [
1068 'entry_filter[httpStatus]' => 200,
1069 ];
1070
1071 $crawler = $client->submit($form, $data);
1072
1073 $this->assertCount(2, $crawler->filter('div[class=entry]'));
1074
1075 $crawler = $client->request('GET', '/all/list');
1076 $form = $crawler->filter('button[id=submit-filter]')->form();
1077
1078 $data = [
1079 'entry_filter[httpStatus]' => 1024,
1080 ];
1081
1082 $crawler = $client->submit($form, $data);
1083
1084 $this->assertCount(8, $crawler->filter('div[class=entry]'));
1085 }
1086
1087 public function testSearch()
1088 {
1089 $this->logInAs('admin');
1090 $client = $this->getClient();
1091
1092 // Search on unread list
1093 $crawler = $client->request('GET', '/unread/list');
1094
1095 $form = $crawler->filter('form[name=search]')->form();
1096 $data = [
1097 'search_entry[term]' => 'title',
1098 ];
1099
1100 $crawler = $client->submit($form, $data);
1101
1102 $this->assertCount(5, $crawler->filter('div[class=entry]'));
1103
1104 // Search on starred list
1105 $crawler = $client->request('GET', '/starred/list');
1106
1107 $form = $crawler->filter('form[name=search]')->form();
1108 $data = [
1109 'search_entry[term]' => 'title',
1110 ];
1111
1112 $crawler = $client->submit($form, $data);
1113
1114 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1115
1116 // Added new article to test on archive list
1117 $crawler = $client->request('GET', '/new');
1118 $form = $crawler->filter('form[name=entry]')->form();
1119 $data = [
1120 'entry[url]' => $this->url,
1121 ];
1122 $client->submit($form, $data);
1123 $content = $client->getContainer()
1124 ->get('doctrine.orm.entity_manager')
1125 ->getRepository('WallabagCoreBundle:Entry')
1126 ->findByUrlAndUserId($this->url, $this->getLoggedInUserId());
1127 $client->request('GET', '/archive/'.$content->getId());
1128
1129 $crawler = $client->request('GET', '/archive/list');
1130
1131 $form = $crawler->filter('form[name=search]')->form();
1132 $data = [
1133 'search_entry[term]' => 'manège',
1134 ];
1135
1136 $crawler = $client->submit($form, $data);
1137
1138 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1139 $client->request('GET', '/delete/'.$content->getId());
1140
1141 // test on list of all articles
1142 $crawler = $client->request('GET', '/all/list');
1143
1144 $form = $crawler->filter('form[name=search]')->form();
1145 $data = [
1146 'search_entry[term]' => 'wxcvbnqsdf', // a string not available in the database
1147 ];
1148
1149 $crawler = $client->submit($form, $data);
1150
1151 $this->assertCount(0, $crawler->filter('div[class=entry]'));
1152
1153 // test url search on list of all articles
1154 $crawler = $client->request('GET', '/all/list');
1155
1156 $form = $crawler->filter('form[name=search]')->form();
1157 $data = [
1158 'search_entry[term]' => 'domain', // the search will match an entry with 'domain' in its url
1159 ];
1160
1161 $crawler = $client->submit($form, $data);
1162
1163 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1164
1165 // same as previous test but for case-sensitivity
1166 $crawler = $client->request('GET', '/all/list');
1167
1168 $form = $crawler->filter('form[name=search]')->form();
1169 $data = [
1170 'search_entry[term]' => 'doMain', // the search will match an entry with 'domain' in its url
1171 ];
1172
1173 $crawler = $client->submit($form, $data);
1174
1175 $this->assertCount(1, $crawler->filter('div[class=entry]'));
1176 }
1177 }