Return color when theming uses no background image

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2017-05-17 13:16:44 +02:00
parent 443cbdc739
commit 81847c01b0
No known key found for this signature in database
GPG Key ID: 4C614C6ED2CDE6DF
2 changed files with 48 additions and 28 deletions

View File

@ -24,6 +24,7 @@
namespace OCA\Theming;
use OCP\Capabilities\ICapability;
use OCP\IConfig;
use OCP\IURLGenerator;
/**
@ -36,17 +37,21 @@ class Capabilities implements ICapability {
/** @var ThemingDefaults */
protected $theming;
/** @var IURLGenerator */
protected $url;
/** @var IConfig */
protected $config;
/**
* @param ThemingDefaults $theming
* @param IURLGenerator $url
* @param IConfig $config
*/
public function __construct(ThemingDefaults $theming, IURLGenerator $url) {
public function __construct(ThemingDefaults $theming, IURLGenerator $url, IConfig $config) {
$this->theming = $theming;
$this->url = $url;
$this->config = $config;
}
/**
@ -55,6 +60,8 @@ class Capabilities implements ICapability {
* @return array
*/
public function getCapabilities() {
$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', false);
return [
'theming' => [
'name' => $this->theming->getName(),
@ -62,7 +69,9 @@ class Capabilities implements ICapability {
'slogan' => $this->theming->getSlogan(),
'color' => $this->theming->getColorPrimary(),
'logo' => $this->url->getAbsoluteURL($this->theming->getLogo()),
'background' => $this->url->getAbsoluteURL($this->theming->getBackground()),
'background' => $backgroundLogo === 'backgroundColor' ?
$this->theming->getColorPrimary() :
$this->url->getAbsoluteURL($this->theming->getBackground()),
],
];
}

View File

@ -22,17 +22,9 @@
namespace OCA\Theming\Tests;
use OCA\Theming\Capabilities;
use OCA\Theming\Controller\ThemingController;
use OCA\Theming\Settings\Admin;
use OCA\Theming\Settings\Section;
use OCA\Theming\ThemingDefaults;
use OCA\Theming\Util;
use OCP\AppFramework\App;
use OCP\Capabilities\ICapability;
use OCP\IL10N;
use OCP\IConfig;
use OCP\IURLGenerator;
use OCP\Settings\ISection;
use OCP\Settings\ISettings;
use Test\TestCase;
/**
@ -48,19 +40,19 @@ class CapabilitiesTest extends TestCase {
/** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
protected $url;
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
protected $config;
/** @var Capabilities */
protected $capabilities;
protected function setUp() {
parent::setUp();
$this->theming = $this->getMockBuilder(ThemingDefaults::class)
->disableOriginalConstructor()
->getMock();
$this->url = $this->getMockBuilder(IURLGenerator::class)
->getMock();
$this->capabilities = new Capabilities($this->theming, $this->url);
$this->theming = $this->createMock(ThemingDefaults::class);
$this->url = $this->getMockBuilder(IURLGenerator::class)->getMock();
$this->config = $this->createMock(IConfig::class);
$this->capabilities = new Capabilities($this->theming, $this->url, $this->config);
}
public function dataGetCapabilities() {
@ -81,6 +73,14 @@ class CapabilitiesTest extends TestCase {
'logo' => 'http://localhost/logo5',
'background' => 'http://localhost/background6',
]],
['name1', 'url2', 'slogan3', 'color4', 'logo5', 'backgroundColor', 'http://localhost/', [
'name' => 'name1',
'url' => 'url2',
'slogan' => 'slogan3',
'color' => 'color4',
'logo' => 'http://localhost/logo5',
'background' => 'color4',
]],
];
}
@ -96,6 +96,9 @@ class CapabilitiesTest extends TestCase {
* @param string[] $expected
*/
public function testGetCapabilities($name, $url, $slogan, $color, $logo, $background, $baseUrl, array $expected) {
$this->config->expects($this->once())
->method('getAppValue')
->willReturn($background);
$this->theming->expects($this->once())
->method('getName')
->willReturn($name);
@ -105,21 +108,29 @@ class CapabilitiesTest extends TestCase {
$this->theming->expects($this->once())
->method('getSlogan')
->willReturn($slogan);
$this->theming->expects($this->once())
$this->theming->expects($this->atLeast(1))
->method('getColorPrimary')
->willReturn($color);
$this->theming->expects($this->once())
->method('getLogo')
->willReturn($logo);
$this->theming->expects($this->once())
->method('getBackground')
->willReturn($background);
$this->url->expects($this->exactly(2))
->method('getAbsoluteURL')
->willReturnCallback(function($url) use($baseUrl) {
return $baseUrl . $url;
});
if($background !== 'backgroundColor') {
$this->theming->expects($this->once())
->method('getBackground')
->willReturn($background);
$this->url->expects($this->exactly(2))
->method('getAbsoluteURL')
->willReturnCallback(function($url) use($baseUrl) {
return $baseUrl . $url;
});
} else {
$this->url->expects($this->once())
->method('getAbsoluteURL')
->willReturnCallback(function($url) use($baseUrl) {
return $baseUrl . $url;
});
}
$this->assertEquals(['theming' => $expected], $this->capabilities->getCapabilities());
}