Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-06-15 18:02:14 +0300
committerGitHub <noreply@github.com>2018-06-15 18:02:14 +0300
commit8f6acbff621b02cead64219eb9e6b03f4951075a (patch)
tree68dec6474e476078801be1cd2de3036401c3fc8b /apps/theming/tests
parentd82ef721611654aa3a3aab0ea3c8c85c7e0187d6 (diff)
parentceee91d9d455eed8b01942bc56767c69077e9f3f (diff)
Merge pull request #9258 from nextcloud/theming-logo-png
Convert theming app logo to PNG to show it properly in emails
Diffstat (limited to 'apps/theming/tests')
-rw-r--r--apps/theming/tests/Controller/IconControllerTest.php13
-rw-r--r--apps/theming/tests/Controller/ThemingControllerTest.php4
-rw-r--r--apps/theming/tests/IconBuilderTest.php23
-rw-r--r--apps/theming/tests/ImageManagerTest.php67
-rw-r--r--apps/theming/tests/ThemingDefaultsTest.php2
5 files changed, 81 insertions, 28 deletions
diff --git a/apps/theming/tests/Controller/IconControllerTest.php b/apps/theming/tests/Controller/IconControllerTest.php
index 6d8ede159b3..b4b45a065b0 100644
--- a/apps/theming/tests/Controller/IconControllerTest.php
+++ b/apps/theming/tests/Controller/IconControllerTest.php
@@ -120,7 +120,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())
@@ -144,7 +144,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';
@@ -165,10 +165,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')
@@ -191,7 +194,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 60ec2c1dc63..360eb7083a4 100644
--- a/apps/theming/tests/Controller/ThemingControllerTest.php
+++ b/apps/theming/tests/Controller/ThemingControllerTest.php
@@ -690,7 +690,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');
@@ -718,7 +718,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 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));
}
/**
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());
}