aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/CoreBundle/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/CoreBundle/Controller')
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php151
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php26
-rw-r--r--tests/Wallabag/CoreBundle/Controller/IgnoreOriginInstanceRuleControllerTest.php148
3 files changed, 314 insertions, 11 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
index b3b3a19a..92d22267 100644
--- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php
@@ -435,7 +435,6 @@ class ConfigControllerTest extends WallabagCoreTestCase
435 public function testTaggingRuleCreation() 435 public function testTaggingRuleCreation()
436 { 436 {
437 $this->logInAs('admin'); 437 $this->logInAs('admin');
438 $this->useTheme('baggy');
439 $client = $this->getClient(); 438 $client = $this->getClient();
440 439
441 $crawler = $client->request('GET', '/config'); 440 $crawler = $client->request('GET', '/config');
@@ -457,7 +456,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
457 456
458 $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]); 457 $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]);
459 458
460 $editLink = $crawler->filter('.mode_edit')->last()->link(); 459 $editLink = $crawler->filter('div[id=set5] a.mode_edit')->last()->link();
461 460
462 $crawler = $client->click($editLink); 461 $crawler = $client->click($editLink);
463 $this->assertSame(302, $client->getResponse()->getStatusCode()); 462 $this->assertSame(302, $client->getResponse()->getStatusCode());
@@ -482,7 +481,7 @@ class ConfigControllerTest extends WallabagCoreTestCase
482 481
483 $this->assertContains('readingTime <= 30', $crawler->filter('body')->extract(['_text'])[0]); 482 $this->assertContains('readingTime <= 30', $crawler->filter('body')->extract(['_text'])[0]);
484 483
485 $deleteLink = $crawler->filter('.delete')->last()->link(); 484 $deleteLink = $crawler->filter('div[id=set5] a.delete')->last()->link();
486 485
487 $crawler = $client->click($deleteLink); 486 $crawler = $client->click($deleteLink);
488 $this->assertSame(302, $client->getResponse()->getStatusCode()); 487 $this->assertSame(302, $client->getResponse()->getStatusCode());
@@ -574,11 +573,11 @@ class ConfigControllerTest extends WallabagCoreTestCase
574 ->getRepository('WallabagCoreBundle:TaggingRule') 573 ->getRepository('WallabagCoreBundle:TaggingRule')
575 ->findAll()[0]; 574 ->findAll()[0];
576 575
577 $crawler = $client->request('GET', '/tagging-rule/edit/' . $rule->getId()); 576 $crawler = $client->request('GET', '/tagging-rule/delete/' . $rule->getId());
578 577
579 $this->assertSame(403, $client->getResponse()->getStatusCode()); 578 $this->assertSame(403, $client->getResponse()->getStatusCode());
580 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); 579 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
581 $this->assertContains('You can not access this tagging rule', $body[0]); 580 $this->assertContains('You can not access this rule', $body[0]);
582 } 581 }
583 582
584 public function testEditingTaggingRuleFromAnOtherUser() 583 public function testEditingTaggingRuleFromAnOtherUser()
@@ -594,7 +593,144 @@ class ConfigControllerTest extends WallabagCoreTestCase
594 593
595 $this->assertSame(403, $client->getResponse()->getStatusCode()); 594 $this->assertSame(403, $client->getResponse()->getStatusCode());
596 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); 595 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
597 $this->assertContains('You can not access this tagging rule', $body[0]); 596 $this->assertContains('You can not access this rule', $body[0]);
597 }
598
599 public function testIgnoreOriginRuleCreation()
600 {
601 $this->logInAs('admin');
602 $client = $this->getClient();
603
604 $crawler = $client->request('GET', '/config');
605
606 $this->assertSame(200, $client->getResponse()->getStatusCode());
607
608 $form = $crawler->filter('button[id=ignore_origin_user_rule_save]')->form();
609
610 $data = [
611 'ignore_origin_user_rule[rule]' => 'host = "example.com"',
612 ];
613
614 $client->submit($form, $data);
615
616 $this->assertSame(302, $client->getResponse()->getStatusCode());
617
618 $crawler = $client->followRedirect();
619
620 $this->assertContains('flashes.config.notice.ignore_origin_rules_updated', $crawler->filter('body')->extract(['_text'])[0]);
621
622 $editLink = $crawler->filter('div[id=set6] a.mode_edit')->last()->link();
623
624 $crawler = $client->click($editLink);
625 $this->assertSame(302, $client->getResponse()->getStatusCode());
626 $this->assertContains('?ignore-origin-user-rule=', $client->getResponse()->headers->get('location'));
627
628 $crawler = $client->followRedirect();
629
630 $form = $crawler->filter('button[id=ignore_origin_user_rule_save]')->form();
631
632 $data = [
633 'ignore_origin_user_rule[rule]' => 'host = "example.org"',
634 ];
635
636 $client->submit($form, $data);
637
638 $this->assertSame(302, $client->getResponse()->getStatusCode());
639
640 $crawler = $client->followRedirect();
641
642 $this->assertContains('flashes.config.notice.ignore_origin_rules_updated', $crawler->filter('body')->extract(['_text'])[0]);
643
644 $this->assertContains('host = "example.org"', $crawler->filter('body')->extract(['_text'])[0]);
645
646 $deleteLink = $crawler->filter('div[id=set6] a.delete')->last()->link();
647
648 $crawler = $client->click($deleteLink);
649 $this->assertSame(302, $client->getResponse()->getStatusCode());
650
651 $crawler = $client->followRedirect();
652 $this->assertContains('flashes.config.notice.ignore_origin_rules_deleted', $crawler->filter('body')->extract(['_text'])[0]);
653 }
654
655 public function dataForIgnoreOriginRuleCreationFail()
656 {
657 return [
658 [
659 [
660 'ignore_origin_user_rule[rule]' => 'foo = "bar"',
661 ],
662 [
663 'The variable',
664 'does not exist.',
665 ],
666 ],
667 [
668 [
669 'ignore_origin_user_rule[rule]' => '_all != "none"',
670 ],
671 [
672 'The operator',
673 'does not exist.',
674 ],
675 ],
676 ];
677 }
678
679 /**
680 * @dataProvider dataForIgnoreOriginRuleCreationFail
681 */
682 public function testIgnoreOriginRuleCreationFail($data, $messages)
683 {
684 $this->logInAs('admin');
685 $client = $this->getClient();
686
687 $crawler = $client->request('GET', '/config');
688
689 $this->assertSame(200, $client->getResponse()->getStatusCode());
690
691 $form = $crawler->filter('button[id=ignore_origin_user_rule_save]')->form();
692
693 $crawler = $client->submit($form, $data);
694
695 $this->assertSame(200, $client->getResponse()->getStatusCode());
696
697 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
698
699 foreach ($messages as $message) {
700 $this->assertContains($message, $body[0]);
701 }
702 }
703
704 public function testDeletingIgnoreOriginRuleFromAnOtherUser()
705 {
706 $this->logInAs('bob');
707 $client = $this->getClient();
708
709 $rule = $client->getContainer()->get('doctrine.orm.entity_manager')
710 ->getRepository('WallabagCoreBundle:IgnoreOriginUserRule')
711 ->findAll()[0];
712
713 $crawler = $client->request('GET', '/ignore-origin-user-rule/edit/' . $rule->getId());
714
715 $this->assertSame(403, $client->getResponse()->getStatusCode());
716 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
717 $this->assertContains('You can not access this rule', $body[0]);
718 }
719
720 public function testEditingIgnoreOriginRuleFromAnOtherUser()
721 {
722 $this->logInAs('bob');
723 $client = $this->getClient();
724
725 $rule = $client->getContainer()->get('doctrine.orm.entity_manager')
726 ->getRepository('WallabagCoreBundle:IgnoreOriginUserRule')
727 ->findAll()[0];
728
729 $crawler = $client->request('GET', '/ignore-origin-user-rule/edit/' . $rule->getId());
730
731 $this->assertSame(403, $client->getResponse()->getStatusCode());
732 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
733 $this->assertContains('You can not access this rule', $body[0]);
598 } 734 }
599 735
600 public function testDemoMode() 736 public function testDemoMode()
@@ -676,6 +812,9 @@ class ConfigControllerTest extends WallabagCoreTestCase
676 $em->flush(); 812 $em->flush();
677 } 813 }
678 814
815 /**
816 * @group NetworkCalls
817 */
679 public function testDeleteAccount() 818 public function testDeleteAccount()
680 { 819 {
681 $client = $this->getClient(); 820 $client = $this->getClient();
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index 5b806830..0aa562d8 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -40,6 +40,9 @@ class EntryControllerTest extends WallabagCoreTestCase
40 $this->assertContains('login', $client->getResponse()->headers->get('location')); 40 $this->assertContains('login', $client->getResponse()->headers->get('location'));
41 } 41 }
42 42
43 /**
44 * @group NetworkCalls
45 */
43 public function testQuickstart() 46 public function testQuickstart()
44 { 47 {
45 $this->logInAs('empty'); 48 $this->logInAs('empty');
@@ -87,6 +90,9 @@ class EntryControllerTest extends WallabagCoreTestCase
87 $this->assertCount(1, $crawler->filter('form[name=entry]')); 90 $this->assertCount(1, $crawler->filter('form[name=entry]'));
88 } 91 }
89 92
93 /**
94 * @group NetworkCalls
95 */
90 public function testPostNewViaBookmarklet() 96 public function testPostNewViaBookmarklet()
91 { 97 {
92 $this->logInAs('admin'); 98 $this->logInAs('admin');
@@ -131,7 +137,7 @@ class EntryControllerTest extends WallabagCoreTestCase
131 } 137 }
132 138
133 /** 139 /**
134 * This test will require an internet connection. 140 * @group NetworkCalls
135 */ 141 */
136 public function testPostNewOk() 142 public function testPostNewOk()
137 { 143 {
@@ -169,6 +175,9 @@ class EntryControllerTest extends WallabagCoreTestCase
169 $client->getContainer()->get('craue_config')->set('store_article_headers', 0); 175 $client->getContainer()->get('craue_config')->set('store_article_headers', 0);
170 } 176 }
171 177
178 /**
179 * @group NetworkCalls
180 */
172 public function testPostWithMultipleAuthors() 181 public function testPostWithMultipleAuthors()
173 { 182 {
174 $url = 'https://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768'; 183 $url = 'https://www.liberation.fr/planete/2017/04/05/donald-trump-et-xi-jinping-tentative-de-flirt-en-floride_1560768';
@@ -229,6 +238,9 @@ class EntryControllerTest extends WallabagCoreTestCase
229 $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); 238 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
230 } 239 }
231 240
241 /**
242 * @group NetworkCalls
243 */
232 public function testPostNewOkUrlExistWithAccent() 244 public function testPostNewOkUrlExistWithAccent()
233 { 245 {
234 $this->logInAs('admin'); 246 $this->logInAs('admin');
@@ -265,7 +277,7 @@ class EntryControllerTest extends WallabagCoreTestCase
265 } 277 }
266 278
267 /** 279 /**
268 * This test will require an internet connection. 280 * @group NetworkCalls
269 */ 281 */
270 public function testPostNewOkUrlExistWithRedirection() 282 public function testPostNewOkUrlExistWithRedirection()
271 { 283 {
@@ -303,7 +315,7 @@ class EntryControllerTest extends WallabagCoreTestCase
303 } 315 }
304 316
305 /** 317 /**
306 * This test will require an internet connection. 318 * @group NetworkCalls
307 */ 319 */
308 public function testPostNewThatWillBeTagged() 320 public function testPostNewThatWillBeTagged()
309 { 321 {
@@ -430,7 +442,7 @@ class EntryControllerTest extends WallabagCoreTestCase
430 } 442 }
431 443
432 /** 444 /**
433 * This test will require an internet connection. 445 * @group NetworkCalls
434 */ 446 */
435 public function testReload() 447 public function testReload()
436 { 448 {
@@ -1056,6 +1068,9 @@ class EntryControllerTest extends WallabagCoreTestCase
1056 $this->assertSame(404, $client->getResponse()->getStatusCode()); 1068 $this->assertSame(404, $client->getResponse()->getStatusCode());
1057 } 1069 }
1058 1070
1071 /**
1072 * @group NetworkCalls
1073 */
1059 public function testNewEntryWithDownloadImagesEnabled() 1074 public function testNewEntryWithDownloadImagesEnabled()
1060 { 1075 {
1061 $this->downloadImagesEnabled = true; 1076 $this->downloadImagesEnabled = true;
@@ -1383,6 +1398,7 @@ class EntryControllerTest extends WallabagCoreTestCase
1383 1398
1384 /** 1399 /**
1385 * @dataProvider dataForLanguage 1400 * @dataProvider dataForLanguage
1401 * @group NetworkCalls
1386 */ 1402 */
1387 public function testLanguageValidation($url, $expectedLanguage) 1403 public function testLanguageValidation($url, $expectedLanguage)
1388 { 1404 {
@@ -1414,7 +1430,7 @@ class EntryControllerTest extends WallabagCoreTestCase
1414 } 1430 }
1415 1431
1416 /** 1432 /**
1417 * This test will require an internet connection. 1433 * @group NetworkCalls
1418 */ 1434 */
1419 public function testRestrictedArticle() 1435 public function testRestrictedArticle()
1420 { 1436 {
diff --git a/tests/Wallabag/CoreBundle/Controller/IgnoreOriginInstanceRuleControllerTest.php b/tests/Wallabag/CoreBundle/Controller/IgnoreOriginInstanceRuleControllerTest.php
new file mode 100644
index 00000000..9783cd25
--- /dev/null
+++ b/tests/Wallabag/CoreBundle/Controller/IgnoreOriginInstanceRuleControllerTest.php
@@ -0,0 +1,148 @@
1<?php
2
3namespace Tests\Wallabag\CoreBundle\Controller;
4
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6
7class IgnoreOriginInstanceRuleControllerTest extends WallabagCoreTestCase
8{
9 public function testListIgnoreOriginInstanceRule()
10 {
11 $this->logInAs('admin');
12 $client = $this->getClient();
13
14 $crawler = $client->request('GET', '/ignore-origin-instance-rules/');
15
16 $this->assertSame(200, $client->getResponse()->getStatusCode());
17
18 $body = $crawler->filter('body')->extract(['_text'])[0];
19
20 $this->assertContains('ignore_origin_instance_rule.description', $body);
21 $this->assertContains('ignore_origin_instance_rule.list.create_new_one', $body);
22 }
23
24 public function testIgnoreOriginInstanceRuleCreationEditionDeletion()
25 {
26 $this->logInAs('admin');
27 $client = $this->getClient();
28
29 // Creation
30 $crawler = $client->request('GET', '/ignore-origin-instance-rules/new');
31
32 $this->assertSame(200, $client->getResponse()->getStatusCode());
33
34 $body = $crawler->filter('body')->extract(['_text'])[0];
35
36 $this->assertContains('ignore_origin_instance_rule.new_ignore_origin_instance_rule', $body);
37 $this->assertContains('ignore_origin_instance_rule.form.back_to_list', $body);
38
39 $form = $crawler->filter('button[id=ignore_origin_instance_rule_save]')->form();
40
41 $data = [
42 'ignore_origin_instance_rule[rule]' => 'host = "foo.example.com"',
43 ];
44
45 $client->submit($form, $data);
46
47 $this->assertSame(302, $client->getResponse()->getStatusCode());
48
49 $crawler = $client->followRedirect();
50
51 $this->assertContains('flashes.ignore_origin_instance_rule.notice.added', $crawler->filter('body')->extract(['_text'])[0]);
52
53 // Edition
54 $editLink = $crawler->filter('div[id=content] table a')->last()->link();
55
56 $crawler = $client->click($editLink);
57
58 $this->assertSame(200, $client->getResponse()->getStatusCode());
59
60 $this->assertContains('foo.example.com', $crawler->filter('form[name=ignore_origin_instance_rule] input[type=text]')->extract(['value'])[0]);
61
62 $body = $crawler->filter('body')->extract(['_text'])[0];
63
64 $this->assertContains('ignore_origin_instance_rule.edit_ignore_origin_instance_rule', $body);
65 $this->assertContains('ignore_origin_instance_rule.form.back_to_list', $body);
66
67 $form = $crawler->filter('button[id=ignore_origin_instance_rule_save]')->form();
68
69 $data = [
70 'ignore_origin_instance_rule[rule]' => 'host = "bar.example.com"',
71 ];
72
73 $client->submit($form, $data);
74
75 $this->assertSame(302, $client->getResponse()->getStatusCode());
76
77 $crawler = $client->followRedirect();
78
79 $this->assertContains('flashes.ignore_origin_instance_rule.notice.updated', $crawler->filter('body')->extract(['_text'])[0]);
80
81 $editLink = $crawler->filter('div[id=content] table a')->last()->link();
82
83 $crawler = $client->click($editLink);
84
85 $this->assertSame(200, $client->getResponse()->getStatusCode());
86
87 $this->assertContains('bar.example.com', $crawler->filter('form[name=ignore_origin_instance_rule] input[type=text]')->extract(['value'])[0]);
88
89 $deleteForm = $crawler->filter('body')->selectButton('ignore_origin_instance_rule.form.delete')->form();
90
91 $client->submit($deleteForm, []);
92
93 $this->assertSame(302, $client->getResponse()->getStatusCode());
94
95 $crawler = $client->followRedirect();
96
97 $this->assertContains('flashes.ignore_origin_instance_rule.notice.deleted', $crawler->filter('body')->extract(['_text'])[0]);
98 }
99
100 public function dataForIgnoreOriginInstanceRuleCreationFail()
101 {
102 return [
103 [
104 [
105 'ignore_origin_instance_rule[rule]' => 'foo = "bar"',
106 ],
107 [
108 'The variable',
109 'does not exist.',
110 ],
111 ],
112 [
113 [
114 'ignore_origin_instance_rule[rule]' => '_all != "none"',
115 ],
116 [
117 'The operator',
118 'does not exist.',
119 ],
120 ],
121 ];
122 }
123
124 /**
125 * @dataProvider dataForIgnoreOriginInstanceRuleCreationFail
126 */
127 public function testIgnoreOriginInstanceRuleCreationFail($data, $messages)
128 {
129 $this->logInAs('admin');
130 $client = $this->getClient();
131
132 $crawler = $client->request('GET', '/ignore-origin-instance-rules/new');
133
134 $this->assertSame(200, $client->getResponse()->getStatusCode());
135
136 $form = $crawler->filter('button[id=ignore_origin_instance_rule_save]')->form();
137
138 $crawler = $client->submit($form, $data);
139
140 $this->assertSame(200, $client->getResponse()->getStatusCode());
141
142 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
143
144 foreach ($messages as $message) {
145 $this->assertContains($message, $body[0]);
146 }
147 }
148}