diff options
author | Julius Härtl <jus@bitgrid.net> | 2022-10-25 12:53:10 +0200 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2022-10-27 14:31:33 +0200 |
commit | 07e94eca6f9fc8ea0bc814d90f6b1403bb9f707a (patch) | |
tree | f37c009a79e42642ed00e53eec83a4f490b1b600 /tests | |
parent | 8ee76c0d89c02dd359640deea53bb789bb982aca (diff) | |
download | nextcloud-server-07e94eca6f9fc8ea0bc814d90f6b1403bb9f707a.tar.gz nextcloud-server-07e94eca6f9fc8ea0bc814d90f6b1403bb9f707a.zip |
Emit typed event when preview is requested
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Preview/GeneratorTest.php | 47 |
1 files changed, 39 insertions, 8 deletions
diff --git a/tests/lib/Preview/GeneratorTest.php b/tests/lib/Preview/GeneratorTest.php index 1e38afd7744..0dec1aaafa8 100644 --- a/tests/lib/Preview/GeneratorTest.php +++ b/tests/lib/Preview/GeneratorTest.php @@ -25,6 +25,7 @@ namespace Test\Preview; use OC\Preview\Generator; use OC\Preview\GeneratorHelper; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\File; use OCP\Files\IAppData; use OCP\Files\NotFoundException; @@ -32,6 +33,7 @@ use OCP\Files\SimpleFS\ISimpleFile; use OCP\Files\SimpleFS\ISimpleFolder; use OCP\IConfig; use OCP\IPreview; +use OCP\Preview\BeforePreviewFetchedEvent; use OCP\Preview\IProviderV2; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\GenericEvent; @@ -50,9 +52,12 @@ class GeneratorTest extends \Test\TestCase { /** @var GeneratorHelper|\PHPUnit\Framework\MockObject\MockObject */ private $helper; - /** @var EventDispatcherInterface|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */ private $eventDispatcher; + /** @var EventDispatcherInterface|\PHPUnit\Framework\MockObject\MockObject */ + private $legacyEventDispatcher; + /** @var Generator */ private $generator; @@ -63,13 +68,15 @@ class GeneratorTest extends \Test\TestCase { $this->previewManager = $this->createMock(IPreview::class); $this->appData = $this->createMock(IAppData::class); $this->helper = $this->createMock(GeneratorHelper::class); - $this->eventDispatcher = $this->createMock(EventDispatcherInterface::class); + $this->eventDispatcher = $this->createMock(IEventDispatcher::class); + $this->legacyEventDispatcher = $this->createMock(EventDispatcherInterface::class); $this->generator = new Generator( $this->config, $this->previewManager, $this->appData, $this->helper, + $this->legacyEventDispatcher, $this->eventDispatcher ); } @@ -109,7 +116,7 @@ class GeneratorTest extends \Test\TestCase { ->with($this->equalTo('256-256.png')) ->willReturn($previewFile); - $this->eventDispatcher->expects($this->once()) + $this->legacyEventDispatcher->expects($this->once()) ->method('dispatch') ->with( $this->equalTo(IPreview::EVENT), @@ -120,6 +127,10 @@ class GeneratorTest extends \Test\TestCase { }) ); + $this->eventDispatcher->expects($this->once()) + ->method('dispatchTyped') + ->with(new BeforePreviewFetchedEvent($file)); + $result = $this->generator->getPreview($file, 100, 100); $this->assertSame($previewFile, $result); } @@ -239,7 +250,7 @@ class GeneratorTest extends \Test\TestCase { ->method('putContent') ->with('my resized data'); - $this->eventDispatcher->expects($this->once()) + $this->legacyEventDispatcher->expects($this->once()) ->method('dispatch') ->with( $this->equalTo(IPreview::EVENT), @@ -250,6 +261,10 @@ class GeneratorTest extends \Test\TestCase { }) ); + $this->eventDispatcher->expects($this->once()) + ->method('dispatchTyped') + ->with(new BeforePreviewFetchedEvent($file)); + $result = $this->generator->getPreview($file, 100, 100); $this->assertSame($previewFile, $result); } @@ -285,7 +300,7 @@ class GeneratorTest extends \Test\TestCase { ->with($this->equalTo('1024-512-crop.png')) ->willThrowException(new NotFoundException()); - $this->eventDispatcher->expects($this->once()) + $this->legacyEventDispatcher->expects($this->once()) ->method('dispatch') ->with( $this->equalTo(IPreview::EVENT), @@ -298,6 +313,10 @@ class GeneratorTest extends \Test\TestCase { }) ); + $this->eventDispatcher->expects($this->once()) + ->method('dispatchTyped') + ->with(new BeforePreviewFetchedEvent($file)); + $this->generator->getPreview($file, 1024, 512, true, IPreview::MODE_COVER, 'invalidType'); } @@ -333,7 +352,7 @@ class GeneratorTest extends \Test\TestCase { $this->previewManager->expects($this->never()) ->method('isMimeSupported'); - $this->eventDispatcher->expects($this->once()) + $this->legacyEventDispatcher->expects($this->once()) ->method('dispatch') ->with( $this->equalTo(IPreview::EVENT), @@ -346,6 +365,10 @@ class GeneratorTest extends \Test\TestCase { }) ); + $this->eventDispatcher->expects($this->once()) + ->method('dispatchTyped') + ->with(new BeforePreviewFetchedEvent($file)); + $result = $this->generator->getPreview($file, 1024, 512, true, IPreview::MODE_COVER, 'invalidType'); $this->assertSame($preview, $result); } @@ -370,7 +393,7 @@ class GeneratorTest extends \Test\TestCase { $this->previewManager->method('getProviders') ->willReturn([]); - $this->eventDispatcher->expects($this->once()) + $this->legacyEventDispatcher->expects($this->once()) ->method('dispatch') ->with( $this->equalTo(IPreview::EVENT), @@ -381,6 +404,10 @@ class GeneratorTest extends \Test\TestCase { }) ); + $this->eventDispatcher->expects($this->once()) + ->method('dispatchTyped') + ->with(new BeforePreviewFetchedEvent($file)); + $this->expectException(NotFoundException::class); $this->generator->getPreview($file, 100, 100); } @@ -502,7 +529,7 @@ class GeneratorTest extends \Test\TestCase { ->with($this->equalTo($filename)) ->willReturn($preview); - $this->eventDispatcher->expects($this->once()) + $this->legacyEventDispatcher->expects($this->once()) ->method('dispatch') ->with( $this->equalTo(IPreview::EVENT), @@ -515,6 +542,10 @@ class GeneratorTest extends \Test\TestCase { }) ); + $this->eventDispatcher->expects($this->once()) + ->method('dispatchTyped') + ->with(new BeforePreviewFetchedEvent($file)); + $result = $this->generator->getPreview($file, $reqX, $reqY, $crop, $mode); if ($expectedX === $maxX && $expectedY === $maxY) { $this->assertSame($maxPreview, $result); |