]>
Commit | Line | Data |
---|---|---|
4d85d7e9 J |
1 | <?php |
2 | ||
23634d5d | 3 | namespace Tests\Wallabag\CoreBundle\Controller; |
4d85d7e9 | 4 | |
23634d5d | 5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
4d85d7e9 | 6 | |
769e19dc | 7 | class ConfigControllerTest extends WallabagCoreTestCase |
4d85d7e9 J |
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]')); | |
c844dc0c | 30 | $this->assertCount(1, $crawler->filter('button[id=update_user_save]')); |
371ac69a J |
31 | $this->assertCount(1, $crawler->filter('button[id=new_user_save]')); |
32 | $this->assertCount(1, $crawler->filter('button[id=rss_config_save]')); | |
4d85d7e9 J |
33 | } |
34 | ||
35 | public function testUpdate() | |
36 | { | |
37 | $this->logInAs('admin'); | |
38 | $client = $this->getClient(); | |
39 | ||
40 | $crawler = $client->request('GET', '/config'); | |
41 | ||
42 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
43 | ||
d9085c63 | 44 | $form = $crawler->filter('button[id=config_save]')->form(); |
4d85d7e9 | 45 | |
4094ea47 | 46 | $data = [ |
23ff8d36 | 47 | 'config[theme]' => 'baggy', |
4d85d7e9 | 48 | 'config[items_per_page]' => '30', |
1b64a84b | 49 | 'config[reading_speed]' => '0.5', |
c89d35e8 | 50 | 'config[language]' => 'en', |
4094ea47 | 51 | ]; |
4d85d7e9 J |
52 | |
53 | $client->submit($form, $data); | |
54 | ||
55 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
56 | ||
57 | $crawler = $client->followRedirect(); | |
58 | ||
bf3dc999 | 59 | $this->assertContains('flashes.config.notice.config_saved', $crawler->filter('body')->extract(['_text'])[0]); |
4d85d7e9 J |
60 | } |
61 | ||
c4c062cc NL |
62 | public function testChangeReadingSpeed() |
63 | { | |
64 | $this->logInAs('admin'); | |
65 | $client = $this->getClient(); | |
66 | ||
67 | $crawler = $client->request('GET', '/unread/list'); | |
68 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
69 | $dataFilters = [ | |
70 | 'entry_filter[readingTime][right_number]' => 22, | |
71 | 'entry_filter[readingTime][left_number]' => 22, | |
72 | ]; | |
73 | $crawler = $client->submit($form, $dataFilters); | |
74 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
75 | ||
76 | // Change reading speed | |
77 | $crawler = $client->request('GET', '/config'); | |
78 | $form = $crawler->filter('button[id=config_save]')->form(); | |
79 | $data = [ | |
80 | 'config[reading_speed]' => '2', | |
81 | ]; | |
82 | $client->submit($form, $data); | |
83 | ||
84 | // Is the entry still available via filters? | |
85 | $crawler = $client->request('GET', '/unread/list'); | |
86 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
87 | $crawler = $client->submit($form, $dataFilters); | |
88 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
89 | ||
90 | // Restore old configuration | |
91 | $crawler = $client->request('GET', '/config'); | |
92 | $form = $crawler->filter('button[id=config_save]')->form(); | |
93 | $data = [ | |
94 | 'config[reading_speed]' => '0.5', | |
95 | ]; | |
96 | $client->submit($form, $data); | |
97 | } | |
98 | ||
4d85d7e9 J |
99 | public function dataForUpdateFailed() |
100 | { | |
4094ea47 JB |
101 | return [ |
102 | [[ | |
23ff8d36 | 103 | 'config[theme]' => 'baggy', |
4d85d7e9 | 104 | 'config[items_per_page]' => '', |
c89d35e8 | 105 | 'config[language]' => 'en', |
4094ea47 JB |
106 | ]], |
107 | ]; | |
4d85d7e9 J |
108 | } |
109 | ||
110 | /** | |
111 | * @dataProvider dataForUpdateFailed | |
112 | */ | |
113 | public function testUpdateFailed($data) | |
114 | { | |
115 | $this->logInAs('admin'); | |
116 | $client = $this->getClient(); | |
117 | ||
118 | $crawler = $client->request('GET', '/config'); | |
119 | ||
120 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
121 | ||
d9085c63 | 122 | $form = $crawler->filter('button[id=config_save]')->form(); |
4d85d7e9 J |
123 | |
124 | $crawler = $client->submit($form, $data); | |
125 | ||
126 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
127 | ||
4094ea47 | 128 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); |
4d85d7e9 J |
129 | $this->assertContains('This value should not be blank', $alert[0]); |
130 | } | |
d9085c63 J |
131 | |
132 | public function dataForChangePasswordFailed() | |
133 | { | |
4094ea47 JB |
134 | return [ |
135 | [ | |
136 | [ | |
4ab58dcf | 137 | 'change_passwd[old_password]' => 'material', |
d9085c63 J |
138 | 'change_passwd[new_password][first]' => '', |
139 | 'change_passwd[new_password][second]' => '', | |
4094ea47 | 140 | ], |
0d42217e | 141 | 'validator.password_wrong_value', |
4094ea47 JB |
142 | ], |
143 | [ | |
144 | [ | |
d9085c63 J |
145 | 'change_passwd[old_password]' => 'mypassword', |
146 | 'change_passwd[new_password][first]' => '', | |
147 | 'change_passwd[new_password][second]' => '', | |
4094ea47 | 148 | ], |
c0d9eba0 | 149 | 'This value should not be blank', |
4094ea47 JB |
150 | ], |
151 | [ | |
152 | [ | |
d9085c63 J |
153 | 'change_passwd[old_password]' => 'mypassword', |
154 | 'change_passwd[new_password][first]' => 'hop', | |
155 | 'change_passwd[new_password][second]' => '', | |
4094ea47 | 156 | ], |
0d42217e | 157 | 'validator.password_must_match', |
4094ea47 JB |
158 | ], |
159 | [ | |
160 | [ | |
d9085c63 J |
161 | 'change_passwd[old_password]' => 'mypassword', |
162 | 'change_passwd[new_password][first]' => 'hop', | |
163 | 'change_passwd[new_password][second]' => 'hop', | |
4094ea47 | 164 | ], |
0d42217e | 165 | 'validator.password_too_short', |
4094ea47 JB |
166 | ], |
167 | ]; | |
d9085c63 J |
168 | } |
169 | ||
170 | /** | |
171 | * @dataProvider dataForChangePasswordFailed | |
172 | */ | |
173 | public function testChangePasswordFailed($data, $expectedMessage) | |
174 | { | |
175 | $this->logInAs('admin'); | |
176 | $client = $this->getClient(); | |
177 | ||
178 | $crawler = $client->request('GET', '/config'); | |
179 | ||
180 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
181 | ||
182 | $form = $crawler->filter('button[id=change_passwd_save]')->form(); | |
183 | ||
184 | $crawler = $client->submit($form, $data); | |
185 | ||
186 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
187 | ||
4094ea47 | 188 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); |
d9085c63 J |
189 | $this->assertContains($expectedMessage, $alert[0]); |
190 | } | |
191 | ||
192 | public function testChangePassword() | |
193 | { | |
194 | $this->logInAs('admin'); | |
195 | $client = $this->getClient(); | |
196 | ||
197 | $crawler = $client->request('GET', '/config'); | |
198 | ||
199 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
200 | ||
201 | $form = $crawler->filter('button[id=change_passwd_save]')->form(); | |
202 | ||
4094ea47 | 203 | $data = [ |
d9085c63 J |
204 | 'change_passwd[old_password]' => 'mypassword', |
205 | 'change_passwd[new_password][first]' => 'mypassword', | |
206 | 'change_passwd[new_password][second]' => 'mypassword', | |
4094ea47 | 207 | ]; |
d9085c63 J |
208 | |
209 | $client->submit($form, $data); | |
210 | ||
211 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
212 | ||
213 | $crawler = $client->followRedirect(); | |
214 | ||
bf3dc999 | 215 | $this->assertContains('flashes.config.notice.password_updated', $crawler->filter('body')->extract(['_text'])[0]); |
d9085c63 | 216 | } |
c0d9eba0 J |
217 | |
218 | public function dataForUserFailed() | |
219 | { | |
4094ea47 JB |
220 | return [ |
221 | [ | |
222 | [ | |
c844dc0c J |
223 | 'update_user[name]' => '', |
224 | 'update_user[email]' => '', | |
4094ea47 | 225 | ], |
0d42217e | 226 | 'fos_user.email.blank', |
4094ea47 JB |
227 | ], |
228 | [ | |
229 | [ | |
c844dc0c J |
230 | 'update_user[name]' => '', |
231 | 'update_user[email]' => 'test', | |
4094ea47 | 232 | ], |
0d42217e | 233 | 'fos_user.email.invalid', |
4094ea47 JB |
234 | ], |
235 | ]; | |
c0d9eba0 J |
236 | } |
237 | ||
238 | /** | |
239 | * @dataProvider dataForUserFailed | |
240 | */ | |
241 | public function testUserFailed($data, $expectedMessage) | |
242 | { | |
243 | $this->logInAs('admin'); | |
244 | $client = $this->getClient(); | |
245 | ||
246 | $crawler = $client->request('GET', '/config'); | |
247 | ||
248 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
249 | ||
c844dc0c | 250 | $form = $crawler->filter('button[id=update_user_save]')->form(); |
c0d9eba0 J |
251 | |
252 | $crawler = $client->submit($form, $data); | |
253 | ||
254 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
255 | ||
4094ea47 | 256 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); |
c0d9eba0 J |
257 | $this->assertContains($expectedMessage, $alert[0]); |
258 | } | |
259 | ||
260 | public function testUserUpdate() | |
261 | { | |
262 | $this->logInAs('admin'); | |
263 | $client = $this->getClient(); | |
264 | ||
265 | $crawler = $client->request('GET', '/config'); | |
266 | ||
267 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
268 | ||
c844dc0c | 269 | $form = $crawler->filter('button[id=update_user_save]')->form(); |
c0d9eba0 | 270 | |
4094ea47 | 271 | $data = [ |
c844dc0c J |
272 | 'update_user[name]' => 'new name', |
273 | 'update_user[email]' => 'admin@wallabag.io', | |
4094ea47 | 274 | ]; |
c0d9eba0 J |
275 | |
276 | $client->submit($form, $data); | |
277 | ||
278 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
279 | ||
280 | $crawler = $client->followRedirect(); | |
281 | ||
4094ea47 | 282 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); |
4204a06b | 283 | $this->assertContains('flashes.config.notice.user_updated', $alert[0]); |
c0d9eba0 | 284 | } |
e4977b8a J |
285 | |
286 | public function dataForNewUserFailed() | |
287 | { | |
4094ea47 JB |
288 | return [ |
289 | [ | |
290 | [ | |
e4977b8a | 291 | 'new_user[username]' => '', |
fcb1fba5 NL |
292 | 'new_user[plainPassword][first]' => '', |
293 | 'new_user[plainPassword][second]' => '', | |
e4977b8a | 294 | 'new_user[email]' => '', |
4094ea47 | 295 | ], |
0d42217e | 296 | 'fos_user.username.blank', |
4094ea47 JB |
297 | ], |
298 | [ | |
299 | [ | |
3f7a6290 | 300 | 'new_user[username]' => 'a', |
fcb1fba5 NL |
301 | 'new_user[plainPassword][first]' => 'mypassword', |
302 | 'new_user[plainPassword][second]' => 'mypassword', | |
e4977b8a | 303 | 'new_user[email]' => '', |
4094ea47 | 304 | ], |
0d42217e | 305 | 'fos_user.username.short', |
4094ea47 JB |
306 | ], |
307 | [ | |
308 | [ | |
e4977b8a | 309 | 'new_user[username]' => 'wallace', |
fcb1fba5 NL |
310 | 'new_user[plainPassword][first]' => 'mypassword', |
311 | 'new_user[plainPassword][second]' => 'mypassword', | |
e4977b8a | 312 | 'new_user[email]' => 'test', |
4094ea47 | 313 | ], |
0d42217e | 314 | 'fos_user.email.invalid', |
4094ea47 JB |
315 | ], |
316 | [ | |
317 | [ | |
c844dc0c | 318 | 'new_user[username]' => 'admin', |
fcb1fba5 NL |
319 | 'new_user[plainPassword][first]' => 'wallacewallace', |
320 | 'new_user[plainPassword][second]' => 'wallacewallace', | |
c844dc0c | 321 | 'new_user[email]' => 'wallace@wallace.me', |
4094ea47 | 322 | ], |
0d42217e | 323 | 'fos_user.username.already_used', |
4094ea47 JB |
324 | ], |
325 | [ | |
326 | [ | |
fcb1fba5 NL |
327 | 'new_user[username]' => 'wallace', |
328 | 'new_user[plainPassword][first]' => 'mypassword1', | |
329 | 'new_user[plainPassword][second]' => 'mypassword2', | |
330 | 'new_user[email]' => 'wallace@wallace.me', | |
4094ea47 | 331 | ], |
0d42217e | 332 | 'validator.password_must_match', |
4094ea47 JB |
333 | ], |
334 | ]; | |
e4977b8a J |
335 | } |
336 | ||
337 | /** | |
338 | * @dataProvider dataForNewUserFailed | |
339 | */ | |
340 | public function testNewUserFailed($data, $expectedMessage) | |
341 | { | |
342 | $this->logInAs('admin'); | |
343 | $client = $this->getClient(); | |
344 | ||
345 | $crawler = $client->request('GET', '/config'); | |
346 | ||
347 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
348 | ||
349 | $form = $crawler->filter('button[id=new_user_save]')->form(); | |
350 | ||
351 | $crawler = $client->submit($form, $data); | |
352 | ||
353 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
354 | ||
4094ea47 | 355 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); |
e4977b8a J |
356 | $this->assertContains($expectedMessage, $alert[0]); |
357 | } | |
358 | ||
359 | public function testNewUserCreated() | |
360 | { | |
361 | $this->logInAs('admin'); | |
362 | $client = $this->getClient(); | |
363 | ||
364 | $crawler = $client->request('GET', '/config'); | |
365 | ||
366 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
367 | ||
368 | $form = $crawler->filter('button[id=new_user_save]')->form(); | |
369 | ||
4094ea47 | 370 | $data = [ |
e4977b8a | 371 | 'new_user[username]' => 'wallace', |
fcb1fba5 NL |
372 | 'new_user[plainPassword][first]' => 'wallace1', |
373 | 'new_user[plainPassword][second]' => 'wallace1', | |
e4977b8a | 374 | 'new_user[email]' => 'wallace@wallace.me', |
4094ea47 | 375 | ]; |
e4977b8a J |
376 | |
377 | $client->submit($form, $data); | |
378 | ||
379 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
380 | ||
381 | $crawler = $client->followRedirect(); | |
382 | ||
bf3dc999 | 383 | $this->assertContains('flashes.config.notice.user_added', $crawler->filter('body')->extract(['_text'])[0]); |
0f30f48b JB |
384 | |
385 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
386 | $user = $em | |
1210dae1 | 387 | ->getRepository('WallabagUserBundle:User') |
0f30f48b JB |
388 | ->findOneByUsername('wallace'); |
389 | ||
390 | $this->assertTrue(false !== $user); | |
391 | $this->assertTrue($user->isEnabled()); | |
83890741 NL |
392 | $this->assertEquals('material', $user->getConfig()->getTheme()); |
393 | $this->assertEquals(12, $user->getConfig()->getItemsPerPage()); | |
394 | $this->assertEquals(50, $user->getConfig()->getRssLimit()); | |
395 | $this->assertEquals('en', $user->getConfig()->getLanguage()); | |
396 | $this->assertEquals(1, $user->getConfig()->getReadingSpeed()); | |
e4977b8a | 397 | } |
371ac69a J |
398 | |
399 | public function testRssUpdateResetToken() | |
400 | { | |
401 | $this->logInAs('admin'); | |
402 | $client = $this->getClient(); | |
403 | ||
404 | // reset the token | |
405 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
406 | $user = $em | |
1210dae1 | 407 | ->getRepository('WallabagUserBundle:User') |
371ac69a J |
408 | ->findOneByUsername('admin'); |
409 | ||
410 | if (!$user) { | |
411 | $this->markTestSkipped('No user found in db.'); | |
412 | } | |
413 | ||
414 | $config = $user->getConfig(); | |
415 | $config->setRssToken(null); | |
416 | $em->persist($config); | |
417 | $em->flush(); | |
418 | ||
419 | $crawler = $client->request('GET', '/config'); | |
420 | ||
421 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
422 | ||
4094ea47 | 423 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
0d42217e | 424 | $this->assertContains('config.form_rss.no_token', $body[0]); |
371ac69a J |
425 | |
426 | $client->request('GET', '/generate-token'); | |
427 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
428 | ||
429 | $crawler = $client->followRedirect(); | |
430 | ||
4094ea47 | 431 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
0d42217e | 432 | $this->assertNotContains('config.form_rss.no_token', $body[0]); |
371ac69a J |
433 | } |
434 | ||
435 | public function testGenerateTokenAjax() | |
436 | { | |
437 | $this->logInAs('admin'); | |
438 | $client = $this->getClient(); | |
439 | ||
440 | $client->request( | |
441 | 'GET', | |
442 | '/generate-token', | |
4094ea47 JB |
443 | [], |
444 | [], | |
445 | ['HTTP_X-Requested-With' => 'XMLHttpRequest'] | |
371ac69a J |
446 | ); |
447 | ||
448 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
9744e971 | 449 | $content = json_decode($client->getResponse()->getContent(), true); |
371ac69a J |
450 | $this->assertArrayHasKey('token', $content); |
451 | } | |
452 | ||
453 | public function testRssUpdate() | |
454 | { | |
455 | $this->logInAs('admin'); | |
456 | $client = $this->getClient(); | |
457 | ||
458 | $crawler = $client->request('GET', '/config'); | |
459 | ||
371ac69a J |
460 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
461 | ||
462 | $form = $crawler->filter('button[id=rss_config_save]')->form(); | |
463 | ||
4094ea47 | 464 | $data = [ |
371ac69a | 465 | 'rss_config[rss_limit]' => 12, |
4094ea47 | 466 | ]; |
371ac69a J |
467 | |
468 | $client->submit($form, $data); | |
469 | ||
470 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
471 | ||
472 | $crawler = $client->followRedirect(); | |
473 | ||
bf3dc999 | 474 | $this->assertContains('flashes.config.notice.rss_updated', $crawler->filter('body')->extract(['_text'])[0]); |
371ac69a J |
475 | } |
476 | ||
477 | public function dataForRssFailed() | |
478 | { | |
4094ea47 JB |
479 | return [ |
480 | [ | |
481 | [ | |
371ac69a | 482 | 'rss_config[rss_limit]' => 0, |
4094ea47 | 483 | ], |
371ac69a | 484 | 'This value should be 1 or more.', |
4094ea47 JB |
485 | ], |
486 | [ | |
487 | [ | |
371ac69a | 488 | 'rss_config[rss_limit]' => 1000000000000, |
4094ea47 | 489 | ], |
0d42217e | 490 | 'validator.rss_limit_too_hight', |
4094ea47 JB |
491 | ], |
492 | ]; | |
371ac69a J |
493 | } |
494 | ||
495 | /** | |
496 | * @dataProvider dataForRssFailed | |
497 | */ | |
498 | public function testRssFailed($data, $expectedMessage) | |
499 | { | |
500 | $this->logInAs('admin'); | |
501 | $client = $this->getClient(); | |
502 | ||
503 | $crawler = $client->request('GET', '/config'); | |
504 | ||
505 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
506 | ||
507 | $form = $crawler->filter('button[id=rss_config_save]')->form(); | |
508 | ||
509 | $crawler = $client->submit($form, $data); | |
510 | ||
511 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
512 | ||
4094ea47 | 513 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); |
371ac69a J |
514 | $this->assertContains($expectedMessage, $alert[0]); |
515 | } | |
8a99c7a8 KG |
516 | |
517 | public function testTaggingRuleCreation() | |
518 | { | |
519 | $this->logInAs('admin'); | |
520 | $client = $this->getClient(); | |
521 | ||
522 | $crawler = $client->request('GET', '/config'); | |
523 | ||
524 | $this->assertTrue($client->getResponse()->isSuccessful()); | |
525 | ||
526 | $form = $crawler->filter('button[id=tagging_rule_save]')->form(); | |
527 | ||
4094ea47 | 528 | $data = [ |
8a99c7a8 KG |
529 | 'tagging_rule[rule]' => 'readingTime <= 3', |
530 | 'tagging_rule[tags]' => 'short reading', | |
4094ea47 | 531 | ]; |
8a99c7a8 KG |
532 | |
533 | $client->submit($form, $data); | |
534 | ||
535 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
536 | ||
537 | $crawler = $client->followRedirect(); | |
538 | ||
bf3dc999 JB |
539 | $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]); |
540 | ||
541 | $editLink = $crawler->filter('.mode_edit')->last()->link(); | |
542 | ||
543 | $crawler = $client->click($editLink); | |
544 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
545 | $this->assertContains('?tagging-rule=', $client->getResponse()->headers->get('location')); | |
546 | ||
547 | $crawler = $client->followRedirect(); | |
548 | ||
549 | $form = $crawler->filter('button[id=tagging_rule_save]')->form(); | |
550 | ||
551 | $data = [ | |
552 | 'tagging_rule[rule]' => 'readingTime <= 30', | |
553 | 'tagging_rule[tags]' => 'short reading', | |
554 | ]; | |
555 | ||
556 | $client->submit($form, $data); | |
557 | ||
558 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
559 | ||
560 | $crawler = $client->followRedirect(); | |
561 | ||
562 | $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]); | |
563 | ||
564 | $this->assertContains('readingTime <= 30', $crawler->filter('body')->extract(['_text'])[0]); | |
8a99c7a8 | 565 | |
958671a7 | 566 | $deleteLink = $crawler->filter('.delete')->last()->link(); |
8a99c7a8 KG |
567 | |
568 | $crawler = $client->click($deleteLink); | |
569 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
570 | ||
571 | $crawler = $client->followRedirect(); | |
bf3dc999 | 572 | $this->assertContains('flashes.config.notice.tagging_rules_deleted', $crawler->filter('body')->extract(['_text'])[0]); |
8a99c7a8 KG |
573 | } |
574 | ||
575 | public function dataForTaggingRuleFailed() | |
576 | { | |
4094ea47 JB |
577 | return [ |
578 | [ | |
579 | [ | |
a3cac44c JB |
580 | 'tagging_rule[rule]' => 'unknownVar <= 3', |
581 | 'tagging_rule[tags]' => 'cool tag', | |
4094ea47 JB |
582 | ], |
583 | [ | |
a3cac44c JB |
584 | 'The variable', |
585 | 'does not exist.', | |
4094ea47 JB |
586 | ], |
587 | ], | |
588 | [ | |
589 | [ | |
a3cac44c JB |
590 | 'tagging_rule[rule]' => 'length(domainName) <= 42', |
591 | 'tagging_rule[tags]' => 'cool tag', | |
4094ea47 JB |
592 | ], |
593 | [ | |
a3cac44c JB |
594 | 'The operator', |
595 | 'does not exist.', | |
4094ea47 JB |
596 | ], |
597 | ], | |
598 | ]; | |
8a99c7a8 | 599 | } |
a3cac44c JB |
600 | |
601 | /** | |
602 | * @dataProvider dataForTaggingRuleFailed | |
603 | */ | |
604 | public function testTaggingRuleCreationFail($data, $messages) | |
605 | { | |
606 | $this->logInAs('admin'); | |
607 | $client = $this->getClient(); | |
608 | ||
609 | $crawler = $client->request('GET', '/config'); | |
610 | ||
611 | $this->assertTrue($client->getResponse()->isSuccessful()); | |
612 | ||
613 | $form = $crawler->filter('button[id=tagging_rule_save]')->form(); | |
614 | ||
4f9cf232 | 615 | $crawler = $client->submit($form, $data); |
a3cac44c JB |
616 | |
617 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
618 | ||
4094ea47 | 619 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
4f9cf232 | 620 | |
a3cac44c | 621 | foreach ($messages as $message) { |
4f9cf232 | 622 | $this->assertContains($message, $body[0]); |
a3cac44c JB |
623 | } |
624 | } | |
625 | ||
626 | public function testDeletingTaggingRuleFromAnOtherUser() | |
627 | { | |
628 | $this->logInAs('bob'); | |
629 | $client = $this->getClient(); | |
630 | ||
631 | $rule = $client->getContainer()->get('doctrine.orm.entity_manager') | |
632 | ->getRepository('WallabagCoreBundle:TaggingRule') | |
633 | ->findAll()[0]; | |
634 | ||
bf3dc999 JB |
635 | $crawler = $client->request('GET', '/tagging-rule/edit/'.$rule->getId()); |
636 | ||
637 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | |
638 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
639 | $this->assertContains('You can not access this tagging rule', $body[0]); | |
640 | } | |
641 | ||
642 | public function testEditingTaggingRuleFromAnOtherUser() | |
643 | { | |
644 | $this->logInAs('bob'); | |
645 | $client = $this->getClient(); | |
646 | ||
647 | $rule = $client->getContainer()->get('doctrine.orm.entity_manager') | |
648 | ->getRepository('WallabagCoreBundle:TaggingRule') | |
649 | ->findAll()[0]; | |
650 | ||
651 | $crawler = $client->request('GET', '/tagging-rule/edit/'.$rule->getId()); | |
4f9cf232 | 652 | |
a3cac44c | 653 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); |
4094ea47 | 654 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
4f9cf232 | 655 | $this->assertContains('You can not access this tagging rule', $body[0]); |
a3cac44c | 656 | } |
b6c00b0b JB |
657 | |
658 | public function testDemoMode() | |
659 | { | |
660 | $this->logInAs('admin'); | |
661 | $client = $this->getClient(); | |
662 | ||
663 | $config = $client->getContainer()->get('craue_config'); | |
664 | $config->set('demo_mode_enabled', 1); | |
665 | $config->set('demo_mode_username', 'admin'); | |
666 | ||
667 | $crawler = $client->request('GET', '/config'); | |
668 | ||
669 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
670 | ||
671 | $form = $crawler->filter('button[id=change_passwd_save]')->form(); | |
672 | ||
4094ea47 | 673 | $data = [ |
b6c00b0b JB |
674 | 'change_passwd[old_password]' => 'mypassword', |
675 | 'change_passwd[new_password][first]' => 'mypassword', | |
676 | 'change_passwd[new_password][second]' => 'mypassword', | |
4094ea47 | 677 | ]; |
b6c00b0b JB |
678 | |
679 | $client->submit($form, $data); | |
680 | ||
681 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
4204a06b | 682 | $this->assertContains('flashes.config.notice.password_not_updated_demo', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); |
b6c00b0b JB |
683 | |
684 | $config->set('demo_mode_enabled', 0); | |
685 | $config->set('demo_mode_username', 'wallabag'); | |
686 | } | |
4d85d7e9 | 687 | } |