diff options
Diffstat (limited to 'apps/theming/tests/ImageManagerTest.php')
-rw-r--r-- | apps/theming/tests/ImageManagerTest.php | 67 |
1 files changed, 57 insertions, 10 deletions
diff --git a/apps/theming/tests/ImageManagerTest.php b/apps/theming/tests/ImageManagerTest.php index 4e258ce7162..38f5fb04969 100644 --- a/apps/theming/tests/ImageManagerTest.php +++ b/apps/theming/tests/ImageManagerTest.php @@ -24,8 +24,11 @@ namespace OCA\Theming\Tests; use OCA\Theming\ImageManager; +use OCA\Theming\ThemingDefaults; use OCP\Files\SimpleFS\ISimpleFile; +use OCP\ICacheFactory; use OCP\IConfig; +use OCP\ILogger; use OCP\IURLGenerator; use Test\TestCase; use OCP\Files\SimpleFS\ISimpleFolder; @@ -42,19 +45,40 @@ class ImageManagerTest extends TestCase { protected $imageManager; /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */ private $urlGenerator; + /** @var ICacheFactory|\PHPUnit_Framework_MockObject_MockObject */ + private $cacheFactory; + /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */ + private $logger; protected function setUp() { parent::setUp(); $this->config = $this->createMock(IConfig::class); $this->appData = $this->createMock(IAppData::class); $this->urlGenerator = $this->createMock(IURLGenerator::class); + $this->cacheFactory = $this->createMock(ICacheFactory::class); + $this->logger = $this->createMock(ILogger::class); $this->imageManager = new ImageManager( $this->config, $this->appData, - $this->urlGenerator + $this->urlGenerator, + $this->cacheFactory, + $this->logger ); } + private function checkImagick() { + if(!extension_loaded('imagick')) { + $this->markTestSkipped('Imagemagick is required for dynamic icon generation.'); + } + $checkImagick = new \Imagick(); + if (empty($checkImagick->queryFormats('SVG'))) { + $this->markTestSkipped('No SVG provider present.'); + } + if (empty($checkImagick->queryFormats('PNG'))) { + $this->markTestSkipped('No PNG provider present.'); + } + } + public function mockGetImage($key, $file) { /** @var \PHPUnit_Framework_MockObject_MockObject $folder */ $folder = $this->createMock(ISimpleFolder::class); @@ -64,10 +88,28 @@ class ImageManagerTest extends TestCase { ->with('logo') ->willThrowException(new NotFoundException()); } else { - $folder->expects($this->once()) + $file->expects($this->once()) + ->method('getContent') + ->willReturn(file_get_contents(__DIR__ . '/../../../tests/data/testimage.png')); + $folder->expects($this->at(0)) + ->method('fileExists') + ->with('logo') + ->willReturn(true); + $folder->expects($this->at(1)) + ->method('fileExists') + ->with('logo.png') + ->willReturn(false); + $folder->expects($this->at(2)) ->method('getFile') ->with('logo') ->willReturn($file); + $newFile = $this->createMock(ISimpleFile::class); + $folder->expects($this->at(3)) + ->method('newFile') + ->with('logo.png') + ->willReturn($newFile); + $newFile->expects($this->once()) + ->method('putContent'); $this->appData->expects($this->once()) ->method('getFolder') ->with('images') @@ -76,19 +118,20 @@ class ImageManagerTest extends TestCase { } public function testGetImageUrl() { + $this->checkImagick(); $file = $this->createMock(ISimpleFile::class); $this->config->expects($this->exactly(2)) ->method('getAppValue') ->withConsecutive( ['theming', 'cachebuster', '0'], - ['theming', 'logoMime', false] + ['theming', 'logoMime', ''] ) ->willReturn(0); $this->mockGetImage('logo', $file); $this->urlGenerator->expects($this->once()) ->method('linkToRoute') ->willReturn('url-to-image'); - $this->assertEquals('url-to-image?v=0', $this->imageManager->getImageUrl('logo')); + $this->assertEquals('url-to-image?v=0', $this->imageManager->getImageUrl('logo', false)); } public function testGetImageUrlDefault() { @@ -107,33 +150,37 @@ class ImageManagerTest extends TestCase { } public function testGetImageUrlAbsolute() { + $this->checkImagick(); $file = $this->createMock(ISimpleFile::class); $this->config->expects($this->exactly(2)) ->method('getAppValue') ->withConsecutive( ['theming', 'cachebuster', '0'], - ['theming', 'logoMime', false] + ['theming', 'logoMime', ''] ) ->willReturn(0); $this->mockGetImage('logo', $file); $this->urlGenerator->expects($this->at(0)) - ->method('linkToRoute') - ->willReturn('url-to-image'); + ->method('getBaseUrl') + ->willReturn('baseurl'); $this->urlGenerator->expects($this->at(1)) ->method('getAbsoluteUrl') - ->with('url-to-image?v=0') ->willReturn('url-to-image-absolute?v=0'); - $this->assertEquals('url-to-image-absolute?v=0', $this->imageManager->getImageUrlAbsolute('logo')); + $this->urlGenerator->expects($this->at(2)) + ->method('getAbsoluteUrl') + ->willReturn('url-to-image-absolute?v=0'); + $this->assertEquals('url-to-image-absolute?v=0', $this->imageManager->getImageUrlAbsolute('logo', false)); } public function testGetImage() { + $this->checkImagick(); $this->config->expects($this->once()) ->method('getAppValue')->with('theming', 'logoMime', false) ->willReturn('png'); $file = $this->createMock(ISimpleFile::class); $this->mockGetImage('logo', $file); - $this->assertEquals($file, $this->imageManager->getImage('logo')); + $this->assertEquals($file, $this->imageManager->getImage('logo', false)); } /** |