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