]>
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'])); |
531c8d0a | 333 | $this->assertNotContains('config.form_feed.no_token', $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 | ||
531c8d0a | 354 | public function testFeedUpdate() |
371ac69a J |
355 | { |
356 | $this->logInAs('admin'); | |
357 | $client = $this->getClient(); | |
358 | ||
359 | $crawler = $client->request('GET', '/config'); | |
360 | ||
f808b016 | 361 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
371ac69a | 362 | |
531c8d0a | 363 | $form = $crawler->filter('button[id=feed_config_save]')->form(); |
371ac69a | 364 | |
4094ea47 | 365 | $data = [ |
531c8d0a | 366 | 'feed_config[feed_limit]' => 12, |
4094ea47 | 367 | ]; |
371ac69a J |
368 | |
369 | $client->submit($form, $data); | |
370 | ||
f808b016 | 371 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
371ac69a J |
372 | |
373 | $crawler = $client->followRedirect(); | |
374 | ||
531c8d0a | 375 | $this->assertContains('flashes.config.notice.feed_updated', $crawler->filter('body')->extract(['_text'])[0]); |
371ac69a J |
376 | } |
377 | ||
531c8d0a | 378 | public function dataForFeedFailed() |
371ac69a | 379 | { |
4094ea47 JB |
380 | return [ |
381 | [ | |
382 | [ | |
531c8d0a | 383 | 'feed_config[feed_limit]' => 0, |
4094ea47 | 384 | ], |
371ac69a | 385 | 'This value should be 1 or more.', |
4094ea47 JB |
386 | ], |
387 | [ | |
388 | [ | |
531c8d0a | 389 | 'feed_config[feed_limit]' => 1000000000000, |
4094ea47 | 390 | ], |
531c8d0a | 391 | 'validator.feed_limit_too_high', |
4094ea47 JB |
392 | ], |
393 | ]; | |
371ac69a J |
394 | } |
395 | ||
396 | /** | |
531c8d0a | 397 | * @dataProvider dataForFeedFailed |
371ac69a | 398 | */ |
531c8d0a | 399 | public function testFeedFailed($data, $expectedMessage) |
371ac69a J |
400 | { |
401 | $this->logInAs('admin'); | |
402 | $client = $this->getClient(); | |
403 | ||
404 | $crawler = $client->request('GET', '/config'); | |
405 | ||
f808b016 | 406 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
371ac69a | 407 | |
531c8d0a | 408 | $form = $crawler->filter('button[id=feed_config_save]')->form(); |
371ac69a J |
409 | |
410 | $crawler = $client->submit($form, $data); | |
411 | ||
f808b016 | 412 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
371ac69a | 413 | |
4094ea47 | 414 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); |
371ac69a J |
415 | $this->assertContains($expectedMessage, $alert[0]); |
416 | } | |
8a99c7a8 KG |
417 | |
418 | public function testTaggingRuleCreation() | |
419 | { | |
420 | $this->logInAs('admin'); | |
7ab5eb95 | 421 | $this->useTheme('baggy'); |
8a99c7a8 KG |
422 | $client = $this->getClient(); |
423 | ||
424 | $crawler = $client->request('GET', '/config'); | |
425 | ||
f808b016 | 426 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
8a99c7a8 KG |
427 | |
428 | $form = $crawler->filter('button[id=tagging_rule_save]')->form(); | |
429 | ||
4094ea47 | 430 | $data = [ |
8a99c7a8 KG |
431 | 'tagging_rule[rule]' => 'readingTime <= 3', |
432 | 'tagging_rule[tags]' => 'short reading', | |
4094ea47 | 433 | ]; |
8a99c7a8 KG |
434 | |
435 | $client->submit($form, $data); | |
436 | ||
f808b016 | 437 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
8a99c7a8 KG |
438 | |
439 | $crawler = $client->followRedirect(); | |
440 | ||
bf3dc999 JB |
441 | $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]); |
442 | ||
443 | $editLink = $crawler->filter('.mode_edit')->last()->link(); | |
444 | ||
445 | $crawler = $client->click($editLink); | |
f808b016 | 446 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
bf3dc999 JB |
447 | $this->assertContains('?tagging-rule=', $client->getResponse()->headers->get('location')); |
448 | ||
449 | $crawler = $client->followRedirect(); | |
450 | ||
451 | $form = $crawler->filter('button[id=tagging_rule_save]')->form(); | |
452 | ||
453 | $data = [ | |
454 | 'tagging_rule[rule]' => 'readingTime <= 30', | |
455 | 'tagging_rule[tags]' => 'short reading', | |
456 | ]; | |
457 | ||
458 | $client->submit($form, $data); | |
459 | ||
f808b016 | 460 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
bf3dc999 JB |
461 | |
462 | $crawler = $client->followRedirect(); | |
463 | ||
464 | $this->assertContains('flashes.config.notice.tagging_rules_updated', $crawler->filter('body')->extract(['_text'])[0]); | |
465 | ||
466 | $this->assertContains('readingTime <= 30', $crawler->filter('body')->extract(['_text'])[0]); | |
8a99c7a8 | 467 | |
958671a7 | 468 | $deleteLink = $crawler->filter('.delete')->last()->link(); |
8a99c7a8 KG |
469 | |
470 | $crawler = $client->click($deleteLink); | |
f808b016 | 471 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
8a99c7a8 KG |
472 | |
473 | $crawler = $client->followRedirect(); | |
bf3dc999 | 474 | $this->assertContains('flashes.config.notice.tagging_rules_deleted', $crawler->filter('body')->extract(['_text'])[0]); |
8a99c7a8 KG |
475 | } |
476 | ||
477 | public function dataForTaggingRuleFailed() | |
478 | { | |
4094ea47 JB |
479 | return [ |
480 | [ | |
481 | [ | |
a3cac44c JB |
482 | 'tagging_rule[rule]' => 'unknownVar <= 3', |
483 | 'tagging_rule[tags]' => 'cool tag', | |
4094ea47 JB |
484 | ], |
485 | [ | |
a3cac44c JB |
486 | 'The variable', |
487 | 'does not exist.', | |
4094ea47 JB |
488 | ], |
489 | ], | |
490 | [ | |
491 | [ | |
a3cac44c JB |
492 | 'tagging_rule[rule]' => 'length(domainName) <= 42', |
493 | 'tagging_rule[tags]' => 'cool tag', | |
4094ea47 JB |
494 | ], |
495 | [ | |
a3cac44c JB |
496 | 'The operator', |
497 | 'does not exist.', | |
4094ea47 JB |
498 | ], |
499 | ], | |
500 | ]; | |
8a99c7a8 | 501 | } |
a3cac44c JB |
502 | |
503 | /** | |
504 | * @dataProvider dataForTaggingRuleFailed | |
505 | */ | |
506 | public function testTaggingRuleCreationFail($data, $messages) | |
507 | { | |
508 | $this->logInAs('admin'); | |
509 | $client = $this->getClient(); | |
510 | ||
511 | $crawler = $client->request('GET', '/config'); | |
512 | ||
f808b016 | 513 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
a3cac44c JB |
514 | |
515 | $form = $crawler->filter('button[id=tagging_rule_save]')->form(); | |
516 | ||
4f9cf232 | 517 | $crawler = $client->submit($form, $data); |
a3cac44c | 518 | |
f808b016 | 519 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
a3cac44c | 520 | |
4094ea47 | 521 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
4f9cf232 | 522 | |
a3cac44c | 523 | foreach ($messages as $message) { |
4f9cf232 | 524 | $this->assertContains($message, $body[0]); |
a3cac44c JB |
525 | } |
526 | } | |
527 | ||
5aa0294c JB |
528 | public function testTaggingRuleTooLong() |
529 | { | |
530 | $this->logInAs('admin'); | |
531 | $client = $this->getClient(); | |
532 | ||
533 | $crawler = $client->request('GET', '/config'); | |
534 | ||
f808b016 | 535 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
5aa0294c JB |
536 | |
537 | $form = $crawler->filter('button[id=tagging_rule_save]')->form(); | |
538 | ||
539 | $crawler = $client->submit($form, [ | |
540 | 'tagging_rule[rule]' => str_repeat('title', 60), | |
541 | 'tagging_rule[tags]' => 'cool tag', | |
542 | ]); | |
543 | ||
f808b016 | 544 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
5aa0294c JB |
545 | |
546 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
547 | ||
548 | $this->assertContains('255 characters', $body[0]); | |
549 | } | |
550 | ||
a3cac44c JB |
551 | public function testDeletingTaggingRuleFromAnOtherUser() |
552 | { | |
553 | $this->logInAs('bob'); | |
554 | $client = $this->getClient(); | |
555 | ||
556 | $rule = $client->getContainer()->get('doctrine.orm.entity_manager') | |
557 | ->getRepository('WallabagCoreBundle:TaggingRule') | |
558 | ->findAll()[0]; | |
559 | ||
f808b016 | 560 | $crawler = $client->request('GET', '/tagging-rule/edit/' . $rule->getId()); |
bf3dc999 | 561 | |
f808b016 | 562 | $this->assertSame(403, $client->getResponse()->getStatusCode()); |
bf3dc999 JB |
563 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
564 | $this->assertContains('You can not access this tagging rule', $body[0]); | |
565 | } | |
566 | ||
567 | public function testEditingTaggingRuleFromAnOtherUser() | |
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()); |
4f9cf232 | 577 | |
f808b016 | 578 | $this->assertSame(403, $client->getResponse()->getStatusCode()); |
4094ea47 | 579 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
4f9cf232 | 580 | $this->assertContains('You can not access this tagging rule', $body[0]); |
a3cac44c | 581 | } |
b6c00b0b JB |
582 | |
583 | public function testDemoMode() | |
584 | { | |
585 | $this->logInAs('admin'); | |
586 | $client = $this->getClient(); | |
587 | ||
588 | $config = $client->getContainer()->get('craue_config'); | |
589 | $config->set('demo_mode_enabled', 1); | |
590 | $config->set('demo_mode_username', 'admin'); | |
591 | ||
592 | $crawler = $client->request('GET', '/config'); | |
593 | ||
f808b016 | 594 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
b6c00b0b JB |
595 | |
596 | $form = $crawler->filter('button[id=change_passwd_save]')->form(); | |
597 | ||
4094ea47 | 598 | $data = [ |
b6c00b0b JB |
599 | 'change_passwd[old_password]' => 'mypassword', |
600 | 'change_passwd[new_password][first]' => 'mypassword', | |
601 | 'change_passwd[new_password][second]' => 'mypassword', | |
4094ea47 | 602 | ]; |
b6c00b0b JB |
603 | |
604 | $client->submit($form, $data); | |
605 | ||
f808b016 | 606 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
4204a06b | 607 | $this->assertContains('flashes.config.notice.password_not_updated_demo', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); |
b6c00b0b JB |
608 | |
609 | $config->set('demo_mode_enabled', 0); | |
610 | $config->set('demo_mode_username', 'wallabag'); | |
611 | } | |
821bb876 NL |
612 | |
613 | public function testDeleteUserButtonVisibility() | |
614 | { | |
615 | $this->logInAs('admin'); | |
616 | $client = $this->getClient(); | |
617 | ||
618 | $crawler = $client->request('GET', '/config'); | |
619 | ||
620 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
876d77a6 | 621 | $this->assertContains('config.form_user.delete.button', $body[0]); |
821bb876 NL |
622 | |
623 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
624 | ||
821bb876 NL |
625 | $user = $em |
626 | ->getRepository('WallabagUserBundle:User') | |
627 | ->findOneByUsername('empty'); | |
5066c3e0 | 628 | $user->setEnabled(false); |
821bb876 NL |
629 | $em->persist($user); |
630 | ||
631 | $user = $em | |
632 | ->getRepository('WallabagUserBundle:User') | |
633 | ->findOneByUsername('bob'); | |
5066c3e0 | 634 | $user->setEnabled(false); |
821bb876 NL |
635 | $em->persist($user); |
636 | ||
637 | $em->flush(); | |
638 | ||
639 | $crawler = $client->request('GET', '/config'); | |
640 | ||
641 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | |
876d77a6 | 642 | $this->assertNotContains('config.form_user.delete.button', $body[0]); |
821bb876 NL |
643 | |
644 | $client->request('GET', '/account/delete'); | |
f808b016 | 645 | $this->assertSame(403, $client->getResponse()->getStatusCode()); |
821bb876 | 646 | |
821bb876 NL |
647 | $user = $em |
648 | ->getRepository('WallabagUserBundle:User') | |
649 | ->findOneByUsername('empty'); | |
5066c3e0 | 650 | $user->setEnabled(true); |
821bb876 NL |
651 | $em->persist($user); |
652 | ||
653 | $user = $em | |
654 | ->getRepository('WallabagUserBundle:User') | |
655 | ->findOneByUsername('bob'); | |
5066c3e0 | 656 | $user->setEnabled(true); |
821bb876 NL |
657 | $em->persist($user); |
658 | ||
659 | $em->flush(); | |
660 | } | |
661 | ||
662 | public function testDeleteAccount() | |
663 | { | |
821bb876 | 664 | $client = $this->getClient(); |
c3396c65 JB |
665 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); |
666 | ||
667 | $user = new User(); | |
668 | $user->setName('Wallace'); | |
669 | $user->setEmail('wallace@wallabag.org'); | |
670 | $user->setUsername('wallace'); | |
671 | $user->setPlainPassword('wallace'); | |
672 | $user->setEnabled(true); | |
673 | $user->addRole('ROLE_SUPER_ADMIN'); | |
674 | ||
675 | $em->persist($user); | |
676 | ||
677 | $config = new Config($user); | |
678 | ||
679 | $config->setTheme('material'); | |
680 | $config->setItemsPerPage(30); | |
681 | $config->setReadingSpeed(1); | |
682 | $config->setLanguage('en'); | |
683 | $config->setPocketConsumerKey('xxxxx'); | |
684 | ||
685 | $em->persist($config); | |
686 | $em->flush(); | |
687 | ||
688 | $this->logInAs('wallace'); | |
876d77a6 | 689 | $loggedInUserId = $this->getLoggedInUserId(); |
821bb876 | 690 | |
b8402687 NL |
691 | // create entry to check after user deletion |
692 | // that this entry is also deleted | |
693 | $crawler = $client->request('GET', '/new'); | |
694 | ||
f808b016 | 695 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
b8402687 NL |
696 | |
697 | $form = $crawler->filter('form[name=entry]')->form(); | |
698 | $data = [ | |
699 | 'entry[url]' => $url = 'https://github.com/wallabag/wallabag', | |
700 | ]; | |
701 | ||
702 | $client->submit($form, $data); | |
f808b016 | 703 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
b8402687 | 704 | |
821bb876 NL |
705 | $crawler = $client->request('GET', '/config'); |
706 | ||
71254701 | 707 | $deleteLink = $crawler->filter('.delete-account')->last()->link(); |
821bb876 NL |
708 | |
709 | $client->click($deleteLink); | |
f808b016 | 710 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
821bb876 NL |
711 | |
712 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
713 | $user = $em | |
714 | ->getRepository('WallabagUserBundle:User') | |
715 | ->createQueryBuilder('u') | |
716 | ->where('u.username = :username')->setParameter('username', 'wallace') | |
717 | ->getQuery() | |
718 | ->getOneOrNullResult() | |
719 | ; | |
720 | ||
71254701 | 721 | $this->assertNull($user); |
b8402687 NL |
722 | |
723 | $entries = $client->getContainer() | |
724 | ->get('doctrine.orm.entity_manager') | |
725 | ->getRepository('WallabagCoreBundle:Entry') | |
876d77a6 | 726 | ->findByUser($loggedInUserId); |
b8402687 NL |
727 | |
728 | $this->assertEmpty($entries); | |
821bb876 | 729 | } |
206bade5 JB |
730 | |
731 | public function testReset() | |
732 | { | |
733 | $this->logInAs('empty'); | |
734 | $client = $this->getClient(); | |
735 | ||
736 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
737 | ||
738 | $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser(); | |
739 | ||
740 | $tag = new Tag(); | |
741 | $tag->setLabel('super'); | |
742 | $em->persist($tag); | |
743 | ||
744 | $entry = new Entry($user); | |
77854331 | 745 | $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 |
746 | $entry->setContent('Youhou'); |
747 | $entry->setTitle('Youhou'); | |
748 | $entry->addTag($tag); | |
749 | $em->persist($entry); | |
750 | ||
751 | $entry2 = new Entry($user); | |
752 | $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'); | |
753 | $entry2->setContent('Youhou'); | |
754 | $entry2->setTitle('Youhou'); | |
755 | $entry2->addTag($tag); | |
756 | $em->persist($entry2); | |
757 | ||
758 | $annotation = new Annotation($user); | |
759 | $annotation->setText('annotated'); | |
760 | $annotation->setQuote('annotated'); | |
761 | $annotation->setRanges([]); | |
762 | $annotation->setEntry($entry); | |
763 | $em->persist($annotation); | |
764 | ||
765 | $em->flush(); | |
766 | ||
767 | // reset annotations | |
768 | $crawler = $client->request('GET', '/config#set3'); | |
769 | ||
f808b016 | 770 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
206bade5 JB |
771 | |
772 | $crawler = $client->click($crawler->selectLink('config.reset.annotations')->link()); | |
773 | ||
f808b016 | 774 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
206bade5 JB |
775 | $this->assertContains('flashes.config.notice.annotations_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); |
776 | ||
777 | $annotationsReset = $em | |
778 | ->getRepository('WallabagAnnotationBundle:Annotation') | |
779 | ->findAnnotationsByPageId($entry->getId(), $user->getId()); | |
780 | ||
781 | $this->assertEmpty($annotationsReset, 'Annotations were reset'); | |
782 | ||
783 | // reset tags | |
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.tags')->link()); | |
789 | ||
f808b016 | 790 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
206bade5 JB |
791 | $this->assertContains('flashes.config.notice.tags_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); |
792 | ||
793 | $tagReset = $em | |
794 | ->getRepository('WallabagCoreBundle:Tag') | |
795 | ->countAllTags($user->getId()); | |
796 | ||
f808b016 | 797 | $this->assertSame(0, $tagReset, 'Tags were reset'); |
206bade5 JB |
798 | |
799 | // reset entries | |
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.entries')->link()); | |
805 | ||
f808b016 | 806 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
206bade5 JB |
807 | $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); |
808 | ||
809 | $entryReset = $em | |
810 | ->getRepository('WallabagCoreBundle:Entry') | |
273b6f06 | 811 | ->countAllEntriesByUser($user->getId()); |
206bade5 | 812 | |
f808b016 | 813 | $this->assertSame(0, $entryReset, 'Entries were reset'); |
206bade5 JB |
814 | } |
815 | ||
6da1aebc TC |
816 | public function testResetArchivedEntries() |
817 | { | |
818 | $this->logInAs('empty'); | |
819 | $client = $this->getClient(); | |
820 | ||
821 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
822 | ||
823 | $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser(); | |
824 | ||
825 | $tag = new Tag(); | |
826 | $tag->setLabel('super'); | |
827 | $em->persist($tag); | |
828 | ||
829 | $entry = new Entry($user); | |
77854331 | 830 | $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 |
831 | $entry->setContent('Youhou'); |
832 | $entry->setTitle('Youhou'); | |
833 | $entry->addTag($tag); | |
834 | $em->persist($entry); | |
835 | ||
836 | $annotation = new Annotation($user); | |
837 | $annotation->setText('annotated'); | |
838 | $annotation->setQuote('annotated'); | |
839 | $annotation->setRanges([]); | |
840 | $annotation->setEntry($entry); | |
841 | $em->persist($annotation); | |
842 | ||
843 | $tagArchived = new Tag(); | |
844 | $tagArchived->setLabel('super'); | |
845 | $em->persist($tagArchived); | |
846 | ||
847 | $entryArchived = new Entry($user); | |
77854331 | 848 | $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 |
849 | $entryArchived->setContent('Youhou'); |
850 | $entryArchived->setTitle('Youhou'); | |
851 | $entryArchived->addTag($tagArchived); | |
7975395d | 852 | $entryArchived->updateArchived(true); |
6da1aebc TC |
853 | $em->persist($entryArchived); |
854 | ||
855 | $annotationArchived = new Annotation($user); | |
856 | $annotationArchived->setText('annotated'); | |
857 | $annotationArchived->setQuote('annotated'); | |
858 | $annotationArchived->setRanges([]); | |
859 | $annotationArchived->setEntry($entryArchived); | |
860 | $em->persist($annotationArchived); | |
861 | ||
862 | $em->flush(); | |
863 | ||
864 | $crawler = $client->request('GET', '/config#set3'); | |
865 | ||
f808b016 | 866 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
6da1aebc TC |
867 | |
868 | $crawler = $client->click($crawler->selectLink('config.reset.archived')->link()); | |
869 | ||
f808b016 | 870 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
6da1aebc TC |
871 | $this->assertContains('flashes.config.notice.archived_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); |
872 | ||
873 | $entryReset = $em | |
874 | ->getRepository('WallabagCoreBundle:Entry') | |
73f28afb | 875 | ->countAllEntriesByUser($user->getId()); |
6da1aebc | 876 | |
f808b016 | 877 | $this->assertSame(1, $entryReset, 'Entries were reset'); |
6da1aebc TC |
878 | |
879 | $tagReset = $em | |
880 | ->getRepository('WallabagCoreBundle:Tag') | |
881 | ->countAllTags($user->getId()); | |
882 | ||
f808b016 | 883 | $this->assertSame(1, $tagReset, 'Tags were reset'); |
6da1aebc TC |
884 | |
885 | $annotationsReset = $em | |
886 | ->getRepository('WallabagAnnotationBundle:Annotation') | |
887 | ->findAnnotationsByPageId($annotationArchived->getId(), $user->getId()); | |
888 | ||
889 | $this->assertEmpty($annotationsReset, 'Annotations were reset'); | |
890 | } | |
891 | ||
206bade5 JB |
892 | public function testResetEntriesCascade() |
893 | { | |
894 | $this->logInAs('empty'); | |
895 | $client = $this->getClient(); | |
896 | ||
897 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | |
898 | ||
899 | $user = static::$kernel->getContainer()->get('security.token_storage')->getToken()->getUser(); | |
900 | ||
901 | $tag = new Tag(); | |
902 | $tag->setLabel('super'); | |
903 | $em->persist($tag); | |
904 | ||
905 | $entry = new Entry($user); | |
77854331 | 906 | $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 |
907 | $entry->setContent('Youhou'); |
908 | $entry->setTitle('Youhou'); | |
909 | $entry->addTag($tag); | |
910 | $em->persist($entry); | |
911 | ||
912 | $annotation = new Annotation($user); | |
913 | $annotation->setText('annotated'); | |
914 | $annotation->setQuote('annotated'); | |
915 | $annotation->setRanges([]); | |
916 | $annotation->setEntry($entry); | |
917 | $em->persist($annotation); | |
918 | ||
919 | $em->flush(); | |
920 | ||
921 | $crawler = $client->request('GET', '/config#set3'); | |
922 | ||
f808b016 | 923 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
206bade5 JB |
924 | |
925 | $crawler = $client->click($crawler->selectLink('config.reset.entries')->link()); | |
926 | ||
f808b016 | 927 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
206bade5 JB |
928 | $this->assertContains('flashes.config.notice.entries_reset', $client->getContainer()->get('session')->getFlashBag()->get('notice')[0]); |
929 | ||
930 | $entryReset = $em | |
931 | ->getRepository('WallabagCoreBundle:Entry') | |
273b6f06 | 932 | ->countAllEntriesByUser($user->getId()); |
206bade5 | 933 | |
f808b016 | 934 | $this->assertSame(0, $entryReset, 'Entries were reset'); |
206bade5 JB |
935 | |
936 | $tagReset = $em | |
937 | ->getRepository('WallabagCoreBundle:Tag') | |
938 | ->countAllTags($user->getId()); | |
939 | ||
f808b016 | 940 | $this->assertSame(0, $tagReset, 'Tags were reset'); |
206bade5 JB |
941 | |
942 | $annotationsReset = $em | |
943 | ->getRepository('WallabagAnnotationBundle:Annotation') | |
944 | ->findAnnotationsByPageId($entry->getId(), $user->getId()); | |
945 | ||
946 | $this->assertEmpty($annotationsReset, 'Annotations were reset'); | |
947 | } | |
8f3ff39c NL |
948 | |
949 | public function testSwitchViewMode() | |
950 | { | |
951 | $this->logInAs('admin'); | |
7ab5eb95 | 952 | $this->useTheme('baggy'); |
8f3ff39c NL |
953 | $client = $this->getClient(); |
954 | ||
955 | $client->request('GET', '/unread/list'); | |
956 | ||
957 | $this->assertNotContains('listmode', $client->getResponse()->getContent()); | |
958 | ||
959 | $client->request('GET', '/config/view-mode'); | |
960 | $crawler = $client->followRedirect(); | |
961 | ||
962 | $client->request('GET', '/unread/list'); | |
963 | ||
964 | $this->assertContains('listmode', $client->getResponse()->getContent()); | |
56a7ce17 NL |
965 | |
966 | $client->request('GET', '/config/view-mode'); | |
8f3ff39c | 967 | } |
4d4147b2 JB |
968 | |
969 | public function testChangeLocaleWithoutReferer() | |
970 | { | |
971 | $client = $this->getClient(); | |
972 | ||
973 | $client->request('GET', '/locale/de'); | |
974 | $client->followRedirect(); | |
975 | ||
976 | $this->assertSame('de', $client->getRequest()->getLocale()); | |
977 | $this->assertSame('de', $client->getContainer()->get('session')->get('_locale')); | |
978 | } | |
979 | ||
980 | public function testChangeLocaleWithReferer() | |
981 | { | |
982 | $client = $this->getClient(); | |
983 | ||
984 | $client->request('GET', '/login'); | |
985 | $client->request('GET', '/locale/de'); | |
986 | $client->followRedirect(); | |
987 | ||
988 | $this->assertSame('de', $client->getRequest()->getLocale()); | |
989 | $this->assertSame('de', $client->getContainer()->get('session')->get('_locale')); | |
990 | } | |
991 | ||
992 | public function testChangeLocaleToBadLocale() | |
993 | { | |
994 | $client = $this->getClient(); | |
995 | ||
996 | $client->request('GET', '/login'); | |
997 | $client->request('GET', '/locale/yuyuyuyu'); | |
998 | $client->followRedirect(); | |
999 | ||
1000 | $this->assertNotSame('yuyuyuyu', $client->getRequest()->getLocale()); | |
1001 | $this->assertNotSame('yuyuyuyu', $client->getContainer()->get('session')->get('_locale')); | |
1002 | } | |
a0c5eb00 JB |
1003 | |
1004 | public function testUserEnable2faEmail() | |
1005 | { | |
1006 | $this->logInAs('admin'); | |
1007 | $client = $this->getClient(); | |
1008 | ||
1009 | $crawler = $client->request('GET', '/config/otp/email'); | |
1010 | ||
1011 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1012 | ||
1013 | $crawler = $client->followRedirect(); | |
1014 | ||
1015 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); | |
1016 | $this->assertContains('flashes.config.notice.otp_enabled', $alert[0]); | |
1017 | ||
1018 | // restore user | |
1019 | $em = $this->getEntityManager(); | |
1020 | $user = $em | |
1021 | ->getRepository('WallabagUserBundle:User') | |
1022 | ->findOneByUsername('admin'); | |
1023 | ||
1024 | $this->assertTrue($user->isEmailTwoFactor()); | |
1025 | ||
1026 | $user->setEmailTwoFactor(false); | |
1027 | $em->persist($user); | |
1028 | $em->flush(); | |
1029 | } | |
1030 | ||
1031 | public function testUserEnable2faGoogle() | |
1032 | { | |
1033 | $this->logInAs('admin'); | |
1034 | $client = $this->getClient(); | |
1035 | ||
1036 | $crawler = $client->request('GET', '/config/otp/app'); | |
1037 | ||
1038 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
1039 | ||
1040 | // restore user | |
1041 | $em = $this->getEntityManager(); | |
1042 | $user = $em | |
1043 | ->getRepository('WallabagUserBundle:User') | |
1044 | ->findOneByUsername('admin'); | |
1045 | ||
1046 | $this->assertTrue($user->isGoogleTwoFactor()); | |
1047 | $this->assertGreaterThan(0, $user->getBackupCodes()); | |
1048 | ||
1049 | $user->setGoogleAuthenticatorSecret(false); | |
1050 | $user->setBackupCodes(null); | |
1051 | $em->persist($user); | |
1052 | $em->flush(); | |
1053 | } | |
1054 | ||
1055 | public function testUserEnable2faGoogleCancel() | |
1056 | { | |
1057 | $this->logInAs('admin'); | |
1058 | $client = $this->getClient(); | |
1059 | ||
1060 | $crawler = $client->request('GET', '/config/otp/app'); | |
1061 | ||
1062 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | |
1063 | ||
1064 | // restore user | |
1065 | $em = $this->getEntityManager(); | |
1066 | $user = $em | |
1067 | ->getRepository('WallabagUserBundle:User') | |
1068 | ->findOneByUsername('admin'); | |
1069 | ||
1070 | $this->assertTrue($user->isGoogleTwoFactor()); | |
1071 | $this->assertGreaterThan(0, $user->getBackupCodes()); | |
1072 | ||
1073 | $crawler = $client->request('GET', '/config/otp/app/cancel'); | |
1074 | ||
1075 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | |
1076 | ||
1077 | $user = $em | |
1078 | ->getRepository('WallabagUserBundle:User') | |
1079 | ->findOneByUsername('admin'); | |
1080 | ||
1081 | $this->assertFalse($user->isGoogleTwoFactor()); | |
1082 | $this->assertEmpty($user->getBackupCodes()); | |
1083 | } | |
4d85d7e9 | 1084 | } |