diff options
author | Julius Härtl <jus@bitgrid.net> | 2018-01-09 23:11:49 +0100 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2018-01-10 13:23:22 +0100 |
commit | d4e106f2b34d4300ec743d3f6f7c8d9847c3e406 (patch) | |
tree | 3d8aef6327a538713f66b640a275b1ed70ec6c26 /apps/theming | |
parent | 9c017084e50a20591e3b5a5c2842101a540e7fb2 (diff) | |
download | nextcloud-server-d4e106f2b34d4300ec743d3f6f7c8d9847c3e406.tar.gz nextcloud-server-d4e106f2b34d4300ec743d3f6f7c8d9847c3e406.zip |
More detailed theming capabilities
This will allow clients to easily check if a custom background is used
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'apps/theming')
-rw-r--r-- | apps/theming/lib/Capabilities.php | 2 | ||||
-rw-r--r-- | apps/theming/lib/ThemingDefaults.php | 15 | ||||
-rw-r--r-- | apps/theming/lib/Util.php | 12 | ||||
-rw-r--r-- | apps/theming/tests/CapabilitiesTest.php | 46 | ||||
-rw-r--r-- | apps/theming/tests/ThemingDefaultsTest.php | 44 | ||||
-rw-r--r-- | apps/theming/tests/UtilTest.php | 33 |
6 files changed, 99 insertions, 53 deletions
diff --git a/apps/theming/lib/Capabilities.php b/apps/theming/lib/Capabilities.php index 1b6bb8927be..a75403a1fd5 100644 --- a/apps/theming/lib/Capabilities.php +++ b/apps/theming/lib/Capabilities.php @@ -81,6 +81,8 @@ class Capabilities implements IPublicCapability { 'background' => $backgroundLogo === 'backgroundColor' ? $this->theming->getColorPrimary() : $this->url->getAbsoluteURL($this->theming->getBackground()), + 'background-plain' => $backgroundLogo === 'backgroundColor', + 'background-default' => !$this->util->isBackgroundThemed(), ], ]; } diff --git a/apps/theming/lib/ThemingDefaults.php b/apps/theming/lib/ThemingDefaults.php index 05d387e6273..9dcc981817e 100644 --- a/apps/theming/lib/ThemingDefaults.php +++ b/apps/theming/lib/ThemingDefaults.php @@ -196,22 +196,13 @@ class ThemingDefaults extends \OC_Defaults { * @return string */ public function getBackground() { - $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime',false); - - $backgroundExists = true; - try { - $this->appData->getFolder('images')->getFile('background'); - } catch (\Exception $e) { - $backgroundExists = false; - } - $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); - if(!$backgroundLogo || !$backgroundExists) { - return $this->urlGenerator->imagePath('core','background.png') . '?v=' . $cacheBusterCounter; + if($this->util->isBackgroundThemed()) { + return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground') . '?v=' . $cacheBusterCounter; } - return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground') . '?v=' . $cacheBusterCounter; + return $this->urlGenerator->imagePath('core','background.png') . '?v=' . $cacheBusterCounter; } /** diff --git a/apps/theming/lib/Util.php b/apps/theming/lib/Util.php index 6a1aa672108..2f6f4128365 100644 --- a/apps/theming/lib/Util.php +++ b/apps/theming/lib/Util.php @@ -235,4 +235,16 @@ class Util { return false; } + public function isBackgroundThemed() { + $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime',false); + + $backgroundExists = true; + try { + $this->appData->getFolder('images')->getFile('background'); + } catch (\Exception $e) { + $backgroundExists = false; + } + return $backgroundLogo && $backgroundLogo !== 'backgroundColor' && $backgroundExists; + } + } diff --git a/apps/theming/tests/CapabilitiesTest.php b/apps/theming/tests/CapabilitiesTest.php index c760c896425..31e0ae79970 100644 --- a/apps/theming/tests/CapabilitiesTest.php +++ b/apps/theming/tests/CapabilitiesTest.php @@ -50,6 +50,9 @@ class CapabilitiesTest extends TestCase { /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ protected $config; + /** @var Util|\PHPUnit_Framework_MockObject_MockObject */ + protected $util; + /** @var Capabilities */ protected $capabilities; @@ -59,13 +62,13 @@ class CapabilitiesTest extends TestCase { $this->theming = $this->createMock(ThemingDefaults::class); $this->url = $this->getMockBuilder(IURLGenerator::class)->getMock(); $this->config = $this->createMock(IConfig::class); - $util = new Util($this->config, $this->createMock(IAppManager::class), $this->createMock(IAppData::class)); - $this->capabilities = new Capabilities($this->theming, $util, $this->url, $this->config); + $this->util = $this->createMock(Util::class); + $this->capabilities = new Capabilities($this->theming, $this->util, $this->url, $this->config); } public function dataGetCapabilities() { return [ - ['name', 'url', 'slogan', '#FFFFFF', '#000000', 'logo', 'background', 'http://absolute/', [ + ['name', 'url', 'slogan', '#FFFFFF', '#000000', 'logo', 'background', 'http://absolute/', true, [ 'name' => 'name', 'url' => 'url', 'slogan' => 'slogan', @@ -74,8 +77,10 @@ class CapabilitiesTest extends TestCase { 'color-element' => '#555555', 'logo' => 'http://absolute/logo', 'background' => 'http://absolute/background', + 'background-plain' => false, + 'background-default' => false, ]], - ['name1', 'url2', 'slogan3', '#01e4a0', '#ffffff', 'logo5', 'background6', 'http://localhost/', [ + ['name1', 'url2', 'slogan3', '#01e4a0', '#ffffff', 'logo5', 'background6', 'http://localhost/', false, [ 'name' => 'name1', 'url' => 'url2', 'slogan' => 'slogan3', @@ -84,8 +89,22 @@ class CapabilitiesTest extends TestCase { 'color-element' => '#01e4a0', 'logo' => 'http://localhost/logo5', 'background' => 'http://localhost/background6', + 'background-plain' => false, + 'background-default' => true, + ]], + ['name1', 'url2', 'slogan3', '#000000', '#ffffff', 'logo5', 'backgroundColor', 'http://localhost/', true, [ + 'name' => 'name1', + 'url' => 'url2', + 'slogan' => 'slogan3', + 'color' => '#000000', + 'color-text' => '#ffffff', + 'color-element' => '#000000', + 'logo' => 'http://localhost/logo5', + 'background' => '#000000', + 'background-plain' => true, + 'background-default' => false, ]], - ['name1', 'url2', 'slogan3', '#000000', '#ffffff', 'logo5', 'backgroundColor', 'http://localhost/', [ + ['name1', 'url2', 'slogan3', '#000000', '#ffffff', 'logo5', 'backgroundColor', 'http://localhost/', false, [ 'name' => 'name1', 'url' => 'url2', 'slogan' => 'slogan3', @@ -94,6 +113,8 @@ class CapabilitiesTest extends TestCase { 'color-element' => '#000000', 'logo' => 'http://localhost/logo5', 'background' => '#000000', + 'background-plain' => true, + 'background-default' => true, ]], ]; } @@ -104,13 +125,14 @@ class CapabilitiesTest extends TestCase { * @param string $url * @param string $slogan * @param string $color - * @param string $logo * @param string $textColor + * @param string $logo * @param string $background * @param string $baseUrl + * @param bool $backgroundThemed * @param string[] $expected */ - public function testGetCapabilities($name, $url, $slogan, $color, $textColor, $logo, $background, $baseUrl, array $expected) { + public function testGetCapabilities($name, $url, $slogan, $color, $textColor, $logo, $background, $baseUrl, $backgroundThemed, array $expected) { $this->config->expects($this->once()) ->method('getAppValue') ->willReturn($background); @@ -133,6 +155,16 @@ class CapabilitiesTest extends TestCase { ->method('getTextColorPrimary') ->willReturn($textColor); + $util = new Util($this->config, $this->createMock(IAppManager::class), $this->createMock(IAppData::class)); + $this->util->expects($this->once()) + ->method('elementColor') + ->with($color) + ->willReturn($util->elementColor($color)); + + $this->util->expects($this->once()) + ->method('isBackgroundThemed') + ->willReturn($backgroundThemed); + if($background !== 'backgroundColor') { $this->theming->expects($this->once()) ->method('getBackground') diff --git a/apps/theming/tests/ThemingDefaultsTest.php b/apps/theming/tests/ThemingDefaultsTest.php index 843c1d34f9e..d0dc6587f74 100644 --- a/apps/theming/tests/ThemingDefaultsTest.php +++ b/apps/theming/tests/ThemingDefaultsTest.php @@ -391,24 +391,14 @@ class ThemingDefaultsTest extends TestCase { } public function testGetBackgroundDefault() { - $this->appData->expects($this->once()) - ->method('getFolder') - ->willThrowException(new NotFoundException()); - $this->config - ->expects($this->at(0)) - ->method('getAppValue') - ->with('theming', 'backgroundMime') - ->willReturn(''); $this->config - ->expects($this->at(1)) + ->expects($this->once()) ->method('getAppValue') ->with('theming', 'cachebuster', '0') ->willReturn('0'); - $this->appData - ->expects($this->once()) - ->method('getFolder') - ->with('images') - ->willThrowException(new \Exception()); + $this->util->expects($this->once()) + ->method('isBackgroundThemed') + ->willReturn(false); $this->urlGenerator->expects($this->once()) ->method('imagePath') ->with('core', 'background.png') @@ -417,24 +407,14 @@ class ThemingDefaultsTest extends TestCase { } public function testGetBackgroundCustom() { - $folder = $this->createMock(ISimpleFolder::class); - $file = $this->createMock(ISimpleFile::class); - $folder->expects($this->once()) - ->method('getFile') - ->willReturn($file); - $this->appData->expects($this->once()) - ->method('getFolder') - ->willReturn($folder); $this->config - ->expects($this->at(0)) - ->method('getAppValue') - ->with('theming', 'backgroundMime', false) - ->willReturn('image/svg+xml'); - $this->config - ->expects($this->at(1)) + ->expects($this->once()) ->method('getAppValue') ->with('theming', 'cachebuster', '0') ->willReturn('0'); + $this->util->expects($this->once()) + ->method('isBackgroundThemed') + ->willReturn(true); $this->urlGenerator->expects($this->once()) ->method('linkToRoute') ->with('theming.Theming.getLoginBackground') @@ -513,12 +493,12 @@ class ThemingDefaultsTest extends TestCase { $this->config->expects($this->at(2))->method('getAppValue')->with('theming', 'backgroundMime', false)->willReturn('jpeg'); $this->config->expects($this->at(3))->method('getAppValue')->with('theming', 'logoMime', false)->willReturn('jpeg'); $this->config->expects($this->at(4))->method('getAppValue')->with('theming', 'cachebuster', '0')->willReturn('0'); - $this->config->expects($this->at(5))->method('getAppValue')->with('theming', 'backgroundMime', false)->willReturn('jpeg'); - $this->config->expects($this->at(6))->method('getAppValue')->with('theming', 'cachebuster', '0')->willReturn('0'); - $this->config->expects($this->at(7))->method('getAppValue')->with('theming', 'color', null)->willReturn($this->defaults->getColorPrimary()); + $this->util->expects($this->once())->method('isBackgroundThemed')->willReturn(true); + $this->config->expects($this->at(5))->method('getAppValue')->with('theming', 'cachebuster', '0')->willReturn('0'); + $this->config->expects($this->at(6))->method('getAppValue')->with('theming', 'color', null)->willReturn($this->defaults->getColorPrimary()); + $this->config->expects($this->at(7))->method('getAppValue')->with('theming', 'color', $this->defaults->getColorPrimary())->willReturn($this->defaults->getColorPrimary()); $this->config->expects($this->at(8))->method('getAppValue')->with('theming', 'color', $this->defaults->getColorPrimary())->willReturn($this->defaults->getColorPrimary()); $this->config->expects($this->at(9))->method('getAppValue')->with('theming', 'color', $this->defaults->getColorPrimary())->willReturn($this->defaults->getColorPrimary()); - $this->config->expects($this->at(10))->method('getAppValue')->with('theming', 'color', $this->defaults->getColorPrimary())->willReturn($this->defaults->getColorPrimary()); $this->util->expects($this->any())->method('invertTextColor')->with($this->defaults->getColorPrimary())->willReturn(false); $this->util->expects($this->any())->method('elementColor')->with($this->defaults->getColorPrimary())->willReturn('#aaaaaa'); diff --git a/apps/theming/tests/UtilTest.php b/apps/theming/tests/UtilTest.php index 1ad77be72d5..247bcbae0b2 100644 --- a/apps/theming/tests/UtilTest.php +++ b/apps/theming/tests/UtilTest.php @@ -189,7 +189,6 @@ class UtilTest extends TestCase { } public function testIsAlreadyThemedFalse() { - $theme = $this->config->getSystemValue('theme', ''); $this->config->expects($this->once()) ->method('getSystemValue') ->with('theme', '') @@ -199,7 +198,6 @@ class UtilTest extends TestCase { } public function testIsAlreadyThemedTrue() { - $theme = $this->config->getSystemValue('theme', ''); $this->config->expects($this->once()) ->method('getSystemValue') ->with('theme', '') @@ -208,4 +206,35 @@ class UtilTest extends TestCase { $this->assertTrue($actual); } + public function dataIsBackgroundThemed() { + return [ + [false, false, false], + ['png', true, true], + ['backgroundColor', false, false], + ]; + } + /** + * @dataProvider dataIsBackgroundThemed + */ + public function testIsBackgroundThemed($backgroundMime, $fileFound, $expected) { + $this->config->expects($this->once()) + ->method('getAppValue') + ->with('theming', 'backgroundMime', false) + ->willReturn($backgroundMime); + $folder = $this->createMock(ISimpleFolder::class); + if ($fileFound) { + $folder->expects($this->once()) + ->method('getFile') + ->willReturn($this->createMock(ISimpleFile::class)); + } else { + $folder->expects($this->once()) + ->method('getFile') + ->willThrowException(new NotFoundException()); + } + $this->appData->expects($this->once()) + ->method('getFolder') + ->willReturn($folder); + $this->assertEquals($expected, $this->util->isBackgroundThemed()); + } + } |