diff options
author | Jérémy Benoist <j0k3r@users.noreply.github.com> | 2019-07-08 12:48:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-08 12:48:25 +0200 |
commit | 8effd6e99e5a1f1d0d663ee77b0f5015220d1b4a (patch) | |
tree | d635438784c4b02e1d182cfbc3d47b62e5032f1d /tests | |
parent | 92cd51aa2c29e23f137cde9b9732ced33ff38e59 (diff) | |
parent | 34be2d5de44ade2a78be73decc0b90a2c1bca720 (diff) | |
download | wallabag-8effd6e99e5a1f1d0d663ee77b0f5015220d1b4a.tar.gz wallabag-8effd6e99e5a1f1d0d663ee77b0f5015220d1b4a.tar.zst wallabag-8effd6e99e5a1f1d0d663ee77b0f5015220d1b4a.zip |
Merge pull request #4028 from wallabag/feature/import-export-tagging-rules
Add ability to import/export tagging rules
Diffstat (limited to 'tests')
3 files changed, 83 insertions, 0 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/TaggingRuleRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/TaggingRuleRestControllerTest.php new file mode 100644 index 00000000..b6477256 --- /dev/null +++ b/tests/Wallabag/ApiBundle/Controller/TaggingRuleRestControllerTest.php | |||
@@ -0,0 +1,15 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\ApiBundle\Controller; | ||
4 | |||
5 | use Tests\Wallabag\ApiBundle\WallabagApiTestCase; | ||
6 | |||
7 | class TaggingRuleRestControllerTest extends WallabagApiTestCase | ||
8 | { | ||
9 | public function testExportEntry() | ||
10 | { | ||
11 | $this->client->request('GET', '/api/taggingrule/export'); | ||
12 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | ||
13 | $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); | ||
14 | } | ||
15 | } | ||
diff --git a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php index b9e0bed2..d8b5f383 100644 --- a/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php | |||
@@ -2,6 +2,7 @@ | |||
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; |
@@ -1097,4 +1098,67 @@ class ConfigControllerTest extends WallabagCoreTestCase | |||
1097 | $this->assertFalse($user->isGoogleTwoFactor()); | 1098 | $this->assertFalse($user->isGoogleTwoFactor()); |
1098 | $this->assertEmpty($user->getBackupCodes()); | 1099 | $this->assertEmpty($user->getBackupCodes()); |
1099 | } | 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 | } | ||
1100 | } | 1164 | } |
diff --git a/tests/Wallabag/CoreBundle/fixtures/tagging_rules_admin.json b/tests/Wallabag/CoreBundle/fixtures/tagging_rules_admin.json new file mode 100644 index 00000000..a54824e2 --- /dev/null +++ b/tests/Wallabag/CoreBundle/fixtures/tagging_rules_admin.json | |||
@@ -0,0 +1,4 @@ | |||
1 | [{ | ||
2 | "rule": "title matches \"football\"", | ||
3 | "tags": ["football"] | ||
4 | }] | ||