From b436e43d686053fbb2ca5fa56c3f256775ba0f18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 28 Apr 2017 18:08:51 +0200 Subject: [PATCH] Make sure that ThemingDefaults uses the correct default values from \OC_Defaults MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- apps/theming/lib/ThemingDefaults.php | 10 +-- apps/theming/tests/ThemingDefaultsTest.php | 81 +++++++++------------- lib/private/Server.php | 1 - 3 files changed, 36 insertions(+), 56 deletions(-) diff --git a/apps/theming/lib/ThemingDefaults.php b/apps/theming/lib/ThemingDefaults.php index 85ad11943d..2935355f26 100644 --- a/apps/theming/lib/ThemingDefaults.php +++ b/apps/theming/lib/ThemingDefaults.php @@ -66,11 +66,11 @@ class ThemingDefaults extends \OC_Defaults { public function __construct(IConfig $config, IL10N $l, IURLGenerator $urlGenerator, - \OC_Defaults $defaults, IAppData $appData, ICacheFactory $cacheFactory, Util $util ) { + parent::__construct(); $this->config = $config; $this->l = $l; $this->urlGenerator = $urlGenerator; @@ -78,10 +78,10 @@ class ThemingDefaults extends \OC_Defaults { $this->cacheFactory = $cacheFactory; $this->util = $util; - $this->name = $defaults->getName(); - $this->url = $defaults->getBaseUrl(); - $this->slogan = $defaults->getSlogan(); - $this->color = $defaults->getColorPrimary(); + $this->name = parent::getName(); + $this->url = parent::getBaseUrl(); + $this->slogan = parent::getSlogan(); + $this->color = parent::getColorPrimary(); } public function getName() { diff --git a/apps/theming/tests/ThemingDefaultsTest.php b/apps/theming/tests/ThemingDefaultsTest.php index f8ecc78d8b..736eeb3afc 100644 --- a/apps/theming/tests/ThemingDefaultsTest.php +++ b/apps/theming/tests/ThemingDefaultsTest.php @@ -65,25 +65,7 @@ class ThemingDefaultsTest extends TestCase { $this->cacheFactory = $this->createMock(ICacheFactory::class); $this->cache = $this->createMock(ICache::class); $this->util = $this->createMock(Util::class); - $this->defaults = $this->getMockBuilder(\OC_Defaults::class) - ->disableOriginalConstructor() - ->getMock(); - $this->defaults - ->expects($this->at(0)) - ->method('getName') - ->willReturn('Nextcloud'); - $this->defaults - ->expects($this->at(1)) - ->method('getBaseUrl') - ->willReturn('https://nextcloud.com/'); - $this->defaults - ->expects($this->at(2)) - ->method('getSlogan') - ->willReturn('Safe Data'); - $this->defaults - ->expects($this->at(3)) - ->method('getColorPrimary') - ->willReturn('#000'); + $this->defaults = new \OC_Defaults(); $this->cacheFactory ->expects($this->any()) ->method('create') @@ -93,7 +75,6 @@ class ThemingDefaultsTest extends TestCase { $this->config, $this->l10n, $this->urlGenerator, - $this->defaults, $this->appData, $this->cacheFactory, $this->util @@ -185,17 +166,17 @@ class ThemingDefaultsTest extends TestCase { $this->config ->expects($this->once()) ->method('getAppValue') - ->with('theming', 'url', 'https://nextcloud.com/') - ->willReturn('https://nextcloud.com/'); + ->with('theming', 'url', $this->defaults->getBaseUrl()) + ->willReturn($this->defaults->getBaseUrl()); - $this->assertEquals('https://nextcloud.com/', $this->template->getBaseUrl()); + $this->assertEquals($this->defaults->getBaseUrl(), $this->template->getBaseUrl()); } public function testGetBaseUrlWithCustom() { $this->config ->expects($this->once()) ->method('getAppValue') - ->with('theming', 'url', 'https://nextcloud.com/') + ->with('theming', 'url', $this->defaults->getBaseUrl()) ->willReturn('https://example.com/'); $this->assertEquals('https://example.com/', $this->template->getBaseUrl()); @@ -205,17 +186,17 @@ class ThemingDefaultsTest extends TestCase { $this->config ->expects($this->once()) ->method('getAppValue') - ->with('theming', 'slogan', 'Safe Data') - ->willReturn('Safe Data'); + ->with('theming', 'slogan', $this->defaults->getSlogan()) + ->willReturn($this->defaults->getSlogan()); - $this->assertEquals('Safe Data', $this->template->getSlogan()); + $this->assertEquals($this->defaults->getSlogan(), $this->template->getSlogan()); } public function testGetSloganWithCustom() { $this->config ->expects($this->once()) ->method('getAppValue') - ->with('theming', 'slogan', 'Safe Data') + ->with('theming', 'slogan', $this->defaults->getSlogan()) ->willReturn('My custom Slogan'); $this->assertEquals('My custom Slogan', $this->template->getSlogan()); @@ -226,9 +207,9 @@ class ThemingDefaultsTest extends TestCase { ->expects($this->exactly(3)) ->method('getAppValue') ->willReturnMap([ - ['theming', 'url', 'https://nextcloud.com/', 'url'], + ['theming', 'url', $this->defaults->getBaseUrl(), 'url'], ['theming', 'name', 'Nextcloud', 'Name'], - ['theming', 'slogan', 'Safe Data', 'Slogan'], + ['theming', 'slogan', $this->defaults->getSlogan(), 'Slogan'], ]); $this->assertEquals('Name – Slogan', $this->template->getShortFooter()); @@ -239,9 +220,9 @@ class ThemingDefaultsTest extends TestCase { ->expects($this->exactly(3)) ->method('getAppValue') ->willReturnMap([ - ['theming', 'url', 'https://nextcloud.com/', 'url'], + ['theming', 'url', $this->defaults->getBaseUrl(), 'url'], ['theming', 'name', 'Nextcloud', 'Name'], - ['theming', 'slogan', 'Safe Data', ''], + ['theming', 'slogan', $this->defaults->getSlogan(), ''], ]); $this->assertEquals('Name', $this->template->getShortFooter()); @@ -251,17 +232,17 @@ class ThemingDefaultsTest extends TestCase { $this->config ->expects($this->once()) ->method('getAppValue') - ->with('theming', 'color', '#000') - ->willReturn('#000'); + ->with('theming', 'color', $this->defaults->getColorPrimary()) + ->willReturn($this->defaults->getColorPrimary()); - $this->assertEquals('#000', $this->template->getColorPrimary()); + $this->assertEquals($this->defaults->getColorPrimary(), $this->template->getColorPrimary()); } public function testgetColorPrimaryWithCustom() { $this->config ->expects($this->once()) ->method('getAppValue') - ->with('theming', 'color', '#000') + ->with('theming', 'color', $this->defaults->getColorPrimary()) ->willReturn('#fff'); $this->assertEquals('#fff', $this->template->getColorPrimary()); @@ -328,10 +309,10 @@ class ThemingDefaultsTest extends TestCase { $this->config ->expects($this->at(3)) ->method('getAppValue') - ->with('theming', 'url', 'https://nextcloud.com/') - ->willReturn('https://nextcloud.com/'); + ->with('theming', 'url', $this->defaults->getBaseUrl()) + ->willReturn($this->defaults->getBaseUrl()); - $this->assertSame('https://nextcloud.com/', $this->template->undo('url')); + $this->assertSame($this->defaults->getBaseUrl(), $this->template->undo('url')); } public function testUndoSlogan() { @@ -351,10 +332,10 @@ class ThemingDefaultsTest extends TestCase { $this->config ->expects($this->at(3)) ->method('getAppValue') - ->with('theming', 'slogan', 'Safe Data') - ->willReturn('Safe Data'); + ->with('theming', 'slogan', $this->defaults->getSlogan()) + ->willReturn($this->defaults->getSlogan()); - $this->assertSame('Safe Data', $this->template->undo('slogan')); + $this->assertSame($this->defaults->getSlogan(), $this->template->undo('slogan')); } public function testUndoColor() { @@ -374,10 +355,10 @@ class ThemingDefaultsTest extends TestCase { $this->config ->expects($this->at(3)) ->method('getAppValue') - ->with('theming', 'color', '#000') - ->willReturn('#000'); + ->with('theming', 'color', $this->defaults->getColorPrimary()) + ->willReturn($this->defaults->getColorPrimary()); - $this->assertSame('#000', $this->template->undo('color')); + $this->assertSame($this->defaults->getColorPrimary(), $this->template->undo('color')); } public function testUndoDefaultAction() { @@ -502,11 +483,11 @@ class ThemingDefaultsTest extends TestCase { $this->config->expects($this->at(1))->method('getAppValue')->with('theming', 'logoMime', false)->willReturn('jpeg'); $this->config->expects($this->at(2))->method('getAppValue')->with('theming', 'cachebuster', '0')->willReturn('0'); $this->config->expects($this->at(3))->method('getAppValue')->with('theming', 'backgroundMime', false)->willReturn('jpeg'); - $this->config->expects($this->at(4))->method('getAppValue')->with('theming', 'color', null)->willReturn('#000000'); - $this->config->expects($this->at(5))->method('getAppValue')->with('theming', 'color', '#000')->willReturn('#000000'); - $this->config->expects($this->at(6))->method('getAppValue')->with('theming', 'color', '#000')->willReturn('#000000'); + $this->config->expects($this->at(4))->method('getAppValue')->with('theming', 'color', null)->willReturn($this->defaults->getColorPrimary()); + $this->config->expects($this->at(5))->method('getAppValue')->with('theming', 'color', $this->defaults->getColorPrimary())->willReturn($this->defaults->getColorPrimary()); + $this->config->expects($this->at(6))->method('getAppValue')->with('theming', 'color', $this->defaults->getColorPrimary())->willReturn($this->defaults->getColorPrimary()); - $this->util->expects($this->any())->method('invertTextColor')->with('#000000')->willReturn(false); + $this->util->expects($this->any())->method('invertTextColor')->with($this->defaults->getColorPrimary())->willReturn(false); $this->cache->expects($this->once())->method('get')->with('getScssVariables')->willReturn(null); $folder = $this->createMock(ISimpleFolder::class); $file = $this->createMock(ISimpleFile::class); @@ -532,7 +513,7 @@ class ThemingDefaultsTest extends TestCase { 'theming-cachebuster' => '\'0\'', 'image-logo' => "'absolute-custom-logo?v=0'", 'image-login-background' => "'absolute-custom-background'", - 'color-primary' => '#000000', + 'color-primary' => $this->defaults->getColorPrimary(), 'color-primary-text' => '#ffffff' ]; diff --git a/lib/private/Server.php b/lib/private/Server.php index 25c0b5d9cc..6bc9a1429c 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -868,7 +868,6 @@ class Server extends ServerContainer implements IServerContainer { $c->getConfig(), $c->getL10N('theming'), $c->getURLGenerator(), - new \OC_Defaults(), $c->getAppDataDir('theming'), $c->getMemCacheFactory(), new Util($c->getConfig(), $this->getRootFolder(), $this->getAppManager())