Skip to content

Commit 6dcb8c3

Browse files
authored
Merge pull request #38412 from owncloud/translation-test-genaralized
[Tests-Only]Used json file to store translated messages
2 parents 2056240 + 84a2ba2 commit 6dcb8c3

File tree

3 files changed

+46
-15
lines changed

3 files changed

+46
-15
lines changed

tests/acceptance/features/apiTranslation/translation.feature

+11-14
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,16 @@ Feature: translate messages in api response to preferred language
1212
| Carol |
1313
And using <dav_version> DAV path
1414
And user "Brian" has shared file "textfile0.txt" with user "Carol"
15-
When user "Alice" gets the info of the last share in language "de-DE" using the sharing API
15+
When user "Alice" gets the info of the last share in language "<language>" using the sharing API
1616
Then the OCS status code should be "404"
17-
And the OCS status message should be "Fehlerhafte Freigabe-ID, Freigabe existiert nicht"
18-
When user "Alice" gets the info of the last share in language "zh-CN" using the sharing API
19-
Then the OCS status code should be "404"
20-
And the OCS status message should be "错误的共享 ID,共享不存在"
21-
When user "Alice" gets the info of the last share in language "fr-FR" using the sharing API
22-
Then the OCS status code should be "404"
23-
And the OCS status message should be "Mauvais ID de partage, le partage n'existe pas"
24-
When user "Alice" gets the info of the last share in language "es-ES" using the sharing API
25-
Then the OCS status code should be "404"
26-
And the OCS status message should be "El ID del recurso compartido no es correcto, el recurso compartido no existe"
17+
And the OCS status message should be "Wrong share ID, share doesn't exist" in language "<language>"
2718
Examples:
28-
| dav_version |
29-
| old |
30-
| new |
19+
| dav_version | language |
20+
| old | de-DE |
21+
| new | de-DE |
22+
| old | zh-CN |
23+
| new | zh-CN |
24+
| old | fr-FR |
25+
| new | fr-FR |
26+
| old | es-ES |
27+
| new | es-ES |

tests/acceptance/features/bootstrap/OCSContext.php

+27-1
Original file line numberDiff line numberDiff line change
@@ -705,12 +705,16 @@ public function theOcsStatusCodeShouldBeOr($statusCode1, $statusCode2) {
705705
* Check the text in an OCS status message
706706
*
707707
* @Then /^the OCS status message should be "([^"]*)"$/
708+
* @Then /^the OCS status message should be "([^"]*)" in language "([^"]*)"$/
708709
*
709710
* @param string $statusMessage
711+
* @param string $language
710712
*
711713
* @return void
712714
*/
713-
public function theOCSStatusMessageShouldBe($statusMessage) {
715+
public function theOCSStatusMessageShouldBe($statusMessage, $language=null) {
716+
$statusMessage = $this->getActualStatusMessage($statusMessage, $language);
717+
714718
Assert::assertEquals(
715719
$statusMessage,
716720
$this->getOCSResponseStatusMessage(
@@ -811,6 +815,28 @@ public function getOCSResponseStatusMessage($response) {
811815
return (string) $this->featureContext->getResponseXml($response, __METHOD__)->meta[0]->message;
812816
}
813817

818+
/**
819+
* convert status message in the desired language
820+
*
821+
* @param $statusMessage
822+
* @param $language
823+
*
824+
* @return string
825+
*/
826+
public function getActualStatusMessage($statusMessage, $language) {
827+
if ($language !== null) {
828+
$multiLingualMessage = \json_decode(
829+
\file_get_contents("./tests/acceptance/fixtures/multiLanguageErrors.json"),
830+
true
831+
);
832+
833+
if (isset($multiLingualMessage[$statusMessage][$language])) {
834+
$statusMessage = $multiLingualMessage[$statusMessage][$language];
835+
}
836+
}
837+
return $statusMessage;
838+
}
839+
814840
/**
815841
* check if the HTTP status code and the OCS status code indicate that the request was successful
816842
* this function is aware of the currently used OCS version
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Wrong share ID, share doesn't exist": {
3+
"de-DE": "Fehlerhafte Freigabe-ID, Freigabe existiert nicht",
4+
"zh-CN": "错误的共享 ID,共享不存在",
5+
"fr-FR": "Mauvais ID de partage, le partage n'existe pas",
6+
"es-ES": "El ID del recurso compartido no es correcto, el recurso compartido no existe"
7+
}
8+
}

0 commit comments

Comments
 (0)