From 9e7a9bab9a0e318dd13cfbd856a04b3be257e239 Mon Sep 17 00:00:00 2001 From: Sawjan Gurung Date: Thu, 15 Feb 2024 21:26:17 +0545 Subject: [PATCH] [tests-only] add API test coverage for file MOVE to space-id as destination (#8459) --- .../moveByFileId.feature | 64 +++++++++++++++++++ .../features/bootstrap/SpacesContext.php | 42 ++++++++++++ .../acceptance/features/bootstrap/WebDav.php | 9 ++- 3 files changed, 112 insertions(+), 3 deletions(-) diff --git a/tests/acceptance/features/apiSpacesDavOperation/moveByFileId.feature b/tests/acceptance/features/apiSpacesDavOperation/moveByFileId.feature index 5e9ae60860..9cd8066d8a 100644 --- a/tests/acceptance/features/apiSpacesDavOperation/moveByFileId.feature +++ b/tests/acceptance/features/apiSpacesDavOperation/moveByFileId.feature @@ -706,3 +706,67 @@ Feature: moving/renaming file using file id | dav-path | | /remote.php/dav/spaces/<> | | /dav/spaces/<> | + + @issue-6739 + Scenario Outline: try to move personal file to other spaces using its id as the destination + Given the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API + And user "Alice" has created a space "myspace" with the default quota using the Graph API + And user "Alice" has uploaded file with content "some data" to "textfile.txt" + When user "Alice" tries to move file "textfile.txt" of space "Personal" to space "" using its id in destination path "" + Then the HTTP status code should be "400" + And for user "Alice" the space "Personal" should contain these entries: + | textfile.txt | + Examples: + | dav-path | space | + | /remote.php/dav/spaces | Personal | + | /dav/spaces | Personal | + | /remote.php/dav/spaces | myspace | + | /dav/spaces | myspace | + + @issue-6739 + Scenario Outline: try to move project file to other spaces using its id as the destination + Given the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API + And user "Alice" has created a space "myspace" with the default quota using the Graph API + And user "Alice" has uploaded a file inside space "myspace" with content "some data" to "textfile.txt" + When user "Alice" tries to move file "textfile.txt" of space "myspace" to space "" using its id in destination path "" + Then the HTTP status code should be "400" + And for user "Alice" the space "myspace" should contain these entries: + | textfile.txt | + Examples: + | dav-path | space | + | /remote.php/dav/spaces | Personal | + | /dav/spaces | Personal | + | /remote.php/dav/spaces | myspace | + | /dav/spaces | myspace | + + @issue-6739 + Scenario Outline: move a file to folder using its id as the destination (Personal space) + Given user "Alice" has uploaded file with content "some data" to "textfile.txt" + And user "Alice" has created folder "docs" + When user "Alice" moves file "textfile.txt" of space "Personal" to folder "docs" using its id in destination path "" + Then the HTTP status code should be "204" + And the content of file "docs" for user "Alice" should be "some data" + And as "Alice" file "textfile.txt" should not exist + And as "Alice" folder "docs" should not exist + And as "Alice" folder "docs" should exist in the trashbin of the space "Personal" + Examples: + | dav-path | + | /remote.php/dav/spaces | + | /dav/spaces | + + @issue-6739 + Scenario Outline: move a file to folder using its id as the destination (Project space) + Given the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API + And user "Alice" has created a space "myspace" with the default quota using the Graph API + And user "Alice" has uploaded a file inside space "myspace" with content "some data" to "textfile.txt" + And user "Alice" has created a folder "docs" in space "myspace" + When user "Alice" moves file "textfile.txt" of space "myspace" to folder "docs" using its id in destination path "" + Then the HTTP status code should be "204" + And for user "Alice" the content of the file "docs" of the space "myspace" should be "some data" + And as "Alice" folder "docs" should exist in the trashbin of the space "myspace" + And for user "Alice" folder "/" of the space "myspace" should not contain these files: + | textfile.txt | + Examples: + | dav-path | + | /remote.php/dav/spaces | + | /dav/spaces | diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index ea11978691..595b23adf8 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -2060,6 +2060,48 @@ class SpacesContext implements Context { } } + /** + * @When /^user "([^"]*)" tries to move (?:file|folder) "([^"]*)" of space "([^"]*)" to (space|folder) "([^"]*)" using its id in destination path "([^"]*)"$/ + * @When /^user "([^"]*)" moves (?:file|folder) "([^"]*)" of space "([^"]*)" to (folder) "([^"]*)" using its id in destination path "([^"]*)"$/ + * + * @param string $user + * @param string $source + * @param string $sourceSpace + * @param string $destinationType + * @param string $destinationName + * @param string $destinationPath + * + * @throws GuzzleException + * @return void + */ + public function userMovesFileToResourceUsingItsIdAsDestinationPath( + string $user, + string $source, + string $sourceSpace, + string $destinationType, + string $destinationName, + string $destinationPath + ): void { + $source = \trim($source, "/"); + $baseUrl = $this->featureContext->getBaseUrl(); + $suffix = ""; + if ($this->featureContext->getDavPathVersion() === WebDavHelper::DAV_VERSION_SPACES) { + $suffix = $this->getSpaceIdByName($user, $sourceSpace) . "/"; + } + $fullUrl = $baseUrl . \rtrim($destinationPath, "/") . "/{$suffix}{$source}"; + + $destinationId = ""; + if ($destinationType === "space") { + $destinationId = $this->getSpaceIdByName($user, $destinationName); + } else { + $destinationId = $this->getResourceId($user, $sourceSpace, $destinationName); + } + $headers['Destination'] = $baseUrl . \rtrim($destinationPath, "/") . "/$destinationId"; + + $response = $this->moveFilesAndFoldersRequest($user, $fullUrl, $headers); + $this->featureContext->setResponse($response); + } + /** * @Given /^user "([^"]*)" has uploaded a file inside space "([^"]*)" with content "([^"]*)" to "([^"]*)"$/ * diff --git a/tests/acceptance/features/bootstrap/WebDav.php b/tests/acceptance/features/bootstrap/WebDav.php index 03e15d2d3d..47a0f00be1 100644 --- a/tests/acceptance/features/bootstrap/WebDav.php +++ b/tests/acceptance/features/bootstrap/WebDav.php @@ -1752,9 +1752,12 @@ trait WebDav { } else { $actualResourceType = "folder"; } - Assert::fail( - "$entry '$path' should not exist. But it does exist and is a $actualResourceType" - ); + + if ($entry === $actualResourceType) { + Assert::fail( + "$entry '$path' should not exist. But it does." + ); + } } }