From 4a5826cddb19c8a3cd8c112eea29d87630591293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 20 Apr 2018 16:21:11 +0200 Subject: Generate PNG version of the theming app logo for mails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- apps/theming/tests/ImageManagerTest.php | 1 + 1 file changed, 1 insertion(+) (limited to 'apps/theming/tests') diff --git a/apps/theming/tests/ImageManagerTest.php b/apps/theming/tests/ImageManagerTest.php index 4e258ce7162..3993efc1c52 100644 --- a/apps/theming/tests/ImageManagerTest.php +++ b/apps/theming/tests/ImageManagerTest.php @@ -24,6 +24,7 @@ namespace OCA\Theming\Tests; use OCA\Theming\ImageManager; +use OCA\Theming\ThemingDefaults; use OCP\Files\SimpleFS\ISimpleFile; use OCP\IConfig; use OCP\IURLGenerator; -- cgit v1.2.3 From 9b919245f67f5511d6be7910f61d639b290eab26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Tue, 8 May 2018 12:40:20 +0200 Subject: Adjust ImageManager tests for png generation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- apps/theming/tests/ImageManagerTest.php | 55 ++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 7 deletions(-) (limited to 'apps/theming/tests') 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'); -- cgit v1.2.3 From d132527aa9c4baad344b11adef3a6f4a46cde3ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Tue, 8 May 2018 13:06:31 +0200 Subject: Use svg opt out as parameter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- apps/theming/tests/ImageManagerTest.php | 6 +++--- apps/theming/tests/ThemingDefaultsTest.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'apps/theming/tests') diff --git a/apps/theming/tests/ImageManagerTest.php b/apps/theming/tests/ImageManagerTest.php index 501ec0e1432..6912395268e 100644 --- a/apps/theming/tests/ImageManagerTest.php +++ b/apps/theming/tests/ImageManagerTest.php @@ -126,7 +126,7 @@ class ImageManagerTest extends TestCase { $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() { @@ -164,7 +164,7 @@ class ImageManagerTest extends TestCase { $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')); + $this->assertEquals('url-to-image-absolute?v=0', $this->imageManager->getImageUrlAbsolute('logo', false)); } @@ -175,7 +175,7 @@ class ImageManagerTest extends TestCase { ->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)); } /** diff --git a/apps/theming/tests/ThemingDefaultsTest.php b/apps/theming/tests/ThemingDefaultsTest.php index 6894b002eb9..ceaf2cc19d5 100644 --- a/apps/theming/tests/ThemingDefaultsTest.php +++ b/apps/theming/tests/ThemingDefaultsTest.php @@ -604,7 +604,7 @@ class ThemingDefaultsTest extends TestCase { $this->urlGenerator->expects($this->once()) ->method('linkToRoute') ->with('theming.Theming.getImage') - ->willReturn('custom-logo'); + ->willReturn('custom-logo?v=0'); $this->assertEquals('custom-logo' . '?v=0', $this->template->getLogo()); } -- cgit v1.2.3 From 5b0ce806a3679b34ae3a6f8e6ae32a0b513a4ca9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Tue, 5 Jun 2018 16:59:05 +0200 Subject: Minor fixes and cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- .../tests/Controller/IconControllerTest.php | 13 +++++++----- .../tests/Controller/ThemingControllerTest.php | 4 ++-- apps/theming/tests/IconBuilderTest.php | 23 ++++++++++++---------- apps/theming/tests/ImageManagerTest.php | 4 ++-- 4 files changed, 25 insertions(+), 19 deletions(-) (limited to 'apps/theming/tests') diff --git a/apps/theming/tests/Controller/IconControllerTest.php b/apps/theming/tests/Controller/IconControllerTest.php index f509005d32c..cc83bae32a7 100644 --- a/apps/theming/tests/Controller/IconControllerTest.php +++ b/apps/theming/tests/Controller/IconControllerTest.php @@ -118,7 +118,7 @@ class IconControllerTest extends TestCase { ->method('getImage') ->with('favicon') ->will($this->throwException(new NotFoundException())); - $this->themingDefaults->expects($this->any()) + $this->imageManager->expects($this->any()) ->method('shouldReplaceIcons') ->willReturn(true); $this->imageManager->expects($this->once()) @@ -142,7 +142,7 @@ class IconControllerTest extends TestCase { ->method('getImage') ->with('favicon') ->will($this->throwException(new NotFoundException())); - $this->themingDefaults->expects($this->any()) + $this->imageManager->expects($this->any()) ->method('shouldReplaceIcons') ->willReturn(false); $fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon.png'; @@ -163,10 +163,13 @@ class IconControllerTest extends TestCase { if (count($checkImagick->queryFormats('SVG')) < 1) { $this->markTestSkipped('No SVG provider present.'); } - $this->themingDefaults->expects($this->any()) + + $this->imageManager->expects($this->once()) + ->method('getImage') + ->will($this->throwException(new NotFoundException())); + $this->imageManager->expects($this->any()) ->method('shouldReplaceIcons') ->willReturn(true); - $this->iconBuilder->expects($this->once()) ->method('getTouchIcon') ->with('core') @@ -189,7 +192,7 @@ class IconControllerTest extends TestCase { ->method('getImage') ->with('favicon') ->will($this->throwException(new NotFoundException())); - $this->themingDefaults->expects($this->any()) + $this->imageManager->expects($this->any()) ->method('shouldReplaceIcons') ->willReturn(false); $fallbackLogo = \OC::$SERVERROOT . '/core/img/favicon-touch.png'; diff --git a/apps/theming/tests/Controller/ThemingControllerTest.php b/apps/theming/tests/Controller/ThemingControllerTest.php index 4a2b780076c..aaed61016e4 100644 --- a/apps/theming/tests/Controller/ThemingControllerTest.php +++ b/apps/theming/tests/Controller/ThemingControllerTest.php @@ -688,7 +688,7 @@ class ThemingControllerTest extends TestCase { ->method('getImage') ->willReturn($file); $this->config - ->expects($this->once()) + ->expects($this->any()) ->method('getAppValue') ->with('theming', 'logoMime', '') ->willReturn('text/svg'); @@ -716,7 +716,7 @@ class ThemingControllerTest extends TestCase { ->willReturn($file); $this->config - ->expects($this->once()) + ->expects($this->any()) ->method('getAppValue') ->with('theming', 'backgroundMime', '') ->willReturn('image/png'); diff --git a/apps/theming/tests/IconBuilderTest.php b/apps/theming/tests/IconBuilderTest.php index 1b9f204cd9e..994e0e4a045 100644 --- a/apps/theming/tests/IconBuilderTest.php +++ b/apps/theming/tests/IconBuilderTest.php @@ -27,6 +27,7 @@ namespace OCA\Theming\Tests; use OC\Files\AppData\AppData; use OCA\Theming\IconBuilder; +use OCA\Theming\ImageManager; use OCA\Theming\ThemingDefaults; use OCA\Theming\Util; use OCP\App\IAppManager; @@ -45,6 +46,8 @@ class IconBuilderTest extends TestCase { protected $themingDefaults; /** @var Util */ protected $util; + /** @var ImageManager */ + protected $imageManager; /** @var IconBuilder */ protected $iconBuilder; /** @var IAppManager */ @@ -53,13 +56,13 @@ class IconBuilderTest extends TestCase { protected function setUp() { parent::setUp(); - $this->config = $this->getMockBuilder(IConfig::class)->getMock(); + $this->config = $this->createMock(IConfig::class); $this->appData = $this->createMock(AppData::class); - $this->themingDefaults = $this->getMockBuilder('OCA\Theming\ThemingDefaults') - ->disableOriginalConstructor()->getMock(); - $this->appManager = $this->getMockBuilder('OCP\App\IAppManager')->getMock(); + $this->themingDefaults = $this->createMock(ThemingDefaults::class); + $this->appManager = $this->createMock(IAppManager::class); + $this->imageManager = $this->createMock(ImageManager::class); $this->util = new Util($this->config, $this->appManager, $this->appData); - $this->iconBuilder = new IconBuilder($this->themingDefaults, $this->util); + $this->iconBuilder = new IconBuilder($this->themingDefaults, $this->util, $this->imageManager); } private function checkImagick() { @@ -152,7 +155,7 @@ class IconBuilderTest extends TestCase { */ public function testGetFavicon($app, $color, $file) { $this->checkImagick(); - $this->themingDefaults->expects($this->once()) + $this->imageManager->expects($this->once()) ->method('shouldReplaceIcons') ->willReturn(true); $this->themingDefaults->expects($this->once()) @@ -183,8 +186,8 @@ class IconBuilderTest extends TestCase { $this->checkImagick(); $this->expectException(Warning::class); $util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock(); - $iconBuilder = new IconBuilder($this->themingDefaults, $util); - $this->themingDefaults->expects($this->once()) + $iconBuilder = new IconBuilder($this->themingDefaults, $util, $this->imageManager); + $this->imageManager->expects($this->once()) ->method('shouldReplaceIcons') ->willReturn(true); $util->expects($this->once()) @@ -197,7 +200,7 @@ class IconBuilderTest extends TestCase { $this->checkImagick(); $this->expectException(Warning::class); $util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock(); - $iconBuilder = new IconBuilder($this->themingDefaults, $util); + $iconBuilder = new IconBuilder($this->themingDefaults, $util, $this->imageManager); $util->expects($this->once()) ->method('getAppIcon') ->willReturn('notexistingfile'); @@ -208,7 +211,7 @@ class IconBuilderTest extends TestCase { $this->checkImagick(); $this->expectException(Warning::class); $util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock(); - $iconBuilder = new IconBuilder($this->themingDefaults, $util); + $iconBuilder = new IconBuilder($this->themingDefaults, $util, $this->imageManager); $util->expects($this->once()) ->method('getAppImage') ->willReturn('notexistingfile'); diff --git a/apps/theming/tests/ImageManagerTest.php b/apps/theming/tests/ImageManagerTest.php index 6912395268e..6bfa5b330a6 100644 --- a/apps/theming/tests/ImageManagerTest.php +++ b/apps/theming/tests/ImageManagerTest.php @@ -66,10 +66,10 @@ class ImageManagerTest extends TestCase { $this->markTestSkipped('Imagemagick is required for dynamic icon generation.'); } $checkImagick = new \Imagick(); - if (count($checkImagick->queryFormats('SVG')) < 1) { + if (empty($checkImagick->queryFormats('SVG'))) { $this->markTestSkipped('No SVG provider present.'); } - if (count($checkImagick->queryFormats('PNG')) < 1) { + if (empty($checkImagick->queryFormats('PNG'))) { $this->markTestSkipped('No PNG provider present.'); } } -- cgit v1.2.3 From ceee91d9d455eed8b01942bc56767c69077e9f3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Thu, 14 Jun 2018 16:55:44 +0200 Subject: Add info message if an exception occurs during the svg to png conversion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- apps/theming/tests/ImageManagerTest.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'apps/theming/tests') diff --git a/apps/theming/tests/ImageManagerTest.php b/apps/theming/tests/ImageManagerTest.php index 6bfa5b330a6..38f5fb04969 100644 --- a/apps/theming/tests/ImageManagerTest.php +++ b/apps/theming/tests/ImageManagerTest.php @@ -28,6 +28,7 @@ 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; @@ -46,6 +47,8 @@ class ImageManagerTest extends TestCase { private $urlGenerator; /** @var ICacheFactory|\PHPUnit_Framework_MockObject_MockObject */ private $cacheFactory; + /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */ + private $logger; protected function setUp() { parent::setUp(); @@ -53,11 +56,13 @@ class ImageManagerTest extends TestCase { $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->cacheFactory + $this->cacheFactory, + $this->logger ); } -- cgit v1.2.3