diff options
Diffstat (limited to 'tests/Wallabag')
-rw-r--r-- | tests/Wallabag/CoreBundle/Controller/IgnoreOriginInstanceRuleControllerTest.php | 148 |
1 files changed, 148 insertions, 0 deletions
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 | |||
3 | namespace Tests\Wallabag\CoreBundle\Controller; | ||
4 | |||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | ||
6 | |||
7 | class 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 | } | ||