diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2015-02-23 20:56:09 +0100 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2015-02-23 20:56:09 +0100 |
commit | 0e7971d8354b0923d2e8f38690b9fe46e695dd93 (patch) | |
tree | 7026acde83f5d38a9ad94d92f926d880aa233dbe /src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php | |
parent | 2f6a596760c62efd9e43602f787fa44400d522b3 (diff) | |
parent | c641baad0ec52198d77f2018c7bf8acdfe5957ce (diff) | |
download | wallabag-0e7971d8354b0923d2e8f38690b9fe46e695dd93.tar.gz wallabag-0e7971d8354b0923d2e8f38690b9fe46e695dd93.tar.zst wallabag-0e7971d8354b0923d2e8f38690b9fe46e695dd93.zip |
Merge pull request #1095 from wallabag/v2-config
V2 config
Diffstat (limited to 'src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php | 350 |
1 files changed, 350 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php new file mode 100644 index 00000000..9b1a0986 --- /dev/null +++ b/src/Wallabag/CoreBundle/Tests/Controller/ConfigControllerTest.php | |||
@@ -0,0 +1,350 @@ | |||
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 | |||
28 | $this->assertCount(1, $crawler->filter('button[id=config_save]')); | ||
29 | $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]')); | ||
30 | $this->assertCount(1, $crawler->filter('button[id=user_save]')); | ||
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 | |||
42 | $form = $crawler->filter('button[id=config_save]')->form(); | ||
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 | |||
88 | $form = $crawler->filter('button[id=config_save]')->form(); | ||
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 | } | ||
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 | ), | ||
107 | 'Wrong value for your current password', | ||
108 | ), | ||
109 | array( | ||
110 | array( | ||
111 | 'change_passwd[old_password]' => 'mypassword', | ||
112 | 'change_passwd[new_password][first]' => '', | ||
113 | 'change_passwd[new_password][second]' => '', | ||
114 | ), | ||
115 | 'This value should not be blank', | ||
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 | ), | ||
123 | 'The password fields must match', | ||
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 | ), | ||
131 | 'Password should by at least', | ||
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 | } | ||
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 | } | ||
263 | |||
264 | public function dataForNewUserFailed() | ||
265 | { | ||
266 | return array( | ||
267 | array( | ||
268 | array( | ||
269 | 'new_user[username]' => '', | ||
270 | 'new_user[password]' => '', | ||
271 | 'new_user[email]' => '', | ||
272 | ), | ||
273 | 'This value should not be blank.', | ||
274 | ), | ||
275 | array( | ||
276 | array( | ||
277 | 'new_user[username]' => 'ad', | ||
278 | 'new_user[password]' => '', | ||
279 | 'new_user[email]' => '', | ||
280 | ), | ||
281 | 'This value is too short.', | ||
282 | ), | ||
283 | array( | ||
284 | array( | ||
285 | 'new_user[username]' => 'wallace', | ||
286 | 'new_user[password]' => '', | ||
287 | 'new_user[email]' => 'test', | ||
288 | ), | ||
289 | 'This value is not a valid email address.', | ||
290 | ), | ||
291 | array( | ||
292 | array( | ||
293 | 'new_user[username]' => 'wallace', | ||
294 | 'new_user[password]' => 'admin', | ||
295 | 'new_user[email]' => 'wallace@wallace.me', | ||
296 | ), | ||
297 | 'Password should by at least', | ||
298 | ), | ||
299 | ); | ||
300 | } | ||
301 | |||
302 | /** | ||
303 | * @dataProvider dataForNewUserFailed | ||
304 | */ | ||
305 | public function testNewUserFailed($data, $expectedMessage) | ||
306 | { | ||
307 | $this->logInAs('admin'); | ||
308 | $client = $this->getClient(); | ||
309 | |||
310 | $crawler = $client->request('GET', '/config'); | ||
311 | |||
312 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
313 | |||
314 | $form = $crawler->filter('button[id=new_user_save]')->form(); | ||
315 | |||
316 | $crawler = $client->submit($form, $data); | ||
317 | |||
318 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
319 | |||
320 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(array('_text'))); | ||
321 | $this->assertContains($expectedMessage, $alert[0]); | ||
322 | } | ||
323 | |||
324 | public function testNewUserCreated() | ||
325 | { | ||
326 | $this->logInAs('admin'); | ||
327 | $client = $this->getClient(); | ||
328 | |||
329 | $crawler = $client->request('GET', '/config'); | ||
330 | |||
331 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
332 | |||
333 | $form = $crawler->filter('button[id=new_user_save]')->form(); | ||
334 | |||
335 | $data = array( | ||
336 | 'new_user[username]' => 'wallace', | ||
337 | 'new_user[password]' => 'wallace1', | ||
338 | 'new_user[email]' => 'wallace@wallace.me', | ||
339 | ); | ||
340 | |||
341 | $client->submit($form, $data); | ||
342 | |||
343 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
344 | |||
345 | $crawler = $client->followRedirect(); | ||
346 | |||
347 | $this->assertGreaterThan(1, $alert = $crawler->filter('div.flash-notice')->extract(array('_text'))); | ||
348 | $this->assertContains('User "wallace" added', $alert[0]); | ||
349 | } | ||
350 | } | ||