Merge pull request #20451 from exussum12/AllowPreviewWhenGeneratorHasBeenRemoved
Always try and show pre rendered preview
This commit is contained in:
commit
75c659cfbc
|
@ -126,9 +126,6 @@ class Generator {
|
||||||
if ($mimeType === null) {
|
if ($mimeType === null) {
|
||||||
$mimeType = $file->getMimeType();
|
$mimeType = $file->getMimeType();
|
||||||
}
|
}
|
||||||
if (!$this->previewManager->isMimeSupported($mimeType)) {
|
|
||||||
throw new NotFoundException();
|
|
||||||
}
|
|
||||||
|
|
||||||
$previewFolder = $this->getPreviewFolder($file);
|
$previewFolder = $this->getPreviewFolder($file);
|
||||||
|
|
||||||
|
@ -155,7 +152,7 @@ class Generator {
|
||||||
$crop = $specification['crop'] ?? false;
|
$crop = $specification['crop'] ?? false;
|
||||||
$mode = $specification['mode'] ?? IPreview::MODE_FILL;
|
$mode = $specification['mode'] ?? IPreview::MODE_FILL;
|
||||||
|
|
||||||
// If both width and heigth are -1 we just want the max preview
|
// If both width and height are -1 we just want the max preview
|
||||||
if ($width === -1 && $height === -1) {
|
if ($width === -1 && $height === -1) {
|
||||||
$width = $maxWidth;
|
$width = $maxWidth;
|
||||||
$height = $maxHeight;
|
$height = $maxHeight;
|
||||||
|
@ -176,6 +173,10 @@ class Generator {
|
||||||
try {
|
try {
|
||||||
$preview = $this->getCachedPreview($previewFolder, $width, $height, $crop, $maxPreview->getMimeType(), $previewVersion);
|
$preview = $this->getCachedPreview($previewFolder, $width, $height, $crop, $maxPreview->getMimeType(), $previewVersion);
|
||||||
} catch (NotFoundException $e) {
|
} catch (NotFoundException $e) {
|
||||||
|
if (!$this->previewManager->isMimeSupported($mimeType)) {
|
||||||
|
throw new NotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
if ($maxPreviewImage === null) {
|
if ($maxPreviewImage === null) {
|
||||||
$maxPreviewImage = $this->helper->getImage($maxPreview);
|
$maxPreviewImage = $this->helper->getImage($maxPreview);
|
||||||
}
|
}
|
||||||
|
|
|
@ -256,25 +256,92 @@ class GeneratorTest extends \Test\TestCase {
|
||||||
$file = $this->createMock(File::class);
|
$file = $this->createMock(File::class);
|
||||||
$file->method('isReadable')
|
$file->method('isReadable')
|
||||||
->willReturn(true);
|
->willReturn(true);
|
||||||
|
$file->method('getId')
|
||||||
|
->willReturn(42);
|
||||||
|
|
||||||
$this->previewManager->method('isMimeSupported')
|
$this->previewManager->method('isMimeSupported')
|
||||||
->with('invalidType')
|
->with('invalidType')
|
||||||
->willReturn(false);
|
->willReturn(false);
|
||||||
|
|
||||||
|
$previewFolder = $this->createMock(ISimpleFolder::class);
|
||||||
|
$this->appData->method('getFolder')
|
||||||
|
->with($this->equalTo(42))
|
||||||
|
->willReturn($previewFolder);
|
||||||
|
|
||||||
|
$maxPreview = $this->createMock(ISimpleFile::class);
|
||||||
|
$maxPreview->method('getName')
|
||||||
|
->willReturn('2048-2048-max.png');
|
||||||
|
$maxPreview->method('getMimeType')
|
||||||
|
->willReturn('image/png');
|
||||||
|
|
||||||
|
$previewFolder->method('getDirectoryListing')
|
||||||
|
->willReturn([$maxPreview]);
|
||||||
|
|
||||||
|
$previewFolder->method('getFile')
|
||||||
|
->with($this->equalTo('1024-512-crop.png'))
|
||||||
|
->willThrowException(new NotFoundException());
|
||||||
|
|
||||||
$this->eventDispatcher->expects($this->once())
|
$this->eventDispatcher->expects($this->once())
|
||||||
->method('dispatch')
|
->method('dispatch')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo(IPreview::EVENT),
|
$this->equalTo(IPreview::EVENT),
|
||||||
$this->callback(function (GenericEvent $event) use ($file) {
|
$this->callback(function (GenericEvent $event) use ($file) {
|
||||||
return $event->getSubject() === $file &&
|
return $event->getSubject() === $file &&
|
||||||
$event->getArgument('width') === 0 &&
|
$event->getArgument('width') === 1024 &&
|
||||||
$event->getArgument('height') === 0 &&
|
$event->getArgument('height') === 512 &&
|
||||||
$event->getArgument('crop') === true &&
|
$event->getArgument('crop') === true &&
|
||||||
$event->getArgument('mode') === IPreview::MODE_COVER;
|
$event->getArgument('mode') === IPreview::MODE_COVER;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->generator->getPreview($file, 0, 0, true, IPreview::MODE_COVER, 'invalidType');
|
$this->generator->getPreview($file, 1024, 512, true, IPreview::MODE_COVER, 'invalidType');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testReturnCachedPreviewsWithoutCheckingSupportedMimetype() {
|
||||||
|
$file = $this->createMock(File::class);
|
||||||
|
$file->method('isReadable')
|
||||||
|
->willReturn(true);
|
||||||
|
$file->method('getId')
|
||||||
|
->willReturn(42);
|
||||||
|
|
||||||
|
|
||||||
|
$previewFolder = $this->createMock(ISimpleFolder::class);
|
||||||
|
$this->appData->method('getFolder')
|
||||||
|
->with($this->equalTo(42))
|
||||||
|
->willReturn($previewFolder);
|
||||||
|
|
||||||
|
$maxPreview = $this->createMock(ISimpleFile::class);
|
||||||
|
$maxPreview->method('getName')
|
||||||
|
->willReturn('2048-2048-max.png');
|
||||||
|
$maxPreview->method('getMimeType')
|
||||||
|
->willReturn('image/png');
|
||||||
|
|
||||||
|
$previewFolder->method('getDirectoryListing')
|
||||||
|
->willReturn([$maxPreview]);
|
||||||
|
|
||||||
|
$preview = $this->createMock(ISimpleFile::class);
|
||||||
|
$previewFolder->method('getFile')
|
||||||
|
->with($this->equalTo('1024-512-crop.png'))
|
||||||
|
->willReturn($preview);
|
||||||
|
|
||||||
|
$this->previewManager->expects($this->never())
|
||||||
|
->method('isMimeSupported');
|
||||||
|
|
||||||
|
$this->eventDispatcher->expects($this->once())
|
||||||
|
->method('dispatch')
|
||||||
|
->with(
|
||||||
|
$this->equalTo(IPreview::EVENT),
|
||||||
|
$this->callback(function (GenericEvent $event) use ($file) {
|
||||||
|
return $event->getSubject() === $file &&
|
||||||
|
$event->getArgument('width') === 1024 &&
|
||||||
|
$event->getArgument('height') === 512 &&
|
||||||
|
$event->getArgument('crop') === true &&
|
||||||
|
$event->getArgument('mode') === IPreview::MODE_COVER;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
$result = $this->generator->getPreview($file, 1024, 512, true, IPreview::MODE_COVER, 'invalidType');
|
||||||
|
$this->assertSame($preview, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNoProvider() {
|
public function testNoProvider() {
|
||||||
|
@ -286,10 +353,6 @@ class GeneratorTest extends \Test\TestCase {
|
||||||
$file->method('getId')
|
$file->method('getId')
|
||||||
->willReturn(42);
|
->willReturn(42);
|
||||||
|
|
||||||
$this->previewManager->method('isMimeSupported')
|
|
||||||
->with($this->equalTo('myMimeType'))
|
|
||||||
->willReturn(true);
|
|
||||||
|
|
||||||
$previewFolder = $this->createMock(ISimpleFolder::class);
|
$previewFolder = $this->createMock(ISimpleFolder::class);
|
||||||
$this->appData->method('getFolder')
|
$this->appData->method('getFolder')
|
||||||
->with($this->equalTo(42))
|
->with($this->equalTo(42))
|
||||||
|
|
Loading…
Reference in New Issue