diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index df291e845f1..d41e53b2e15 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -217,8 +217,10 @@ public function getSpaceByNameFromResponse(string $name): array { * @throws GuzzleException */ public function getSpaceByName(string $user, string $spaceName): array { + if ($spaceName === "Personal") { + $spaceName = $this->featureContext->getUserDisplayName($user); + } $this->theUserListsAllHisAvailableSpacesUsingTheGraphApi($user); - $spaces = $this->getAvailableSpaces(); Assert::assertIsArray($spaces[$spaceName], "Space with name $spaceName for user $user not found"); Assert::assertNotEmpty($spaces[$spaceName]["root"]["webDavUrl"], "WebDavUrl for space with name $spaceName for user $user not found"); @@ -804,13 +806,14 @@ public function theUserListsTheContentOfAPersonalSpaceRootUsingTheWebDAvApi( Assert::assertIsArray($space); Assert::assertNotEmpty($spaceId = $space["id"]); Assert::assertNotEmpty($spaceWebDavUrl = $space["root"]["webDavUrl"]); + $headers['Depth'] = 'infinity'; $this->featureContext->setResponse( $this->sendPropfindRequestToUrl( $spaceWebDavUrl . '/' . $foldersPath, $user, $this->featureContext->getPasswordForUser($user), "", - [], + $headers, ) ); $this->setResponseSpaceId($spaceId); @@ -1708,6 +1711,97 @@ public function theUserHasCreatedASpaceByDefaultUsingTheGraphApi( ); } + /** + * @When /^user "([^"]*)" copies (?:file|folder) "([^"]*)" to "([^"]*)" in space "([^"]*)" using the WebDAV API$/ + * + * @param string $user + * @param string $fileSource + * @param string $fileDestination + * @param string $spaceName + * + * @return void + */ + public function userCopiesFileWithinSpaceUsingTheWebDAVAPI( + string $user, + string $fileSource, + string $fileDestination, + string $spaceName + ):void { + $space = $this->getSpaceByName($user, $spaceName); + $headers['Destination'] = $this->destinationHeaderValueWithSpaceName( + $user, + $fileDestination, + $spaceName + ); + + $fullUrl = $this->baseUrl . "/dav/spaces/" . $space['id'] . '/' . \trim($fileSource, "/"); + $this->copyFilesAndFoldersRequest($user, $fullUrl, $headers); + } + + /** + * @When /^user "([^"]*)" copies (?:file|folder) "([^"]*)" from space "([^"]*)" to "([^"]*)" inside space "([^"]*)" using the WebDAV API$/ + * + * @param string $user + * @param string $fileSource + * @param string $fromSpaceName + * @param string $fileDestination + * @param string $toSpaceName + * + * @return void + * @throws GuzzleException + */ + public function userCopiesFileFromAndToSpaceBetweenSpaces( + string $user, + string $fileSource, + string $fromSpaceName, + string $fileDestination, + string $toSpaceName + ):void { + $space = $this->getSpaceByName($user, $fromSpaceName); + $headers['Destination'] = $this->destinationHeaderValueWithSpaceName($user, $fileDestination, $toSpaceName); + $fullUrl = $this->baseUrl . "/dav/spaces/" . $space['id'] . '/' . \trim($fileSource, "/"); + $this->copyFilesAndFoldersRequest($user, $fullUrl, $headers); + } + + /** + * returns a url for destination with spacename + * + * @param string $user + * @param string $fileDestination + * @param string $spaceName + * + * @return string + * @throws GuzzleException + */ + public function destinationHeaderValueWithSpaceName(string $user, string $fileDestination, string $spaceName):string { + $space = $this->getSpaceByName($user, $spaceName); + $fullUrl = $this->baseUrl . "/dav/spaces/" . $space['id']; + return \rtrim($fullUrl, '/') . '/' . \ltrim($fileDestination, '/'); + } + + /** + * COPY request for files|folders + * + * @param string $user + * @param string $fullUrl + * @param string $headers + * + * @return void + * @throws GuzzleException + */ + public function copyFilesAndFoldersRequest(string $user, string $fullUrl, array $headers):void { + $this->featureContext->setResponse( + HttpRequestHelper::sendRequest( + $fullUrl, + $this->featureContext->getStepLineRef(), + 'COPY', + $user, + $this->featureContext->getPasswordForUser($user), + $headers, + ) + ); + } + /** * @Given /^user "([^"]*)" has uploaded a file inside space "([^"]*)" with content "([^"]*)" to "([^"]*)"$/ * @@ -2366,7 +2460,7 @@ public function downloadVersionOfTheFile( ); } $url = $this->baseUrl . $fileVersion[$index][0]; - + $this->featureContext->setResponse( HttpRequestHelper::sendRequest( $url,