From fbbf33c2ecf8ab1c48b82ad6a3e1623bb015251f Mon Sep 17 00:00:00 2001 From: talank Date: Thu, 18 Feb 2021 13:54:07 +0545 Subject: [PATCH 1/2] used environment variable for language setup --- .drone.star | 2 +- tests/acceptance/features/bootstrap/OCSContext.php | 5 +++++ tests/acceptance/features/bootstrap/Sharing.php | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.drone.star b/.drone.star index 602d348a9f3b..751f11562c32 100644 --- a/.drone.star +++ b/.drone.star @@ -1338,7 +1338,7 @@ def acceptance(ctx): 'replaceUsernames': False, 'extraSetup': [], 'extraServices': [], - 'extraEnvironment': {}, + 'extraEnvironment': {'OC_LANGUAGE':'en-EN'}, 'extraCommandsBeforeTestRun': [], 'extraApps': {}, 'useBundledApp': False, diff --git a/tests/acceptance/features/bootstrap/OCSContext.php b/tests/acceptance/features/bootstrap/OCSContext.php index 4c8f029180b1..be52ffa45055 100644 --- a/tests/acceptance/features/bootstrap/OCSContext.php +++ b/tests/acceptance/features/bootstrap/OCSContext.php @@ -713,6 +713,11 @@ public function theOcsStatusCodeShouldBeOr($statusCode1, $statusCode2) { * @return void */ public function theOCSStatusMessageShouldBe($statusMessage, $language=null) { + if (!isset($language)) { + if (\getenv('OC_LANGUAGE') !== false) { + $language = \getenv('OC_LANGUAGE'); + } + } $statusMessage = $this->getActualStatusMessage($statusMessage, $language); Assert::assertEquals( diff --git a/tests/acceptance/features/bootstrap/Sharing.php b/tests/acceptance/features/bootstrap/Sharing.php index 63c39aed2567..c66067c894fe 100644 --- a/tests/acceptance/features/bootstrap/Sharing.php +++ b/tests/acceptance/features/bootstrap/Sharing.php @@ -1631,6 +1631,11 @@ public function theUserGetsInfoOfLastShareUsingTheSharingApi() { */ public function userGetsInfoOfLastShareUsingTheSharingApi($user, $language=null) { $share_id = $this->getLastShareIdOf($user); + if (!isset($language)) { + if (\getenv('OC_LANGUAGE') !== false) { + $language = \getenv('OC_LANGUAGE'); + } + } $this->getShareData($user, $share_id, $language); } From 331151fb09b292e618eda79ab302ec3f04a016a2 Mon Sep 17 00:00:00 2001 From: talank Date: Thu, 25 Feb 2021 10:13:05 +0545 Subject: [PATCH 2/2] Added translation helper file --- tests/TestHelpers/TranslationHelper.php | 45 +++++++++++++++++++ .../features/bootstrap/OCSContext.php | 7 +-- .../acceptance/features/bootstrap/Sharing.php | 7 +-- 3 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 tests/TestHelpers/TranslationHelper.php diff --git a/tests/TestHelpers/TranslationHelper.php b/tests/TestHelpers/TranslationHelper.php new file mode 100644 index 000000000000..6adac964929c --- /dev/null +++ b/tests/TestHelpers/TranslationHelper.php @@ -0,0 +1,45 @@ + + * @copyright Copyright (c) 2021 Talank Baral talank@jankaritech.com + * + * This code 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 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 + * + */ +namespace TestHelpers; + +/** + * Class TranslationHelper + * + * Helper functions that are needed to run tests on different languages + * + * @package TestHelpers + */ +class TranslationHelper { + /** + * @param $language + * + * @return string + */ + public static function getLanguage($language) { + if (!isset($language)) { + if (\getenv('OC_LANGUAGE') !== false) { + $language = \getenv('OC_LANGUAGE'); + } + } + return $language; + } +} diff --git a/tests/acceptance/features/bootstrap/OCSContext.php b/tests/acceptance/features/bootstrap/OCSContext.php index be52ffa45055..1d510d897db0 100644 --- a/tests/acceptance/features/bootstrap/OCSContext.php +++ b/tests/acceptance/features/bootstrap/OCSContext.php @@ -27,6 +27,7 @@ use Psr\Http\Message\ResponseInterface; use PHPUnit\Framework\Assert; use TestHelpers\OcsApiHelper; +use TestHelpers\TranslationHelper; require_once 'bootstrap.php'; @@ -713,11 +714,7 @@ public function theOcsStatusCodeShouldBeOr($statusCode1, $statusCode2) { * @return void */ public function theOCSStatusMessageShouldBe($statusMessage, $language=null) { - if (!isset($language)) { - if (\getenv('OC_LANGUAGE') !== false) { - $language = \getenv('OC_LANGUAGE'); - } - } + $language = TranslationHelper::getLanguage($language); $statusMessage = $this->getActualStatusMessage($statusMessage, $language); Assert::assertEquals( diff --git a/tests/acceptance/features/bootstrap/Sharing.php b/tests/acceptance/features/bootstrap/Sharing.php index c66067c894fe..d34817461d76 100644 --- a/tests/acceptance/features/bootstrap/Sharing.php +++ b/tests/acceptance/features/bootstrap/Sharing.php @@ -29,6 +29,7 @@ use TestHelpers\OcisHelper; use TestHelpers\SharingHelper; use TestHelpers\HttpRequestHelper; +use TestHelpers\TranslationHelper; /** * Sharing trait @@ -1631,11 +1632,7 @@ public function theUserGetsInfoOfLastShareUsingTheSharingApi() { */ public function userGetsInfoOfLastShareUsingTheSharingApi($user, $language=null) { $share_id = $this->getLastShareIdOf($user); - if (!isset($language)) { - if (\getenv('OC_LANGUAGE') !== false) { - $language = \getenv('OC_LANGUAGE'); - } - } + $language = TranslationHelper::getLanguage($language); $this->getShareData($user, $share_id, $language); }