Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tests-Only]Used json file to store translated messages #38412

Merged
merged 2 commits into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions tests/acceptance/features/apiTranslation/translation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,16 @@ Feature: translate messages in api response to preferred language
| Carol |
And using <dav_version> DAV path
And user "Brian" has shared file "textfile0.txt" with user "Carol"
When user "Alice" gets the info of the last share in language "de-DE" using the sharing API
When user "Alice" gets the info of the last share in language "<language>" using the sharing API
Then the OCS status code should be "404"
And the OCS status message should be "Fehlerhafte Freigabe-ID, Freigabe existiert nicht"
When user "Alice" gets the info of the last share in language "zh-CN" using the sharing API
Then the OCS status code should be "404"
And the OCS status message should be "错误的共享 ID,共享不存在"
When user "Alice" gets the info of the last share in language "fr-FR" using the sharing API
Then the OCS status code should be "404"
And the OCS status message should be "Mauvais ID de partage, le partage n'existe pas"
When user "Alice" gets the info of the last share in language "es-ES" using the sharing API
Then the OCS status code should be "404"
And the OCS status message should be "El ID del recurso compartido no es correcto, el recurso compartido no existe"
And the OCS status message should be "Wrong share ID, share doesn't exist" in language "<language>"
Examples:
| dav_version |
| old |
| new |
| dav_version | language |
| old | de-DE |
| new | de-DE |
| old | zh-CN |
| new | zh-CN |
| old | fr-FR |
| new | fr-FR |
| old | es-ES |
| new | es-ES |
Comment on lines +19 to +27
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just have a data table rather than senario outline, that will make tests a lot faster

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we? 🤔 Also, I wanted to reuse the logic from the step Then the OCS status message should be "<message>". So, I am not sure if it is a great idea. What do you think @phil-davis

28 changes: 27 additions & 1 deletion tests/acceptance/features/bootstrap/OCSContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -698,12 +698,16 @@ public function theOcsStatusCodeShouldBeOr($statusCode1, $statusCode2) {
* Check the text in an OCS status message
*
* @Then /^the OCS status message should be "([^"]*)"$/
* @Then /^the OCS status message should be "([^"]*)" in language "([^"]*)"$/
*
* @param string $statusMessage
* @param string $language
*
* @return void
*/
public function theOCSStatusMessageShouldBe($statusMessage) {
public function theOCSStatusMessageShouldBe($statusMessage, $language=null) {
$statusMessage = $this->getActualStatusMessage($statusMessage, $language);

Assert::assertEquals(
$statusMessage,
$this->getOCSResponseStatusMessage(
Expand Down Expand Up @@ -804,6 +808,28 @@ public function getOCSResponseStatusMessage($response) {
return (string) $this->featureContext->getResponseXml($response, __METHOD__)->meta[0]->message;
}

/**
* convert status message in the desired language
*
* @param $statusMessage
* @param $language
*
* @return string
*/
public function getActualStatusMessage($statusMessage, $language) {
if ($language !== null) {
$multiLingualMessage = \json_decode(
\file_get_contents("./tests/acceptance/fixtures/multiLanguageErrors.json"),
true
);

if (isset($multiLingualMessage[$statusMessage][$language])) {
$statusMessage = $multiLingualMessage[$statusMessage][$language];
}
}
return $statusMessage;
}

/**
* check if the HTTP status code and the OCS status code indicate that the request was successful
* this function is aware of the currently used OCS version
Expand Down
8 changes: 8 additions & 0 deletions tests/acceptance/fixtures/multiLanguageErrors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Wrong share ID, share doesn't exist": {
"de-DE": "Fehlerhafte Freigabe-ID, Freigabe existiert nicht",
"zh-CN": "错误的共享 ID,共享不存在",
"fr-FR": "Mauvais ID de partage, le partage n'existe pas",
"es-ES": "El ID del recurso compartido no es correcto, el recurso compartido no existe"
}
}