Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2020-04-10 16:57:06 +0300
committerGitHub <noreply@github.com>2020-04-10 16:57:06 +0300
commiteba3726e1e1b7ce0a98df4552cfdecfe05e0d63a (patch)
tree7d50a939305460fbb34078c1da49f992552747e7 /tests/lib/Preview
parentedf8ce32cffdb920e8171207b342abbd7f1fbe73 (diff)
parent8f9bac26f874e105c017de2b1791b23c2a135b28 (diff)
Merge pull request #19495 from nextcloud/preview-generate-batch
optimize batch generation of previews
Diffstat (limited to 'tests/lib/Preview')
-rw-r--r--tests/lib/Preview/GeneratorTest.php37
1 files changed, 23 insertions, 14 deletions
diff --git a/tests/lib/Preview/GeneratorTest.php b/tests/lib/Preview/GeneratorTest.php
index 919f7198c08..bfe464f785b 100644
--- a/tests/lib/Preview/GeneratorTest.php
+++ b/tests/lib/Preview/GeneratorTest.php
@@ -227,19 +227,11 @@ class GeneratorTest extends \Test\TestCase {
->with($this->equalTo('256-256.png'))
->willThrowException(new NotFoundException());
- $image = $this->createMock(IImage::class);
+ $image = $this->getMockImage(2048, 2048, 'my resized data');
$this->helper->method('getImage')
->with($this->equalTo($maxPreview))
->willReturn($image);
- $image->expects($this->once())
- ->method('resize')
- ->with(256);
- $image->method('data')
- ->willReturn('my resized data');
- $image->method('valid')->willReturn(true);
- $image->method('dataMimeType')->willReturn('image/png');
-
$previewFile->expects($this->once())
->method('putContent')
->with('my resized data');
@@ -325,6 +317,27 @@ class GeneratorTest extends \Test\TestCase {
$this->generator->getPreview($file, 100, 100);
}
+ private function getMockImage($width, $height, $data = null) {
+ $image = $this->createMock(IImage::class);
+ $image->method('height')->willReturn($width);
+ $image->method('width')->willReturn($height);
+ $image->method('valid')->willReturn(true);
+ $image->method('dataMimeType')->willReturn('image/png');
+ $image->method('data')->willReturn($data);
+
+ $image->method('resizeCopy')->willReturnCallback(function($size) use ($data) {
+ return $this->getMockImage($size, $size, $data);
+ });
+ $image->method('preciseResizeCopy')->willReturnCallback(function($width, $height) use ($data) {
+ return $this->getMockImage($width, $height, $data);
+ });
+ $image->method('cropCopy')->willReturnCallback(function($x, $y, $width, $height) use ($data) {
+ return $this->getMockImage($width, $height, $data);
+ });
+
+ return $image;
+ }
+
public function dataSize() {
return [
[1024, 2048, 512, 512, false, IPreview::MODE_FILL, 256, 512],
@@ -409,14 +422,10 @@ class GeneratorTest extends \Test\TestCase {
->with($this->equalTo($filename))
->willThrowException(new NotFoundException());
- $image = $this->createMock(IImage::class);
+ $image = $this->getMockImage($maxX, $maxY);
$this->helper->method('getImage')
->with($this->equalTo($maxPreview))
->willReturn($image);
- $image->method('height')->willReturn($maxY);
- $image->method('width')->willReturn($maxX);
- $image->method('valid')->willReturn(true);
- $image->method('dataMimeType')->willReturn('image/png');
$preview = $this->createMock(ISimpleFile::class);
$previewFolder->method('newFile')