diff --git a/tests/acceptance/features/bootstrap/FilesVersionsContext.php b/tests/acceptance/features/bootstrap/FilesVersionsContext.php index b18f2591e..9959515c0 100644 --- a/tests/acceptance/features/bootstrap/FilesVersionsContext.php +++ b/tests/acceptance/features/bootstrap/FilesVersionsContext.php @@ -134,17 +134,14 @@ class FilesVersionsContext implements Context { } /** - * @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 - * * @param string $user * @param int $versionIndex * @param string $path * - * @return void + * @return ResponseInterface * @throws Exception */ - public function userRestoresVersionIndexOfFile(string $user, int $versionIndex, string $path):void { + public function restoreVersionIndexOfFile(string $user, int $versionIndex, string $path):ResponseInterface { $user = $this->featureContext->getActualUsername($user); $fileId = $this->featureContext->getFileIdForPath($user, $path); Assert::assertNotNull($fileId, __METHOD__ . " fileid of file $path user $user not found (the file may not exist)"); @@ -155,7 +152,7 @@ class FilesVersionsContext implements Context { WebDavHelper::getDavPath($user, 2) . \trim($path, "/"); $fullUrl = $this->featureContext->getBaseUrlWithoutPath() . $xmlPart[$versionIndex]; - $response = HttpRequestHelper::sendRequest( + return HttpRequestHelper::sendRequest( $fullUrl, $this->featureContext->getStepLineRef(), 'COPY', @@ -163,6 +160,35 @@ class FilesVersionsContext implements Context { $this->featureContext->getPasswordForUser($user), ['Destination' => $destinationUrl] ); + } + + /** + * @Given user :user has restored version index :versionIndex of file :path + * + * @param string $user + * @param int $versionIndex + * @param string $path + * + * @return void + * @throws Exception + */ + public function userHasRestoredVersionIndexOfFile(string $user, int $versionIndex, string $path):void { + $response = $this->restoreVersionIndexOfFile($user, $versionIndex, $path); + $this->featureContext->theHTTPStatusCodeShouldBe(204, "", $response); + } + + /** + * @When user :user restores version index :versionIndex of file :path using the WebDAV API + * + * @param string $user + * @param int $versionIndex + * @param string $path + * + * @return void + * @throws Exception + */ + public function userRestoresVersionIndexOfFile(string $user, int $versionIndex, string $path):void { + $response = $this->restoreVersionIndexOfFile($user, $versionIndex, $path); $this->featureContext->setResponse($response, $user); } @@ -280,16 +306,14 @@ class FilesVersionsContext implements Context { } /** - * @When user :user downloads the version of file :path with the index :index - * * @param string $user * @param string $path * @param string $index * - * @return void + * @return ResponseInterface * @throws Exception */ - public function downloadVersion(string $user, string $path, string $index):void { + public function downloadVersion(string $user, string $path, string $index):ResponseInterface { $user = $this->featureContext->getActualUsername($user); $fileId = $this->featureContext->getFileIdForPath($user, $path); Assert::assertNotNull($fileId, __METHOD__ . " fileid of file $path user $user not found (the file may not exist)"); @@ -305,13 +329,26 @@ class FilesVersionsContext implements Context { $url = WebDavHelper::sanitizeUrl( $this->featureContext->getBaseUrlWithoutPath() . $xmlPart[$index] ); - $response = HttpRequestHelper::get( + return HttpRequestHelper::get( $url, $this->featureContext->getStepLineRef(), $user, $this->featureContext->getPasswordForUser($user) ); - $this->featureContext->setResponse($response, $user); + } + + /** + * @When user :user downloads the version of file :path with the index :index + * + * @param string $user + * @param string $path + * @param string $index + * + * @return void + * @throws Exception + */ + public function userDownloadsVersion(string $user, string $path, string $index):void { + $this->featureContext->setResponse($this->downloadVersion($user, $path, $index), $user); } /** @@ -331,9 +368,9 @@ class FilesVersionsContext implements Context { string $user, string $content ): void { - $this->downloadVersion($user, $path, $index); - $this->featureContext->theHTTPStatusCodeShouldBe("200"); - $this->featureContext->downloadedContentShouldBe($content); + $response = $this->downloadVersion($user, $path, $index); + $this->featureContext->theHTTPStatusCodeShouldBe("200", '', $response); + $this->featureContext->checkDownloadedContentMatches($content, '', $response); } /** diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index cc34c07e6..bed6ba653 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -2673,7 +2673,7 @@ class SpacesContext implements Context { string $spaceName ): void { $this->setSpaceIDByName($user, $spaceName); - $this->filesVersionsContext->downloadVersion($user, $fileName, $index); + $this->featureContext->setResponse($this->filesVersionsContext->downloadVersion($user, $fileName, $index)); WebDavHelper::$SPACE_ID_FROM_OCIS = ''; } diff --git a/tests/acceptance/features/bootstrap/WebDav.php b/tests/acceptance/features/bootstrap/WebDav.php index 1e5809cb6..710b2d1f1 100644 --- a/tests/acceptance/features/bootstrap/WebDav.php +++ b/tests/acceptance/features/bootstrap/WebDav.php @@ -455,9 +455,9 @@ trait WebDav { * @param string|null $width * @param string|null $height * - * @return void + * @return ResponseInterface */ - public function downloadPreviews(string $user, ?string $path, ?string $doDavRequestAsUser, ?string $width, ?string $height):void { + public function downloadPreviews(string $user, ?string $path, ?string $doDavRequestAsUser, ?string $width, ?string $height):ResponseInterface { $user = $this->getActualUsername($user); $doDavRequestAsUser = $this->getActualUsername($doDavRequestAsUser); $urlParameter = [ @@ -466,7 +466,7 @@ trait WebDav { 'forceIcon' => '0', 'preview' => '1' ]; - $this->response = $this->makeDavRequest( + return $this->makeDavRequest( $user, "GET", $path, @@ -1053,14 +1053,17 @@ trait WebDav { /** * @param string $expectedContent * @param string $extraErrorText + * @param ResponseInterface|null $response * * @return void */ public function checkDownloadedContentMatches( string $expectedContent, - string $extraErrorText = "" + string $extraErrorText = "", + ?ResponseInterface $response = null ):void { - $actualContent = (string) $this->response->getBody(); + $response = $response ?? $this->response; + $actualContent = (string) $response->getBody(); // For this test we really care about the content. // A separate "Then" step can specifically check the HTTP status. // But if the content is wrong (e.g. empty) then it is useful to @@ -4637,13 +4640,14 @@ trait WebDav { * @return void */ public function downloadPreviewOfFiles(string $user, string $path, string $width, string $height):void { - $this->downloadPreviews( + $response = $this->downloadPreviews( $user, $path, null, $width, $height ); + $this->setResponse($response); } /** @@ -4658,13 +4662,14 @@ trait WebDav { * @return void */ public function downloadPreviewOfOtherUser(string $user1, string $path, string $doDavRequestAsUser, string $width, string $height):void { - $this->downloadPreviews( + $response = $this->downloadPreviews( $user1, $path, $doDavRequestAsUser, $width, $height ); + $this->setResponse($response); } /**