Skip to content

Commit

Permalink
Merge pull request #10134 from owncloud/tests-preview-with-all-proces…
Browse files Browse the repository at this point in the history
…sors

[tests-only][full-ci] add test to download preview of an image with all available processors
  • Loading branch information
prashant-gurung899 authored Sep 26, 2024
2 parents 854dbcf + d7fc256 commit 775c597
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 8 deletions.
1 change: 0 additions & 1 deletion tests/acceptance/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
52 changes: 45 additions & 7 deletions tests/acceptance/bootstrap/WebDav.php
Original file line number Diff line number Diff line change
Expand Up @@ -3741,6 +3741,40 @@ public function userDownloadsThePreviewOfSharedResourceWithWidthAndHeightUsingTh
}
}

/**
* @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
*
Expand All @@ -3760,8 +3794,9 @@ public function userHasDownloadedThePreviewOfSharedResourceWithWidthAndHeight(st
$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();
}

/**
Expand Down Expand Up @@ -3953,10 +3988,9 @@ public function imageDimensionsShouldBe(string $width, string $height): void {
*/
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");
Expand All @@ -3972,7 +4006,10 @@ public function checkImageDimensions(string $width, string $height, ?ResponseInt
*/
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);
}

/**
Expand All @@ -3995,8 +4032,9 @@ public function userDownloadsThePreviewOfWithWidthAndHeight(string $user, string
);
$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();
}

/**
Expand Down
22 changes: 22 additions & 0 deletions tests/acceptance/features/coreApiWebdavPreviews/previews.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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-version> 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 <processor> using the WebDAV API
Then the HTTP status code should be "200"
And the downloaded preview content should match with <expected-image> 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 |
Binary file added tests/acceptance/fixtures/fill.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/acceptance/fixtures/fit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/acceptance/fixtures/resize.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/acceptance/fixtures/thumbnail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 775c597

Please sign in to comment.