diff --git a/tests/acceptance/config/behat.yml b/tests/acceptance/config/behat.yml index ff8ff74ccf5..874db10c58b 100644 --- a/tests/acceptance/config/behat.yml +++ b/tests/acceptance/config/behat.yml @@ -13,7 +13,7 @@ default: ldapGroupsOU: TestGroups ldapInitialUserFilePath: /../../config/ldap-users.ldif contexts: - - RoleAssignmentContext: + - SettingsContext: - GraphContext: - SpacesContext: - FeatureContext: &common_feature_context_params @@ -37,7 +37,7 @@ default: - '%paths.base%/../features/apiSpaces' context: *common_ldap_suite_context contexts: - - RoleAssignmentContext: + - SettingsContext: - SpacesContext: - FeatureContext: *common_feature_context_params - CapabilitiesContext: @@ -60,7 +60,7 @@ default: - '%paths.base%/../features/apiSpacesShares' context: *common_ldap_suite_context contexts: - - RoleAssignmentContext: + - SettingsContext: - SpacesContext: - FeatureContext: *common_feature_context_params - CapabilitiesContext: @@ -82,7 +82,7 @@ default: - '%paths.base%/../features/apiContract' context: *common_ldap_suite_context contexts: - - RoleAssignmentContext: + - SettingsContext: - SpacesContext: - FeatureContext: *common_feature_context_params - CapabilitiesContext: @@ -103,7 +103,7 @@ default: - '%paths.base%/../features/apiArchiver' context: *common_ldap_suite_context contexts: - - RoleAssignmentContext: + - SettingsContext: - ArchiverContext: - SpacesContext: - FeatureContext: *common_feature_context_params @@ -122,7 +122,7 @@ default: - '%paths.base%/../features/apiGraph' context: *common_ldap_suite_context contexts: - - RoleAssignmentContext: + - SettingsContext: - GraphContext: - SpacesContext: - FeatureContext: *common_feature_context_params @@ -185,7 +185,7 @@ default: - FavoritesContext: - ChecksumContext: - FilesVersionsContext: - - RoleAssignmentContext: + - SettingsContext: extensions: rdx\behatvars\BehatVariablesExtension: ~ diff --git a/tests/acceptance/features/apiSpaces/notification.feature b/tests/acceptance/features/apiSpaces/notification.feature index b29d3846e2f..763f8fe2602 100644 --- a/tests/acceptance/features/apiSpaces/notification.feature +++ b/tests/acceptance/features/apiSpaces/notification.feature @@ -1,4 +1,4 @@ -@api +@api Feature: Notification As a user I want to be notified of actions related to me @@ -21,108 +21,160 @@ Feature: Notification When user "Brian" lists all notifications Then the HTTP status code should be "200" And the JSON response should contain a notification message with the subject "Space shared" and the message-details should match - """ - { - "type": "object", - "required": [ - "app", - "datetime", - "message", - "messageRich", - "messageRichParameters", - "notification_id", - "object_id", - "object_type", - "subject", - "subjectRich", - "user" - ], - "properties": { - "app": { - "type": "string", - "enum": ["userlog"] - }, - "message": { - "type": "string", - "enum": ["Alice Hansen added you to Space notification checking"] - }, - "messageRich": { - "type": "string", - "enum": ["{user} added you to Space {space}"] - }, - "messageRichParameters": { - "type": "object", - "required": [ - "space", - "user" - ], - "properties": { - "space": { - "type": "object", - "required": [ - "id", - "name" - ], - "properties": { - "id": { - "type": "string", - "pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}\\$[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}![a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$" - }, - "name": { - "type": "string", - "enum": ["notification checking"] + """ + { + "type": "object", + "required": [ + "app", + "datetime", + "message", + "messageRich", + "messageRichParameters", + "notification_id", + "object_id", + "object_type", + "subject", + "subjectRich", + "user" + ], + "properties": { + "app": { + "type": "string", + "enum": [ + "userlog" + ] + }, + "message": { + "type": "string", + "enum": [ + "Alice Hansen added you to Space notification checking" + ] + }, + "messageRich": { + "type": "string", + "enum": [ + "{user} added you to Space {space}" + ] + }, + "messageRichParameters": { + "type": "object", + "required": [ + "space", + "user" + ], + "properties": { + "space": { + "type": "object", + "required": [ + "id", + "name" + ], + "properties": { + "id": { + "type": "string", + "pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}\\$[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}![a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$" + }, + "name": { + "type": "string", + "enum": [ + "notification checking" + ] + } } - } - }, - "user": { - "type": "object", - "required": [ - "displayname", - "id", - "name" - ], - "properties": { - "displayname": { - "type": "string", - "enum": ["Alice Hansen"] - }, - "id": { - "type": "string", - "enim": ["%user_id%"] - }, - "name": { - "type": "string", - "enum": ["Alice"] + }, + "user": { + "type": "object", + "required": [ + "displayname", + "id", + "name" + ], + "properties": { + "displayname": { + "type": "string", + "enum": [ + "Alice Hansen" + ] + }, + "id": { + "type": "string", + "enim": [ + "%user_id%" + ] + }, + "name": { + "type": "string", + "enum": [ + "Alice" + ] + } } } } + }, + "notification_id": { + "type": "string" + }, + "object_id": { + "type": "string", + "pattern": "^%space_id_pattern%$" + }, + "object_type": { + "type": "string", + "enum": [ + "storagespace" + ] + }, + "subject": { + "type": "string", + "enum": [ + "Space shared" + ] + }, + "subjectRich": { + "type": "string", + "enum": [ + "Space shared" + ] + }, + "user": { + "type": "string", + "enum": [ + "Alice" + ] } - }, - "notification_id": { - "type": "string" + } + } + """ - }, - "object_id": { - "type": "string" - }, - "object_type": { - "type": "string", - "enum": ["storagespace"] - }, - "subject": { - "type": "string", - "enum": ["Space shared"] - }, - "subjectRich": { - "type": "string", - "enum": ["Space shared"] - }, - "user": { - "type": "string", - "enum": ["Alice"] + Scenario Outline: user gets a notification of space sharing in different languages + Given user "Alice" has created a space "notification checking" with the default quota using the GraphApi + And user "Brian" has switched the system language to "" + And user "Alice" has shared a space "notification checking" with settings: + | shareWith | Brian | + | role | editor | + When user "Brian" 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 + """ + { + "type": "object", + "required": [ + "message" + ], + "properties": { + "message": { + "type": "string", + "enum": [ + "" + ] + } } } - } - """ - + """ + Examples: + | language | subject | message | + | de | Space freigegeben | Alice Hansen hat Sie zu Space notification checking hinzugefügt | + | en | Space shared | Alice Hansen added you to Space notification checking | + | es | Space compartido | Alice Hansen te añadió al Space notification checking | diff --git a/tests/acceptance/features/bootstrap/NotificationContext.php b/tests/acceptance/features/bootstrap/NotificationContext.php index 59af1f7d681..011faa688cf 100644 --- a/tests/acceptance/features/bootstrap/NotificationContext.php +++ b/tests/acceptance/features/bootstrap/NotificationContext.php @@ -22,9 +22,8 @@ */ class NotificationContext implements Context { private FeatureContext $featureContext; - private SpacesContext $spacesContext; - + private SettingsContext $settingsContext; private string $notificationEndpointPath = '/apps/notifications/api/v1/notifications?format=json'; private array $notificationIds; @@ -78,6 +77,7 @@ public function setUpScenario(BeforeScenarioScope $scope):void { // Get all the contexts you need in this context $this->featureContext = $environment->getContext('FeatureContext'); $this->spacesContext = $environment->getContext('SpacesContext'); + $this->settingsContext = $environment->getContext('SettingsContext'); } /** @@ -89,13 +89,17 @@ public function setUpScenario(BeforeScenarioScope $scope):void { */ public function userListAllNotifications(string $user):void { $this->setUserRecipient($user); + $headers = ["accept-language" => $this->settingsContext->getSettingLanguageValue($user)]; $response = OcsApiHelper::sendRequest( $this->featureContext->getBaseUrl(), $this->featureContext->getActualUsername($user), $this->featureContext->getPasswordForUser($user), 'GET', $this->notificationEndpointPath, - $this->featureContext->getStepLineRef() + $this->featureContext->getStepLineRef(), + [], + 2, + $headers ); $this->featureContext->setResponse($response); } diff --git a/tests/acceptance/features/bootstrap/RoleAssignmentContext.php b/tests/acceptance/features/bootstrap/SettingsContext.php similarity index 65% rename from tests/acceptance/features/bootstrap/RoleAssignmentContext.php rename to tests/acceptance/features/bootstrap/SettingsContext.php index fd90c5f56e4..4801eb09bd9 100644 --- a/tests/acceptance/features/bootstrap/RoleAssignmentContext.php +++ b/tests/acceptance/features/bootstrap/SettingsContext.php @@ -1,4 +1,5 @@ featureContext->getJsonDecodedResponse($this->featureContext->getResponse())["assignments"][0]["roleId"]; Assert::assertEquals($this->userGetRoleIdByRoleName($this->featureContext->getAdminUserName(), $role), $assignmentRoleId, "user has no role $role"); } + + /** + * @param string $user + * + * @return void + * + * @throws GuzzleException + * @throws Exception + */ + public function sendRequestGetBundlesList(string $user): void { + $fullUrl = $this->baseUrl . $this->settingsUrl . "bundles-list"; + $this->featureContext->setResponse( + $this->spacesContext->sendPostRequestToUrl($fullUrl, $user, $this->featureContext->getPasswordForUser($user), '{}') + ); + + $this->featureContext->theHTTPStatusCodeShouldBe( + 201, + "Expected response status code should be 201" + ); + } + + /** + * @param string $user + * @param string $bundleName + * + * @return array + * + * @throws GuzzleException + * @throws Exception + */ + public function getBundlesList(string $user, string $bundleName): array { + $this->sendRequestGetBundlesList($user); + $body = json_decode((string)$this->featureContext->getResponse()->getBody(), true, 512, JSON_THROW_ON_ERROR); + foreach ($body["bundles"] as $value) { + if ($value["displayName"] === $bundleName) { + return $value; + } + } + return []; + } + + /** + * @param string $user + * + * @return void + * + * @throws GuzzleException + * @throws Exception + */ + public function sendRequestGetSettingsValuesList(string $user): void { + $fullUrl = $this->baseUrl . $this->settingsUrl . "values-list"; + $body = json_encode(["account_uuid" => "me"], JSON_THROW_ON_ERROR); + $this->featureContext->setResponse( + $this->spacesContext->sendPostRequestToUrl($fullUrl, $user, $this->featureContext->getPasswordForUser($user), $body) + ); + + $this->featureContext->theHTTPStatusCodeShouldBe( + 201, + "Expected response status code should be 201" + ); + } + + /** + * @param string $user + * + * @return string + * + * @throws GuzzleException + * @throws Exception + */ + public function getSettingLanguageValue(string $user): string { + $this->sendRequestGetSettingsValuesList($user); + $body = json_decode((string)$this->featureContext->getResponse()->getBody(), true, 512, JSON_THROW_ON_ERROR); + + // if no language is set, the request body is empty return English as the default language + if (empty($body)) { + return "en"; + } + foreach ($body["values"] as $value) { + if ($value["identifier"]["setting"] === "language") { + return $value["value"]["listValue"]["values"][0]["stringValue"]; + } + } + } + + /** + * @param string $user + * @param string $language + * + * @return void + * + * @throws GuzzleException + * @throws Exception + */ + public function sendRequestToSwitchSystemLanguage(string $user, string $language): void { + $profileBundlesList = $this->getBundlesList($user, "Profile"); + Assert::assertNotEmpty($profileBundlesList, "bundles list is empty"); + + $settingId = ''; + foreach ($profileBundlesList["settings"] as $value) { + if ($value["name"] === "language") { + $settingId = $value["id"]; + break; + } + } + Assert::assertNotEmpty($settingId, "settingId is empty"); + + $fullUrl = $this->baseUrl . $this->settingsUrl . "values-save"; + $userId = $this->featureContext->getAttributeOfCreatedUser($user, 'id'); + $body = json_encode( + [ + "value" => [ + "account_uuid" => "me", + "bundleId" => $profileBundlesList["id"], + "id" => $userId, + "listValue" => [ + "values" => [ + [ + "stringValue" => $language + ] + ] + ], + "resource" => [ + "type" => "TYPE_USER" + ], + "settingId" => $settingId + ] + ], + JSON_THROW_ON_ERROR + ); + + $this->featureContext->setResponse( + $this->spacesContext->sendPostRequestToUrl($fullUrl, $user, $this->featureContext->getPasswordForUser($user), $body) + ); + } + + /** + * @Given /^user "([^"]*)" has switched the system language to "([^"]*)"$/ + * + * @param string $user + * @param string $language + * + * @return void + * + * @throws Exception + */ + public function theUserHasSwitchedSysemLanguage(string $user, string $language): void { + $this->sendRequestToSwitchSystemLanguage($user, $language); + $this->featureContext->theHTTPStatusCodeShouldBe( + 201, + "Expected response status code should be 201" + ); + } }