diff --git a/tests/acceptance/bootstrap/FeatureContext.php b/tests/acceptance/bootstrap/FeatureContext.php index 692f93dbd..9d6070bf6 100644 --- a/tests/acceptance/bootstrap/FeatureContext.php +++ b/tests/acceptance/bootstrap/FeatureContext.php @@ -145,7 +145,6 @@ class FeatureContext extends BehatVariablesContext { private int $ocsApiVersion = 1; private ?ResponseInterface $response = null; private string $responseUser = ''; - private ?string $responseBodyContent = null; public array $emailRecipients = []; private CookieJar $cookieJar; private string $requestToken; diff --git a/tests/acceptance/bootstrap/WebDav.php b/tests/acceptance/bootstrap/WebDav.php index 78496558d..23bcf561f 100644 --- a/tests/acceptance/bootstrap/WebDav.php +++ b/tests/acceptance/bootstrap/WebDav.php @@ -3741,6 +3741,40 @@ trait WebDav { } } + /** + * @When user :user downloads the preview of :path with width :width and height :height and processor :processor using the WebDAV API + * + * @param string $user + * @param string $path + * @param string $width + * @param string $height + * @param string $processor + * + * @return void + */ + public function userDownloadsThePreviewOfWithWidthHeightProcessorUsingWebDAVAPI(string $user, string $path, string $width, string $height, string $processor): void { + $user = $this->getActualUsername($user); + $urlParameter = [ + 'x' => $width, + 'y' => $height, + 'preview' => '1', + 'processor' => $processor + ]; + $response = $this->makeDavRequest( + $user, + "GET", + $path, + [], + null, + "files", + null, + false, + null, + $urlParameter, + ); + $this->setResponse($response); + } + /** * @Given user :user has downloaded the preview of shared resource :path with width :width and height :height * @@ -3760,8 +3794,9 @@ trait WebDav { $this->setResponse($response); $this->theHTTPStatusCodeShouldBe(200, '', $response); $this->checkImageDimensions($width, $height); + $response->getBody()->rewind(); // save response to user response dictionary for further comparisons - $this->userResponseBodyContents[$user] = $this->responseBodyContent; + $this->userResponseBodyContents[$user] = $response->getBody()->getContents(); } /** @@ -3953,10 +3988,9 @@ trait WebDav { */ public function checkImageDimensions(string $width, string $height, ?ResponseInterface $response = null) : void { $response = $response ?? $this->getResponse(); - if ($this->responseBodyContent === null) { - $this->responseBodyContent = $response->getBody()->getContents(); - } - $size = \getimagesizefromstring($this->responseBodyContent); + $response->getBody()->rewind(); + $responseBodyContent = $response->getBody()->getContents(); + $size = \getimagesizefromstring($responseBodyContent); Assert::assertNotFalse($size, "could not get size of image"); Assert::assertEquals($width, $size[0], "width not as expected"); Assert::assertEquals($height, $size[1], "height not as expected"); @@ -3972,7 +4006,10 @@ trait WebDav { */ public function theDownloadedPreviewContentShouldMatchWithFixturesPreviewContentFor(string $filename):void { $expectedPreview = \file_get_contents(__DIR__ . "/../fixtures/" . $filename); - Assert::assertEquals($expectedPreview, $this->responseBodyContent); + $response = $response ?? $this->getResponse(); + $response->getBody()->rewind(); + $responseBodyContent = $response->getBody()->getContents(); + Assert::assertEquals($expectedPreview, $responseBodyContent); } /** @@ -3995,8 +4032,9 @@ trait WebDav { ); $this->theHTTPStatusCodeShouldBe(200, "", $response); $this->checkImageDimensions($width, $height, $response); + $response->getBody()->rewind(); // save response to user response dictionary for further comparisons - $this->userResponseBodyContents[$user] = $this->responseBodyContent; + $this->userResponseBodyContents[$user] = $response->getBody()->getContents(); } /** diff --git a/tests/acceptance/features/coreApiWebdavPreviews/previews.feature b/tests/acceptance/features/coreApiWebdavPreviews/previews.feature index dcb2807a9..9f0d18c44 100644 --- a/tests/acceptance/features/coreApiWebdavPreviews/previews.feature +++ b/tests/acceptance/features/coreApiWebdavPreviews/previews.feature @@ -344,3 +344,25 @@ Feature: previews of files downloaded through the webdav API | old | | new | | spaces | + + + Scenario Outline: download previews of an image with different processors + Given using DAV path + And user "Alice" has uploaded file "filesForUpload/testavatar.jpg" to "/testimage.jpg" + When user "Alice" downloads the preview of "/testimage.jpg" with width "32" and height "32" and processor using the WebDAV API + Then the HTTP status code should be "200" + And the downloaded preview content should match with fixtures preview content + Examples: + | dav-path-version | processor | expected-image | + | old | fit | fit.png | + | old | fill | fill.png | + | old | resize | resize.png | + | old | thumbnail | thumbnail.png | + | new | fit | fit.png | + | new | fill | fill.png | + | new | resize | resize.png | + | new | thumbnail | thumbnail.png | + | spaces | fit | fit.png | + | spaces | fill | fill.png | + | spaces | resize | resize.png | + | spaces | thumbnail | thumbnail.png | diff --git a/tests/acceptance/fixtures/fill.png b/tests/acceptance/fixtures/fill.png new file mode 100644 index 000000000..7110deebe Binary files /dev/null and b/tests/acceptance/fixtures/fill.png differ diff --git a/tests/acceptance/fixtures/fit.png b/tests/acceptance/fixtures/fit.png new file mode 100644 index 000000000..75ebf39b0 Binary files /dev/null and b/tests/acceptance/fixtures/fit.png differ diff --git a/tests/acceptance/fixtures/resize.png b/tests/acceptance/fixtures/resize.png new file mode 100644 index 000000000..8dad978da Binary files /dev/null and b/tests/acceptance/fixtures/resize.png differ diff --git a/tests/acceptance/fixtures/thumbnail.png b/tests/acceptance/fixtures/thumbnail.png new file mode 100644 index 000000000..7110deebe Binary files /dev/null and b/tests/acceptance/fixtures/thumbnail.png differ