Skip to content

Commit

Permalink
Refactor when step and add scenarios from and to different space
Browse files Browse the repository at this point in the history
  • Loading branch information
SagarGi committed Jul 11, 2022
1 parent 02c87cb commit 1e98c96
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 37 deletions.
45 changes: 40 additions & 5 deletions tests/acceptance/features/apiSpaces/copySpaces.feature
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Feature: copy file
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" in space "Project2" using the WebDAV API
When user "Alice" copies file "project1.txt" from space "Project1" to "project1.txt" inside space "Project2" using the WebDAV API
And the HTTP status code should be "201"
And for user "Alice" the content of the file "project1.txt" of the space "Project2" should be "Project1 content"
Examples:
Expand All @@ -59,7 +59,7 @@ Feature: copy file
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>"
When user "Alice" copies file "project1.txt" from space "Project1" to "project1.txt" in space "Project2" using the WebDAV API
When user "Alice" copies file "project1.txt" from space "Project1" to "project1.txt" inside space "Project2" using the WebDAV API
And the HTTP status code should be "201"
And for user "Alice" the content of the file "project1.txt" of the space "Project2" should be "Project1 content"
Examples:
Expand All @@ -75,7 +75,7 @@ Feature: copy file
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 "viewer"
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" in space "Project2" using the WebDAV API
When user "Alice" copies file "project1.txt" from space "Project1" to "project1.txt" inside space "Project2" using the WebDAV API
And the HTTP status code should be "403"
Examples:
| role |
Expand All @@ -88,12 +88,47 @@ Feature: copy file
And user "Brian" has created a space "Project" with the default quota using the GraphApi
And user "Brian" has uploaded a file inside space "Project" with content "Project content" to "project.txt"
And user "Brian" has shared a space "Project" to user "Alice" with role "<role>"
When user "Alice" copies file "project.txt" from space "Project" to "project.txt" inside personal using the WebDAV API
And the HTTP status code should be "201"
When user "Alice" copies file "project.txt" from space "Project" to "project.txt" inside space "Personal" using the WebDAV API
Then the HTTP status code should be "201"
And as "Alice" file "/project.txt" should exist
And the content of file "project.txt" for user "Alice" should be "Project content"
Examples:
| role |
| manager |
| editor |
| viewer |

Scenario Outline: User copy a file from space project with different role to shares jail with editor role
Given the administrator has given "Brian" the role "Space Admin" using the settings api
And user "Brian" has created a space "Project" with the default quota using the GraphApi
And user "Brian" has created folder "/testshare"
And user "Brian" has uploaded a file inside space "Project" with content "Project content" to "project.txt"
And user "Brian" has shared a space "Project" to user "Alice" with role "<role>"
And user "Brian" has shared folder "/testshare" with user "Alice" with permissions "31"
And user "Alice" has accepted share "/testshare" offered by user "Brian"
When user "Alice" copies file "project.txt" from space "Project" to "/testshare/project.txt" inside space "Shares Jail" using the WebDAV API
Then the HTTP status code should be "201"
And as "Alice" file "/Shares/testshare/project.txt" should exist
And the content of file "/Shares/testshare/project.txt" for user "Alice" should be "Project content"
Examples:
| role |
| manager |
| editor |
| viewer |


Scenario Outline: User copy a file from space project with different role to shares jail with viewer role
Given the administrator has given "Brian" the role "Space Admin" using the settings api
And user "Brian" has created a space "Project" with the default quota using the GraphApi
And user "Brian" has created folder "/testshare"
And user "Brian" has uploaded a file inside space "Project" with content "Project content" to "project.txt"
And user "Brian" has shared a space "Project" to user "Alice" with role "<role>"
And user "Brian" has shared folder "/testshare" with user "Alice" with permissions "17"
And user "Alice" has accepted share "/testshare" offered by user "Brian"
When user "Alice" copies file "project.txt" from space "Project" to "/testshare/project.txt" inside space "Shares Jail" using the WebDAV API
Then the HTTP status code should be "403"
Examples:
| role |
| manager |
| editor |
| viewer |
54 changes: 22 additions & 32 deletions tests/acceptance/features/bootstrap/SpacesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -1736,7 +1736,7 @@ public function userCopiesFileUsingTheAPI(
}

/**
* @When /^user "([^"]*)" copies (?:file|folder) "([^"]*)" from space "([^"]*)" to "([^"]*)" in space "([^"]*)" using the WebDAV API$/
* @When /^user "([^"]*)" copies (?:file|folder) "([^"]*)" from space "([^"]*)" to "([^"]*)" inside space "([^"]*)" using the WebDAV API$/
*
* @param string $user
* @param string $fileSource
Expand All @@ -1753,38 +1753,28 @@ public function userCopiesFileFromAndToSpaceBetweenProjects(
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);
}

/**
* @When /^user "([^"]*)" copies (?:file|folder) "([^"]*)" from space "([^"]*)" to "([^"]*)" inside personal using the WebDAV API$/
*
* @param string $user
* @param string $fileSource
* @param string $spaceName
* @param string $fileDestination
*
* @return void
*/
public function userCopiesFileFromProjectToPersonal(
string $user,
string $fileSource,
string $spaceName,
string $fileDestination
):void {
$space = $this->getSpaceByName($user, $spaceName);
$headers['Destination'] = $this->destinationHeaderValueWithUserPersonalSpaceID(
$user,
$fileDestination,
);
$fullUrl = $this->baseUrl . "/dav/spaces/" . $space['id'] . '/' . $fileSource;
// get headers
if($toSpaceName === "Personal"){
$headers['Destination'] = $this->destinationHeaderValueWithUserPersonalSpaceID(
$user,
$fileDestination,
);
} else {
$headers['Destination'] = $this->destinationHeaderValueWithSpaceName(
$user,
$fileDestination,
$toSpaceName
);
}

if($fromSpaceName === "Personal"){
$userPersonalSpaceID = $this->featureContext->getPersonalSpaceIdForUser($user, true);
$fullUrl = $this->baseUrl . "/dav/spaces/" . $userPersonalSpaceID . '/' . $fileSource;
}else {
$space = $this->getSpaceByName($user, $fromSpaceName);
$fullUrl = $this->baseUrl . "/dav/spaces/" . $space['id'] . '/' . $fileSource;
}
$this->copyFilesAndFoldersRequest($user, $fullUrl, $headers);
}

Expand Down

0 comments on commit 1e98c96

Please sign in to comment.