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