From d7fc2560095e6501dac38dddce84cfa6fc57cf9d Mon Sep 17 00:00:00 2001 From: prashant-gurung899 Date: Wed, 18 Sep 2024 16:39:46 +0545 Subject: [PATCH] add test to download preview with all processors Signed-off-by: prashant-gurung899 --- tests/acceptance/bootstrap/FeatureContext.php | 1 - tests/acceptance/bootstrap/WebDav.php | 52 +++++++++++++++--- .../coreApiWebdavPreviews/previews.feature | 22 ++++++++ tests/acceptance/fixtures/fill.png | Bin 0 -> 874 bytes tests/acceptance/fixtures/fit.png | Bin 0 -> 713 bytes tests/acceptance/fixtures/resize.png | Bin 0 -> 829 bytes tests/acceptance/fixtures/thumbnail.png | Bin 0 -> 874 bytes 7 files changed, 67 insertions(+), 8 deletions(-) create mode 100644 tests/acceptance/fixtures/fill.png create mode 100644 tests/acceptance/fixtures/fit.png create mode 100644 tests/acceptance/fixtures/resize.png create mode 100644 tests/acceptance/fixtures/thumbnail.png 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 0000000000000000000000000000000000000000..7110deebe72065c0cece8986a811e1d237c15921 GIT binary patch literal 874 zcmex=KU|?coW@chxW@Tkz0jjJ8$}zAA zvI;30I#U-U>$dGXcJ4ZK_{h;?$4{I*b?NeztJkjIxOwa0qsLF4K70P+<*SdM zK7aZ8?fZ|PzZe;qA>IL!5Dy{wM-b>ACKeWE7Iu(-7@5j}m|2j8Rnd@5$T5&Tu~1ma zsF6d&Y2w0-2RW6EgFc8R6KQ!#m{`Vr(Mu#brIP!m}`f_n(=pZ~WQc$gW15ymXY zV9)UVSITC0ru?ag))h|nOXFJFd4O4MXZGDZUk9aVO^+jU<}KgG`Q?46#GRSmQ*Om3 z-CS2Qf41Z;`EA(_0&b2c*0FwN7ux7{gIR_#DopCZri{lKpG9UQpTB!vhTreU>Zx|e z3RmB`H#@jX>EYtytv3xAo;2{ko}kV0;#zNo?w*}%Z2Usj*}wc-OE{O_ zJa)9jQhicn=gG(O{Nvc|uIhX%`>uFoBir4cdF?%q**8ksbRFW$e06SC*X%HlXQ`KT zRrX92lYBD6D>T`YsVy{Ab;kU%x3B%9d9^}zTyZH^RA4p~lVHzyP;0k$b>)}cmYlkR vcRZ|{H{>+-Jdt@WBYb}^yVoXN>Dsw&2Np1RNW{&Q<+D!P`rP1&{r{T)&74M2 literal 0 HcmV?d00001 diff --git a/tests/acceptance/fixtures/fit.png b/tests/acceptance/fixtures/fit.png new file mode 100644 index 0000000000000000000000000000000000000000..75ebf39b022461213616c1f315f07025e306ff47 GIT binary patch literal 713 zcmex=s3e1d3 z3`~NI%z}*nk1#G`U|?ir1Oo;rU}R!uVP#|I;N;>KU|?coW@chxW@Tkz0jjJ8$}zAA zvI;30I#U-U>$dGXcJ4ZK_{h;?$4{I*b?NeztJkjIxOwa0qsLF4K70P+<*SdM zK7aZ8?fZ|PzZe;qA>IL!5Dy{wM-b>ACKeWE7Iu(-7@5j}m|2j8Rnd@5$T5&Tu~1ma zsF6d&Y2w0-2RW6EgFc8R6KQ!#m{`Vr(Mu#brIP!m}`f_n(=pZ~WQc$gW15ymXY zV9)UV*YXuvh7rd<%bYs=#3$YUxv9?Uf=C~}1?6``-kH42XWDw|z?=4`LDuDx$10c1 z+m?}M_x7@8R7Ib$w(eoxnZFMt=jN|w3pnM-zEHILZwE`u-&q%@YKU|?coW@chxW@Tkz0jjJ8$}zAA zvI;30I#U-U>$dGXcJ4ZK_{h;?$4{I*b?NeztJkjIxOwa0qsLF4K70P+<*SdM zK7aZ8?fZ|PzZe;qA>IL!5Dy{wM-b>ACKeWE7Iu(-7@5j}m|2j8Rnd@5$T5&Tu~1ma zsF6d&Y2w0-2RW6EgFc8R6KQ!#m{`Vr(Mu#brIP!m}`f_n(=pZ~WQc$gW15ymXY zV9)UVSN5)Bt#_MNNUB_3tsJx8?4$0MgrAd{&o5v}n-yLrTo$e$b?<2TGmg)n%=oH* zU!CKU|?coW@chxW@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