From 67ac275ace8c7bf7eb0b9738c20adef6dc87a360 Mon Sep 17 00:00:00 2001 From: Viktor Scharf Date: Thu, 9 Feb 2023 16:58:39 +0100 Subject: [PATCH] [test-only] Fix failed test (#5541) * fix failed test * another way fixing --- .../apiSpacesShares/shareSpaces.feature | 16 +++----- .../features/bootstrap/SpacesContext.php | 40 +++++++++++++++++++ 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/tests/acceptance/features/apiSpacesShares/shareSpaces.feature b/tests/acceptance/features/apiSpacesShares/shareSpaces.feature index 3e838818d3..a52c7727e4 100644 --- a/tests/acceptance/features/apiSpacesShares/shareSpaces.feature +++ b/tests/acceptance/features/apiSpacesShares/shareSpaces.feature @@ -35,11 +35,8 @@ Feature: Share spaces Scenario: A user can see who has been granted access - Given user "Alice" has shared a space "share space" to user "Brian" with role "viewer" - And the user "Alice" should have a space called "share space" granted to "Brian" with these key and value pairs: - | key | value | - | root@@@permissions@@@1@@@grantedToIdentities@@@0@@@user@@@id | %user_id% | - | root@@@permissions@@@1@@@roles@@@0 | viewer | + When user "Alice" shares a space "share space" to user "Brian" with role "viewer" + Then the user "Alice" should have a space called "share space" granted to user "Brian" with role "viewer" Scenario: A user can see that the group has been granted access @@ -47,12 +44,9 @@ Feature: Share spaces When user "Alice" shares a space "share space" to group "sales" with role "viewer" Then the HTTP status code should be "200" And the OCS status code should be "200" - And the user "Alice" should have a space called "share space" granted to group "sales" with these key and value pairs: - | key | value | - | root@@@permissions@@@1@@@grantedToIdentities@@@0@@@group@@@id | %group_id% | - | root@@@permissions@@@1@@@roles@@@0 | viewer | - - + And the user "Alice" should have a space called "share space" granted to group "sales" with role "viewer" + + Scenario: A user can see a file in a received shared space Given user "Alice" has uploaded a file inside space "share space" with content "Test" to "test.txt" And user "Alice" has created a folder "Folder Main" in space "share space" diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 938b3f7616..072ad928a4 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -3249,4 +3249,44 @@ class SpacesContext implements Context { ); } } + + /** + * @Then /^the user "([^"]*)" should have a space called "([^"]*)" granted to (user|group)\s? "([^"]*)" with role "([^"]*)"$/ + * + * @param string $user + * @param string $spaceName + * @param string $recipientType + * @param string $recipient + * @param string $role + * + * @return void + * + * @throws GuzzleException + * @throws Exception + */ + public function theUserShouldHaveSpaceWithRecipient( + string $user, + string $spaceName, + string $recipientType, + string $recipient, + string $role + ): void { + $this->theUserListsAllHisAvailableSpacesUsingTheGraphApi($user); + $this->featureContext->theHTTPStatusCodeShouldBe( + 200, + "Expected response status code should be 200" + ); + Assert::assertIsArray($spaceAsArray = $this->getSpaceByNameFromResponse($spaceName), "No space with name $spaceName found"); + $recipientType === 'user' ? $recipientId = $this->getUserIdByUserName($recipient) : $recipientId = $this->getGroupIdByGroupName($recipient); + + $recipientId = $this->getUserIdByUserName($user); + foreach ($spaceAsArray['root']['permissions'] as $permission) { + $foundRoleInResponse = false; + if ($permission['roles'][0] === $role || $permission['grantedToIdentities'][0][$recipientType]['id'] === $recipientId) { + $foundRoleInResponse = true; + break; + } + Assert::assertTrue($foundRoleInResponse, "the response does not contain the $recipientType $recipient"); + } + } }