Skip to content

Commit

Permalink
Added implementation for copy request operation
Browse files Browse the repository at this point in the history
  • Loading branch information
SagarGi committed Jul 11, 2022
1 parent 46ff825 commit 8cf094d
Showing 1 changed file with 96 additions and 2 deletions.
98 changes: 96 additions & 2 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 @@ -1708,6 +1710,98 @@ 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'] . '/' . $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'] . '/' . $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,
"",
'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 8cf094d

Please sign in to comment.