]>
Commit | Line | Data |
---|---|---|
4d85d7e9 J |
1 | <?php |
2 | ||
23634d5d | 3 | namespace Tests\Wallabag\CoreBundle\Controller; |
4d85d7e9 | 4 | |
23634d5d | 5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
c3396c65 JB |
6 | use Wallabag\CoreBundle\Entity\Config; |
7 | use Wallabag\UserBundle\Entity\User; | |
4d85d7e9 | 8 | |
769e19dc | 9 | class ConfigControllerTest extends WallabagCoreTestCase |
4d85d7e9 J |
10 | { |
11 | public function testLogin() | |
12 | { | |
13 | $client = $this->getClient(); | |
14 | ||
15 | $client->request('GET', '/new'); | |
16 | ||
17 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
18 | $this->assertContains('login', $client->getResponse()->headers->get('location')); | |
19 | } | |
20 | ||
21 | public function testIndex() | |
22 | { | |
23 | $this->logInAs('admin'); | |
24 | $client = $this->getClient(); | |
25 | ||
26 | $crawler = $client->request('GET', '/config'); | |
27 | ||
28 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
29 | ||
d9085c63 J |
30 | $this->assertCount(1, $crawler->filter('button[id=config_save]')); |
31 | $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]')); | |
c844dc0c | 32 | $this->assertCount(1, $crawler->filter('button[id=update_user_save]')); |
371ac69a | 33 | $this->assertCount(1, $crawler->filter('button[id=rss_config_save]')); |
4d85d7e9 J |
34 | } |
35 | ||
36 | public function testUpdate() | |
37 | { | |
38 | $this->logInAs('admin'); | |
39 | $client = $this->getClient(); | |
40 | ||
41 | $crawler = $client->request('GET', '/config'); | |
42 | ||
43 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
44 | ||
d9085c63 | 45 | $form = $crawler->filter('button[id=config_save]')->form(); |
4d85d7e9 | 46 | |
4094ea47 | 47 | $data = [ |
23ff8d36 | 48 | 'config[theme]' => 'baggy', |
4d85d7e9 | 49 | 'config[items_per_page]' => '30', |
1b64a84b | 50 | 'config[reading_speed]' => '0.5', |
c89d35e8 | 51 | 'config[language]' => 'en', |
4094ea47 | 52 | ]; |
4d85d7e9 J |
53 | |
54 | $client->submit($form, $data); | |
55 | ||
56 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
57 | ||
58 | $crawler = $client->followRedirect(); | |
59 | ||
bf3dc999 | 60 | $this->assertContains('flashes.config.notice.config_saved', $crawler->filter('body')->extract(['_text'])[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 | ||
bf3dc999 | 216 | $this->assertContains('flashes.config.notice.password_updated', $crawler->filter('body')->extract(['_text'])[0]); |
d9085c63 | 217 | } |
c0d9eba0 J |
218 | |
219 | public function dataForUserFailed() | |
220 | { | |
4094ea47 JB |
221 | return [ |
222 | [ | |
223 | [ | |
c844dc0c J |
224 | 'update_user[name]' => '', |
225 | 'update_user[email]' => '', | |
4094ea47 | 226 | ], |
0d42217e | 227 | 'fos_user.email.blank', |
4094ea47 JB |
228 | ], |
229 | [ | |
230 | [ | |
c844dc0c J |
231 | 'update_user[name]' => '', |
232 | 'update_user[email]' => 'test', | |
4094ea47 | 233 | ], |
0d42217e | 234 | 'fos_user.email.invalid', |
4094ea47 JB |
235 | ], |
236 | ]; | |
c0d9eba0 J |
237 | } |
238 | ||
239 | /** | |
240 | * @dataProvider dataForUserFailed | |
241 | */ | |
242 | public function testUserFailed($data, $expectedMessage) | |
243 | { | |
244 | $this->logInAs('admin'); | |
245 | $client = $this->getClient(); | |
246 | ||
247 | $crawler = $client->request('GET', '/config'); | |
248 | ||
249 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
250 | ||
c844dc0c | 251 | $form = $crawler->filter('button[id=update_user_save]')->form(); |
c0d9eba0 J |
252 | |
253 | $crawler = $client->submit($form, $data); | |
254 | ||
255 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
256 | ||
4094ea47 | 257 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); |
c0d9eba0 J |
258 | $this->assertContains($expectedMessage, $alert[0]); |
259 | } | |
260 | ||
261 | public function testUserUpdate() | |
262 | { | |
263 | $this->logInAs('admin'); | |
264 | $client = $this->getClient(); | |
265 | ||
266 | $crawler = $client->request('GET', '/config'); | |
267 | ||
268 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
269 | ||
c844dc0c | 270 | $form = $crawler->filter('button[id=update_user_save]')->form(); |
c0d9eba0 | 271 | |
4094ea47 | 272 | $data = [ |
c844dc0c J |
273 | 'update_user[name]' => 'new name', |
274 | 'update_user[email]' => 'admin@wallabag.io', | |
4094ea47 | 275 | ]; |
c0d9eba0 J |
276 | |
277 | $client->submit($form, $data); | |
278 | ||
279 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
280 | ||
281 | $crawler = $client->followRedirect(); | |
282 | ||
4094ea47 | 283 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); |
4204a06b | 284 | $this->assertContains('flashes.config.notice.user_updated', $alert[0]); |
c0d9eba0 | 285 | } |
e4977b8a | 286 | |
371ac69a J |
287 | public function testRssUpdateResetToken() |
288 | { | |
289 | $this->logInAs('admin'); | |
290 | $client = $this->getClient(); | |
291 | ||
292 | // reset the token | |
293 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
294 | $user = $em | |
1210dae1 | 295 | ->getRepository('WallabagUserBundle:User') |
371ac69a J |
296 | ->findOneByUsername('admin'); |
297 | ||
298 | if (!$user) { | |
299 | $this->markTestSkipped('No user found in db.'); | |
300 | } | |
301 | ||
302 | $config = $user->getConfig(); | |
303 | $config->setRssToken(null); | |
304 | $em->persist($config); | |
305 | $em->flush(); | |
306 | ||
307 | $crawler = $client->request('GET', '/config'); | |
308 | ||
309 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
310 | ||
4094ea47 | 311 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
0d42217e | 312 | $this->assertContains('config.form_rss.no_token', $body[0]); |
371ac69a J |
313 | |
314 | $client->request('GET', '/generate-token'); | |
315 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
316 | ||
317 | $crawler = $client->followRedirect(); | |
318 | ||
4094ea47 | 319 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
0d42217e | 320 | $this->assertNotContains('config.form_rss.no_token', $body[0]); |
371ac69a J |
321 | } |
322 | ||
323 | public function testGenerateTokenAjax() | |
324 | { | |
325 | $this->logInAs('admin'); | |
326 | $client = $this->getClient(); | |
327 | ||
328 | $client->request( | |
329 | 'GET', | |
330 | '/generate-token', | |
4094ea47 JB |
331 | [], |
332 | [], | |
333 | ['HTTP_X-Requested-With' => 'XMLHttpRequest'] | |
371ac69a J |
334 | ); |
335 | ||
336 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
9744e971 | 337 | $content = json_decode($client->getResponse()->getContent(), true); |
371ac69a J |
338 | $this->assertArrayHasKey('token', $content); |
339 | } | |
340 | ||
341 | public function testRssUpdate() | |
342 | { | |
343 | $this->logInAs('admin'); | |
344 | $client = $this->getClient(); | |
345 | ||
346 | $crawler = $client->request('GET', '/config'); | |
347 | ||
371ac69a J |
348 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
349 | ||
350 | $form = $crawler->filter('button[id=rss_config_save]')->form(); | |
351 | ||
4094ea47 | 352 | $data = [ |
371ac69a | 353 | 'rss_config[rss_limit]' => 12, |
4094ea47 | 354 | ]; |
371ac69a J |
355 | |
356 | $client->submit($form, $data); | |
357 | ||
358 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
359 | ||
360 | $crawler = $client->followRedirect(); | |
361 | ||
bf3dc999 | 362 | $this->assertContains('flashes.config.notice.rss_updated', $crawler->filter('body')->extract(['_text'])[0]); |
371ac69a J |
363 | } |
364 | ||
365 | public function dataForRssFailed() | |
366 | { | |
4094ea47 JB |
367 | return [ |
368 | [ | |
369 | [ | |
371ac69a | 370 | 'rss_config[rss_limit]' => 0, |
4094ea47 | 371 | ], |
371ac69a | 372 | 'This value should be 1 or more.', |
4094ea47 JB |
373 | ], |
374 | [ | |
375 | [ | |
371ac69a | 376 | 'rss_config[rss_limit]' => 1000000000000, |
4094ea47 | 377 | ], |
0d42217e | 378 | 'validator.rss_limit_too_hight', |
4094ea47 JB |
379 | ], |
380 | ]; | |
371ac69a J |
381 | } |
382 | ||
383 | /** | |
384 | * @dataProvider dataForRssFailed | |
385 | */ | |
386 | public function testRssFailed($data, $expectedMessage) | |
387 | { | |
388 | $this->logInAs('admin'); | |
389 | $client = $this->getClient(); | |
390 | ||
391 | $crawler = $client->request('GET', '/config'); | |
392 | ||
393 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
394 | ||
395 | $form = $crawler->filter('button[id=rss_config_save]')->form(); | |
396 | ||
397 | $crawler = $client->submit($form, $data); | |
398 | ||
399 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
400 | ||
4094ea47 | 401 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); |
371ac69a J |
402 | $this->assertContains($expectedMessage, $alert[0]); |
403 | } | |
8a99c7a8 KG |
404 | |
405 | public function testTaggingRuleCreation() | |
406 | { | |
407 | $this->logInAs('admin'); | |
408 | $client = $this->getClient(); | |
409 | ||
410 | $crawler = $client->request('GET', '/config'); | |
411 | ||
412 | $this->assertTrue($client->getResponse()->isSuccessful()); | |
413 | ||
414 | $form = $crawler->filter('button[id=tagging_rule_save]')->form(); | |
415 | ||
4094ea47 | 416 | $data = [ |
8a99c7a8 KG |
417 | 'tagging_rule[rule]' => 'readingTime <= 3', |
418 | 'tagging_rule[tags]' => 'short reading', | |
4094ea47 | 419 | ]; |
8a99c7a8 KG |
420 | |
421 | $client->submit($form, $data); | |
422 | ||
423 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
424 | ||
425 | $crawler = $client->followRedirect(); | |
426 | ||
bf3dc999 JB |
427 | $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]); |
428 | ||
429 | $editLink = $crawler->filter('.mode_edit')->last()->link(); | |
430 | ||
431 | $crawler = $client->click($editLink); | |
432 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
433 | $this->assertContains('?tagging-rule=', $client->getResponse()->headers->get('location')); | |
434 | ||
435 | $crawler = $client->followRedirect(); | |
436 | ||
437 | $form = $crawler->filter('button[id=tagging_rule_save]')->form(); | |
438 | ||
439 | $data = [ | |
440 | 'tagging_rule[rule]' => 'readingTime <= 30', | |
441 | 'tagging_rule[tags]' => 'short reading', | |
442 | ]; | |
443 | ||
444 | $client->submit($form, $data); | |
445 | ||
446 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
447 | ||
448 | $crawler = $client->followRedirect(); | |
449 | ||
450 | $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]); | |
451 | ||
452 | $this->assertContains('readingTime <= 30', $crawler->filter('body')->extract(['_text'])[0]); | |
8a99c7a8 | 453 | |
958671a7 | 454 | $deleteLink = $crawler->filter('.delete')->last()->link(); |
8a99c7a8 KG |
455 | |
456 | $crawler = $client->click($deleteLink); | |
457 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
458 | ||
459 | $crawler = $client->followRedirect(); | |
bf3dc999 | 460 | $this->assertContains('flashes.config.notice.tagging_rules_deleted', $crawler->filter('body')->extract(['_text'])[0]); |
8a99c7a8 KG |
461 | } |
462 | ||
463 | public function dataForTaggingRuleFailed() | |
464 | { | |
4094ea47 JB |
465 | return [ |
466 | [ | |
467 | [ | |
a3cac44c JB |
468 | 'tagging_rule[rule]' => 'unknownVar <= 3', |
469 | 'tagging_rule[tags]' => 'cool tag', | |
4094ea47 JB |
470 | ], |
471 | [ | |
a3cac44c JB |
472 | 'The variable', |
473 | 'does not exist.', | |
4094ea47 JB |
474 | ], |
475 | ], | |
476 | [ | |
477 | [ | |
a3cac44c JB |
478 | 'tagging_rule[rule]' => 'length(domainName) <= 42', |
479 | 'tagging_rule[tags]' => 'cool tag', | |
4094ea47 JB |
480 | ], |
481 | [ | |
a3cac44c JB |
482 | 'The operator', |
483 | 'does not exist.', | |
4094ea47 JB |
484 | ], |
485 | ], | |
486 | ]; | |
8a99c7a8 | 487 | } |
a3cac44c JB |
488 | |
489 | /** | |
490 | * @dataProvider dataForTaggingRuleFailed | |
491 | */ | |
492 | public function testTaggingRuleCreationFail($data, $messages) | |
493 | { | |
494 | $this->logInAs('admin'); | |
495 | $client = $this->getClient(); | |
496 | ||
497 | $crawler = $client->request('GET', '/config'); | |
498 | ||
499 | $this->assertTrue($client->getResponse()->isSuccessful()); | |
500 | ||
501 | $form = $crawler->filter('button[id=tagging_rule_save]')->form(); | |
502 | ||
4f9cf232 | 503 | $crawler = $client->submit($form, $data); |
a3cac44c JB |
504 | |
505 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
506 | ||
4094ea47 | 507 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
4f9cf232 | 508 | |
a3cac44c | 509 | foreach ($messages as $message) { |
4f9cf232 | 510 | $this->assertContains($message, $body[0]); |
a3cac44c JB |
511 | } |
512 | } | |
513 | ||
514 | public function testDeletingTaggingRuleFromAnOtherUser() | |
515 | { | |
516 | $this->logInAs('bob'); | |
517 | $client = $this->getClient(); | |
518 | ||
519 | $rule = $client->getContainer()->get('doctrine.orm.entity_manager') | |
520 | ->getRepository('WallabagCoreBundle:TaggingRule') | |
521 | ->findAll()[0]; | |
522 | ||
bf3dc999 JB |
523 | $crawler = $client->request('GET', '/tagging-rule/edit/'.$rule->getId()); |
524 | ||
525 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | |
526 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
527 | $this->assertContains('You can not access this tagging rule', $body[0]); | |
528 | } | |
529 | ||
530 | public function testEditingTaggingRuleFromAnOtherUser() | |
531 | { | |
532 | $this->logInAs('bob'); | |
533 | $client = $this->getClient(); | |
534 | ||
535 | $rule = $client->getContainer()->get('doctrine.orm.entity_manager') | |
536 | ->getRepository('WallabagCoreBundle:TaggingRule') | |
537 | ->findAll()[0]; | |
538 | ||
539 | $crawler = $client->request('GET', '/tagging-rule/edit/'.$rule->getId()); | |
4f9cf232 | 540 | |
a3cac44c | 541 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); |
4094ea47 | 542 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
4f9cf232 | 543 | $this->assertContains('You can not access this tagging rule', $body[0]); |
a3cac44c | 544 | } |
b6c00b0b JB |
545 | |
546 | public function testDemoMode() | |
547 | { | |
548 | $this->logInAs('admin'); | |
549 | $client = $this->getClient(); | |
550 | ||
551 | $config = $client->getContainer()->get('craue_config'); | |
552 | $config->set('demo_mode_enabled', 1); | |
553 | $config->set('demo_mode_username', 'admin'); | |
554 | ||
555 | $crawler = $client->request('GET', '/config'); | |
556 | ||
557 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
558 | ||
559 | $form = $crawler->filter('button[id=change_passwd_save]')->form(); | |
560 | ||
4094ea47 | 561 | $data = [ |
b6c00b0b JB |
562 | 'change_passwd[old_password]' => 'mypassword', |
563 | 'change_passwd[new_password][first]' => 'mypassword', | |
564 | 'change_passwd[new_password][second]' => 'mypassword', | |
4094ea47 | 565 | ]; |
b6c00b0b JB |
566 | |
567 | $client->submit($form, $data); | |
568 | ||
569 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
4204a06b | 570 | $this->assertContains('flashes.config.notice.password_not_updated_demo', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); |
b6c00b0b JB |
571 | |
572 | $config->set('demo_mode_enabled', 0); | |
573 | $config->set('demo_mode_username', 'wallabag'); | |
574 | } | |
821bb876 NL |
575 | |
576 | public function testDeleteUserButtonVisibility() | |
577 | { | |
578 | $this->logInAs('admin'); | |
579 | $client = $this->getClient(); | |
580 | ||
581 | $crawler = $client->request('GET', '/config'); | |
582 | ||
583 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
876d77a6 | 584 | $this->assertContains('config.form_user.delete.button', $body[0]); |
821bb876 NL |
585 | |
586 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
587 | ||
821bb876 NL |
588 | $user = $em |
589 | ->getRepository('WallabagUserBundle:User') | |
590 | ->findOneByUsername('empty'); | |
591 | $user->setExpired(1); | |
592 | $em->persist($user); | |
593 | ||
594 | $user = $em | |
595 | ->getRepository('WallabagUserBundle:User') | |
596 | ->findOneByUsername('bob'); | |
597 | $user->setExpired(1); | |
598 | $em->persist($user); | |
599 | ||
600 | $em->flush(); | |
601 | ||
602 | $crawler = $client->request('GET', '/config'); | |
603 | ||
604 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
876d77a6 | 605 | $this->assertNotContains('config.form_user.delete.button', $body[0]); |
821bb876 NL |
606 | |
607 | $client->request('GET', '/account/delete'); | |
608 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | |
609 | ||
821bb876 NL |
610 | $user = $em |
611 | ->getRepository('WallabagUserBundle:User') | |
612 | ->findOneByUsername('empty'); | |
613 | $user->setExpired(0); | |
614 | $em->persist($user); | |
615 | ||
616 | $user = $em | |
617 | ->getRepository('WallabagUserBundle:User') | |
618 | ->findOneByUsername('bob'); | |
619 | $user->setExpired(0); | |
620 | $em->persist($user); | |
621 | ||
622 | $em->flush(); | |
623 | } | |
624 | ||
625 | public function testDeleteAccount() | |
626 | { | |
821bb876 | 627 | $client = $this->getClient(); |
c3396c65 JB |
628 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); |
629 | ||
630 | $user = new User(); | |
631 | $user->setName('Wallace'); | |
632 | $user->setEmail('wallace@wallabag.org'); | |
633 | $user->setUsername('wallace'); | |
634 | $user->setPlainPassword('wallace'); | |
635 | $user->setEnabled(true); | |
636 | $user->addRole('ROLE_SUPER_ADMIN'); | |
637 | ||
638 | $em->persist($user); | |
639 | ||
640 | $config = new Config($user); | |
641 | ||
642 | $config->setTheme('material'); | |
643 | $config->setItemsPerPage(30); | |
644 | $config->setReadingSpeed(1); | |
645 | $config->setLanguage('en'); | |
646 | $config->setPocketConsumerKey('xxxxx'); | |
647 | ||
648 | $em->persist($config); | |
649 | $em->flush(); | |
650 | ||
651 | $this->logInAs('wallace'); | |
876d77a6 | 652 | $loggedInUserId = $this->getLoggedInUserId(); |
821bb876 | 653 | |
b8402687 NL |
654 | // create entry to check after user deletion |
655 | // that this entry is also deleted | |
656 | $crawler = $client->request('GET', '/new'); | |
657 | ||
658 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | |
659 | ||
660 | $form = $crawler->filter('form[name=entry]')->form(); | |
661 | $data = [ | |
662 | 'entry[url]' => $url = 'https://github.com/wallabag/wallabag', | |
663 | ]; | |
664 | ||
665 | $client->submit($form, $data); | |
666 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
667 | ||
821bb876 NL |
668 | $crawler = $client->request('GET', '/config'); |
669 | ||
71254701 | 670 | $deleteLink = $crawler->filter('.delete-account')->last()->link(); |
821bb876 NL |
671 | |
672 | $client->click($deleteLink); | |
673 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | |
674 | ||
675 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
676 | $user = $em | |
677 | ->getRepository('WallabagUserBundle:User') | |
678 | ->createQueryBuilder('u') | |
679 | ->where('u.username = :username')->setParameter('username', 'wallace') | |
680 | ->getQuery() | |
681 | ->getOneOrNullResult() | |
682 | ; | |
683 | ||
71254701 | 684 | $this->assertNull($user); |
b8402687 NL |
685 | |
686 | $entries = $client->getContainer() | |
687 | ->get('doctrine.orm.entity_manager') | |
688 | ->getRepository('WallabagCoreBundle:Entry') | |
876d77a6 | 689 | ->findByUser($loggedInUserId); |
b8402687 NL |
690 | |
691 | $this->assertEmpty($entries); | |
821bb876 | 692 | } |
4d85d7e9 | 693 | } |