diff options
Diffstat (limited to 'tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php')
-rw-r--r-- | tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php | 240 |
1 files changed, 218 insertions, 22 deletions
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index e07c57dd..fa93c9c2 100644 --- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php | |||
@@ -1,7 +1,8 @@ | |||
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | namespace tests\Wallabag\CoreBundle\Controller; | 3 | namespace Tests\Wallabag\CoreBundle\Controller; |
4 | 4 | ||
5 | use Symfony\Component\HttpFoundation\File\UploadedFile; | ||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | 6 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; |
6 | use Wallabag\AnnotationBundle\Entity\Annotation; | 7 | use Wallabag\AnnotationBundle\Entity\Annotation; |
7 | use Wallabag\CoreBundle\Entity\Config; | 8 | use Wallabag\CoreBundle\Entity\Config; |
@@ -33,7 +34,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
33 | $this->assertCount(1, $crawler->filter('button[id=config_save]')); | 34 | $this->assertCount(1, $crawler->filter('button[id=config_save]')); |
34 | $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]')); | 35 | $this->assertCount(1, $crawler->filter('button[id=change_passwd_save]')); |
35 | $this->assertCount(1, $crawler->filter('button[id=update_user_save]')); | 36 | $this->assertCount(1, $crawler->filter('button[id=update_user_save]')); |
36 | $this->assertCount(1, $crawler->filter('button[id=rss_config_save]')); | 37 | $this->assertCount(1, $crawler->filter('button[id=feed_config_save]')); |
37 | } | 38 | } |
38 | 39 | ||
39 | public function testUpdate() | 40 | public function testUpdate() |
@@ -50,7 +51,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
50 | $data = [ | 51 | $data = [ |
51 | 'config[theme]' => 'baggy', | 52 | 'config[theme]' => 'baggy', |
52 | 'config[items_per_page]' => '30', | 53 | 'config[items_per_page]' => '30', |
53 | 'config[reading_speed]' => '0.5', | 54 | 'config[reading_speed]' => '100', |
54 | 'config[action_mark_as_read]' => '0', | 55 | 'config[action_mark_as_read]' => '0', |
55 | 'config[language]' => 'en', | 56 | 'config[language]' => 'en', |
56 | ]; | 57 | ]; |
@@ -91,7 +92,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
91 | $crawler = $client->request('GET', '/config'); | 92 | $crawler = $client->request('GET', '/config'); |
92 | $form = $crawler->filter('button[id=config_save]')->form(); | 93 | $form = $crawler->filter('button[id=config_save]')->form(); |
93 | $data = [ | 94 | $data = [ |
94 | 'config[reading_speed]' => '2', | 95 | 'config[reading_speed]' => '400', |
95 | ]; | 96 | ]; |
96 | $client->submit($form, $data); | 97 | $client->submit($form, $data); |
97 | 98 | ||
@@ -105,7 +106,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
105 | $crawler = $client->request('GET', '/config'); | 106 | $crawler = $client->request('GET', '/config'); |
106 | $form = $crawler->filter('button[id=config_save]')->form(); | 107 | $form = $crawler->filter('button[id=config_save]')->form(); |
107 | $data = [ | 108 | $data = [ |
108 | 'config[reading_speed]' => '0.5', | 109 | 'config[reading_speed]' => '100', |
109 | ]; | 110 | ]; |
110 | $client->submit($form, $data); | 111 | $client->submit($form, $data); |
111 | } | 112 | } |
@@ -297,7 +298,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
297 | $this->assertContains('flashes.config.notice.user_updated', $alert[0]); | 298 | $this->assertContains('flashes.config.notice.user_updated', $alert[0]); |
298 | } | 299 | } |
299 | 300 | ||
300 | public function testRssUpdateResetToken() | 301 | public function testFeedUpdateResetToken() |
301 | { | 302 | { |
302 | $this->logInAs('admin'); | 303 | $this->logInAs('admin'); |
303 | $client = $this->getClient(); | 304 | $client = $this->getClient(); |
@@ -313,7 +314,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
313 | } | 314 | } |
314 | 315 | ||
315 | $config = $user->getConfig(); | 316 | $config = $user->getConfig(); |
316 | $config->setRssToken(null); | 317 | $config->setFeedToken(null); |
317 | $em->persist($config); | 318 | $em->persist($config); |
318 | $em->flush(); | 319 | $em->flush(); |
319 | 320 | ||
@@ -322,7 +323,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
322 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | 323 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
323 | 324 | ||
324 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | 325 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
325 | $this->assertContains('config.form_rss.no_token', $body[0]); | 326 | $this->assertContains('config.form_feed.no_token', $body[0]); |
326 | 327 | ||
327 | $client->request('GET', '/generate-token'); | 328 | $client->request('GET', '/generate-token'); |
328 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | 329 | $this->assertSame(302, $client->getResponse()->getStatusCode()); |
@@ -330,7 +331,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
330 | $crawler = $client->followRedirect(); | 331 | $crawler = $client->followRedirect(); |
331 | 332 | ||
332 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); | 333 | $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); |
333 | $this->assertNotContains('config.form_rss.no_token', $body[0]); | 334 | $this->assertContains('config.form_feed.token_reset', $body[0]); |
334 | } | 335 | } |
335 | 336 | ||
336 | public function testGenerateTokenAjax() | 337 | public function testGenerateTokenAjax() |
@@ -351,7 +352,23 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
351 | $this->assertArrayHasKey('token', $content); | 352 | $this->assertArrayHasKey('token', $content); |
352 | } | 353 | } |
353 | 354 | ||
354 | public function testRssUpdate() | 355 | public function testRevokeTokenAjax() |
356 | { | ||
357 | $this->logInAs('admin'); | ||
358 | $client = $this->getClient(); | ||
359 | |||
360 | $client->request( | ||
361 | 'GET', | ||
362 | '/revoke-token', | ||
363 | [], | ||
364 | [], | ||
365 | ['HTTP_X-Requested-With' => 'XMLHttpRequest'] | ||
366 | ); | ||
367 | |||
368 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
369 | } | ||
370 | |||
371 | public function testFeedUpdate() | ||
355 | { | 372 | { |
356 | $this->logInAs('admin'); | 373 | $this->logInAs('admin'); |
357 | $client = $this->getClient(); | 374 | $client = $this->getClient(); |
@@ -360,10 +377,10 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
360 | 377 | ||
361 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | 378 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
362 | 379 | ||
363 | $form = $crawler->filter('button[id=rss_config_save]')->form(); | 380 | $form = $crawler->filter('button[id=feed_config_save]')->form(); |
364 | 381 | ||
365 | $data = [ | 382 | $data = [ |
366 | 'rss_config[rss_limit]' => 12, | 383 | 'feed_config[feed_limit]' => 12, |
367 | ]; | 384 | ]; |
368 | 385 | ||
369 | $client->submit($form, $data); | 386 | $client->submit($form, $data); |
@@ -372,31 +389,31 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
372 | 389 | ||
373 | $crawler = $client->followRedirect(); | 390 | $crawler = $client->followRedirect(); |
374 | 391 | ||
375 | $this->assertContains('flashes.config.notice.rss_updated', $crawler->filter('body')->extract(['_text'])[0]); | 392 | $this->assertContains('flashes.config.notice.feed_updated', $crawler->filter('body')->extract(['_text'])[0]); |
376 | } | 393 | } |
377 | 394 | ||
378 | public function dataForRssFailed() | 395 | public function dataForFeedFailed() |
379 | { | 396 | { |
380 | return [ | 397 | return [ |
381 | [ | 398 | [ |
382 | [ | 399 | [ |
383 | 'rss_config[rss_limit]' => 0, | 400 | 'feed_config[feed_limit]' => 0, |
384 | ], | 401 | ], |
385 | 'This value should be 1 or more.', | 402 | 'This value should be 1 or more.', |
386 | ], | 403 | ], |
387 | [ | 404 | [ |
388 | [ | 405 | [ |
389 | 'rss_config[rss_limit]' => 1000000000000, | 406 | 'feed_config[feed_limit]' => 1000000000000, |
390 | ], | 407 | ], |
391 | 'validator.rss_limit_too_high', | 408 | 'validator.feed_limit_too_high', |
392 | ], | 409 | ], |
393 | ]; | 410 | ]; |
394 | } | 411 | } |
395 | 412 | ||
396 | /** | 413 | /** |
397 | * @dataProvider dataForRssFailed | 414 | * @dataProvider dataForFeedFailed |
398 | */ | 415 | */ |
399 | public function testRssFailed($data, $expectedMessage) | 416 | public function testFeedFailed($data, $expectedMessage) |
400 | { | 417 | { |
401 | $this->logInAs('admin'); | 418 | $this->logInAs('admin'); |
402 | $client = $this->getClient(); | 419 | $client = $this->getClient(); |
@@ -405,7 +422,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
405 | 422 | ||
406 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | 423 | $this->assertSame(200, $client->getResponse()->getStatusCode()); |
407 | 424 | ||
408 | $form = $crawler->filter('button[id=rss_config_save]')->form(); | 425 | $form = $crawler->filter('button[id=feed_config_save]')->form(); |
409 | 426 | ||
410 | $crawler = $client->submit($form, $data); | 427 | $crawler = $client->submit($form, $data); |
411 | 428 | ||
@@ -678,7 +695,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
678 | 695 | ||
679 | $config->setTheme('material'); | 696 | $config->setTheme('material'); |
680 | $config->setItemsPerPage(30); | 697 | $config->setItemsPerPage(30); |
681 | $config->setReadingSpeed(1); | 698 | $config->setReadingSpeed(200); |
682 | $config->setLanguage('en'); | 699 | $config->setLanguage('en'); |
683 | $config->setPocketConsumerKey('xxxxx'); | 700 | $config->setPocketConsumerKey('xxxxx'); |
684 | 701 | ||
@@ -849,7 +866,7 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
849 | $entryArchived->setContent('Youhou'); | 866 | $entryArchived->setContent('Youhou'); |
850 | $entryArchived->setTitle('Youhou'); | 867 | $entryArchived->setTitle('Youhou'); |
851 | $entryArchived->addTag($tagArchived); | 868 | $entryArchived->addTag($tagArchived); |
852 | $entryArchived->setArchived(true); | 869 | $entryArchived->updateArchived(true); |
853 | $em->persist($entryArchived); | 870 | $em->persist($entryArchived); |
854 | 871 | ||
855 | $annotationArchived = new Annotation($user); | 872 | $annotationArchived = new Annotation($user); |
@@ -965,4 +982,183 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
965 | 982 | ||
966 | $client->request('GET', '/config/view-mode'); | 983 | $client->request('GET', '/config/view-mode'); |
967 | } | 984 | } |
985 | |||
986 | public function testChangeLocaleWithoutReferer() | ||
987 | { | ||
988 | $client = $this->getClient(); | ||
989 | |||
990 | $client->request('GET', '/locale/de'); | ||
991 | $client->followRedirect(); | ||
992 | |||
993 | $this->assertSame('de', $client->getRequest()->getLocale()); | ||
994 | $this->assertSame('de', $client->getContainer()->get('session')->get('_locale')); | ||
995 | } | ||
996 | |||
997 | public function testChangeLocaleWithReferer() | ||
998 | { | ||
999 | $client = $this->getClient(); | ||
1000 | |||
1001 | $client->request('GET', '/login'); | ||
1002 | $client->request('GET', '/locale/de'); | ||
1003 | $client->followRedirect(); | ||
1004 | |||
1005 | $this->assertSame('de', $client->getRequest()->getLocale()); | ||
1006 | $this->assertSame('de', $client->getContainer()->get('session')->get('_locale')); | ||
1007 | } | ||
1008 | |||
1009 | public function testChangeLocaleToBadLocale() | ||
1010 | { | ||
1011 | $client = $this->getClient(); | ||
1012 | |||
1013 | $client->request('GET', '/login'); | ||
1014 | $client->request('GET', '/locale/yuyuyuyu'); | ||
1015 | $client->followRedirect(); | ||
1016 | |||
1017 | $this->assertNotSame('yuyuyuyu', $client->getRequest()->getLocale()); | ||
1018 | $this->assertNotSame('yuyuyuyu', $client->getContainer()->get('session')->get('_locale')); | ||
1019 | } | ||
1020 | |||
1021 | public function testUserEnable2faEmail() | ||
1022 | { | ||
1023 | $this->logInAs('admin'); | ||
1024 | $client = $this->getClient(); | ||
1025 | |||
1026 | $crawler = $client->request('GET', '/config/otp/email'); | ||
1027 | |||
1028 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
1029 | |||
1030 | $crawler = $client->followRedirect(); | ||
1031 | |||
1032 | $this->assertGreaterThan(1, $alert = $crawler->filter('body')->extract(['_text'])); | ||
1033 | $this->assertContains('flashes.config.notice.otp_enabled', $alert[0]); | ||
1034 | |||
1035 | // restore user | ||
1036 | $em = $this->getEntityManager(); | ||
1037 | $user = $em | ||
1038 | ->getRepository('WallabagUserBundle:User') | ||
1039 | ->findOneByUsername('admin'); | ||
1040 | |||
1041 | $this->assertTrue($user->isEmailTwoFactor()); | ||
1042 | |||
1043 | $user->setEmailTwoFactor(false); | ||
1044 | $em->persist($user); | ||
1045 | $em->flush(); | ||
1046 | } | ||
1047 | |||
1048 | public function testUserEnable2faGoogle() | ||
1049 | { | ||
1050 | $this->logInAs('admin'); | ||
1051 | $client = $this->getClient(); | ||
1052 | |||
1053 | $crawler = $client->request('GET', '/config/otp/app'); | ||
1054 | |||
1055 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
1056 | |||
1057 | // restore user | ||
1058 | $em = $this->getEntityManager(); | ||
1059 | $user = $em | ||
1060 | ->getRepository('WallabagUserBundle:User') | ||
1061 | ->findOneByUsername('admin'); | ||
1062 | |||
1063 | $this->assertTrue($user->isGoogleTwoFactor()); | ||
1064 | $this->assertGreaterThan(0, $user->getBackupCodes()); | ||
1065 | |||
1066 | $user->setGoogleAuthenticatorSecret(false); | ||
1067 | $user->setBackupCodes(null); | ||
1068 | $em->persist($user); | ||
1069 | $em->flush(); | ||
1070 | } | ||
1071 | |||
1072 | public function testUserEnable2faGoogleCancel() | ||
1073 | { | ||
1074 | $this->logInAs('admin'); | ||
1075 | $client = $this->getClient(); | ||
1076 | |||
1077 | $crawler = $client->request('GET', '/config/otp/app'); | ||
1078 | |||
1079 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
1080 | |||
1081 | // restore user | ||
1082 | $em = $this->getEntityManager(); | ||
1083 | $user = $em | ||
1084 | ->getRepository('WallabagUserBundle:User') | ||
1085 | ->findOneByUsername('admin'); | ||
1086 | |||
1087 | $this->assertTrue($user->isGoogleTwoFactor()); | ||
1088 | $this->assertGreaterThan(0, $user->getBackupCodes()); | ||
1089 | |||
1090 | $crawler = $client->request('GET', '/config/otp/app/cancel'); | ||
1091 | |||
1092 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
1093 | |||
1094 | $user = $em | ||
1095 | ->getRepository('WallabagUserBundle:User') | ||
1096 | ->findOneByUsername('admin'); | ||
1097 | |||
1098 | $this->assertFalse($user->isGoogleTwoFactor()); | ||
1099 | $this->assertEmpty($user->getBackupCodes()); | ||
1100 | } | ||
1101 | |||
1102 | public function testExportTaggingRule() | ||
1103 | { | ||
1104 | $this->logInAs('admin'); | ||
1105 | $client = $this->getClient(); | ||
1106 | |||
1107 | ob_start(); | ||
1108 | $crawler = $client->request('GET', '/tagging-rule/export'); | ||
1109 | ob_end_clean(); | ||
1110 | |||
1111 | $this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
1112 | |||
1113 | $headers = $client->getResponse()->headers; | ||
1114 | $this->assertSame('application/json', $headers->get('content-type')); | ||
1115 | $this->assertSame('attachment; filename="tagging_rules_admin.json"', $headers->get('content-disposition')); | ||
1116 | $this->assertSame('UTF-8', $headers->get('content-transfer-encoding')); | ||
1117 | |||
1118 | $content = json_decode($client->getResponse()->getContent(), true); | ||
1119 | |||
1120 | $this->assertCount(4, $content); | ||
1121 | $this->assertSame('content matches "spurs"', $content[0]['rule']); | ||
1122 | $this->assertSame('sport', $content[0]['tags'][0]); | ||
1123 | } | ||
1124 | |||
1125 | public function testImportTagginfRuleBadFile() | ||
1126 | { | ||
1127 | $this->logInAs('admin'); | ||
1128 | $client = $this->getClient(); | ||
1129 | |||
1130 | $crawler = $client->request('GET', '/config'); | ||
1131 | $form = $crawler->filter('form[name=upload_tagging_rule_file] > button[type=submit]')->form(); | ||
1132 | |||
1133 | $data = [ | ||
1134 | 'upload_tagging_rule_file[file]' => '', | ||
1135 | ]; | ||
1136 | |||
1137 | $client->submit($form, $data); | ||
1138 | |||
1139 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
1140 | } | ||
1141 | |||
1142 | public function testImportTagginfRuleFile() | ||
1143 | { | ||
1144 | $this->logInAs('admin'); | ||
1145 | $client = $this->getClient(); | ||
1146 | |||
1147 | $crawler = $client->request('GET', '/config'); | ||
1148 | $form = $crawler->filter('form[name=upload_tagging_rule_file] > button[type=submit]')->form(); | ||
1149 | |||
1150 | $file = new UploadedFile(__DIR__ . '/../fixtures/tagging_rules_admin.json', 'tagging_rules_admin.json'); | ||
1151 | |||
1152 | $data = [ | ||
1153 | 'upload_tagging_rule_file[file]' => $file, | ||
1154 | ]; | ||
1155 | |||
1156 | $client->submit($form, $data); | ||
1157 | $this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
1158 | |||
1159 | $user = $client->getContainer()->get('fos_user.user_manager.test')->findUserBy(['username' => 'admin']); | ||
1160 | $taggingRules = $user->getConfig()->getTaggingRules()->toArray(); | ||
1161 | $this->assertCount(5, $taggingRules); | ||
1162 | $this->assertSame('title matches "football"', $taggingRules[4]->getRule()); | ||
1163 | } | ||
968 | } | 1164 | } |