From fb36bb078d2a9c1155018b28440825e77a6e1931 Mon Sep 17 00:00:00 2001 From: Illia Pushnov Date: Wed, 10 Nov 2021 20:14:32 +0100 Subject: [PATCH 1/2] Acceptance tests for owncloud/core#39126 Co-authored-by: Ilia Pushnov --- .../features/apiVersions/fileVersions.feature | 30 ++++++++++ .../acceptance/features/bootstrap/WebDav.php | 58 +++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/tests/acceptance/features/apiVersions/fileVersions.feature b/tests/acceptance/features/apiVersions/fileVersions.feature index 5a4571f22ee8..a626c947c1b5 100644 --- a/tests/acceptance/features/apiVersions/fileVersions.feature +++ b/tests/acceptance/features/apiVersions/fileVersions.feature @@ -469,3 +469,33 @@ Feature: dav-versions | header | value | | Content-Disposition | attachment; filename*=UTF-8''textfile0.txt; filename="textfile0.txt" | And the downloaded content should be "uploaded content" + + + Scenario: enable file versioning and check the history of changes from multiple users + Given the administrator has enabled file version storage feature + And user "Brian" has been created with default attributes and without skeleton files + And user "Carol" has been created with default attributes and without skeleton files + And user "Alice" creates folder "/test" using the WebDAV API + And user "Alice" shares folder "/test" with user "Brian" with permissions "all" using the sharing API + And user "Alice" shares folder "/test" with user "Carol" with permissions "all" using the sharing API + When user "Alice" has uploaded file with content "uploaded content" to "/test/textfile0.txt" + When user "Brian" has uploaded file with content "uploaded content new" to "/test/textfile0.txt" + When user "Carol" has uploaded file with content "uploaded content new again" to "/test/textfile0.txt" + When user "Alice" gets the number of versions of file "/test/textfile0.txt" + Then the author of the created version with index "1" should be "Carol" + Then the author of the created version with index "2" should be "Brian" + And user "Alice" downloads the version of file "/test/textfile0.txt" with the index "1" + Then the HTTP status code should be "200" + And the following headers should be set + | header | value | + | Content-Disposition | attachment; filename*=UTF-8''textfile0.txt; filename="textfile0.txt" | + And the downloaded content should be "uploaded content new again" + When user "Alice" downloads the version of file "test/textfile0.txt" with the index "2" + And the following headers should be set + | header | value | + | Content-Disposition | attachment; filename*=UTF-8''textfile0.txt; filename="textfile0.txt" | + And the downloaded content should be "uploaded content new" + When user "Alice" deletes folder "/test/" using the WebDAV API + Then the HTTP status code should be "204" + And as "Alice" folder "/test/" should not exist + diff --git a/tests/acceptance/features/bootstrap/WebDav.php b/tests/acceptance/features/bootstrap/WebDav.php index 75babbe4c02c..add13476273b 100644 --- a/tests/acceptance/features/bootstrap/WebDav.php +++ b/tests/acceptance/features/bootstrap/WebDav.php @@ -5052,4 +5052,62 @@ public function resetPreviousSettingsAfterScenario():void { ); } } + + /** + * @Given /^the administrator has (enabled|disabled) file version storage feature/ + * + * @param string $enabledOrDisabled + * + * @return void + * @throws Exception + */ + public function theAdministratorHasEnabledTheFileVersionStorage($enabledOrDisabled) { + $switch = ($enabledOrDisabled !== "disabled"); + if ($switch) { + $value = 'true'; + } else { + $value = 'false'; + } + $this->runOcc( + [ + 'config:system:set', + 'file_storage.save_version_author', + '--type', + 'boolean', + '--value', + $value] + ); + } + /** + * @Then the author of the created version with index :arg1 should be :arg2 + * + * @param string $index + * @param string $user + * + * @return void + * @throws Exception + */ + public function theAuthorOfEditedVersionFile($index, $user) { + $expectedUser = $this->getUserDisplayName($user); + $resXml = $this->getResponseXmlObject(); + if ($resXml === null) { + $resXml = HttpRequestHelper::getResponseXml( + $this->getResponse(), + __METHOD__ + ); + } + $xmlPart = $resXml->xpath("//oc:meta-version-edited-by//text()"); + if (!isset($xmlPart[$index - 1])) { + Assert::fail( + 'could not find version with index "' . $index . '"' + ); + } + $actualUser = $xmlPart[$index - 1][0]; + Assert::assertEquals( + $expectedUser, + $actualUser, + "Expected user of version was '$expectedUser', but got '$actualUser'" + ); + } } + From 60ad79f587b7d78c5a2829ea39748c5e0d11903d Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Thu, 18 Nov 2021 23:29:20 +0545 Subject: [PATCH 2/2] Adjust API acceptance test for version metadata --- .../features/apiVersions/fileVersions.feature | 28 ++++++++++------- .../features/bootstrap/FeatureContext.php | 2 ++ .../bootstrap/FilesVersionsContext.php | 31 +++++++++++++++++++ .../acceptance/features/bootstrap/WebDav.php | 29 ++++++++++++----- 4 files changed, 71 insertions(+), 19 deletions(-) diff --git a/tests/acceptance/features/apiVersions/fileVersions.feature b/tests/acceptance/features/apiVersions/fileVersions.feature index a626c947c1b5..cc05fa165f30 100644 --- a/tests/acceptance/features/apiVersions/fileVersions.feature +++ b/tests/acceptance/features/apiVersions/fileVersions.feature @@ -472,30 +472,34 @@ Feature: dav-versions Scenario: enable file versioning and check the history of changes from multiple users - Given the administrator has enabled file version storage feature + Given the administrator has enabled the file version storage feature And user "Brian" has been created with default attributes and without skeleton files And user "Carol" has been created with default attributes and without skeleton files And user "Alice" creates folder "/test" using the WebDAV API And user "Alice" shares folder "/test" with user "Brian" with permissions "all" using the sharing API And user "Alice" shares folder "/test" with user "Carol" with permissions "all" using the sharing API - When user "Alice" has uploaded file with content "uploaded content" to "/test/textfile0.txt" - When user "Brian" has uploaded file with content "uploaded content new" to "/test/textfile0.txt" - When user "Carol" has uploaded file with content "uploaded content new again" to "/test/textfile0.txt" + And user "Alice" has uploaded file with content "uploaded content first" to "/test/textfile0.txt" + And user "Brian" has uploaded file with content "uploaded content changed" to "/test/textfile0.txt" + And user "Carol" has uploaded file with content "uploaded content latest" to "/test/textfile0.txt" When user "Alice" gets the number of versions of file "/test/textfile0.txt" + Then the number of versions should be "2" + When user "Alice" gets the version metadata of file "/test/textfile0.txt" Then the author of the created version with index "1" should be "Carol" - Then the author of the created version with index "2" should be "Brian" - And user "Alice" downloads the version of file "/test/textfile0.txt" with the index "1" + And the author of the created version with index "2" should be "Brian" + # Actually Alice was the author of the oldest version of the file, + # and Brian was the author of the 2nd-oldest version of the file, + # and Carol is the author of current file, which is not in the version history. + #Then the author of the created version with index "1" should be "Brian" + #And the author of the created version with index "2" should be "Alice" + When user "Alice" downloads the version of file "/test/textfile0.txt" with the index "1" Then the HTTP status code should be "200" And the following headers should be set | header | value | | Content-Disposition | attachment; filename*=UTF-8''textfile0.txt; filename="textfile0.txt" | - And the downloaded content should be "uploaded content new again" + And the downloaded content should be "uploaded content changed" When user "Alice" downloads the version of file "test/textfile0.txt" with the index "2" + Then the HTTP status code should be "200" And the following headers should be set | header | value | | Content-Disposition | attachment; filename*=UTF-8''textfile0.txt; filename="textfile0.txt" | - And the downloaded content should be "uploaded content new" - When user "Alice" deletes folder "/test/" using the WebDAV API - Then the HTTP status code should be "204" - And as "Alice" folder "/test/" should not exist - + And the downloaded content should be "uploaded content first" diff --git a/tests/acceptance/features/bootstrap/FeatureContext.php b/tests/acceptance/features/bootstrap/FeatureContext.php index a0e53e9470cd..cf18781be107 100644 --- a/tests/acceptance/features/bootstrap/FeatureContext.php +++ b/tests/acceptance/features/bootstrap/FeatureContext.php @@ -1148,6 +1148,8 @@ public function setResponse(?ResponseInterface $response):void { $this->response = $response; //after a new response reset the response xml $this->responseXml = []; + //after a new response reset the response xml object + $this->responseXmlObject = null; } /** diff --git a/tests/acceptance/features/bootstrap/FilesVersionsContext.php b/tests/acceptance/features/bootstrap/FilesVersionsContext.php index 2cd39e877439..7f90d067b2d3 100644 --- a/tests/acceptance/features/bootstrap/FilesVersionsContext.php +++ b/tests/acceptance/features/bootstrap/FilesVersionsContext.php @@ -97,6 +97,37 @@ public function userGetsFileVersions(string $user, string $file):void { $this->featureContext->setResponse($response); } + /** + * @When user :user gets the version metadata of file :file + * + * @param string $user + * @param string $file + * + * @return void + * @throws Exception + */ + public function userGetsVersionMetadataOfFile(string $user, string $file):void { + $user = $this->featureContext->getActualUsername($user); + $fileId = $this->featureContext->getFileIdForPath($user, $file); + $body = ' + + + + + +'; + $response = $this->featureContext->makeDavRequest( + $user, + "PROPFIND", + $this->getVersionsPathForFileId($fileId), + null, + $body, + null, + '2' + ); + $this->featureContext->setResponse($response); + } + /** * @When user :user restores version index :versionIndex of file :path using the WebDAV API * @Given user :user has restored version index :versionIndex of file :path diff --git a/tests/acceptance/features/bootstrap/WebDav.php b/tests/acceptance/features/bootstrap/WebDav.php index add13476273b..b2885492a41f 100644 --- a/tests/acceptance/features/bootstrap/WebDav.php +++ b/tests/acceptance/features/bootstrap/WebDav.php @@ -430,6 +430,7 @@ public function theNumberOfVersionsShouldBe(int $number):void { $this->getResponse(), __METHOD__ ); + $this->setResponseXmlObject($resXml); } $xmlPart = $resXml->xpath("//d:getlastmodified"); $actualNumber = \count($xmlPart); @@ -5054,14 +5055,14 @@ public function resetPreviousSettingsAfterScenario():void { } /** - * @Given /^the administrator has (enabled|disabled) file version storage feature/ + * @Given /^the administrator has (enabled|disabled) the file version storage feature/ * * @param string $enabledOrDisabled * * @return void * @throws Exception */ - public function theAdministratorHasEnabledTheFileVersionStorage($enabledOrDisabled) { + public function theAdministratorHasEnabledTheFileVersionStorage(string $enabledOrDisabled): void { $switch = ($enabledOrDisabled !== "disabled"); if ($switch) { $value = 'true'; @@ -5078,23 +5079,25 @@ public function theAdministratorHasEnabledTheFileVersionStorage($enabledOrDisabl $value] ); } + /** - * @Then the author of the created version with index :arg1 should be :arg2 + * @Then the author of the created version with index :index should be :expectedUser * * @param string $index - * @param string $user + * @param string $expectedUser * * @return void * @throws Exception */ - public function theAuthorOfEditedVersionFile($index, $user) { - $expectedUser = $this->getUserDisplayName($user); + public function theAuthorOfEditedVersionFile(string $index, string $expectedUser): void { + $expectedUserDisplayName = $this->getUserDisplayName($expectedUser); $resXml = $this->getResponseXmlObject(); if ($resXml === null) { $resXml = HttpRequestHelper::getResponseXml( $this->getResponse(), __METHOD__ ); + $this->setResponseXmlObject($resXml); } $xmlPart = $resXml->xpath("//oc:meta-version-edited-by//text()"); if (!isset($xmlPart[$index - 1])) { @@ -5108,6 +5111,18 @@ public function theAuthorOfEditedVersionFile($index, $user) { $actualUser, "Expected user of version was '$expectedUser', but got '$actualUser'" ); + + $xmlPart = $resXml->xpath("//oc:meta-version-edited-by-name//text()"); + if (!isset($xmlPart[$index - 1])) { + Assert::fail( + 'could not find version with index "' . $index . '"' + ); + } + $actualUserDisplayName = $xmlPart[$index - 1][0]; + Assert::assertEquals( + $expectedUserDisplayName, + $actualUserDisplayName, + "Expected user of version was '$expectedUser', but got '$actualUser'" + ); } } -