diff --git a/tests/acceptance/features/apiVersions/fileVersions.feature b/tests/acceptance/features/apiVersions/fileVersions.feature index b6b514cb2348..9eb661635539 100644 --- a/tests/acceptance/features/apiVersions/fileVersions.feature +++ b/tests/acceptance/features/apiVersions/fileVersions.feature @@ -415,3 +415,15 @@ Feature: dav-versions Then the HTTP status code should be "207" And the number of etag elements in the response should be "2" And the number of versions should be "2" + + + Scenario: download an old versions of a file + Given user "Alice" has uploaded file with content "uploaded content" to "textfile0.txt" + And user "Alice" has uploaded file with content "version 1" to "textfile0.txt" + And user "Alice" has uploaded file with content "version 2" to "textfile0.txt" + When user "Alice" downloads the version of file "textfile0.txt" with the index "0" + Then the HTTP status code should be "200" + And the downloaded content should be "version 1" + When user "Alice" downloads the version of file "textfile0.txt" with the index "1" + Then the HTTP status code should be "200" + And the downloaded content should be "uploaded content" diff --git a/tests/acceptance/features/bootstrap/FilesVersionsContext.php b/tests/acceptance/features/bootstrap/FilesVersionsContext.php index a6e0e16ae195..facc0cceb728 100644 --- a/tests/acceptance/features/bootstrap/FilesVersionsContext.php +++ b/tests/acceptance/features/bootstrap/FilesVersionsContext.php @@ -202,6 +202,36 @@ public function theContentLengthOfFileForUserInVersionsFolderIs( ); } + /** + * @When user :user downloads the version of file :path with the index :index + * + * @param string $user + * @param string $path + * @param string $index + * + * @return void + */ + public function downloadVersion(string $user, string $path, string $index) { + $user = $this->featureContext->getActualUsername($user); + $fileId = $this->featureContext->getFileIdForPath($user, $path); + $index = (int)$index; + $responseXml = $this->listVersionFolder($user, $fileId, 1); + + //xpath index starts with 0 and the first reported href is the link to all versions, so need to add 2 here + $xmlPart = $responseXml->xpath("(//d:href)[" . ($index + 2) . "]"); + + // the href already contains the path + $url = WebDavHelper::sanitizeUrl( + $this->featureContext->getBaseUrlWithoutPath() . $xmlPart[0][0] + ); + $response = HttpRequestHelper::get( + $url, + $user, + $this->featureContext->getPasswordForUser($user) + ); + $this->featureContext->setResponse($response); + } + /** * returns the result parsed into an SimpleXMLElement * with an registered namespace with 'd' as prefix and 'DAV:' as namespace