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>
This commit is contained in:
Julius Härtl 2018-01-09 23:11:49 +01:00
parent 9c017084e5
commit d4e106f2b3
No known key found for this signature in database
GPG key ID: 4C614C6ED2CDE6DF
6 changed files with 99 additions and 53 deletions

View file

@ -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(),
],
];
}

View file

@ -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;
}
/**

View file

@ -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;
}
}

View file

@ -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,10 @@ 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/', [
['name1', 'url2', 'slogan3', '#000000', '#ffffff', 'logo5', 'backgroundColor', 'http://localhost/', true, [
'name' => 'name1',
'url' => 'url2',
'slogan' => 'slogan3',
@ -94,6 +101,20 @@ class CapabilitiesTest extends TestCase {
'color-element' => '#000000',
'logo' => 'http://localhost/logo5',
'background' => '#000000',
'background-plain' => true,
'background-default' => false,
]],
['name1', 'url2', 'slogan3', '#000000', '#ffffff', 'logo5', 'backgroundColor', 'http://localhost/', false, [
'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' => 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')

View file

@ -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');

View file

@ -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());
}
}