diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2023-05-04 10:50:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-04 10:50:27 +0200 |
commit | 217a59c81564d75146229be2ad749cf19d19d1db (patch) | |
tree | 6f542b047d1269429e6430166741d4987a9d8f5b /tests | |
parent | 84153ff63b0dfd3da355af337500a6ab368965c1 (diff) | |
parent | a7493323bb0df4a043679804d7de56760e9414dd (diff) |
Merge pull request #9437 from nextcloud/bugfix/9435/XML-capabilities-are-broken
fix(capabilities): Convert TranslationTuples to arrays so they work in XML
Diffstat (limited to 'tests')
-rw-r--r-- | tests/integration/features/bootstrap/FeatureContext.php | 52 | ||||
-rw-r--r-- | tests/integration/features/integration/capabilities.feature | 8 | ||||
-rw-r--r-- | tests/integration/spreedcheats/lib/AppInfo/Application.php | 6 | ||||
-rw-r--r-- | tests/integration/spreedcheats/lib/SpeechToText/LoremIpsumSpeechToTextProvider.php (renamed from tests/integration/spreedcheats/lib/SpeechToText/LoremIpsumProvider.php) | 2 | ||||
-rw-r--r-- | tests/integration/spreedcheats/lib/Translation/LoremIpsumTranslationProvider.php | 51 |
5 files changed, 105 insertions, 14 deletions
diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index 27537c1c3..43ed29135 100644 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -2718,7 +2718,7 @@ class FeatureContext implements Context, SnippetAcceptingContext { } /** - * Parses the xml answer to get the array of users returned. + * Parses the JSON answer to get the array of users returned. * @param ResponseInterface $response * @return array */ @@ -3155,19 +3155,12 @@ class FeatureContext implements Context, SnippetAcceptingContext { } /** - * @When wait for :seconds second + * @When wait for :seconds (second|seconds) */ public function waitForXSecond($seconds): void { sleep($seconds); } - /** - * @When wait for :seconds seconds - */ - public function waitForXSeconds($seconds): void { - sleep($seconds); - } - /* * Requests */ @@ -3450,6 +3443,26 @@ class FeatureContext implements Context, SnippetAcceptingContext { } /** + * @When /^last response body (contains|does not contain|starts with|starts not with|ends with|ends not with) "([^"]*)"$/ + * @param string $needle + */ + public function lastResponseBodyContains(string $comparison, string $needle) { + if ($comparison === 'contains') { + Assert::assertStringContainsString($needle, $this->response->getBody()->getContents()); + } elseif ($comparison === 'does not contain') { + Assert::assertStringNotContainsString($needle, $this->response->getBody()->getContents()); + } elseif ($comparison === 'starts with') { + Assert::assertStringStartsWith($needle, $this->response->getBody()->getContents()); + } elseif ($comparison === 'starts not with') { + Assert::assertStringStartsNotWith($needle, $this->response->getBody()->getContents()); + } elseif ($comparison === 'ends with') { + Assert::assertStringEndsWith($needle, $this->response->getBody()->getContents()); + } elseif ($comparison === 'ends not with') { + Assert::assertStringEndsNotWith($needle, $this->response->getBody()->getContents()); + } + } + + /** * @When /^sending "([^"]*)" to "([^"]*)" with$/ * @param string $verb * @param string $url @@ -3462,6 +3475,23 @@ class FeatureContext implements Context, SnippetAcceptingContext { } /** + * @When /^sending "([^"]*)" to "([^"]*)" for xml with$/ + * @param string $verb + * @param string $url + * @param TableNode|array|null $body + * @param array $headers + */ + public function sendXMLRequest($verb, $url, $body = null, array $headers = [], array $options = []) { + $fullUrl = $this->baseUrl . 'ocs/v2.php' . $url; + + $headers = array_merge([ + 'Accept' => 'application/xml', + ], $headers); + + $this->sendRequestFullUrl($verb, $fullUrl, $body, $headers, $options); + } + + /** * @param string $verb * @param string $url * @param TableNode|array|null $body @@ -3495,10 +3525,10 @@ class FeatureContext implements Context, SnippetAcceptingContext { $options['body'] = $body; } - $options['headers'] = array_merge($headers, [ + $options['headers'] = array_merge([ 'OCS-ApiRequest' => 'true', 'Accept' => 'application/json', - ]); + ], $headers); try { $this->response = $client->{$verb}($fullUrl, $options); diff --git a/tests/integration/features/integration/capabilities.feature b/tests/integration/features/integration/capabilities.feature new file mode 100644 index 000000000..8920b80a6 --- /dev/null +++ b/tests/integration/features/integration/capabilities.feature @@ -0,0 +1,8 @@ +Feature: integration/dashboard + Background: + Given user "participant1" exists + + Scenario: User gets the available dashboard widgets + Given as user "participant1" + When sending "GET" to "/cloud/capabilities" for xml with + Then last response body contains "<toLabel>Lorem ipsum</toLabel>" diff --git a/tests/integration/spreedcheats/lib/AppInfo/Application.php b/tests/integration/spreedcheats/lib/AppInfo/Application.php index 4940681a0..910c0f0aa 100644 --- a/tests/integration/spreedcheats/lib/AppInfo/Application.php +++ b/tests/integration/spreedcheats/lib/AppInfo/Application.php @@ -23,7 +23,8 @@ declare(strict_types=1); namespace OCA\SpreedCheats\AppInfo; -use OCA\SpreedCheats\SpeechToText\LoremIpsumProvider; +use OCA\SpreedCheats\SpeechToText\LoremIpsumSpeechToTextProvider; +use OCA\SpreedCheats\Translation\LoremIpsumTranslationProvider; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; @@ -37,7 +38,8 @@ class Application extends App implements IBootstrap { } public function register(IRegistrationContext $context): void { - $context->registerSpeechToTextProvider(LoremIpsumProvider::class); + $context->registerSpeechToTextProvider(LoremIpsumSpeechToTextProvider::class); + $context->registerTranslationProvider(LoremIpsumTranslationProvider::class); } public function boot(IBootContext $context): void { diff --git a/tests/integration/spreedcheats/lib/SpeechToText/LoremIpsumProvider.php b/tests/integration/spreedcheats/lib/SpeechToText/LoremIpsumSpeechToTextProvider.php index 6d818ca62..7310d84e0 100644 --- a/tests/integration/spreedcheats/lib/SpeechToText/LoremIpsumProvider.php +++ b/tests/integration/spreedcheats/lib/SpeechToText/LoremIpsumSpeechToTextProvider.php @@ -29,7 +29,7 @@ namespace OCA\SpreedCheats\SpeechToText; use OCP\Files\File; use OCP\SpeechToText\ISpeechToTextProvider; -class LoremIpsumProvider implements ISpeechToTextProvider { +class LoremIpsumSpeechToTextProvider implements ISpeechToTextProvider { public function getName(): string { return 'Lorem ipsum - Talk Integrationtests'; diff --git a/tests/integration/spreedcheats/lib/Translation/LoremIpsumTranslationProvider.php b/tests/integration/spreedcheats/lib/Translation/LoremIpsumTranslationProvider.php new file mode 100644 index 000000000..4e7484340 --- /dev/null +++ b/tests/integration/spreedcheats/lib/Translation/LoremIpsumTranslationProvider.php @@ -0,0 +1,51 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2023 Joas Schilling <coding@schilljs.com> + * + * @author Joas Schilling <coding@schilljs.com> + * + * @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\SpreedCheats\Translation; + +use OCP\Translation\ITranslationProvider; +use OCP\Translation\LanguageTuple; + +class LoremIpsumTranslationProvider implements ITranslationProvider { + public function getName(): string { + return 'Lorem ipsum - Talk Integrationtests'; + } + + public function getAvailableLanguages(): array { + return [ + new LanguageTuple( + 'en', + 'English', + 'lorem', + 'Lorem ipsum', + ) + ]; + } + + public function translate(?string $fromLanguage, string $toLanguage, string $text): string { + return 'Lorem ipsum'; + } +} |