diff options
author | Morris Jobke <hey@morrisjobke.de> | 2020-08-13 23:24:21 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2020-08-13 23:24:21 +0200 |
commit | 8e249569af23fc461c109ec3a1abcc382c09d7d7 (patch) | |
tree | eaff7f83c057f7306f385b9319e7d6f72cdc2f68 /tests | |
parent | b12a390220a0a38ec18557b52c2eec7cf25dfc49 (diff) | |
download | nextcloud-server-8e249569af23fc461c109ec3a1abcc382c09d7d7.tar.gz nextcloud-server-8e249569af23fc461c109ec3a1abcc382c09d7d7.zip |
Fix existing test and add a specific one for the new case
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
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)) |