]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix existing test and add a specific one for the new case 20451/head
authorMorris Jobke <hey@morrisjobke.de>
Thu, 13 Aug 2020 21:24:21 +0000 (23:24 +0200)
committerMorris Jobke <hey@morrisjobke.de>
Thu, 13 Aug 2020 21:24:21 +0000 (23:24 +0200)
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
tests/lib/Preview/GeneratorTest.php

index d2bfcad9955f807ce37a039070c0cad7a9c2c2ba..43f5c1e0d365abb66b406b2495d2011018587fae 100644 (file)
@@ -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))