diff options
Diffstat (limited to 'tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php')
-rw-r--r-- | tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php | 152 |
1 files changed, 134 insertions, 18 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index e07c57dd..d8478ce3 100644 --- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php | |||
@@ -1,6 +1,6 @@ | |||
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | namespace tests\Wallabag\CoreBundle\Controller; | 3 | namespace Tests\Wallabag\CoreBundle\Controller; |
4 | 4 | ||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | 5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
6 | use Wallabag\AnnotationBundle\Entity\Annotation; | 6 | use Wallabag\AnnotationBundle\Entity\Annotation; |
@@ -33,7 +33,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
33 | $this->assertCount(1, $crawler->filter('button[id=config_save]')); | 33 | $this->assertCount(1, $crawler->filter('button[id=config_save]')); |
34 | $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]')); | 34 | $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]')); |
35 | $this->assertCount(1, $crawler->filter('button[id=update_user_save]')); | 35 | $this->assertCount(1, $crawler->filter('button[id=update_user_save]')); |
36 | $this->assertCount(1, $crawler->filter('button[id=rss_config_save]')); | 36 | $this->assertCount(1, $crawler->filter('button[id=feed_config_save]')); |
37 | } | 37 | } |
38 | 38 | ||
39 | public function testUpdate() | 39 | public function testUpdate() |
@@ -297,7 +297,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
297 | $this->assertContains('flashes.config.notice.user_updated', $alert[0]); | 297 | $this->assertContains('flashes.config.notice.user_updated', $alert[0]); |
298 | } | 298 | } |
299 | 299 | ||
300 | public function testRssUpdateResetToken() | 300 | public function testFeedUpdateResetToken() |
301 | { | 301 | { |
302 | $this->logInAs('admin'); | 302 | $this->logInAs('admin'); |
303 | $client = $this->getClient(); | 303 | $client = $this->getClient(); |
@@ -313,7 +313,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
313 | } | 313 | } |
314 | 314 | ||
315 | $config = $user->getConfig(); | 315 | $config = $user->getConfig(); |
316 | $config->setRssToken(null); | 316 | $config->setFeedToken(null); |
317 | $em->persist($config); | 317 | $em->persist($config); |
318 | $em->flush(); | 318 | $em->flush(); |
319 | 319 | ||
@@ -322,7 +322,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
322 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | 322 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
323 | 323 | ||
324 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | 324 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
325 | $this->assertContains('config.form_rss.no_token', $body[0]); | 325 | $this->assertContains('config.form_feed.no_token', $body[0]); |
326 | 326 | ||
327 | $client->request('GET', '/generate-token'); | 327 | $client->request('GET', '/generate-token'); |
328 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | 328 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
@@ -330,7 +330,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
330 | $crawler = $client->followRedirect(); | 330 | $crawler = $client->followRedirect(); |
331 | 331 | ||
332 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | 332 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
333 | $this->assertNotContains('config.form_rss.no_token', $body[0]); | 333 | $this->assertNotContains('config.form_feed.no_token', $body[0]); |
334 | } | 334 | } |
335 | 335 | ||
336 | public function testGenerateTokenAjax() | 336 | public function testGenerateTokenAjax() |
@@ -351,7 +351,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
351 | $this->assertArrayHasKey('token', $content); | 351 | $this->assertArrayHasKey('token', $content); |
352 | } | 352 | } |
353 | 353 | ||
354 | public function testRssUpdate() | 354 | public function testFeedUpdate() |
355 | { | 355 | { |
356 | $this->logInAs('admin'); | 356 | $this->logInAs('admin'); |
357 | $client = $this->getClient(); | 357 | $client = $this->getClient(); |
@@ -360,10 +360,10 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
360 | 360 | ||
361 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | 361 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
362 | 362 | ||
363 | $form = $crawler->filter('button[id=rss_config_save]')->form(); | 363 | $form = $crawler->filter('button[id=feed_config_save]')->form(); |
364 | 364 | ||
365 | $data = [ | 365 | $data = [ |
366 | 'rss_config[rss_limit]' => 12, | 366 | 'feed_config[feed_limit]' => 12, |
367 | ]; | 367 | ]; |
368 | 368 | ||
369 | $client->submit($form, $data); | 369 | $client->submit($form, $data); |
@@ -372,31 +372,31 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
372 | 372 | ||
373 | $crawler = $client->followRedirect(); | 373 | $crawler = $client->followRedirect(); |
374 | 374 | ||
375 | $this->assertContains('flashes.config.notice.rss_updated', $crawler->filter('body')->extract(['_text'])[0]); | 375 | $this->assertContains('flashes.config.notice.feed_updated', $crawler->filter('body')->extract(['_text'])[0]); |
376 | } | 376 | } |
377 | 377 | ||
378 | public function dataForRssFailed() | 378 | public function dataForFeedFailed() |
379 | { | 379 | { |
380 | return [ | 380 | return [ |
381 | [ | 381 | [ |
382 | [ | 382 | [ |
383 | 'rss_config[rss_limit]' => 0, | 383 | 'feed_config[feed_limit]' => 0, |
384 | ], | 384 | ], |
385 | 'This value should be 1 or more.', | 385 | 'This value should be 1 or more.', |
386 | ], | 386 | ], |
387 | [ | 387 | [ |
388 | [ | 388 | [ |
389 | 'rss_config[rss_limit]' => 1000000000000, | 389 | 'feed_config[feed_limit]' => 1000000000000, |
390 | ], | 390 | ], |
391 | 'validator.rss_limit_too_high', | 391 | 'validator.feed_limit_too_high', |
392 | ], | 392 | ], |
393 | ]; | 393 | ]; |
394 | } | 394 | } |
395 | 395 | ||
396 | /** | 396 | /** |
397 | * @dataProvider dataForRssFailed | 397 | * @dataProvider dataForFeedFailed |
398 | */ | 398 | */ |
399 | public function testRssFailed($data, $expectedMessage) | 399 | public function testFeedFailed($data, $expectedMessage) |
400 | { | 400 | { |
401 | $this->logInAs('admin'); | 401 | $this->logInAs('admin'); |
402 | $client = $this->getClient(); | 402 | $client = $this->getClient(); |
@@ -405,7 +405,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
405 | 405 | ||
406 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | 406 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
407 | 407 | ||
408 | $form = $crawler->filter('button[id=rss_config_save]')->form(); | 408 | $form = $crawler->filter('button[id=feed_config_save]')->form(); |
409 | 409 | ||
410 | $crawler = $client->submit($form, $data); | 410 | $crawler = $client->submit($form, $data); |
411 | 411 | ||
@@ -849,7 +849,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
849 | $entryArchived->setContent('Youhou'); | 849 | $entryArchived->setContent('Youhou'); |
850 | $entryArchived->setTitle('Youhou'); | 850 | $entryArchived->setTitle('Youhou'); |
851 | $entryArchived->addTag($tagArchived); | 851 | $entryArchived->addTag($tagArchived); |
852 | $entryArchived->setArchived(true); | 852 | $entryArchived->updateArchived(true); |
853 | $em->persist($entryArchived); | 853 | $em->persist($entryArchived); |
854 | 854 | ||
855 | $annotationArchived = new Annotation($user); | 855 | $annotationArchived = new Annotation($user); |
@@ -965,4 +965,120 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
965 | 965 | ||
966 | $client->request('GET', '/config/view-mode'); | 966 | $client->request('GET', '/config/view-mode'); |
967 | } | 967 | } |
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 | } | ||
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 | } | ||
968 | } | 1084 | } |