Skip to content

Commit

Permalink
fix preview generation tests
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Apr 9, 2020
1 parent 7d38687 commit 1388357
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/private/Preview/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public function generatePreviews(File $file, array $specifications, $mimeType =
$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) {
Expand Down Expand Up @@ -478,7 +478,7 @@ private function getExtention($mimeType) {
case 'image/gif':
return 'gif';
default:
throw new \InvalidArgumentException('Not a valid mimetype');
throw new \InvalidArgumentException('Not a valid mimetype: "' . $mimeType . '"');
}
}
}
26 changes: 21 additions & 5 deletions tests/lib/Preview/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,26 @@ public function testNoProvider() {
$this->generator->getPreview($file, 100, 100);
}

private function getMockImage($width, $height) {
$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('resizeCopy')->willReturnCallback(function($size) {
return $this->getMockImage($size, $size);
});
$image->method('preciseResizeCopy')->willReturnCallback(function($width, $height) {
return $this->getMockImage($width, $height);
});
$image->method('cropCopy')->willReturnCallback(function($x, $y, $width, $height) {
return $this->getMockImage($width, $height);
});

return $image;
}

public function dataSize() {
return [
[1024, 2048, 512, 512, false, IPreview::MODE_FILL, 256, 512],
Expand Down Expand Up @@ -409,14 +429,10 @@ public function testCorrectSize($maxX, $maxY, $reqX, $reqY, $crop, $mode, $expec
->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')
Expand Down

0 comments on commit 1388357

Please sign in to comment.