]>
Commit | Line | Data |
---|---|---|
4d85d7e9 J |
1 | <?php |
2 | ||
3 | namespace Wallabag\CoreBundle\Tests\Controller; | |
4 | ||
5 | use Wallabag\CoreBundle\Tests\WallabagTestCase; | |
6 | ||
7 | class ConfigControllerTest extends WallabagTestCase | |
8 | { | |
9 | public function testLogin() | |
10 | { | |
11 | $client = $this->getClient(); | |
12 | ||
13 | $client->request('GET', '/new'); | |
14 | ||
15 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
16 | $this->assertContains('login', $client->getResponse()->headers->get('location')); | |
17 | } | |
18 | ||
19 | public function testIndex() | |
20 | { | |
21 | $this->logInAs('admin'); | |
22 | $client = $this->getClient(); | |
23 | ||
24 | $crawler = $client->request('GET', '/config'); | |
25 | ||
26 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
27 | ||
d9085c63 J |
28 | $this->assertCount(1, $crawler->filter('button[id=config_save]')); |
29 | $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]')); | |
c0d9eba0 | 30 | $this->assertCount(1, $crawler->filter('button[id=user_save]')); |
4d85d7e9 J |
31 | } |
32 | ||
33 | public function testUpdate() | |
34 | { | |
35 | $this->logInAs('admin'); | |
36 | $client = $this->getClient(); | |
37 | ||
38 | $crawler = $client->request('GET', '/config'); | |
39 | ||
40 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
41 | ||
d9085c63 | 42 | $form = $crawler->filter('button[id=config_save]')->form(); |
4d85d7e9 J |
43 | |
44 | $data = array( | |
45 | 'config[theme]' => 'baggy', | |
46 | 'config[items_per_page]' => '30', | |
47 | 'config[language]' => 'fr_FR', | |
48 | ); | |
49 | ||
50 | $client->submit($form, $data); | |
51 | ||
52 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
53 | ||
54 | $crawler = $client->followRedirect(); | |
55 | ||
56 | $this->assertGreaterThan(1, $alert = $crawler->filter('div.flash-notice')->extract(array('_text'))); | |
57 | $this->assertContains('Config saved', $alert[0]); | |
58 | } | |
59 | ||
60 | public function dataForUpdateFailed() | |
61 | { | |
62 | return array( | |
63 | array(array( | |
64 | 'config[theme]' => 'baggy', | |
65 | 'config[items_per_page]' => '', | |
66 | 'config[language]' => 'fr_FR', | |
67 | )), | |
68 | array(array( | |
69 | 'config[theme]' => 'baggy', | |
70 | 'config[items_per_page]' => '12', | |
71 | 'config[language]' => '', | |
72 | )), | |
73 | ); | |
74 | } | |
75 | ||
76 | /** | |
77 | * @dataProvider dataForUpdateFailed | |
78 | */ | |
79 | public function testUpdateFailed($data) | |
80 | { | |
81 | $this->logInAs('admin'); | |
82 | $client = $this->getClient(); | |
83 | ||
84 | $crawler = $client->request('GET', '/config'); | |
85 | ||
86 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
87 | ||
d9085c63 | 88 | $form = $crawler->filter('button[id=config_save]')->form(); |
4d85d7e9 J |
89 | |
90 | $crawler = $client->submit($form, $data); | |
91 | ||
92 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
93 | ||
94 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(array('_text'))); | |
95 | $this->assertContains('This value should not be blank', $alert[0]); | |
96 | } | |
d9085c63 J |
97 | |
98 | public function dataForChangePasswordFailed() | |
99 | { | |
100 | return array( | |
101 | array( | |
102 | array( | |
103 | 'change_passwd[old_password]' => 'baggy', | |
104 | 'change_passwd[new_password][first]' => '', | |
105 | 'change_passwd[new_password][second]' => '', | |
106 | ), | |
c0d9eba0 | 107 | 'Wrong value for your current password', |
d9085c63 J |
108 | ), |
109 | array( | |
110 | array( | |
111 | 'change_passwd[old_password]' => 'mypassword', | |
112 | 'change_passwd[new_password][first]' => '', | |
113 | 'change_passwd[new_password][second]' => '', | |
114 | ), | |
c0d9eba0 | 115 | 'This value should not be blank', |
d9085c63 J |
116 | ), |
117 | array( | |
118 | array( | |
119 | 'change_passwd[old_password]' => 'mypassword', | |
120 | 'change_passwd[new_password][first]' => 'hop', | |
121 | 'change_passwd[new_password][second]' => '', | |
122 | ), | |
c0d9eba0 | 123 | 'The password fields must match', |
d9085c63 J |
124 | ), |
125 | array( | |
126 | array( | |
127 | 'change_passwd[old_password]' => 'mypassword', | |
128 | 'change_passwd[new_password][first]' => 'hop', | |
129 | 'change_passwd[new_password][second]' => 'hop', | |
130 | ), | |
c0d9eba0 | 131 | 'Password should by at least 6 chars long', |
d9085c63 J |
132 | ), |
133 | ); | |
134 | } | |
135 | ||
136 | /** | |
137 | * @dataProvider dataForChangePasswordFailed | |
138 | */ | |
139 | public function testChangePasswordFailed($data, $expectedMessage) | |
140 | { | |
141 | $this->logInAs('admin'); | |
142 | $client = $this->getClient(); | |
143 | ||
144 | $crawler = $client->request('GET', '/config'); | |
145 | ||
146 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
147 | ||
148 | $form = $crawler->filter('button[id=change_passwd_save]')->form(); | |
149 | ||
150 | $crawler = $client->submit($form, $data); | |
151 | ||
152 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
153 | ||
154 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(array('_text'))); | |
155 | $this->assertContains($expectedMessage, $alert[0]); | |
156 | } | |
157 | ||
158 | public function testChangePassword() | |
159 | { | |
160 | $this->logInAs('admin'); | |
161 | $client = $this->getClient(); | |
162 | ||
163 | $crawler = $client->request('GET', '/config'); | |
164 | ||
165 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
166 | ||
167 | $form = $crawler->filter('button[id=change_passwd_save]')->form(); | |
168 | ||
169 | $data = array( | |
170 | 'change_passwd[old_password]' => 'mypassword', | |
171 | 'change_passwd[new_password][first]' => 'mypassword', | |
172 | 'change_passwd[new_password][second]' => 'mypassword', | |
173 | ); | |
174 | ||
175 | $client->submit($form, $data); | |
176 | ||
177 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
178 | ||
179 | $crawler = $client->followRedirect(); | |
180 | ||
181 | $this->assertGreaterThan(1, $alert = $crawler->filter('div.flash-notice')->extract(array('_text'))); | |
182 | $this->assertContains('Password updated', $alert[0]); | |
183 | } | |
c0d9eba0 J |
184 | |
185 | public function dataForUserFailed() | |
186 | { | |
187 | return array( | |
188 | array( | |
189 | array( | |
190 | 'user[username]' => '', | |
191 | 'user[name]' => '', | |
192 | 'user[email]' => '', | |
193 | ), | |
194 | 'This value should not be blank.', | |
195 | ), | |
196 | array( | |
197 | array( | |
198 | 'user[username]' => 'ad', | |
199 | 'user[name]' => '', | |
200 | 'user[email]' => '', | |
201 | ), | |
202 | 'This value is too short.', | |
203 | ), | |
204 | array( | |
205 | array( | |
206 | 'user[username]' => 'admin', | |
207 | 'user[name]' => '', | |
208 | 'user[email]' => 'test', | |
209 | ), | |
210 | 'This value is not a valid email address.', | |
211 | ), | |
212 | ); | |
213 | } | |
214 | ||
215 | /** | |
216 | * @dataProvider dataForUserFailed | |
217 | */ | |
218 | public function testUserFailed($data, $expectedMessage) | |
219 | { | |
220 | $this->logInAs('admin'); | |
221 | $client = $this->getClient(); | |
222 | ||
223 | $crawler = $client->request('GET', '/config'); | |
224 | ||
225 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
226 | ||
227 | $form = $crawler->filter('button[id=user_save]')->form(); | |
228 | ||
229 | $crawler = $client->submit($form, $data); | |
230 | ||
231 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
232 | ||
233 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(array('_text'))); | |
234 | $this->assertContains($expectedMessage, $alert[0]); | |
235 | } | |
236 | ||
237 | public function testUserUpdate() | |
238 | { | |
239 | $this->logInAs('admin'); | |
240 | $client = $this->getClient(); | |
241 | ||
242 | $crawler = $client->request('GET', '/config'); | |
243 | ||
244 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
245 | ||
246 | $form = $crawler->filter('button[id=user_save]')->form(); | |
247 | ||
248 | $data = array( | |
249 | 'user[username]' => 'admin', | |
250 | 'user[name]' => 'new name', | |
251 | 'user[email]' => 'admin@wallabag.io', | |
252 | ); | |
253 | ||
254 | $client->submit($form, $data); | |
255 | ||
256 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
257 | ||
258 | $crawler = $client->followRedirect(); | |
259 | ||
260 | $this->assertGreaterThan(1, $alert = $crawler->filter('div.flash-notice')->extract(array('_text'))); | |
261 | $this->assertContains('Information updated', $alert[0]); | |
262 | } | |
4d85d7e9 | 263 | } |