aboutsummaryrefslogtreecommitdiffstats
path: root/apps/testing
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2023-08-14 10:37:40 +0200
committerJulius Härtl <jus@bitgrid.net>2023-09-12 10:53:20 +0200
commitf894754372b85d834d0751f03d5988836e001bcd (patch)
tree685a88589b15f1ea2a7bef73200c75129fe54c20 /apps/testing
parent8c38beff9f7e86c84b3105da36c9e2108f118709 (diff)
downloadnextcloud-server-f894754372b85d834d0751f03d5988836e001bcd.tar.gz
nextcloud-server-f894754372b85d834d0751f03d5988836e001bcd.zip
feat(testing): Add fake providers for translations and text processing
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'apps/testing')
-rw-r--r--apps/testing/composer/composer/autoload_classmap.php2
-rw-r--r--apps/testing/composer/composer/autoload_static.php2
-rw-r--r--apps/testing/lib/AppInfo/Application.php4
-rw-r--r--apps/testing/lib/Provider/FakeTextProcessingProvider.php43
-rw-r--r--apps/testing/lib/Provider/FakeTranslationProvider.php44
5 files changed, 95 insertions, 0 deletions
diff --git a/apps/testing/composer/composer/autoload_classmap.php b/apps/testing/composer/composer/autoload_classmap.php
index c4688abedf4..d176ec2784d 100644
--- a/apps/testing/composer/composer/autoload_classmap.php
+++ b/apps/testing/composer/composer/autoload_classmap.php
@@ -13,4 +13,6 @@ return array(
'OCA\\Testing\\Controller\\LockingController' => $baseDir . '/../lib/Controller/LockingController.php',
'OCA\\Testing\\Controller\\RateLimitTestController' => $baseDir . '/../lib/Controller/RateLimitTestController.php',
'OCA\\Testing\\Locking\\FakeDBLockingProvider' => $baseDir . '/../lib/Locking/FakeDBLockingProvider.php',
+ 'OCA\\Testing\\Provider\\FakeTextProcessingProvider' => $baseDir . '/../lib/Provider/FakeTextProcessingProvider.php',
+ 'OCA\\Testing\\Provider\\FakeTranslationProvider' => $baseDir . '/../lib/Provider/FakeTranslationProvider.php',
);
diff --git a/apps/testing/composer/composer/autoload_static.php b/apps/testing/composer/composer/autoload_static.php
index 15b46171838..76909190cb2 100644
--- a/apps/testing/composer/composer/autoload_static.php
+++ b/apps/testing/composer/composer/autoload_static.php
@@ -28,6 +28,8 @@ class ComposerStaticInitTesting
'OCA\\Testing\\Controller\\LockingController' => __DIR__ . '/..' . '/../lib/Controller/LockingController.php',
'OCA\\Testing\\Controller\\RateLimitTestController' => __DIR__ . '/..' . '/../lib/Controller/RateLimitTestController.php',
'OCA\\Testing\\Locking\\FakeDBLockingProvider' => __DIR__ . '/..' . '/../lib/Locking/FakeDBLockingProvider.php',
+ 'OCA\\Testing\\Provider\\FakeTextProcessingProvider' => __DIR__ . '/..' . '/../lib/Provider/FakeTextProcessingProvider.php',
+ 'OCA\\Testing\\Provider\\FakeTranslationProvider' => __DIR__ . '/..' . '/../lib/Provider/FakeTranslationProvider.php',
);
public static function getInitializer(ClassLoader $loader)
diff --git a/apps/testing/lib/AppInfo/Application.php b/apps/testing/lib/AppInfo/Application.php
index 4bf4b5cb470..98c211acaab 100644
--- a/apps/testing/lib/AppInfo/Application.php
+++ b/apps/testing/lib/AppInfo/Application.php
@@ -25,6 +25,8 @@
namespace OCA\Testing\AppInfo;
use OCA\Testing\AlternativeHomeUserBackend;
+use OCA\Testing\Provider\FakeTranslationProvider;
+use OCA\Testing\Provider\FakeTextProcessingProvider;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
@@ -36,6 +38,8 @@ class Application extends App implements IBootstrap {
}
public function register(IRegistrationContext $context): void {
+ $context->registerTranslationProvider(FakeTranslationProvider::class);
+ $context->registerTextProcessingProvider(FakeTextProcessingProvider::class);
}
public function boot(IBootContext $context): void {
diff --git a/apps/testing/lib/Provider/FakeTextProcessingProvider.php b/apps/testing/lib/Provider/FakeTextProcessingProvider.php
new file mode 100644
index 00000000000..f95b528dfbe
--- /dev/null
+++ b/apps/testing/lib/Provider/FakeTextProcessingProvider.php
@@ -0,0 +1,43 @@
+<?php
+/**
+ * @copyright Copyright (c) 2023 Julius Härtl <jus@bitgrid.net>
+ *
+ * @author Julius Härtl <jus@bitgrid.net>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace OCA\Testing\Provider;
+
+use OCP\TextProcessing\FreePromptTaskType;
+use OCP\TextProcessing\IProvider;
+use OCP\TextProcessing\ITaskType;
+
+/** @template-implements IProvider<FreePromptTaskType|ITaskType> */
+class FakeTextProcessingProvider implements IProvider {
+
+ public function getName(): string {
+ return 'Fake text processing provider';
+ }
+
+ public function process(string $prompt): string {
+ return strrev($prompt);
+ }
+
+ public function getTaskType(): string {
+ return FreePromptTaskType::class;
+ }
+}
diff --git a/apps/testing/lib/Provider/FakeTranslationProvider.php b/apps/testing/lib/Provider/FakeTranslationProvider.php
new file mode 100644
index 00000000000..2a5e3102887
--- /dev/null
+++ b/apps/testing/lib/Provider/FakeTranslationProvider.php
@@ -0,0 +1,44 @@
+<?php
+/**
+ * @copyright Copyright (c) 2023 Julius Härtl <jus@bitgrid.net>
+ *
+ * @author Julius Härtl <jus@bitgrid.net>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace OCA\Testing\Provider;
+
+use OCP\Translation\ITranslationProvider;
+use OCP\Translation\LanguageTuple;
+
+class FakeTranslationProvider implements ITranslationProvider {
+
+ public function getName(): string {
+ return 'Fake translation';
+ }
+
+ public function getAvailableLanguages(): array {
+ return [
+ new LanguageTuple('de', 'German', 'en', 'English'),
+ new LanguageTuple('en', 'English', 'de', 'German'),
+ ];
+ }
+
+ public function translate(?string $fromLanguage, string $toLanguage, string $text): string {
+ return strrev($text);
+ }
+}