diff options
author | Julius Härtl <jus@bitgrid.net> | 2018-05-08 12:40:20 +0200 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2018-06-05 16:47:38 +0200 |
commit | 9b919245f67f5511d6be7910f61d639b290eab26 (patch) | |
tree | 51dc22ed31709c7e78af630de298b548dba3f863 /apps/theming/tests | |
parent | 4a5826cddb19c8a3cd8c112eea29d87630591293 (diff) | |
download | nextcloud-server-9b919245f67f5511d6be7910f61d639b290eab26.tar.gz nextcloud-server-9b919245f67f5511d6be7910f61d639b290eab26.zip |
Adjust ImageManager tests for png generation
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'apps/theming/tests')
-rw-r--r-- | apps/theming/tests/ImageManagerTest.php | 55 |
1 files changed, 48 insertions, 7 deletions
diff --git a/apps/theming/tests/ImageManagerTest.php b/apps/theming/tests/ImageManagerTest.php index 3993efc1c52..501ec0e1432 100644 --- a/apps/theming/tests/ImageManagerTest.php +++ b/apps/theming/tests/ImageManagerTest.php @@ -26,6 +26,7 @@ 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\IURLGenerator; use Test\TestCase; @@ -43,19 +44,36 @@ class ImageManagerTest extends TestCase { protected $imageManager; /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */ private $urlGenerator; + /** @var ICacheFactory|\PHPUnit_Framework_MockObject_MockObject */ + private $cacheFactory; 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->imageManager = new ImageManager( $this->config, $this->appData, - $this->urlGenerator + $this->urlGenerator, + $this->cacheFactory ); } + private function checkImagick() { + if(!extension_loaded('imagick')) { + $this->markTestSkipped('Imagemagick is required for dynamic icon generation.'); + } + $checkImagick = new \Imagick(); + if (count($checkImagick->queryFormats('SVG')) < 1) { + $this->markTestSkipped('No SVG provider present.'); + } + if (count($checkImagick->queryFormats('PNG')) < 1) { + $this->markTestSkipped('No PNG provider present.'); + } + } + public function mockGetImage($key, $file) { /** @var \PHPUnit_Framework_MockObject_MockObject $folder */ $folder = $this->createMock(ISimpleFolder::class); @@ -65,10 +83,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') @@ -77,12 +113,13 @@ 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); @@ -108,27 +145,31 @@ 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->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')); } public function testGetImage() { + $this->checkImagick(); $this->config->expects($this->once()) ->method('getAppValue')->with('theming', 'logoMime', false) ->willReturn('png'); |