aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2019-06-26 22:31:47 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2019-07-08 09:38:32 +0200
commit34be2d5de44ade2a78be73decc0b90a2c1bca720 (patch)
treed635438784c4b02e1d182cfbc3d47b62e5032f1d /tests
parent92cd51aa2c29e23f137cde9b9732ced33ff38e59 (diff)
downloadwallabag-34be2d5de44ade2a78be73decc0b90a2c1bca720.tar.gz
wallabag-34be2d5de44ade2a78be73decc0b90a2c1bca720.tar.zst
wallabag-34be2d5de44ade2a78be73decc0b90a2c1bca720.zip
Add ability to import/export tagging rules
- Add missing translations - Add some tests - Add `/api/taggingrule/export` API endpoint - Add baggy theme - Add error message when importing tagging rules failed - Also fix all translations (I think we are good now)
Diffstat (limited to 'tests')
-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}]