From 580e8aeb46b69e50a1211c088346b78fdfac6941 Mon Sep 17 00:00:00 2001 From: Swikriti Tripathi <41103328+SwikritiT@users.noreply.github.com> Date: Tue, 28 Nov 2023 15:33:17 +0545 Subject: [PATCH] tests: add api tests for changing system language using graph api (#7817) --- tests/TestHelpers/GraphHelper.php | 22 +++++++++ .../features/apiAntivirus/antivirus.feature | 2 +- .../deprovisioningNotification.feature | 2 +- .../apiNotification/emailNotification.feature | 12 ++--- .../apiNotification/notification.feature | 10 ++-- .../apiNotification/spaceNotification.feature | 2 +- .../features/bootstrap/GraphContext.php | 47 +++++++++++++++++++ .../features/bootstrap/SettingsContext.php | 2 +- 8 files changed, 85 insertions(+), 14 deletions(-) diff --git a/tests/TestHelpers/GraphHelper.php b/tests/TestHelpers/GraphHelper.php index c9ff5cce0..f5dbbc762 100644 --- a/tests/TestHelpers/GraphHelper.php +++ b/tests/TestHelpers/GraphHelper.php @@ -1470,4 +1470,26 @@ class GraphHelper { . " Cannot find share mountpoint id of '$path' for user '$user'" ); } + + /** + * @param string $baseUrl + * @param string $xRequestId + * @param string $user + * @param string $password + * @param string $language + * + * @return ResponseInterface + * @throws GuzzleException + */ + public static function switchSystemLanguage( + string $baseUrl, + string $xRequestId, + string $user, + string $password, + string $language + ): ResponseInterface { + $fullUrl = self::getFullUrl($baseUrl, 'me'); + $payload['preferredLanguage'] = $language; + return HttpRequestHelper::sendRequest($fullUrl, $xRequestId, 'PATCH', $user, $password, null, \json_encode($payload)); + } } diff --git a/tests/acceptance/features/apiAntivirus/antivirus.feature b/tests/acceptance/features/apiAntivirus/antivirus.feature index 3f223b5dc..3d15227c4 100644 --- a/tests/acceptance/features/apiAntivirus/antivirus.feature +++ b/tests/acceptance/features/apiAntivirus/antivirus.feature @@ -308,7 +308,7 @@ Feature: antivirus @issue-enterprise-5706 Scenario Outline: upload a file with virus and get notification in different languages - Given user "Alice" has switched the system language to "" + Given user "Alice" has switched the system language to "" using the Graph API And using DAV path When user "Alice" uploads file "filesForUpload/filesWithVirus/eicar.com" to "/aFileWithVirus.txt" using the WebDAV API Then the HTTP status code should be "201" diff --git a/tests/acceptance/features/apiNotification/deprovisioningNotification.feature b/tests/acceptance/features/apiNotification/deprovisioningNotification.feature index 8dd20c6bc..58348093a 100644 --- a/tests/acceptance/features/apiNotification/deprovisioningNotification.feature +++ b/tests/acceptance/features/apiNotification/deprovisioningNotification.feature @@ -102,7 +102,7 @@ Feature: Deprovisioning notification Scenario Outline: get a deprovisioning notification in various languages Given the administrator has created a deprovisioning notification - And user "Alice" has switched the system language to "" + And user "Alice" has switched the system language to "" using the Graph API When user "Alice" lists all notifications Then the HTTP status code should be "200" And the JSON response should contain a notification message with the subject "" and the message-details should match diff --git a/tests/acceptance/features/apiNotification/emailNotification.feature b/tests/acceptance/features/apiNotification/emailNotification.feature index 33a26728c..9c1f23139 100644 --- a/tests/acceptance/features/apiNotification/emailNotification.feature +++ b/tests/acceptance/features/apiNotification/emailNotification.feature @@ -78,8 +78,8 @@ Feature: Email notification And group "group1" has been created And user "Brian" has been added to group "group1" And user "Carol" has been added to group "group1" - And user "Brian" has switched the system language to "es" - And user "Carol" has switched the system language to "de" + And user "Brian" has switched the system language to "es" using the Graph API + And user "Carol" has switched the system language to "de" using the Graph API And user "Alice" has created folder "/HelloWorld" When user "Alice" shares folder "HelloWorld" with group "group1" using the sharing API Then the HTTP status code should be "200" @@ -107,8 +107,8 @@ Feature: Email notification And group "group1" has been created And user "Brian" has been added to group "group1" And user "Carol" has been added to group "group1" - And user "Brian" has switched the system language to "es" - And user "Carol" has switched the system language to "de" + And user "Brian" has switched the system language to "es" using the Graph API + And user "Carol" has switched the system language to "de" using the Graph API And user "Alice" has uploaded file with content "hello world" to "text.txt" When user "Alice" shares file "text.txt" with group "group1" using the sharing API Then the HTTP status code should be "200" @@ -137,8 +137,8 @@ Feature: Email notification And group "group1" has been created And user "Brian" has been added to group "group1" And user "Carol" has been added to group "group1" - And user "Brian" has switched the system language to "es" - And user "Carol" has switched the system language to "de" + And user "Brian" has switched the system language to "es" using the Graph API + And user "Carol" has switched the system language to "de" using the Graph API And user "Alice" has created a space "new-space" with the default quota using the Graph API When user "Alice" shares a space "new-space" with settings: | shareWith | group1 | diff --git a/tests/acceptance/features/apiNotification/notification.feature b/tests/acceptance/features/apiNotification/notification.feature index 5c0719faa..b9e13fc47 100644 --- a/tests/acceptance/features/apiNotification/notification.feature +++ b/tests/acceptance/features/apiNotification/notification.feature @@ -241,7 +241,7 @@ Feature: Notification Scenario Outline: get a notification about a file share in various languages - Given user "Brian" has switched the system language to "" + Given user "Brian" has switched the system language to "" using the API And user "Alice" has shared entry "textfile1.txt" with user "Brian" with permissions "17" When user "Brian" lists all notifications Then the HTTP status code should be "200" @@ -263,9 +263,11 @@ Feature: Notification } """ Examples: - | language | subject | message | - | de | Neue Freigabe | Alice Hansen hat textfile1.txt mit Ihnen geteilt | - | es | Recurso compartido | Alice Hansen compartió textfile1.txt contigo | + | language | subject | message | api | + | de | Neue Freigabe | Alice Hansen hat textfile1.txt mit Ihnen geteilt | Graph | + | de | Neue Freigabe | Alice Hansen hat textfile1.txt mit Ihnen geteilt | settings | + | es | Recurso compartido | Alice Hansen compartió textfile1.txt contigo | Graph | + | es | Recurso compartido | Alice Hansen compartió textfile1.txt contigo | settings | @env-config Scenario: get a notification about a file share in default languages diff --git a/tests/acceptance/features/apiNotification/spaceNotification.feature b/tests/acceptance/features/apiNotification/spaceNotification.feature index f8d7bd8f2..e03a080b4 100644 --- a/tests/acceptance/features/apiNotification/spaceNotification.feature +++ b/tests/acceptance/features/apiNotification/spaceNotification.feature @@ -419,7 +419,7 @@ Feature: Notification Scenario Outline: get a notification about a space share in various languages - Given user "Brian" has switched the system language to "" + Given user "Brian" has switched the system language to "" using the Graph API And user "Alice" has shared a space "notification checking" with settings: | shareWith | Brian | | role | editor | diff --git a/tests/acceptance/features/bootstrap/GraphContext.php b/tests/acceptance/features/bootstrap/GraphContext.php index bc8a1a5e5..b8a2e8e25 100644 --- a/tests/acceptance/features/bootstrap/GraphContext.php +++ b/tests/acceptance/features/bootstrap/GraphContext.php @@ -2466,4 +2466,51 @@ class GraphContext implements Context { ) ); } + + /** + * @Given user :user has switched the system language to :language using the Graph API + * + * @param string $user + * @param string $language + * + * @return void + * @throws GuzzleException + */ + public function userHasSwitchedTheSystemLanguageUsingGraphApi(string $user, string $language): void { + $credentials = $this->getAdminOrUserCredentials($user); + $response = GraphHelper::switchSystemLanguage( + $this->featureContext->getBaseUrl(), + $this->featureContext->getStepLineRef(), + $credentials['username'], + $credentials['password'], + $language + ); + $this->featureContext->theHTTPStatusCodeShouldBe( + 200, + "Expected response status code should be 200", + $response + ); + } + + /** + * @When user :user switches the system language to :language using the Graph API + * + * @param string $user + * @param string $language + * + * @return void + * @throws GuzzleException + */ + public function userSwitchesTheSystemLanguageUsingGraphApi(string $user, string $language): void { + $credentials = $this->getAdminOrUserCredentials($user); + $this->featureContext->setResponse( + GraphHelper::switchSystemLanguage( + $this->featureContext->getBaseUrl(), + $this->featureContext->getStepLineRef(), + $credentials['username'], + $credentials['password'], + $language + ) + ); + } } diff --git a/tests/acceptance/features/bootstrap/SettingsContext.php b/tests/acceptance/features/bootstrap/SettingsContext.php index 62805b2cb..56a73aa00 100644 --- a/tests/acceptance/features/bootstrap/SettingsContext.php +++ b/tests/acceptance/features/bootstrap/SettingsContext.php @@ -443,7 +443,7 @@ class SettingsContext implements Context { } /** - * @Given /^user "([^"]*)" has switched the system language to "([^"]*)"$/ + * @Given /^user "([^"]*)" has switched the system language to "([^"]*)" using the settings API$/ * * @param string $user * @param string $language