diff --git a/tests/acceptance/features/apiVersions/fileVersions.feature b/tests/acceptance/features/apiVersions/fileVersions.feature index 5a4571f22ee8..cc05fa165f30 100644 --- a/tests/acceptance/features/apiVersions/fileVersions.feature +++ b/tests/acceptance/features/apiVersions/fileVersions.feature @@ -469,3 +469,37 @@ 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 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 + 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" + 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 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 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 75babbe4c02c..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); @@ -5052,4 +5053,76 @@ public function resetPreviousSettingsAfterScenario():void { ); } } + + /** + * @Given /^the administrator has (enabled|disabled) the file version storage feature/ + * + * @param string $enabledOrDisabled + * + * @return void + * @throws Exception + */ + public function theAdministratorHasEnabledTheFileVersionStorage(string $enabledOrDisabled): void { + $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 :index should be :expectedUser + * + * @param string $index + * @param string $expectedUser + * + * @return void + * @throws Exception + */ + 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])) { + 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'" + ); + + $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'" + ); + } }