aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag
diff options
context:
space:
mode:
authorJérémy Benoist <j0k3r@users.noreply.github.com>2019-07-08 12:48:25 +0200
committerGitHub <noreply@github.com>2019-07-08 12:48:25 +0200
commit8effd6e99e5a1f1d0d663ee77b0f5015220d1b4a (patch)
treed635438784c4b02e1d182cfbc3d47b62e5032f1d /tests/Wallabag
parent92cd51aa2c29e23f137cde9b9732ced33ff38e59 (diff)
parent34be2d5de44ade2a78be73decc0b90a2c1bca720 (diff)
downloadwallabag-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/Wallabag')
-rw-r--r--tests/Wallabag/ApiBundle/Controller/TaggingRuleRestControllerTest.php15
-rw-r--r--tests/Wallabag/CoreBundle/Controller/ConfigControllerTest.php64
-rw-r--r--tests/Wallabag/CoreBundle/fixtures/tagging_rules_admin.json4
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
3namespace Tests\Wallabag\ApiBundle\Controller;
4
5use Tests\Wallabag\ApiBundle\WallabagApiTestCase;
6
7class 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
3namespace Tests\Wallabag\CoreBundle\Controller; 3namespace Tests\Wallabag\CoreBundle\Controller;
4 4
5use Symfony\Component\HttpFoundation\File\UploadedFile;
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; 6use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6use Wallabag\AnnotationBundle\Entity\Annotation; 7use Wallabag\AnnotationBundle\Entity\Annotation;
7use Wallabag\CoreBundle\Entity\Config; 8use 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}]