Skip to content

Commit

Permalink
Added implementation for copy operations
Browse files Browse the repository at this point in the history
  • Loading branch information
SagarGi committed Jul 12, 2022
1 parent e9f6683 commit dbd95f0
Showing 1 changed file with 97 additions and 3 deletions.
100 changes: 97 additions & 3 deletions tests/acceptance/features/bootstrap/SpacesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 "([^"]*)"$/
*
Expand Down Expand Up @@ -2366,7 +2460,7 @@ public function downloadVersionOfTheFile(
);
}
$url = $this->baseUrl . $fileVersion[$index][0];

$this->featureContext->setResponse(
HttpRequestHelper::sendRequest(
$url,
Expand Down

0 comments on commit dbd95f0

Please sign in to comment.