diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Preview/GeneratorTest.php | 81 |
1 files changed, 72 insertions, 9 deletions
diff --git a/tests/lib/Preview/GeneratorTest.php b/tests/lib/Preview/GeneratorTest.php index d2bfcad9955..43f5c1e0d36 100644 --- a/tests/lib/Preview/GeneratorTest.php +++ b/tests/lib/Preview/GeneratorTest.php @@ -256,25 +256,92 @@ class GeneratorTest extends \Test\TestCase { $file = $this->createMock(File::class); $file->method('isReadable') ->willReturn(true); + $file->method('getId') + ->willReturn(42); $this->previewManager->method('isMimeSupported') ->with('invalidType') ->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()) + ->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; + }) + ); + + $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') === 0 && - $event->getArgument('height') === 0 && - $event->getArgument('crop') === true && - $event->getArgument('mode') === IPreview::MODE_COVER; + $event->getArgument('width') === 1024 && + $event->getArgument('height') === 512 && + $event->getArgument('crop') === true && + $event->getArgument('mode') === IPreview::MODE_COVER; }) ); - $this->generator->getPreview($file, 0, 0, true, IPreview::MODE_COVER, 'invalidType'); + $result = $this->generator->getPreview($file, 1024, 512, true, IPreview::MODE_COVER, 'invalidType'); + $this->assertSame($preview, $result); } public function testNoProvider() { @@ -286,10 +353,6 @@ class GeneratorTest extends \Test\TestCase { $file->method('getId') ->willReturn(42); - $this->previewManager->method('isMimeSupported') - ->with($this->equalTo('myMimeType')) - ->willReturn(true); - $previewFolder = $this->createMock(ISimpleFolder::class); $this->appData->method('getFolder') ->with($this->equalTo(42)) |