Skip to content

Commit

Permalink
Added test for the copy with file-id in url
Browse files Browse the repository at this point in the history
  • Loading branch information
SagarGi committed Sep 21, 2023
1 parent 1047ea3 commit 7b7a6ce
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
Feature: copying file using file id
As a user
I want to copy the file using file id
So that I can manage my resource

Background:
Given using spaces DAV path
And user "Alice" has been created with default attributes and without skeleton files

Scenario Outline: copy a file into a folder in personal space
Given user "Alice" has created folder "/folder"
And user "Alice" has uploaded file with content "some data" to "/textfile.txt"
And we save it into "FILEID"
When user "Alice" copies a file with file_id in URL "<dav-path>" to "/folder/textfile.txt" inside space "Personal"
Then the HTTP status code should be "201"
And for user "Alice" the space "Personal" should contain these entries:
| folder/textfile.txt |
Examples:
| dav-path |
| /remote.php/dav/spaces/<<FILEID>> |
| /dav/spaces/<<FILEID>> |


Scenario Outline: copy a file into a sub-folder in personal space
Given user "Alice" has created folder "/folder"
And user "Alice" has created folder "folder/sub-folder"
And user "Alice" has uploaded file with content "some data" to "/textfile.txt"
And we save it into "FILEID"
When user "Alice" copies a file with file_id in URL "<dav-path>" to "/folder/sub-folder/textfile.txt" inside space "Personal"
Then the HTTP status code should be "201"
And for user "Alice" the space "Personal" should contain these entries:
| folder/sub-folder/textfile.txt |
Examples:
| dav-path |
| /remote.php/dav/spaces/<<FILEID>> |
| /dav/spaces/<<FILEID>> |


Scenario Outline: copy a file from folder to root in personal space
Given user "Alice" has created folder "/folder"
And user "Alice" has uploaded file with content "some data" to "folder/textfile.txt"
And we save it into "FILEID"
When user "Alice" copies a file with file_id in URL "<dav-path>" to "/textfile.txt" inside space "Personal"
Then the HTTP status code should be "201"
And for user "Alice" the space "Personal" should contain these entries:
| textfile.txt |
Examples:
| dav-path |
| /remote.php/dav/spaces/<<FILEID>> |
| /dav/spaces/<<FILEID>> |


Scenario Outline: copy a file from sub-folder to root in personal space
Given user "Alice" has created folder "/folder"
And user "Alice" has created folder "folder/sub-folder"
And user "Alice" has uploaded file with content "some data" to "folder/sub-folder/textfile.txt"
And we save it into "FILEID"
When user "Alice" copies a file with file_id in URL "<dav-path>" to "/textfile.txt" inside space "Personal"
Then the HTTP status code should be "201"
And for user "Alice" the space "Personal" should contain these entries:
| textfile.txt |
Examples:
| dav-path |
| /remote.php/dav/spaces/<<FILEID>> |
| /dav/spaces/<<FILEID>> |
29 changes: 25 additions & 4 deletions tests/acceptance/features/bootstrap/SpacesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -1609,6 +1609,23 @@ public function userHasMovedFileWithinSpaceUsingTheWebDAVAPI(
);
}

/**
* @When /^user "([^"]*)" copies a file with file_id in URL "([^"]*)" to "([^"]*)" inside space "([^"]*)"$/
*
* @param string $user
* @param string $url
* @param string $fileDestination
* @param string $toSpaceName
*
* @throws GuzzleException
* @return void
*/
public function userCopiesFileWithFileIdFromAndToSpaceBetweenSpaces(string $user, string $url, string $fileDestination, string $toSpaceName): void {
$headers['Destination'] = $this->destinationHeaderValueWithSpaceName($user, $fileDestination, $toSpaceName, $url);
$fullUrl = $this->featureContext->getBaseUrl() . $url;
$this->featureContext->setResponse($this->copyFilesAndFoldersRequest($user, $fullUrl, $headers));
}

/**
* MOVE request for files|folders
*
Expand Down Expand Up @@ -1642,7 +1659,7 @@ public function moveFilesAndFoldersRequest(string $user, string $fullUrl, array
* @return void
* @throws GuzzleException
*/
public function userCopiesFileFromAndToSpaceBetweenSpaces(
public function userCopyFileFromAndToSpaceBetweenSpaces(
string $user,
string $fileSource,
string $fromSpaceName,
Expand Down Expand Up @@ -1753,15 +1770,19 @@ public function userMovesFileFromAndToSpaceBetweenSpaces(
* @param string $user
* @param string $fileDestination
* @param string $spaceName
* @param string|null $endPath
*
* @return string
* @throws GuzzleException
*/
public function destinationHeaderValueWithSpaceName(string $user, string $fileDestination, string $spaceName):string {
public function destinationHeaderValueWithSpaceName(string $user, string $fileDestination, string $spaceName, string $endPath = null):string {
$space = $this->getSpaceByName($user, $spaceName);

$fileDestination = $this->escapePath(\ltrim($fileDestination, "/"));

if ($endPath && str_contains($endPath, 'remote.php')) {
// this is check for when we want to check with the endpoint having `remote.php` in space webdav
// by default spaces webdav is '/dav/spaces'
return $this->featureContext->getBaseUrl() . '/remote.php/dav/spaces/' . $space['id'] . '/' . $fileDestination;
}
return $space["root"]["webDavUrl"] . '/' . $fileDestination;
}

Expand Down

0 comments on commit 7b7a6ce

Please sign in to comment.