diff --git a/tests/acceptance/features/apiNotification/emailNotification.feature b/tests/acceptance/features/apiNotification/emailNotification.feature index 139f4530a0d..14864642720 100644 --- a/tests/acceptance/features/apiNotification/emailNotification.feature +++ b/tests/acceptance/features/apiNotification/emailNotification.feature @@ -140,7 +140,7 @@ Feature: Email notification And user "Brian" has switched the system language to "es" And user "Carol" has switched the system language to "de" And user "Alice" has created a space "new-space" with the default quota using the GraphApi - When user "Alice" has shared a space "new-space" with settings: + When user "Alice" shares a space "new-space" with settings: | shareWith | group1 | | role | viewer | Then the HTTP status code should be "200" diff --git a/tests/acceptance/features/apiSpaces/changeSpaces.feature b/tests/acceptance/features/apiSpaces/changeSpaces.feature index ca087a08ede..5992d457eff 100644 --- a/tests/acceptance/features/apiSpaces/changeSpaces.feature +++ b/tests/acceptance/features/apiSpaces/changeSpaces.feature @@ -339,6 +339,7 @@ Feature: Change data of space When user "" uploads a file inside space "Project Jupiter" owned by the user "Alice" with content "new content" to ".space/readme.md" using the WebDAV API Then the HTTP status code should be "" And for user "" the content of the file ".space/readme.md" of the space "Project Jupiter" should be "" + When user "" lists all available spaces via the GraphApi And the JSON response should contain space called "Project Jupiter" owned by "Alice" with description file ".space/readme.md" and match """ { @@ -422,7 +423,7 @@ Feature: Change data of space Given user "Alice" has created a folder ".space" in space "Project Jupiter" And user "Alice" has uploaded a file inside space "Project Jupiter" with content "" to ".space/spaceImage.jpeg" And user "Alice" has set the file ".space/spaceImage.jpeg" as a space image in a special section of the "Project Jupiter" space - When user "" has uploaded a file inside space "Project Jupiter" with content "" to ".space/newSpaceImage.png" + When user "" uploads a file inside space "Project Jupiter" with content "" to ".space/newSpaceImage.png" using the WebDAV API And user "" sets the file ".space/newSpaceImage.png" as a space image in a special section of the "Project Jupiter" space Then the HTTP status code should be "200" And the JSON response should contain space called "Project Jupiter" owned by "Alice" with description file ".space/newSpaceImage.png" and match diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 62fbd95b003..b5eafbe5d05 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -159,16 +159,18 @@ public function getSpaceIdByNameFromResponse(string $name): string { * Get Space Array by name * * @param string $name + * @param ResponseInterface|null $response * * @return array * * @throws Exception */ - public function getSpaceByNameFromResponse(string $name): array { - $response = json_decode((string)$this->featureContext->getResponse()->getBody(), true, 512, JSON_THROW_ON_ERROR); - $spaceAsArray = $response; - if (isset($response['name']) && $response['name'] === $name) { - return $response; + public function getSpaceByNameFromResponse(string $name, ?ResponseInterface $response = null): array { + $response = $response ?? $this->featureContext->getResponse(); + $decodedResponse = $this->featureContext->getJsonDecodedResponse($response); + $spaceAsArray = $decodedResponse; + if (isset($decodedResponse['name']) && $decodedResponse['name'] === $name) { + return $decodedResponse; } if (isset($spaceAsArray["value"])) { foreach ($spaceAsArray["value"] as $spaceCandidate) { @@ -194,9 +196,9 @@ public function getSpaceByName(string $user, string $spaceName): array { $spaceName = $this->featureContext->getUserDisplayName($user); } if (strtolower($user) === 'admin') { - $this->theUserListsAllAvailableSpacesUsingTheGraphApi($user); + $this->listAllAvailableSpaces($user); } else { - $this->theUserListsAllHisAvailableSpacesUsingTheGraphApi($user); + $this->listAllAvailableSpacesOfUser($user); } $spaces = $this->getAvailableSpaces(); Assert::assertArrayHasKey($spaceName, $spaces, "Space with name $spaceName for user $user not found"); @@ -245,7 +247,7 @@ public function setSpaceIDByName(string $user, string $spaceName): void { * @throws GuzzleException */ public function getSpaceByNameManager(string $user, string $spaceName): array { - $this->theUserListsAllAvailableSpacesUsingTheGraphApi($user); + $this->listAllAvailableSpaces($user); $spaces = $this->getAvailableSpaces(); Assert::assertArrayHasKey($spaceName, $spaces, "Space with name '$spaceName' for user '$user' not found"); @@ -425,7 +427,7 @@ public function deleteAllProjectSpaces(): void { $query = "\$filter=driveType eq project"; $userAdmin = $this->featureContext->getAdminUsername(); - $this->theUserListsAllAvailableSpacesUsingTheGraphApi( + $this->listAllAvailableSpaces( $userAdmin, $query ); @@ -501,6 +503,27 @@ public function sendCreateFolderRequest( return HttpRequestHelper::sendRequest($fullUrl, $xRequestId, $method, $user, $password, $headers); } + /** + * @param string $user + * @param string $query + * + * @return ResponseInterface + * + * @throws GuzzleException + * @throws Exception + */ + public function listAllAvailableSpacesOfUser(string $user, string $query = ''): ResponseInterface { + $response = GraphHelper::getMySpaces( + $this->featureContext->getBaseUrl(), + $user, + $this->featureContext->getPasswordForUser($user), + "?" . $query, + $this->featureContext->getStepLineRef() + ); + $this->rememberTheAvailableSpaces($response); + return $response; + } + /** * @When /^user "([^"]*)" lists all available spaces via the GraphApi$/ * @When /^user "([^"]*)" lists all available spaces via the GraphApi with query "([^"]*)"$/ @@ -514,21 +537,33 @@ public function sendCreateFolderRequest( * @throws Exception */ public function theUserListsAllHisAvailableSpacesUsingTheGraphApi(string $user, string $query = ''): void { - $this->featureContext->setResponse( - GraphHelper::getMySpaces( - $this->featureContext->getBaseUrl(), - $user, - $this->featureContext->getPasswordForUser($user), - "?" . $query, - $this->featureContext->getStepLineRef() - ) - ); - $this->rememberTheAvailableSpaces(); + $this->featureContext->setResponse($this->listAllAvailableSpacesOfUser($user, $query)); } /** * The method is used on the administration setting tab, which only the Admin user and the Space admin user have access to * + * @param string $user + * @param string $query + * + * @return ResponseInterface + * + * @throws GuzzleException + * @throws Exception + */ + public function listAllAvailableSpaces(string $user, string $query = ''): ResponseInterface { + $response = GraphHelper::getAllSpaces( + $this->featureContext->getBaseUrl(), + $user, + $this->featureContext->getPasswordForUser($user), + "?" . $query, + $this->featureContext->getStepLineRef() + ); + $this->rememberTheAvailableSpaces($response); + return $response; + } + + /** * @When /^user "([^"]*)" lists all spaces via the GraphApi$/ * @When /^user "([^"]*)" lists all spaces via the GraphApi with query "([^"]*)"$/ * @When /^user "([^"]*)" tries to list all spaces via the GraphApi$/ @@ -543,15 +578,8 @@ public function theUserListsAllHisAvailableSpacesUsingTheGraphApi(string $user, */ public function theUserListsAllAvailableSpacesUsingTheGraphApi(string $user, string $query = ''): void { $this->featureContext->setResponse( - GraphHelper::getAllSpaces( - $this->featureContext->getBaseUrl(), - $user, - $this->featureContext->getPasswordForUser($user), - "?" . $query, - $this->featureContext->getStepLineRef() - ) + $this->listAllAvailableSpaces($user, $query) ); - $this->rememberTheAvailableSpaces(); } /** @@ -872,7 +900,6 @@ public function theJsonDataFromLastResponseShouldMatch( null, $userName, ); - $this->featureContext->assertJsonDocumentMatchesSchema( $responseBody, $this->featureContext->getJSONSchema($schemaString) @@ -896,12 +923,13 @@ public function checkPermissionsInResponse( string $grantedUser, string $role ): void { - $this->theUserListsAllHisAvailableSpacesUsingTheGraphApi($user); + $response = $this->listAllAvailableSpacesOfUser($user); $this->featureContext->theHTTPStatusCodeShouldBe( 200, - "Expected response status code should be 200" + "Expected response status code should be 200", + $response ); - Assert::assertIsArray($spaceAsArray = $this->getSpaceByNameFromResponse($spaceName), "No space with name $spaceName found"); + Assert::assertIsArray($spaceAsArray = $this->getSpaceByNameFromResponse($spaceName, $response), "No space with name $spaceName found"); $permissions = $spaceAsArray["root"]["permissions"]; $userId = $this->featureContext->getUserIdByUserName($grantedUser); @@ -945,15 +973,16 @@ public function userShouldNotHaveSpace( string $shouldOrNot, string $spaceName ): void { - $this->theUserListsAllHisAvailableSpacesUsingTheGraphApi($user); + $response = $this->listAllAvailableSpacesOfUser($user); $this->featureContext->theHTTPStatusCodeShouldBe( 200, - "Expected response status code should be 200" + "Expected response status code should be 200", + $response ); if (\trim($shouldOrNot) === "not") { - $this->jsonRespondedShouldNotContain($spaceName); + Assert::assertEmpty($this->getSpaceByNameFromResponse($spaceName, $response), "space $spaceName should not be available for a user"); } else { - Assert::assertNotEmpty($this->getSpaceByNameFromResponse($spaceName), "space '$spaceName' should be available for a user '$user' but not found"); + Assert::assertNotEmpty($this->getSpaceByNameFromResponse($spaceName, $response), "space '$spaceName' should be available for a user '$user' but not found"); } } @@ -970,14 +999,15 @@ public function theUserShouldHaveASpaceInTheDisableState( string $user, string $spaceName ): void { - $this->theUserListsAllHisAvailableSpacesUsingTheGraphApi($user); + $response = $this->listAllAvailableSpacesOfUser($user); $this->featureContext->theHTTPStatusCodeShouldBe( 200, - "Expected response status code should be 200" + "Expected response status code should be 200", + $response ); - $response = json_decode((string)$this->featureContext->getResponse()->getBody(), true, 512, JSON_THROW_ON_ERROR); - if (isset($response["value"])) { - foreach ($response["value"] as $spaceCandidate) { + $decodedResponse = $this->featureContext->getJsonDecodedResponse($response); + if (isset($decodedResponse["value"])) { + foreach ($decodedResponse["value"] as $spaceCandidate) { if ($spaceCandidate['name'] === $spaceName) { if ($spaceCandidate['root']['deleted']['state'] !== 'trashed') { throw new \Exception( @@ -1355,10 +1385,12 @@ public function userHasChangedDescription( string $spaceName, string $newDescription ): void { - $this->updateSpaceDescription($user, $spaceName, $newDescription); + $bodyData = ["description" => $newDescription]; + $response = $this->updateSpace($user, $spaceName, $bodyData, ''); $this->featureContext->theHTTPStatusCodeShouldBe( 200, - "Expected response status code should be 200" + "Expected response status code should be 200", + $response ); } @@ -1402,22 +1434,22 @@ public function userHasChangedTheQuotaOfTheSpaceTo( string $spaceName, int $newQuota ): void { - $this->updateSpaceQuota($user, $spaceName, $newQuota); + $bodyData = ["quota" => ["total" => $newQuota]]; + $response = $this->updateSpace($user, $spaceName, $bodyData, ''); $this->featureContext->theHTTPStatusCodeShouldBe( 200, - "Expected response status code should be 200" + "Expected response status code should be 200", + $response ); } /** - * @When /^user "([^"]*)" sets the file "([^"]*)" as a (description|space image)\s? in a special section of the "([^"]*)" space$/ - * * @param string $user * @param string $file * @param string $type * @param string $spaceName * - * @return void + * @return ResponseInterface * @throws GuzzleException * @throws Exception */ @@ -1426,7 +1458,7 @@ public function updateSpaceSpecialSection( string $file, string $type, string $spaceName - ): void { + ): ResponseInterface { $space = $this->getSpaceByName($user, $spaceName); $spaceId = $space["id"]; $fileId = $this->getFileId($user, $spaceName, $file); @@ -1439,15 +1471,40 @@ public function updateSpaceSpecialSection( $bodyData = ["special" => [["specialFolder" => ["name" => "$type"], "id" => "$fileId"]]]; $body = json_encode($bodyData, JSON_THROW_ON_ERROR); + return GraphHelper::updateSpace( + $this->featureContext->getBaseUrl(), + $user, + $this->featureContext->getPasswordForUser($user), + $body, + $spaceId, + $this->featureContext->getStepLineRef() + ); + } + /** + * @When /^user "([^"]*)" sets the file "([^"]*)" as a (description|space image)\s? in a special section of the "([^"]*)" space$/ + * + * @param string $user + * @param string $file + * @param string $type + * @param string $spaceName + * + * @return void + * @throws GuzzleException + * @throws Exception + */ + public function userSetsFileAsDescriptionOrImageInSpecialSectionOfSpace( + string $user, + string $file, + string $type, + string $spaceName + ): void { $this->featureContext->setResponse( - GraphHelper::updateSpace( - $this->featureContext->getBaseUrl(), + $this->updateSpaceSpecialSection( $user, - $this->featureContext->getPasswordForUser($user), - $body, - $spaceId, - $this->featureContext->getStepLineRef() + $file, + $type, + $spaceName ) ); } @@ -1470,10 +1527,11 @@ public function userHasUpdatedSpaceSpecialSection( string $type, string $spaceName ): void { - $this->updateSpaceSpecialSection($user, $file, $type, $spaceName); + $response = $this->updateSpaceSpecialSection($user, $file, $type, $spaceName); $this->featureContext->theHTTPStatusCodeShouldBe( 200, - "Expected response status code should be 200" + "Expected response status code should be 200", + $response ); } @@ -1495,11 +1553,12 @@ public function userHasCreatedSpace( int $quota ): void { $space = ["Name" => $spaceName, "driveType" => $spaceType, "quota" => ["total" => $quota]]; - $this->featureContext->setResponse($this->createSpace($user, $space)); + $response = $this->createSpace($user, $space); $this->setSpaceCreator($spaceName, $user); $this->featureContext->theHTTPStatusCodeShouldBe( 201, - "Expected response status code should be 201 (Created)" + "Expected response status code should be 201 (Created)", + $response ); } @@ -1519,11 +1578,12 @@ public function theUserHasCreatedASpaceByDefaultUsingTheGraphApi( string $spaceName ): void { $space = ["Name" => $spaceName]; - $this->featureContext->setResponse($this->createSpace($user, $space)); + $response = $this->createSpace($user, $space); $this->setSpaceCreator($spaceName, $user); $this->featureContext->theHTTPStatusCodeShouldBe( 201, - "Expected response status code should be 201 (Created)" + "Expected response status code should be 201 (Created)", + $response ); } @@ -1578,22 +1638,20 @@ public function userCopiesFileWithinSpaceUsingTheWebDAVAPI( } /** - * @When /^user "([^"]*)" moves (?:file|folder) "([^"]*)" to "([^"]*)" in space "([^"]*)" using the WebDAV API$/ - * * @param string $user * @param string $fileSource * @param string $fileDestination * @param string $spaceName * - * @return void + * @return ResponseInterface * @throws GuzzleException */ - public function userMovesFileWithinSpaceUsingTheWebDAVAPI( + public function moveFileWithinSpace( string $user, string $fileSource, string $fileDestination, string $spaceName - ):void { + ):ResponseInterface { $space = $this->getSpaceByName($user, $spaceName); $headers['Destination'] = $this->destinationHeaderValueWithSpaceName( $user, @@ -1604,7 +1662,27 @@ public function userMovesFileWithinSpaceUsingTheWebDAVAPI( $fileSource = $this->escapePath(\trim($fileSource, "/")); $fullUrl = $space["root"]["webDavUrl"] . '/' . $fileSource; - $this->featureContext->setResponse($this->moveFilesAndFoldersRequest($user, $fullUrl, $headers)); + return $this->moveFilesAndFoldersRequest($user, $fullUrl, $headers); + } + + /** + * @When /^user "([^"]*)" moves (?:file|folder) "([^"]*)" to "([^"]*)" in space "([^"]*)" using the WebDAV API$/ + * + * @param string $user + * @param string $fileSource + * @param string $fileDestination + * @param string $spaceName + * + * @return void + * @throws GuzzleException + */ + public function userMovesFileWithinSpaceUsingTheWebDAVAPI( + string $user, + string $fileSource, + string $fileDestination, + string $spaceName + ):void { + $this->featureContext->setResponse($this->moveFileWithinSpace($user, $fileSource, $fileDestination, $spaceName)); $this->featureContext->pushToLastHttpStatusCodesArray(); } @@ -1625,7 +1703,7 @@ public function userHasMovedFileWithinSpaceUsingTheWebDAVAPI( string $fileDestination, string $spaceName ):void { - $this->userMovesFileWithinSpaceUsingTheWebDAVAPI( + $response = $this->moveFileWithinSpace( $user, $fileSource, $fileDestination, @@ -1634,8 +1712,9 @@ public function userHasMovedFileWithinSpaceUsingTheWebDAVAPI( $this->featureContext->theHTTPStatusCodeShouldBe( 201, __METHOD__ . "Expected response status code should be 201 (Created)\n" . - "Actual response status code was: " . $this->featureContext->getResponse()->getStatusCode() . "\n" . - "Actual response body was: " . $this->featureContext->getResponse()->getBody() + "Actual response status code was: " . $response->getStatusCode() . "\n" . + "Actual response body was: " . $response->getBody(), + $response ); } @@ -1868,7 +1947,8 @@ public function userHasUploadedFile( string $fileContent, string $destination ): array { - $this->theUserListsAllHisAvailableSpacesUsingTheGraphApi($user); + $response = $this->listAllAvailableSpacesOfUser($user); + $this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response); $this->setSpaceIDByName($user, $spaceName); $response = $this->featureContext->uploadFileWithContent($user, $fileContent, $destination, true); $this->featureContext->theHTTPStatusCodeShouldBe(['201', '204'], "", $response); @@ -1953,20 +2033,18 @@ public function userExpiresTheShareOfSpaceForUser(string $user, string $shareTyp } /** - * @When /^user "([^"]*)" creates a share inside of space "([^"]*)" with settings:$/ - * * @param string $user * @param string $spaceName * @param TableNode $table * - * @return void + * @return ResponseInterface * @throws GuzzleException */ public function createShareResource( string $user, string $spaceName, TableNode $table - ): void { + ): ResponseInterface { $rows = $table->getRowsHash(); $rows["path"] = \array_key_exists("path", $rows) ? $rows["path"] : null; $rows["shareType"] = \array_key_exists("shareType", $rows) ? $rows["shareType"] : 0; @@ -1982,17 +2060,36 @@ public function createShareResource( ]; $fullUrl = $this->baseUrl . $this->ocsApiUrl; + $response = $this->sendPostRequestToUrl( + $fullUrl, + $user, + $this->featureContext->getPasswordForUser($user), + $body, + $this->featureContext->getStepLineRef() + ); + $responseXml = $this->featureContext->getResponseXml($response, __METHOD__); + $this->featureContext->addToCreatedPublicShares($responseXml->data); + return $response; + } + + /** + * @When /^user "([^"]*)" creates a share inside of space "([^"]*)" with settings:$/ + * + * @param string $user + * @param string $spaceName + * @param TableNode $table + * + * @return void + * @throws GuzzleException + */ + public function userCreatesShareInsideOfSpaceWithSettings( + string $user, + string $spaceName, + TableNode $table + ): void { $this->featureContext->setResponse( - $this->sendPostRequestToUrl( - $fullUrl, - $user, - $this->featureContext->getPasswordForUser($user), - $body, - $this->featureContext->getStepLineRef() - ) + $this->createShareResource($user, $spaceName, $table) ); - $response = $this->featureContext->getResponseXml(null, __METHOD__); - $this->featureContext->addToCreatedPublicShares($response->data); } /** @@ -2005,17 +2102,13 @@ public function createShareResource( * @return void * @throws GuzzleException */ - public function hasSharedTheFollowingEntityInsideOfSpace( + public function userHasSharedTheFollowingEntityInsideOfSpace( string $user, string $spaceName, TableNode $table ): void { - $this->createShareResource($user, $spaceName, $table); - Assert::assertEquals( - $this->featureContext->getResponse()->getStatusCode(), - 200, - "Expected response status code should be 200" - ); + $response = $this->createShareResource($user, $spaceName, $table); + $this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response); } /** @@ -2070,21 +2163,20 @@ public function userExpiresLastResourceShare(string $user): void { $rows['expireDate'] = $dateTime->format('Y-m-d\\TH:i:sP'); $this->featureContext->setResponse($this->updateSharedResource($user, $rows)); } + /** - * @When /^user "([^"]*)" creates a public link share inside of space "([^"]*)" with settings:$/ - * * @param string $user * @param string $spaceName * @param TableNode $table * - * @return void + * @return ResponseInterface * @throws GuzzleException */ public function createPublicLinkToEntityInsideOfSpaceRequest( string $user, string $spaceName, TableNode $table - ): void { + ): ResponseInterface { $space = $this->getSpaceByName($user, $spaceName); $rows = $table->getRowsHash(); @@ -2106,18 +2198,37 @@ public function createPublicLinkToEntityInsideOfSpaceRequest( $fullUrl = $this->baseUrl . $this->ocsApiUrl; - $this->featureContext->setResponse( - $this->sendPostRequestToUrl( - $fullUrl, - $user, - $this->featureContext->getPasswordForUser($user), - $body, - $this->featureContext->getStepLineRef() - ) + $response = $this->sendPostRequestToUrl( + $fullUrl, + $user, + $this->featureContext->getPasswordForUser($user), + $body, + $this->featureContext->getStepLineRef() ); - $response = $this->featureContext->getResponseXml(null, __METHOD__); - $this->featureContext->addToCreatedPublicShares($response->data); + $responseXml = $this->featureContext->getResponseXml($response, __METHOD__); + $this->featureContext->addToCreatedPublicShares($responseXml->data); + return $response; + } + + /** + * @When /^user "([^"]*)" creates a public link share inside of space "([^"]*)" with settings:$/ + * + * @param string $user + * @param string $spaceName + * @param TableNode $table + * + * @return void + * @throws GuzzleException + */ + public function userCreatesPublicLinkShareInsideOfSpaceWithSettings( + string $user, + string $spaceName, + TableNode $table + ): void { + $this->featureContext->setResponse( + $this->createPublicLinkToEntityInsideOfSpaceRequest($user, $spaceName, $table) + ); } /** @@ -2135,12 +2246,12 @@ public function userHasCreatedPublicLinkToEntityInsideOfSpaceRequest( string $spaceName, TableNode $table ): void { - $this->createPublicLinkToEntityInsideOfSpaceRequest($user, $spaceName, $table); + $response = $this->createPublicLinkToEntityInsideOfSpaceRequest($user, $spaceName, $table); - $expectedHTTPStatus = "200"; $this->featureContext->theHTTPStatusCodeShouldBe( - $expectedHTTPStatus, - "Expected response status code should be $expectedHTTPStatus" + 200, + "Expected response status code should be 200", + $response ); } @@ -2159,14 +2270,16 @@ public function userHasSharedSpace( string $spaceName, TableNode $tableNode ): void { - $this->sendShareSpaceRequest($user, $spaceName, $tableNode); + $rows = $tableNode->getRowsHash(); + $response = $this->shareSpace($user, $spaceName, $rows); $expectedHTTPStatus = "200"; $this->featureContext->theHTTPStatusCodeShouldBe( $expectedHTTPStatus, - "Expected response status code should be $expectedHTTPStatus" + "Expected response status code should be $expectedHTTPStatus", + $response ); $expectedOCSStatus = "200"; - $this->ocsContext->theOCSStatusCodeShouldBe($expectedOCSStatus, "Expected OCS response status code $expectedOCSStatus"); + $this->ocsContext->theOCSStatusCodeShouldBe($expectedOCSStatus, "Expected OCS response status code $expectedOCSStatus", $response); } /** @@ -2184,38 +2297,78 @@ public function userHasUnsharedASpaceSharedWith( string $spaceName, string $recipient ): void { - $this->sendUnshareSpaceRequest($user, $spaceName, $recipient); + $response = $this->sendUnshareSpaceRequest($user, $spaceName, $recipient); $this->featureContext->theHTTPStatusCodeShouldBe( 200, - "Expected response status code should be 200" + "Expected response status code should be 200", + $response ); } /** - * @When /^user "([^"]*)" unshares a space "([^"]*)" to (?:user|group) "([^"]*)"$/ - * * @param string $user * @param string $spaceName * @param string $recipient * - * @return void + * @return ResponseInterface * @throws GuzzleException */ public function sendUnshareSpaceRequest( string $user, string $spaceName, string $recipient - ): void { + ): ResponseInterface { $space = $this->getSpaceByName($user, $spaceName); $fullUrl = $this->baseUrl . $this->ocsApiUrl . "/" . $space['id'] . "?shareWith=" . $recipient; + return HttpRequestHelper::delete( + $fullUrl, + $this->featureContext->getStepLineRef(), + $user, + $this->featureContext->getPasswordForUser($user) + ); + } + + /** + * @When /^user "([^"]*)" unshares a space "([^"]*)" to (?:user|group) "([^"]*)"$/ + * + * @param string $user + * @param string $spaceName + * @param string $recipient + * + * @return void + * @throws GuzzleException + */ + public function userUnsharesSpace( + string $user, + string $spaceName, + string $recipient + ): void { $this->featureContext->setResponse( - HttpRequestHelper::delete( - $fullUrl, - $this->featureContext->getStepLineRef(), - $user, - $this->featureContext->getPasswordForUser($user) - ) + $this->sendUnshareSpaceRequest($user, $spaceName, $recipient) + ); + } + + /** + * @param string $user + * @param string $object + * @param string $spaceName + * + * @return ResponseInterface + * @throws GuzzleException + */ + public function removeObjectFromSpace( + string $user, + string $object, + string $spaceName + ): ResponseInterface { + $space = $this->getSpaceByName($user, $spaceName); + $spaceWebDavUrl = $space["root"]["webDavUrl"] . '/' . ltrim($object, "/"); + return HttpRequestHelper::delete( + $spaceWebDavUrl, + $this->featureContext->getStepLineRef(), + $user, + $this->featureContext->getPasswordForUser($user) ); } @@ -2229,20 +2382,13 @@ public function sendUnshareSpaceRequest( * @return void * @throws GuzzleException */ - public function sendRemoveObjectFromSpaceRequest( + public function userRemovesFileOrFolderFromSpace( string $user, string $object, string $spaceName ): void { - $space = $this->getSpaceByName($user, $spaceName); - $spaceWebDavUrl = $space["root"]["webDavUrl"] . '/' . ltrim($object, "/"); $this->featureContext->setResponse( - HttpRequestHelper::delete( - $spaceWebDavUrl, - $this->featureContext->getStepLineRef(), - $user, - $this->featureContext->getPasswordForUser($user) - ) + $this->removeObjectFromSpace($user, $object, $spaceName) ); } @@ -2259,10 +2405,34 @@ public function userHasDeletedASpaceOwnedByUser( string $user, string $spaceName ):void { - $this->sendDeleteSpaceRequest($user, $spaceName); + $response = $this->deleteSpace($user, $spaceName); $this->featureContext->theHTTPStatusCodeShouldBe( 204, - "Expected response status code should be 200" + "Expected response status code should be 200", + $response + ); + } + + /** + * @param string $user + * @param string $spaceName + * @param string $owner + * + * @return ResponseInterface + * @throws GuzzleException + */ + public function disableSpace( + string $user, + string $spaceName, + string $owner = '' + ): ResponseInterface { + $space = $this->getSpaceByName(($owner !== "") ? $owner : $user, $spaceName); + return GraphHelper::disableSpace( + $this->featureContext->getBaseUrl(), + $user, + $this->featureContext->getPasswordForUser($user), + $space["id"], + $this->featureContext->getStepLineRef() ); } @@ -2277,20 +2447,13 @@ public function userHasDeletedASpaceOwnedByUser( * @return void * @throws GuzzleException */ - public function sendDisableSpaceRequest( + public function userDisablesSpace( string $user, string $spaceName, string $owner = '' ): void { - $space = $this->getSpaceByName(($owner !== "") ? $owner : $user, $spaceName); $this->featureContext->setResponse( - GraphHelper::disableSpace( - $this->featureContext->getBaseUrl(), - $user, - $this->featureContext->getPasswordForUser($user), - $space["id"], - $this->featureContext->getStepLineRef() - ) + $this->disableSpace($user, $spaceName, $owner) ); } @@ -2304,16 +2467,17 @@ public function sendDisableSpaceRequest( * @return void * @throws GuzzleException */ - public function sendUserHasRemovedObjectFromSpaceRequest( + public function userHasRemovedFileOrFolderFromSpace( string $user, string $object, string $spaceName ): void { - $this->sendRemoveObjectFromSpaceRequest($user, $object, $spaceName); + $response = $this->removeObjectFromSpace($user, $object, $spaceName); $expectedHTTPStatus = "204"; $this->featureContext->theHTTPStatusCodeShouldBe( $expectedHTTPStatus, - "Expected response status code should be $expectedHTTPStatus" + "Expected response status code should be $expectedHTTPStatus", + $response ); } @@ -2330,11 +2494,36 @@ public function sendUserHasDisabledSpaceRequest( string $user, string $spaceName ): void { - $this->sendDisableSpaceRequest($user, $spaceName); + $response = $this->disableSpace($user, $spaceName); $expectedHTTPStatus = "204"; $this->featureContext->theHTTPStatusCodeShouldBe( $expectedHTTPStatus, - "Expected response status code should be $expectedHTTPStatus" + "Expected response status code should be $expectedHTTPStatus", + $response + ); + } + + /** + * @param string $user + * @param string $spaceName + * @param string $owner + * + * @return ResponseInterface + * @throws GuzzleException + */ + public function deleteSpace( + string $user, + string $spaceName, + string $owner = '' + ): ResponseInterface { + $space = $this->getSpaceByName(($owner !== "") ? $owner : $user, $spaceName); + + return GraphHelper::deleteSpace( + $this->featureContext->getBaseUrl(), + $user, + $this->featureContext->getPasswordForUser($user), + $space["id"], + $this->featureContext->getStepLineRef() ); } @@ -2349,21 +2538,36 @@ public function sendUserHasDisabledSpaceRequest( * @return void * @throws GuzzleException */ - public function sendDeleteSpaceRequest( + public function userDeletesSpace( string $user, string $spaceName, string $owner = '' ): void { - $space = $this->getSpaceByName(($owner !== "") ? $owner : $user, $spaceName); - $this->featureContext->setResponse( - GraphHelper::deleteSpace( - $this->featureContext->getBaseUrl(), - $user, - $this->featureContext->getPasswordForUser($user), - $space["id"], - $this->featureContext->getStepLineRef() - ) + $this->deleteSpace($user, $spaceName, $owner) + ); + } + + /** + * @param string $user + * @param string $spaceName + * @param string $owner + * + * @return ResponseInterface + * @throws GuzzleException + */ + public function restoreSpace( + string $user, + string $spaceName, + string $owner = '' + ): ResponseInterface { + $space = $this->getSpaceByName(($owner !== "") ? $owner : $user, $spaceName); + return GraphHelper::restoreSpace( + $this->featureContext->getBaseUrl(), + $user, + $this->featureContext->getPasswordForUser($user), + $space["id"], + $this->featureContext->getStepLineRef() ); } @@ -2378,20 +2582,13 @@ public function sendDeleteSpaceRequest( * @return void * @throws GuzzleException */ - public function sendRestoreSpaceRequest( + public function userRestoresADisabledSpace( string $user, string $spaceName, string $owner = '' ): void { - $space = $this->getSpaceByName(($owner !== "") ? $owner : $user, $spaceName); $this->featureContext->setResponse( - GraphHelper::restoreSpace( - $this->featureContext->getBaseUrl(), - $user, - $this->featureContext->getPasswordForUser($user), - $space["id"], - $this->featureContext->getStepLineRef() - ) + $this->restoreSpace($user, $spaceName, $owner) ); } @@ -2408,11 +2605,34 @@ public function userHasRestoredSpaceRequest( string $user, string $spaceName ): void { - $this->sendRestoreSpaceRequest($user, $spaceName); + $response = $this->restoreSpace($user, $spaceName); $expectedHTTPStatus = "200"; $this->featureContext->theHTTPStatusCodeShouldBe( $expectedHTTPStatus, - "Expected response status code should be $expectedHTTPStatus" + "Expected response status code should be $expectedHTTPStatus", + $response + ); + } + + /** + * @param string $user + * @param string $spaceName + * + * @return ResponseInterface + * @throws GuzzleException + */ + public function listAllDeletedFilesFromTrash( + string $user, + string $spaceName + ): ResponseInterface { + $space = $this->getSpaceByName($user, $spaceName); + $fullUrl = $this->baseUrl . $this->davSpacesUrl . "trash-bin/" . $space["id"]; + return HttpRequestHelper::sendRequest( + $fullUrl, + $this->featureContext->getStepLineRef(), + 'PROPFIND', + $user, + $this->featureContext->getPasswordForUser($user) ); } @@ -2429,10 +2649,8 @@ public function userListAllDeletedFilesInTrash( string $user, string $spaceName ): void { - $space = $this->getSpaceByName($user, $spaceName); - $fullUrl = $this->baseUrl . $this->davSpacesUrl . "trash-bin/" . $space["id"]; $this->featureContext->setResponse( - HttpRequestHelper::sendRequest($fullUrl, $this->featureContext->getStepLineRef(), 'PROPFIND', $user, $this->featureContext->getPasswordForUser($user)) + $this->listAllDeletedFilesFromTrash($user, $spaceName) ); } @@ -2479,13 +2697,14 @@ public function getObjectsInTrashbin( string $user, string $spaceName ): array { - $this->userListAllDeletedFilesInTrash($user, $spaceName); + $response = $this->listAllDeletedFilesFromTrash($user, $spaceName); $this->featureContext->theHTTPStatusCodeShouldBe( 207, - "Expected response status code should be 207" + "Expected response status code should be 207", + $response ); return $this->trashbinContext->getTrashbinContentFromResponseXml( - $this->featureContext->getResponseXml($this->featureContext->getResponse()) + $this->featureContext->getResponseXml($response) ); } @@ -2910,20 +3129,18 @@ public function userHasStoredEtagOfElementOnPathFromSpace(string $user, string $ } /** - * @When /^user "([^"]*)" creates a public link share of the space "([^"]*)" with settings:$/ - * * @param string $user * @param string $spaceName * @param TableNode|null $table * - * @return void + * @return ResponseInterface * @throws GuzzleException */ public function sendShareSpaceViaLinkRequest( string $user, string $spaceName, ?TableNode $table - ): void { + ): ResponseInterface { $space = $this->getSpaceByName($user, $spaceName); $rows = $table->getRowsHash(); @@ -2944,18 +3161,41 @@ public function sendShareSpaceViaLinkRequest( $fullUrl = $this->baseUrl . $this->ocsApiUrl; + $response = $this->sendPostRequestToUrl( + $fullUrl, + $user, + $this->featureContext->getPasswordForUser($user), + $body, + $this->featureContext->getStepLineRef() + ); + + $responseXml = $this->featureContext->getResponseXml($response, __METHOD__); + $this->featureContext->addToCreatedPublicShares($responseXml->data); + return $response; + } + + /** + * @When /^user "([^"]*)" creates a public link share of the space "([^"]*)" with settings:$/ + * + * @param string $user + * @param string $spaceName + * @param TableNode|null $table + * + * @return void + * @throws GuzzleException + */ + public function userCreatesAPublicLinkShareOfSpaceWithSettings( + string $user, + string $spaceName, + ?TableNode $table + ): void { $this->featureContext->setResponse( - $this->sendPostRequestToUrl( - $fullUrl, + $this->sendShareSpaceViaLinkRequest( $user, - $this->featureContext->getPasswordForUser($user), - $body, - $this->featureContext->getStepLineRef() + $spaceName, + $table ) ); - - $response = $this->featureContext->getResponseXml(null, __METHOD__); - $this->featureContext->addToCreatedPublicShares($response->data); } /** @@ -2973,12 +3213,13 @@ public function userHasCreatedPublicLinkShareOfSpace( string $spaceName, ?TableNode $table ): void { - $this->sendShareSpaceViaLinkRequest($user, $spaceName, $table); + $response = $this->sendShareSpaceViaLinkRequest($user, $spaceName, $table); $expectedHTTPStatus = "200"; $this->featureContext->theHTTPStatusCodeShouldBe( $expectedHTTPStatus, - "Expected response status code should be $expectedHTTPStatus" + "Expected response status code should be $expectedHTTPStatus", + $response ); } @@ -3374,12 +3615,13 @@ public function theUserShouldHaveSpaceWithRecipient( string $role, string $expirationDate = null ): void { - $this->theUserListsAllHisAvailableSpacesUsingTheGraphApi($user); + $response = $this->listAllAvailableSpacesOfUser($user); $this->featureContext->theHTTPStatusCodeShouldBe( 200, - "Expected response status code should be 200" + "Expected response status code should be 200", + $response ); - Assert::assertIsArray($spaceAsArray = $this->getSpaceByNameFromResponse($spaceName), "No space with name $spaceName found"); + Assert::assertIsArray($spaceAsArray = $this->getSpaceByNameFromResponse($spaceName, $response), "No space with name $spaceName found"); $recipientType === 'user' ? $recipientId = $this->featureContext->getUserIdByUserName($recipient) : $recipientId = $this->featureContext->getGroupIdByGroupName($recipient); $foundRoleInResponse = false; foreach ($spaceAsArray['root']['permissions'] as $permission) {