]>
Commit | Line | Data |
---|---|---|
4d85d7e9 J |
1 | <?php |
2 | ||
1e0d8ad7 | 3 | namespace Tests\Wallabag\CoreBundle\Controller; |
4d85d7e9 | 4 | |
23634d5d | 5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
f808b016 | 6 | use Wallabag\AnnotationBundle\Entity\Annotation; |
c3396c65 | 7 | use Wallabag\CoreBundle\Entity\Config; |
206bade5 JB |
8 | use Wallabag\CoreBundle\Entity\Entry; |
9 | use Wallabag\CoreBundle\Entity\Tag; | |
f808b016 | 10 | use Wallabag\UserBundle\Entity\User; |
4d85d7e9 | 11 | |
769e19dc | 12 | class ConfigControllerTest extends WallabagCoreTestCase |
4d85d7e9 J |
13 | { |
14 | public function testLogin() | |
15 | { | |
16 | $client = $this->getClient(); | |
17 | ||
18 | $client->request('GET', '/new'); | |
19 | ||
f808b016 | 20 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
4d85d7e9 J |
21 | $this->assertContains('login', $client->getResponse()->headers->get('location')); |
22 | } | |
23 | ||
24 | public function testIndex() | |
25 | { | |
26 | $this->logInAs('admin'); | |
27 | $client = $this->getClient(); | |
28 | ||
29 | $crawler = $client->request('GET', '/config'); | |
30 | ||
f808b016 | 31 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
4d85d7e9 | 32 | |
d9085c63 J |
33 | $this->assertCount(1, $crawler->filter('button[id=config_save]')); |
34 | $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]')); | |
c844dc0c | 35 | $this->assertCount(1, $crawler->filter('button[id=update_user_save]')); |
531c8d0a | 36 | $this->assertCount(1, $crawler->filter('button[id=feed_config_save]')); |
4d85d7e9 J |
37 | } |
38 | ||
39 | public function testUpdate() | |
40 | { | |
41 | $this->logInAs('admin'); | |
42 | $client = $this->getClient(); | |
43 | ||
44 | $crawler = $client->request('GET', '/config'); | |
45 | ||
f808b016 | 46 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
4d85d7e9 | 47 | |
d9085c63 | 48 | $form = $crawler->filter('button[id=config_save]')->form(); |
4d85d7e9 | 49 | |
4094ea47 | 50 | $data = [ |
23ff8d36 | 51 | 'config[theme]' => 'baggy', |
4d85d7e9 | 52 | 'config[items_per_page]' => '30', |
1b64a84b | 53 | 'config[reading_speed]' => '0.5', |
a42f38d9 | 54 | 'config[action_mark_as_read]' => '0', |
c89d35e8 | 55 | 'config[language]' => 'en', |
4094ea47 | 56 | ]; |
4d85d7e9 J |
57 | |
58 | $client->submit($form, $data); | |
59 | ||
f808b016 | 60 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
4d85d7e9 J |
61 | |
62 | $crawler = $client->followRedirect(); | |
63 | ||
bf3dc999 | 64 | $this->assertContains('flashes.config.notice.config_saved', $crawler->filter('body')->extract(['_text'])[0]); |
4d85d7e9 J |
65 | } |
66 | ||
c4c062cc NL |
67 | public function testChangeReadingSpeed() |
68 | { | |
69 | $this->logInAs('admin'); | |
7ab5eb95 | 70 | $this->useTheme('baggy'); |
c4c062cc NL |
71 | $client = $this->getClient(); |
72 | ||
7ab5eb95 | 73 | $entry = new Entry($this->getLoggedInUser()); |
74 | $entry->setUrl('http://0.0.0.0/test-entry1') | |
75 | ->setReadingTime(22); | |
76 | $this->getEntityManager()->persist($entry); | |
77 | ||
78 | $this->getEntityManager()->flush(); | |
79 | $this->getEntityManager()->clear(); | |
80 | ||
c4c062cc NL |
81 | $crawler = $client->request('GET', '/unread/list'); |
82 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
83 | $dataFilters = [ | |
84 | 'entry_filter[readingTime][right_number]' => 22, | |
85 | 'entry_filter[readingTime][left_number]' => 22, | |
86 | ]; | |
87 | $crawler = $client->submit($form, $dataFilters); | |
88 | $this->assertCount(1, $crawler->filter('div[class=entry]')); | |
89 | ||
90 | // Change reading speed | |
91 | $crawler = $client->request('GET', '/config'); | |
92 | $form = $crawler->filter('button[id=config_save]')->form(); | |
93 | $data = [ | |
94 | 'config[reading_speed]' => '2', | |
95 | ]; | |
96 | $client->submit($form, $data); | |
97 | ||
98 | // Is the entry still available via filters? | |
99 | $crawler = $client->request('GET', '/unread/list'); | |
100 | $form = $crawler->filter('button[id=submit-filter]')->form(); | |
101 | $crawler = $client->submit($form, $dataFilters); | |
102 | $this->assertCount(0, $crawler->filter('div[class=entry]')); | |
103 | ||
104 | // Restore old configuration | |
105 | $crawler = $client->request('GET', '/config'); | |
106 | $form = $crawler->filter('button[id=config_save]')->form(); | |
107 | $data = [ | |
108 | 'config[reading_speed]' => '0.5', | |
109 | ]; | |
110 | $client->submit($form, $data); | |
111 | } | |
112 | ||
4d85d7e9 J |
113 | public function dataForUpdateFailed() |
114 | { | |
4094ea47 JB |
115 | return [ |
116 | [[ | |
23ff8d36 | 117 | 'config[theme]' => 'baggy', |
4d85d7e9 | 118 | 'config[items_per_page]' => '', |
c89d35e8 | 119 | 'config[language]' => 'en', |
4094ea47 JB |
120 | ]], |
121 | ]; | |
4d85d7e9 J |
122 | } |
123 | ||
124 | /** | |
125 | * @dataProvider dataForUpdateFailed | |
126 | */ | |
127 | public function testUpdateFailed($data) | |
128 | { | |
129 | $this->logInAs('admin'); | |
130 | $client = $this->getClient(); | |
131 | ||
132 | $crawler = $client->request('GET', '/config'); | |
133 | ||
f808b016 | 134 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
4d85d7e9 | 135 | |
d9085c63 | 136 | $form = $crawler->filter('button[id=config_save]')->form(); |
4d85d7e9 J |
137 | |
138 | $crawler = $client->submit($form, $data); | |
139 | ||
f808b016 | 140 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
4d85d7e9 | 141 | |
4094ea47 | 142 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); |
4d85d7e9 J |
143 | $this->assertContains('This value should not be blank', $alert[0]); |
144 | } | |
d9085c63 J |
145 | |
146 | public function dataForChangePasswordFailed() | |
147 | { | |
4094ea47 JB |
148 | return [ |
149 | [ | |
150 | [ | |
4ab58dcf | 151 | 'change_passwd[old_password]' => 'material', |
d9085c63 J |
152 | 'change_passwd[new_password][first]' => '', |
153 | 'change_passwd[new_password][second]' => '', | |
4094ea47 | 154 | ], |
0d42217e | 155 | 'validator.password_wrong_value', |
4094ea47 JB |
156 | ], |
157 | [ | |
158 | [ | |
d9085c63 J |
159 | 'change_passwd[old_password]' => 'mypassword', |
160 | 'change_passwd[new_password][first]' => '', | |
161 | 'change_passwd[new_password][second]' => '', | |
4094ea47 | 162 | ], |
c0d9eba0 | 163 | 'This value should not be blank', |
4094ea47 JB |
164 | ], |
165 | [ | |
166 | [ | |
d9085c63 J |
167 | 'change_passwd[old_password]' => 'mypassword', |
168 | 'change_passwd[new_password][first]' => 'hop', | |
169 | 'change_passwd[new_password][second]' => '', | |
4094ea47 | 170 | ], |
0d42217e | 171 | 'validator.password_must_match', |
4094ea47 JB |
172 | ], |
173 | [ | |
174 | [ | |
d9085c63 J |
175 | 'change_passwd[old_password]' => 'mypassword', |
176 | 'change_passwd[new_password][first]' => 'hop', | |
177 | 'change_passwd[new_password][second]' => 'hop', | |
4094ea47 | 178 | ], |
0d42217e | 179 | 'validator.password_too_short', |
4094ea47 JB |
180 | ], |
181 | ]; | |
d9085c63 J |
182 | } |
183 | ||
184 | /** | |
185 | * @dataProvider dataForChangePasswordFailed | |
186 | */ | |
187 | public function testChangePasswordFailed($data, $expectedMessage) | |
188 | { | |
189 | $this->logInAs('admin'); | |
190 | $client = $this->getClient(); | |
191 | ||
192 | $crawler = $client->request('GET', '/config'); | |
193 | ||
f808b016 | 194 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
d9085c63 J |
195 | |
196 | $form = $crawler->filter('button[id=change_passwd_save]')->form(); | |
197 | ||
198 | $crawler = $client->submit($form, $data); | |
199 | ||
f808b016 | 200 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
d9085c63 | 201 | |
4094ea47 | 202 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); |
d9085c63 J |
203 | $this->assertContains($expectedMessage, $alert[0]); |
204 | } | |
205 | ||
206 | public function testChangePassword() | |
207 | { | |
208 | $this->logInAs('admin'); | |
209 | $client = $this->getClient(); | |
210 | ||
211 | $crawler = $client->request('GET', '/config'); | |
212 | ||
f808b016 | 213 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
d9085c63 J |
214 | |
215 | $form = $crawler->filter('button[id=change_passwd_save]')->form(); | |
216 | ||
4094ea47 | 217 | $data = [ |
d9085c63 J |
218 | 'change_passwd[old_password]' => 'mypassword', |
219 | 'change_passwd[new_password][first]' => 'mypassword', | |
220 | 'change_passwd[new_password][second]' => 'mypassword', | |
4094ea47 | 221 | ]; |
d9085c63 J |
222 | |
223 | $client->submit($form, $data); | |
224 | ||
f808b016 | 225 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
d9085c63 J |
226 | |
227 | $crawler = $client->followRedirect(); | |
228 | ||
bf3dc999 | 229 | $this->assertContains('flashes.config.notice.password_updated', $crawler->filter('body')->extract(['_text'])[0]); |
d9085c63 | 230 | } |
c0d9eba0 J |
231 | |
232 | public function dataForUserFailed() | |
233 | { | |
4094ea47 JB |
234 | return [ |
235 | [ | |
236 | [ | |
c844dc0c J |
237 | 'update_user[name]' => '', |
238 | 'update_user[email]' => '', | |
4094ea47 | 239 | ], |
0d42217e | 240 | 'fos_user.email.blank', |
4094ea47 JB |
241 | ], |
242 | [ | |
243 | [ | |
c844dc0c J |
244 | 'update_user[name]' => '', |
245 | 'update_user[email]' => 'test', | |
4094ea47 | 246 | ], |
0d42217e | 247 | 'fos_user.email.invalid', |
4094ea47 JB |
248 | ], |
249 | ]; | |
c0d9eba0 J |
250 | } |
251 | ||
252 | /** | |
253 | * @dataProvider dataForUserFailed | |
254 | */ | |
255 | public function testUserFailed($data, $expectedMessage) | |
256 | { | |
257 | $this->logInAs('admin'); | |
258 | $client = $this->getClient(); | |
259 | ||
260 | $crawler = $client->request('GET', '/config'); | |
261 | ||
f808b016 | 262 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
c0d9eba0 | 263 | |
c844dc0c | 264 | $form = $crawler->filter('button[id=update_user_save]')->form(); |
c0d9eba0 J |
265 | |
266 | $crawler = $client->submit($form, $data); | |
267 | ||
f808b016 | 268 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
c0d9eba0 | 269 | |
4094ea47 | 270 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); |
c0d9eba0 J |
271 | $this->assertContains($expectedMessage, $alert[0]); |
272 | } | |
273 | ||
274 | public function testUserUpdate() | |
275 | { | |
276 | $this->logInAs('admin'); | |
277 | $client = $this->getClient(); | |
278 | ||
279 | $crawler = $client->request('GET', '/config'); | |
280 | ||
f808b016 | 281 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
c0d9eba0 | 282 | |
c844dc0c | 283 | $form = $crawler->filter('button[id=update_user_save]')->form(); |
c0d9eba0 | 284 | |
4094ea47 | 285 | $data = [ |
c844dc0c J |
286 | 'update_user[name]' => 'new name', |
287 | 'update_user[email]' => 'admin@wallabag.io', | |
4094ea47 | 288 | ]; |
c0d9eba0 J |
289 | |
290 | $client->submit($form, $data); | |
291 | ||
f808b016 | 292 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
c0d9eba0 J |
293 | |
294 | $crawler = $client->followRedirect(); | |
295 | ||
4094ea47 | 296 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); |
4204a06b | 297 | $this->assertContains('flashes.config.notice.user_updated', $alert[0]); |
c0d9eba0 | 298 | } |
e4977b8a | 299 | |
531c8d0a | 300 | public function testFeedUpdateResetToken() |
371ac69a J |
301 | { |
302 | $this->logInAs('admin'); | |
303 | $client = $this->getClient(); | |
304 | ||
305 | // reset the token | |
306 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
307 | $user = $em | |
1210dae1 | 308 | ->getRepository('WallabagUserBundle:User') |
371ac69a J |
309 | ->findOneByUsername('admin'); |
310 | ||
311 | if (!$user) { | |
312 | $this->markTestSkipped('No user found in db.'); | |
313 | } | |
314 | ||
315 | $config = $user->getConfig(); | |
531c8d0a | 316 | $config->setFeedToken(null); |
371ac69a J |
317 | $em->persist($config); |
318 | $em->flush(); | |
319 | ||
320 | $crawler = $client->request('GET', '/config'); | |
321 | ||
f808b016 | 322 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
371ac69a | 323 | |
4094ea47 | 324 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
531c8d0a | 325 | $this->assertContains('config.form_feed.no_token', $body[0]); |
371ac69a J |
326 | |
327 | $client->request('GET', '/generate-token'); | |
f808b016 | 328 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
371ac69a J |
329 | |
330 | $crawler = $client->followRedirect(); | |
331 | ||
4094ea47 | 332 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
c4bf12aa | 333 | $this->assertContains('config.form_feed.token_reset', $body[0]); |
371ac69a J |
334 | } |
335 | ||
336 | public function testGenerateTokenAjax() | |
337 | { | |
338 | $this->logInAs('admin'); | |
339 | $client = $this->getClient(); | |
340 | ||
341 | $client->request( | |
342 | 'GET', | |
343 | '/generate-token', | |
4094ea47 JB |
344 | [], |
345 | [], | |
346 | ['HTTP_X-Requested-With' => 'XMLHttpRequest'] | |
371ac69a J |
347 | ); |
348 | ||
f808b016 | 349 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
9744e971 | 350 | $content = json_decode($client->getResponse()->getContent(), true); |
371ac69a J |
351 | $this->assertArrayHasKey('token', $content); |
352 | } | |
353 | ||
c4bf12aa JB |
354 | public function testRevokeTokenAjax() |
355 | { | |
356 | $this->logInAs('admin'); | |
357 | $client = $this->getClient(); | |
358 | ||
359 | $client->request( | |
360 | 'GET', | |
361 | '/revoke-token', | |
362 | [], | |
363 | [], | |
364 | ['HTTP_X-Requested-With' => 'XMLHttpRequest'] | |
365 | ); | |
366 | ||
367 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
368 | } | |
369 | ||
531c8d0a | 370 | public function testFeedUpdate() |
371ac69a J |
371 | { |
372 | $this->logInAs('admin'); | |
373 | $client = $this->getClient(); | |
374 | ||
375 | $crawler = $client->request('GET', '/config'); | |
376 | ||
f808b016 | 377 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
371ac69a | 378 | |
531c8d0a | 379 | $form = $crawler->filter('button[id=feed_config_save]')->form(); |
371ac69a | 380 | |
4094ea47 | 381 | $data = [ |
531c8d0a | 382 | 'feed_config[feed_limit]' => 12, |
4094ea47 | 383 | ]; |
371ac69a J |
384 | |
385 | $client->submit($form, $data); | |
386 | ||
f808b016 | 387 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
371ac69a J |
388 | |
389 | $crawler = $client->followRedirect(); | |
390 | ||
531c8d0a | 391 | $this->assertContains('flashes.config.notice.feed_updated', $crawler->filter('body')->extract(['_text'])[0]); |
371ac69a J |
392 | } |
393 | ||
531c8d0a | 394 | public function dataForFeedFailed() |
371ac69a | 395 | { |
4094ea47 JB |
396 | return [ |
397 | [ | |
398 | [ | |
531c8d0a | 399 | 'feed_config[feed_limit]' => 0, |
4094ea47 | 400 | ], |
371ac69a | 401 | 'This value should be 1 or more.', |
4094ea47 JB |
402 | ], |
403 | [ | |
404 | [ | |
531c8d0a | 405 | 'feed_config[feed_limit]' => 1000000000000, |
4094ea47 | 406 | ], |
531c8d0a | 407 | 'validator.feed_limit_too_high', |
4094ea47 JB |
408 | ], |
409 | ]; | |
371ac69a J |
410 | } |
411 | ||
412 | /** | |
531c8d0a | 413 | * @dataProvider dataForFeedFailed |
371ac69a | 414 | */ |
531c8d0a | 415 | public function testFeedFailed($data, $expectedMessage) |
371ac69a J |
416 | { |
417 | $this->logInAs('admin'); | |
418 | $client = $this->getClient(); | |
419 | ||
420 | $crawler = $client->request('GET', '/config'); | |
421 | ||
f808b016 | 422 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
371ac69a | 423 | |
531c8d0a | 424 | $form = $crawler->filter('button[id=feed_config_save]')->form(); |
371ac69a J |
425 | |
426 | $crawler = $client->submit($form, $data); | |
427 | ||
f808b016 | 428 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
371ac69a | 429 | |
4094ea47 | 430 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); |
371ac69a J |
431 | $this->assertContains($expectedMessage, $alert[0]); |
432 | } | |
8a99c7a8 KG |
433 | |
434 | public function testTaggingRuleCreation() | |
435 | { | |
436 | $this->logInAs('admin'); | |
7ab5eb95 | 437 | $this->useTheme('baggy'); |
8a99c7a8 KG |
438 | $client = $this->getClient(); |
439 | ||
440 | $crawler = $client->request('GET', '/config'); | |
441 | ||
f808b016 | 442 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
8a99c7a8 KG |
443 | |
444 | $form = $crawler->filter('button[id=tagging_rule_save]')->form(); | |
445 | ||
4094ea47 | 446 | $data = [ |
8a99c7a8 KG |
447 | 'tagging_rule[rule]' => 'readingTime <= 3', |
448 | 'tagging_rule[tags]' => 'short reading', | |
4094ea47 | 449 | ]; |
8a99c7a8 KG |
450 | |
451 | $client->submit($form, $data); | |
452 | ||
f808b016 | 453 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
8a99c7a8 KG |
454 | |
455 | $crawler = $client->followRedirect(); | |
456 | ||
bf3dc999 JB |
457 | $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]); |
458 | ||
459 | $editLink = $crawler->filter('.mode_edit')->last()->link(); | |
460 | ||
461 | $crawler = $client->click($editLink); | |
f808b016 | 462 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
bf3dc999 JB |
463 | $this->assertContains('?tagging-rule=', $client->getResponse()->headers->get('location')); |
464 | ||
465 | $crawler = $client->followRedirect(); | |
466 | ||
467 | $form = $crawler->filter('button[id=tagging_rule_save]')->form(); | |
468 | ||
469 | $data = [ | |
470 | 'tagging_rule[rule]' => 'readingTime <= 30', | |
471 | 'tagging_rule[tags]' => 'short reading', | |
472 | ]; | |
473 | ||
474 | $client->submit($form, $data); | |
475 | ||
f808b016 | 476 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
bf3dc999 JB |
477 | |
478 | $crawler = $client->followRedirect(); | |
479 | ||
480 | $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]); | |
481 | ||
482 | $this->assertContains('readingTime <= 30', $crawler->filter('body')->extract(['_text'])[0]); | |
8a99c7a8 | 483 | |
958671a7 | 484 | $deleteLink = $crawler->filter('.delete')->last()->link(); |
8a99c7a8 KG |
485 | |
486 | $crawler = $client->click($deleteLink); | |
f808b016 | 487 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
8a99c7a8 KG |
488 | |
489 | $crawler = $client->followRedirect(); | |
bf3dc999 | 490 | $this->assertContains('flashes.config.notice.tagging_rules_deleted', $crawler->filter('body')->extract(['_text'])[0]); |
8a99c7a8 KG |
491 | } |
492 | ||
493 | public function dataForTaggingRuleFailed() | |
494 | { | |
4094ea47 JB |
495 | return [ |
496 | [ | |
497 | [ | |
a3cac44c JB |
498 | 'tagging_rule[rule]' => 'unknownVar <= 3', |
499 | 'tagging_rule[tags]' => 'cool tag', | |
4094ea47 JB |
500 | ], |
501 | [ | |
a3cac44c JB |
502 | 'The variable', |
503 | 'does not exist.', | |
4094ea47 JB |
504 | ], |
505 | ], | |
506 | [ | |
507 | [ | |
a3cac44c JB |
508 | 'tagging_rule[rule]' => 'length(domainName) <= 42', |
509 | 'tagging_rule[tags]' => 'cool tag', | |
4094ea47 JB |
510 | ], |
511 | [ | |
a3cac44c JB |
512 | 'The operator', |
513 | 'does not exist.', | |
4094ea47 JB |
514 | ], |
515 | ], | |
516 | ]; | |
8a99c7a8 | 517 | } |
a3cac44c JB |
518 | |
519 | /** | |
520 | * @dataProvider dataForTaggingRuleFailed | |
521 | */ | |
522 | public function testTaggingRuleCreationFail($data, $messages) | |
523 | { | |
524 | $this->logInAs('admin'); | |
525 | $client = $this->getClient(); | |
526 | ||
527 | $crawler = $client->request('GET', '/config'); | |
528 | ||
f808b016 | 529 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
a3cac44c JB |
530 | |
531 | $form = $crawler->filter('button[id=tagging_rule_save]')->form(); | |
532 | ||
4f9cf232 | 533 | $crawler = $client->submit($form, $data); |
a3cac44c | 534 | |
f808b016 | 535 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
a3cac44c | 536 | |
4094ea47 | 537 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
4f9cf232 | 538 | |
a3cac44c | 539 | foreach ($messages as $message) { |
4f9cf232 | 540 | $this->assertContains($message, $body[0]); |
a3cac44c JB |
541 | } |
542 | } | |
543 | ||
5aa0294c JB |
544 | public function testTaggingRuleTooLong() |
545 | { | |
546 | $this->logInAs('admin'); | |
547 | $client = $this->getClient(); | |
548 | ||
549 | $crawler = $client->request('GET', '/config'); | |
550 | ||
f808b016 | 551 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
5aa0294c JB |
552 | |
553 | $form = $crawler->filter('button[id=tagging_rule_save]')->form(); | |
554 | ||
555 | $crawler = $client->submit($form, [ | |
556 | 'tagging_rule[rule]' => str_repeat('title', 60), | |
557 | 'tagging_rule[tags]' => 'cool tag', | |
558 | ]); | |
559 | ||
f808b016 | 560 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
5aa0294c JB |
561 | |
562 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
563 | ||
564 | $this->assertContains('255 characters', $body[0]); | |
565 | } | |
566 | ||
a3cac44c JB |
567 | public function testDeletingTaggingRuleFromAnOtherUser() |
568 | { | |
569 | $this->logInAs('bob'); | |
570 | $client = $this->getClient(); | |
571 | ||
572 | $rule = $client->getContainer()->get('doctrine.orm.entity_manager') | |
573 | ->getRepository('WallabagCoreBundle:TaggingRule') | |
574 | ->findAll()[0]; | |
575 | ||
f808b016 | 576 | $crawler = $client->request('GET', '/tagging-rule/edit/' . $rule->getId()); |
bf3dc999 | 577 | |
f808b016 | 578 | $this->assertSame(403, $client->getResponse()->getStatusCode()); |
bf3dc999 JB |
579 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
580 | $this->assertContains('You can not access this tagging rule', $body[0]); | |
581 | } | |
582 | ||
583 | public function testEditingTaggingRuleFromAnOtherUser() | |
584 | { | |
585 | $this->logInAs('bob'); | |
586 | $client = $this->getClient(); | |
587 | ||
588 | $rule = $client->getContainer()->get('doctrine.orm.entity_manager') | |
589 | ->getRepository('WallabagCoreBundle:TaggingRule') | |
590 | ->findAll()[0]; | |
591 | ||
f808b016 | 592 | $crawler = $client->request('GET', '/tagging-rule/edit/' . $rule->getId()); |
4f9cf232 | 593 | |
f808b016 | 594 | $this->assertSame(403, $client->getResponse()->getStatusCode()); |
4094ea47 | 595 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
4f9cf232 | 596 | $this->assertContains('You can not access this tagging rule', $body[0]); |
a3cac44c | 597 | } |
b6c00b0b JB |
598 | |
599 | public function testDemoMode() | |
600 | { | |
601 | $this->logInAs('admin'); | |
602 | $client = $this->getClient(); | |
603 | ||
604 | $config = $client->getContainer()->get('craue_config'); | |
605 | $config->set('demo_mode_enabled', 1); | |
606 | $config->set('demo_mode_username', 'admin'); | |
607 | ||
608 | $crawler = $client->request('GET', '/config'); | |
609 | ||
f808b016 | 610 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
b6c00b0b JB |
611 | |
612 | $form = $crawler->filter('button[id=change_passwd_save]')->form(); | |
613 | ||
4094ea47 | 614 | $data = [ |
b6c00b0b JB |
615 | 'change_passwd[old_password]' => 'mypassword', |
616 | 'change_passwd[new_password][first]' => 'mypassword', | |
617 | 'change_passwd[new_password][second]' => 'mypassword', | |
4094ea47 | 618 | ]; |
b6c00b0b JB |
619 | |
620 | $client->submit($form, $data); | |
621 | ||
f808b016 | 622 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
4204a06b | 623 | $this->assertContains('flashes.config.notice.password_not_updated_demo', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); |
b6c00b0b JB |
624 | |
625 | $config->set('demo_mode_enabled', 0); | |
626 | $config->set('demo_mode_username', 'wallabag'); | |
627 | } | |
821bb876 NL |
628 | |
629 | public function testDeleteUserButtonVisibility() | |
630 | { | |
631 | $this->logInAs('admin'); | |
632 | $client = $this->getClient(); | |
633 | ||
634 | $crawler = $client->request('GET', '/config'); | |
635 | ||
636 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
876d77a6 | 637 | $this->assertContains('config.form_user.delete.button', $body[0]); |
821bb876 NL |
638 | |
639 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
640 | ||
821bb876 NL |
641 | $user = $em |
642 | ->getRepository('WallabagUserBundle:User') | |
643 | ->findOneByUsername('empty'); | |
5066c3e0 | 644 | $user->setEnabled(false); |
821bb876 NL |
645 | $em->persist($user); |
646 | ||
647 | $user = $em | |
648 | ->getRepository('WallabagUserBundle:User') | |
649 | ->findOneByUsername('bob'); | |
5066c3e0 | 650 | $user->setEnabled(false); |
821bb876 NL |
651 | $em->persist($user); |
652 | ||
653 | $em->flush(); | |
654 | ||
655 | $crawler = $client->request('GET', '/config'); | |
656 | ||
657 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
876d77a6 | 658 | $this->assertNotContains('config.form_user.delete.button', $body[0]); |
821bb876 NL |
659 | |
660 | $client->request('GET', '/account/delete'); | |
f808b016 | 661 | $this->assertSame(403, $client->getResponse()->getStatusCode()); |
821bb876 | 662 | |
821bb876 NL |
663 | $user = $em |
664 | ->getRepository('WallabagUserBundle:User') | |
665 | ->findOneByUsername('empty'); | |
5066c3e0 | 666 | $user->setEnabled(true); |
821bb876 NL |
667 | $em->persist($user); |
668 | ||
669 | $user = $em | |
670 | ->getRepository('WallabagUserBundle:User') | |
671 | ->findOneByUsername('bob'); | |
5066c3e0 | 672 | $user->setEnabled(true); |
821bb876 NL |
673 | $em->persist($user); |
674 | ||
675 | $em->flush(); | |
676 | } | |
677 | ||
678 | public function testDeleteAccount() | |
679 | { | |
821bb876 | 680 | $client = $this->getClient(); |
c3396c65 JB |
681 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); |
682 | ||
683 | $user = new User(); | |
684 | $user->setName('Wallace'); | |
685 | $user->setEmail('wallace@wallabag.org'); | |
686 | $user->setUsername('wallace'); | |
687 | $user->setPlainPassword('wallace'); | |
688 | $user->setEnabled(true); | |
689 | $user->addRole('ROLE_SUPER_ADMIN'); | |
690 | ||
691 | $em->persist($user); | |
692 | ||
693 | $config = new Config($user); | |
694 | ||
695 | $config->setTheme('material'); | |
696 | $config->setItemsPerPage(30); | |
697 | $config->setReadingSpeed(1); | |
698 | $config->setLanguage('en'); | |
699 | $config->setPocketConsumerKey('xxxxx'); | |
700 | ||
701 | $em->persist($config); | |
702 | $em->flush(); | |
703 | ||
704 | $this->logInAs('wallace'); | |
876d77a6 | 705 | $loggedInUserId = $this->getLoggedInUserId(); |
821bb876 | 706 | |
b8402687 NL |
707 | // create entry to check after user deletion |
708 | // that this entry is also deleted | |
709 | $crawler = $client->request('GET', '/new'); | |
710 | ||
f808b016 | 711 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
b8402687 NL |
712 | |
713 | $form = $crawler->filter('form[name=entry]')->form(); | |
714 | $data = [ | |
715 | 'entry[url]' => $url = 'https://github.com/wallabag/wallabag', | |
716 | ]; | |
717 | ||
718 | $client->submit($form, $data); | |
f808b016 | 719 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
b8402687 | 720 | |
821bb876 NL |
721 | $crawler = $client->request('GET', '/config'); |
722 | ||
71254701 | 723 | $deleteLink = $crawler->filter('.delete-account')->last()->link(); |
821bb876 NL |
724 | |
725 | $client->click($deleteLink); | |
f808b016 | 726 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
821bb876 NL |
727 | |
728 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
729 | $user = $em | |
730 | ->getRepository('WallabagUserBundle:User') | |
731 | ->createQueryBuilder('u') | |
732 | ->where('u.username = :username')->setParameter('username', 'wallace') | |
733 | ->getQuery() | |
734 | ->getOneOrNullResult() | |
735 | ; | |
736 | ||
71254701 | 737 | $this->assertNull($user); |
b8402687 NL |
738 | |
739 | $entries = $client->getContainer() | |
740 | ->get('doctrine.orm.entity_manager') | |
741 | ->getRepository('WallabagCoreBundle:Entry') | |
876d77a6 | 742 | ->findByUser($loggedInUserId); |
b8402687 NL |
743 | |
744 | $this->assertEmpty($entries); | |
821bb876 | 745 | } |
206bade5 JB |
746 | |
747 | public function testReset() | |
748 | { | |
749 | $this->logInAs('empty'); | |
750 | $client = $this->getClient(); | |
751 | ||
752 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
753 | ||
754 | $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser(); | |
755 | ||
756 | $tag = new Tag(); | |
757 | $tag->setLabel('super'); | |
758 | $em->persist($tag); | |
759 | ||
760 | $entry = new Entry($user); | |
77854331 | 761 | $entry->setUrl('https://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html'); |
206bade5 JB |
762 | $entry->setContent('Youhou'); |
763 | $entry->setTitle('Youhou'); | |
764 | $entry->addTag($tag); | |
765 | $em->persist($entry); | |
766 | ||
767 | $entry2 = new Entry($user); | |
768 | $entry2->setUrl('http://www.lemonde.de/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html'); | |
769 | $entry2->setContent('Youhou'); | |
770 | $entry2->setTitle('Youhou'); | |
771 | $entry2->addTag($tag); | |
772 | $em->persist($entry2); | |
773 | ||
774 | $annotation = new Annotation($user); | |
775 | $annotation->setText('annotated'); | |
776 | $annotation->setQuote('annotated'); | |
777 | $annotation->setRanges([]); | |
778 | $annotation->setEntry($entry); | |
779 | $em->persist($annotation); | |
780 | ||
781 | $em->flush(); | |
782 | ||
783 | // reset annotations | |
784 | $crawler = $client->request('GET', '/config#set3'); | |
785 | ||
f808b016 | 786 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
206bade5 JB |
787 | |
788 | $crawler = $client->click($crawler->selectLink('config.reset.annotations')->link()); | |
789 | ||
f808b016 | 790 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
206bade5 JB |
791 | $this->assertContains('flashes.config.notice.annotations_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); |
792 | ||
793 | $annotationsReset = $em | |
794 | ->getRepository('WallabagAnnotationBundle:Annotation') | |
795 | ->findAnnotationsByPageId($entry->getId(), $user->getId()); | |
796 | ||
797 | $this->assertEmpty($annotationsReset, 'Annotations were reset'); | |
798 | ||
799 | // reset tags | |
800 | $crawler = $client->request('GET', '/config#set3'); | |
801 | ||
f808b016 | 802 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
206bade5 JB |
803 | |
804 | $crawler = $client->click($crawler->selectLink('config.reset.tags')->link()); | |
805 | ||
f808b016 | 806 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
206bade5 JB |
807 | $this->assertContains('flashes.config.notice.tags_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); |
808 | ||
809 | $tagReset = $em | |
810 | ->getRepository('WallabagCoreBundle:Tag') | |
811 | ->countAllTags($user->getId()); | |
812 | ||
f808b016 | 813 | $this->assertSame(0, $tagReset, 'Tags were reset'); |
206bade5 JB |
814 | |
815 | // reset entries | |
816 | $crawler = $client->request('GET', '/config#set3'); | |
817 | ||
f808b016 | 818 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
206bade5 JB |
819 | |
820 | $crawler = $client->click($crawler->selectLink('config.reset.entries')->link()); | |
821 | ||
f808b016 | 822 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
206bade5 JB |
823 | $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); |
824 | ||
825 | $entryReset = $em | |
826 | ->getRepository('WallabagCoreBundle:Entry') | |
273b6f06 | 827 | ->countAllEntriesByUser($user->getId()); |
206bade5 | 828 | |
f808b016 | 829 | $this->assertSame(0, $entryReset, 'Entries were reset'); |
206bade5 JB |
830 | } |
831 | ||
6da1aebc TC |
832 | public function testResetArchivedEntries() |
833 | { | |
834 | $this->logInAs('empty'); | |
835 | $client = $this->getClient(); | |
836 | ||
837 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
838 | ||
839 | $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser(); | |
840 | ||
841 | $tag = new Tag(); | |
842 | $tag->setLabel('super'); | |
843 | $em->persist($tag); | |
844 | ||
845 | $entry = new Entry($user); | |
77854331 | 846 | $entry->setUrl('https://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html'); |
6da1aebc TC |
847 | $entry->setContent('Youhou'); |
848 | $entry->setTitle('Youhou'); | |
849 | $entry->addTag($tag); | |
850 | $em->persist($entry); | |
851 | ||
852 | $annotation = new Annotation($user); | |
853 | $annotation->setText('annotated'); | |
854 | $annotation->setQuote('annotated'); | |
855 | $annotation->setRanges([]); | |
856 | $annotation->setEntry($entry); | |
857 | $em->persist($annotation); | |
858 | ||
859 | $tagArchived = new Tag(); | |
860 | $tagArchived->setLabel('super'); | |
861 | $em->persist($tagArchived); | |
862 | ||
863 | $entryArchived = new Entry($user); | |
77854331 | 864 | $entryArchived->setUrl('https://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html'); |
6da1aebc TC |
865 | $entryArchived->setContent('Youhou'); |
866 | $entryArchived->setTitle('Youhou'); | |
867 | $entryArchived->addTag($tagArchived); | |
7975395d | 868 | $entryArchived->updateArchived(true); |
6da1aebc TC |
869 | $em->persist($entryArchived); |
870 | ||
871 | $annotationArchived = new Annotation($user); | |
872 | $annotationArchived->setText('annotated'); | |
873 | $annotationArchived->setQuote('annotated'); | |
874 | $annotationArchived->setRanges([]); | |
875 | $annotationArchived->setEntry($entryArchived); | |
876 | $em->persist($annotationArchived); | |
877 | ||
878 | $em->flush(); | |
879 | ||
880 | $crawler = $client->request('GET', '/config#set3'); | |
881 | ||
f808b016 | 882 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
6da1aebc TC |
883 | |
884 | $crawler = $client->click($crawler->selectLink('config.reset.archived')->link()); | |
885 | ||
f808b016 | 886 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
6da1aebc TC |
887 | $this->assertContains('flashes.config.notice.archived_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); |
888 | ||
889 | $entryReset = $em | |
890 | ->getRepository('WallabagCoreBundle:Entry') | |
73f28afb | 891 | ->countAllEntriesByUser($user->getId()); |
6da1aebc | 892 | |
f808b016 | 893 | $this->assertSame(1, $entryReset, 'Entries were reset'); |
6da1aebc TC |
894 | |
895 | $tagReset = $em | |
896 | ->getRepository('WallabagCoreBundle:Tag') | |
897 | ->countAllTags($user->getId()); | |
898 | ||
f808b016 | 899 | $this->assertSame(1, $tagReset, 'Tags were reset'); |
6da1aebc TC |
900 | |
901 | $annotationsReset = $em | |
902 | ->getRepository('WallabagAnnotationBundle:Annotation') | |
903 | ->findAnnotationsByPageId($annotationArchived->getId(), $user->getId()); | |
904 | ||
905 | $this->assertEmpty($annotationsReset, 'Annotations were reset'); | |
906 | } | |
907 | ||
206bade5 JB |
908 | public function testResetEntriesCascade() |
909 | { | |
910 | $this->logInAs('empty'); | |
911 | $client = $this->getClient(); | |
912 | ||
913 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
914 | ||
915 | $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser(); | |
916 | ||
917 | $tag = new Tag(); | |
918 | $tag->setLabel('super'); | |
919 | $em->persist($tag); | |
920 | ||
921 | $entry = new Entry($user); | |
77854331 | 922 | $entry->setUrl('https://www.lemonde.fr/europe/article/2016/10/01/pour-le-psoe-chaque-election-s-est-transformee-en-une-agonie_5006476_3214.html'); |
206bade5 JB |
923 | $entry->setContent('Youhou'); |
924 | $entry->setTitle('Youhou'); | |
925 | $entry->addTag($tag); | |
926 | $em->persist($entry); | |
927 | ||
928 | $annotation = new Annotation($user); | |
929 | $annotation->setText('annotated'); | |
930 | $annotation->setQuote('annotated'); | |
931 | $annotation->setRanges([]); | |
932 | $annotation->setEntry($entry); | |
933 | $em->persist($annotation); | |
934 | ||
935 | $em->flush(); | |
936 | ||
937 | $crawler = $client->request('GET', '/config#set3'); | |
938 | ||
f808b016 | 939 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
206bade5 JB |
940 | |
941 | $crawler = $client->click($crawler->selectLink('config.reset.entries')->link()); | |
942 | ||
f808b016 | 943 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
206bade5 JB |
944 | $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); |
945 | ||
946 | $entryReset = $em | |
947 | ->getRepository('WallabagCoreBundle:Entry') | |
273b6f06 | 948 | ->countAllEntriesByUser($user->getId()); |
206bade5 | 949 | |
f808b016 | 950 | $this->assertSame(0, $entryReset, 'Entries were reset'); |
206bade5 JB |
951 | |
952 | $tagReset = $em | |
953 | ->getRepository('WallabagCoreBundle:Tag') | |
954 | ->countAllTags($user->getId()); | |
955 | ||
f808b016 | 956 | $this->assertSame(0, $tagReset, 'Tags were reset'); |
206bade5 JB |
957 | |
958 | $annotationsReset = $em | |
959 | ->getRepository('WallabagAnnotationBundle:Annotation') | |
960 | ->findAnnotationsByPageId($entry->getId(), $user->getId()); | |
961 | ||
962 | $this->assertEmpty($annotationsReset, 'Annotations were reset'); | |
963 | } | |
8f3ff39c NL |
964 | |
965 | public function testSwitchViewMode() | |
966 | { | |
967 | $this->logInAs('admin'); | |
7ab5eb95 | 968 | $this->useTheme('baggy'); |
8f3ff39c NL |
969 | $client = $this->getClient(); |
970 | ||
971 | $client->request('GET', '/unread/list'); | |
972 | ||
973 | $this->assertNotContains('listmode', $client->getResponse()->getContent()); | |
974 | ||
975 | $client->request('GET', '/config/view-mode'); | |
976 | $crawler = $client->followRedirect(); | |
977 | ||
978 | $client->request('GET', '/unread/list'); | |
979 | ||
980 | $this->assertContains('listmode', $client->getResponse()->getContent()); | |
56a7ce17 NL |
981 | |
982 | $client->request('GET', '/config/view-mode'); | |
8f3ff39c | 983 | } |
4d4147b2 JB |
984 | |
985 | public function testChangeLocaleWithoutReferer() | |
986 | { | |
987 | $client = $this->getClient(); | |
988 | ||
989 | $client->request('GET', '/locale/de'); | |
990 | $client->followRedirect(); | |
991 | ||
992 | $this->assertSame('de', $client->getRequest()->getLocale()); | |
993 | $this->assertSame('de', $client->getContainer()->get('session')->get('_locale')); | |
994 | } | |
995 | ||
996 | public function testChangeLocaleWithReferer() | |
997 | { | |
998 | $client = $this->getClient(); | |
999 | ||
1000 | $client->request('GET', '/login'); | |
1001 | $client->request('GET', '/locale/de'); | |
1002 | $client->followRedirect(); | |
1003 | ||
1004 | $this->assertSame('de', $client->getRequest()->getLocale()); | |
1005 | $this->assertSame('de', $client->getContainer()->get('session')->get('_locale')); | |
1006 | } | |
1007 | ||
1008 | public function testChangeLocaleToBadLocale() | |
1009 | { | |
1010 | $client = $this->getClient(); | |
1011 | ||
1012 | $client->request('GET', '/login'); | |
1013 | $client->request('GET', '/locale/yuyuyuyu'); | |
1014 | $client->followRedirect(); | |
1015 | ||
1016 | $this->assertNotSame('yuyuyuyu', $client->getRequest()->getLocale()); | |
1017 | $this->assertNotSame('yuyuyuyu', $client->getContainer()->get('session')->get('_locale')); | |
1018 | } | |
a0c5eb00 JB |
1019 | |
1020 | public function testUserEnable2faEmail() | |
1021 | { | |
1022 | $this->logInAs('admin'); | |
1023 | $client = $this->getClient(); | |
1024 | ||
1025 | $crawler = $client->request('GET', '/config/otp/email'); | |
1026 | ||
1027 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1028 | ||
1029 | $crawler = $client->followRedirect(); | |
1030 | ||
1031 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); | |
1032 | $this->assertContains('flashes.config.notice.otp_enabled', $alert[0]); | |
1033 | ||
1034 | // restore user | |
1035 | $em = $this->getEntityManager(); | |
1036 | $user = $em | |
1037 | ->getRepository('WallabagUserBundle:User') | |
1038 | ->findOneByUsername('admin'); | |
1039 | ||
1040 | $this->assertTrue($user->isEmailTwoFactor()); | |
1041 | ||
1042 | $user->setEmailTwoFactor(false); | |
1043 | $em->persist($user); | |
1044 | $em->flush(); | |
1045 | } | |
1046 | ||
1047 | public function testUserEnable2faGoogle() | |
1048 | { | |
1049 | $this->logInAs('admin'); | |
1050 | $client = $this->getClient(); | |
1051 | ||
1052 | $crawler = $client->request('GET', '/config/otp/app'); | |
1053 | ||
1054 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
1055 | ||
1056 | // restore user | |
1057 | $em = $this->getEntityManager(); | |
1058 | $user = $em | |
1059 | ->getRepository('WallabagUserBundle:User') | |
1060 | ->findOneByUsername('admin'); | |
1061 | ||
1062 | $this->assertTrue($user->isGoogleTwoFactor()); | |
1063 | $this->assertGreaterThan(0, $user->getBackupCodes()); | |
1064 | ||
1065 | $user->setGoogleAuthenticatorSecret(false); | |
1066 | $user->setBackupCodes(null); | |
1067 | $em->persist($user); | |
1068 | $em->flush(); | |
1069 | } | |
1070 | ||
1071 | public function testUserEnable2faGoogleCancel() | |
1072 | { | |
1073 | $this->logInAs('admin'); | |
1074 | $client = $this->getClient(); | |
1075 | ||
1076 | $crawler = $client->request('GET', '/config/otp/app'); | |
1077 | ||
1078 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
1079 | ||
1080 | // restore user | |
1081 | $em = $this->getEntityManager(); | |
1082 | $user = $em | |
1083 | ->getRepository('WallabagUserBundle:User') | |
1084 | ->findOneByUsername('admin'); | |
1085 | ||
1086 | $this->assertTrue($user->isGoogleTwoFactor()); | |
1087 | $this->assertGreaterThan(0, $user->getBackupCodes()); | |
1088 | ||
1089 | $crawler = $client->request('GET', '/config/otp/app/cancel'); | |
1090 | ||
1091 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1092 | ||
1093 | $user = $em | |
1094 | ->getRepository('WallabagUserBundle:User') | |
1095 | ->findOneByUsername('admin'); | |
1096 | ||
1097 | $this->assertFalse($user->isGoogleTwoFactor()); | |
1098 | $this->assertEmpty($user->getBackupCodes()); | |
1099 | } | |
4d85d7e9 | 1100 | } |