]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix preview generation tests 19495/head
authorRobin Appelman <robin@icewind.nl>
Thu, 9 Apr 2020 13:59:18 +0000 (15:59 +0200)
committerRobin Appelman <robin@icewind.nl>
Fri, 10 Apr 2020 11:39:45 +0000 (13:39 +0200)
Signed-off-by: Robin Appelman <robin@icewind.nl>
lib/private/Preview/Generator.php
tests/lib/Preview/GeneratorTest.php

index eedf80d8522a854fe46962661dc6e0151780555b..cf57f9474f1b4c0f552e5aa203c7897c7a35178e 100644 (file)
@@ -182,7 +182,7 @@ class Generator {
                                        $preview = $this->generatePreview($previewFolder, $maxPreviewImage, $width, $height, $crop, $maxWidth, $maxHeight, $previewVersion);
                                }
                        } catch (\InvalidArgumentException $e) {
-                               throw new NotFoundException();
+                               throw new NotFoundException("", 0, $e);
                        }
 
                        if ($preview->getSize() === 0) {
@@ -478,7 +478,7 @@ class Generator {
                        case 'image/gif':
                                return 'gif';
                        default:
-                               throw new \InvalidArgumentException('Not a valid mimetype');
+                               throw new \InvalidArgumentException('Not a valid mimetype: "' . $mimeType . '"');
                }
        }
 }
index ae84d8eb4b33c7500d4e3d56e25fd8d9c256410e..cc14e78087cde377cfa5dd62255ea48cab666adc 100644 (file)
@@ -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')