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 14, 2022
1 parent 8d14a60 commit a668f09
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 27 deletions.
34 changes: 9 additions & 25 deletions tests/acceptance/features/apiSpaces/copySpaces.feature
Original file line number Diff line number Diff line change
Expand Up @@ -45,37 +45,21 @@ Feature: copy file
And user "Brian" has created a space "Project1" with the default quota using the GraphApi
And user "Brian" has created a space "Project2" with the default quota using the GraphApi
And user "Brian" has uploaded a file inside space "Project1" with content "Project1 content" to "project1.txt"
And user "Brian" has shared a space "Project2" to user "Alice" with role "manager"
And user "Brian" has shared a space "Project1" to user "Alice" with role "<role>"
When user "Alice" copies file "project1.txt" from space "Project1" to "project1.txt" inside space "Project2" using the WebDAV API
Then the HTTP status code should be "201"
And for user "Alice" the space "Project2" should contain these entries:
| project1.txt |
And for user "Alice" the content of the file "project1.txt" of the space "Project2" should be "Project1 content"
Examples:
| role |
| manager |
| editor |
| viewer |


Scenario Outline: User copy a file from a space project with different role to a space project with editor role
Given the administrator has given "Brian" the role "Space Admin" using the settings api
And user "Brian" has created a space "Project1" with the default quota using the GraphApi
And user "Brian" has created a space "Project2" with the default quota using the GraphApi
And user "Brian" has uploaded a file inside space "Project1" with content "Project1 content" to "project1.txt"
And user "Brian" has shared a space "Project2" to user "Alice" with role "editor"
And user "Brian" has shared a space "Project1" to user "Alice" with role "<role>"
And user "Brian" has shared a space "Project2" to user "Alice" with role "<from_role>"
And user "Brian" has shared a space "Project1" to user "Alice" with role "<to_role>"
When user "Alice" copies file "project1.txt" from space "Project1" to "project1.txt" inside space "Project2" using the WebDAV API
Then the HTTP status code should be "201"
And for user "Alice" the space "Project2" should contain these entries:
| project1.txt |
And for user "Alice" the content of the file "project1.txt" of the space "Project2" should be "Project1 content"
Examples:
| role |
| manager |
| editor |
| viewer |
| from_role | to_role |
| manager | manager |
| manager | editor |
| manager | viewer |
| editor | manager |
| editor | editor |
| editor | viewer |


Scenario Outline: User copy a file from a space project with different role to a space project with viewer role
Expand Down
98 changes: 96 additions & 2 deletions tests/acceptance/features/bootstrap/SpacesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,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 @@ -756,13 +758,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 @@ -1660,6 +1663,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 = $space["root"]["webDavUrl"] . '/' . \ltrim($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 = $space["root"]["webDavUrl"] . '/' . \ltrim($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 = $space["root"]["webDavUrl"];
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

0 comments on commit a668f09

Please sign in to comment.