Return color when theming uses no background image
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
parent
443cbdc739
commit
81847c01b0
|
@ -24,6 +24,7 @@
|
||||||
namespace OCA\Theming;
|
namespace OCA\Theming;
|
||||||
|
|
||||||
use OCP\Capabilities\ICapability;
|
use OCP\Capabilities\ICapability;
|
||||||
|
use OCP\IConfig;
|
||||||
use OCP\IURLGenerator;
|
use OCP\IURLGenerator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,17 +37,21 @@ class Capabilities implements ICapability {
|
||||||
/** @var ThemingDefaults */
|
/** @var ThemingDefaults */
|
||||||
protected $theming;
|
protected $theming;
|
||||||
|
|
||||||
|
|
||||||
/** @var IURLGenerator */
|
/** @var IURLGenerator */
|
||||||
protected $url;
|
protected $url;
|
||||||
|
|
||||||
|
/** @var IConfig */
|
||||||
|
protected $config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ThemingDefaults $theming
|
* @param ThemingDefaults $theming
|
||||||
* @param IURLGenerator $url
|
* @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->theming = $theming;
|
||||||
$this->url = $url;
|
$this->url = $url;
|
||||||
|
$this->config = $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,6 +60,8 @@ class Capabilities implements ICapability {
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getCapabilities() {
|
public function getCapabilities() {
|
||||||
|
$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', false);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'theming' => [
|
'theming' => [
|
||||||
'name' => $this->theming->getName(),
|
'name' => $this->theming->getName(),
|
||||||
|
@ -62,7 +69,9 @@ class Capabilities implements ICapability {
|
||||||
'slogan' => $this->theming->getSlogan(),
|
'slogan' => $this->theming->getSlogan(),
|
||||||
'color' => $this->theming->getColorPrimary(),
|
'color' => $this->theming->getColorPrimary(),
|
||||||
'logo' => $this->url->getAbsoluteURL($this->theming->getLogo()),
|
'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()),
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,17 +22,9 @@
|
||||||
namespace OCA\Theming\Tests;
|
namespace OCA\Theming\Tests;
|
||||||
|
|
||||||
use OCA\Theming\Capabilities;
|
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\ThemingDefaults;
|
||||||
use OCA\Theming\Util;
|
use OCP\IConfig;
|
||||||
use OCP\AppFramework\App;
|
|
||||||
use OCP\Capabilities\ICapability;
|
|
||||||
use OCP\IL10N;
|
|
||||||
use OCP\IURLGenerator;
|
use OCP\IURLGenerator;
|
||||||
use OCP\Settings\ISection;
|
|
||||||
use OCP\Settings\ISettings;
|
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,19 +40,19 @@ class CapabilitiesTest extends TestCase {
|
||||||
/** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
|
/** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
protected $url;
|
protected $url;
|
||||||
|
|
||||||
|
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
|
protected $config;
|
||||||
|
|
||||||
/** @var Capabilities */
|
/** @var Capabilities */
|
||||||
protected $capabilities;
|
protected $capabilities;
|
||||||
|
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->theming = $this->getMockBuilder(ThemingDefaults::class)
|
$this->theming = $this->createMock(ThemingDefaults::class);
|
||||||
->disableOriginalConstructor()
|
$this->url = $this->getMockBuilder(IURLGenerator::class)->getMock();
|
||||||
->getMock();
|
$this->config = $this->createMock(IConfig::class);
|
||||||
$this->url = $this->getMockBuilder(IURLGenerator::class)
|
$this->capabilities = new Capabilities($this->theming, $this->url, $this->config);
|
||||||
->getMock();
|
|
||||||
|
|
||||||
$this->capabilities = new Capabilities($this->theming, $this->url);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dataGetCapabilities() {
|
public function dataGetCapabilities() {
|
||||||
|
@ -81,6 +73,14 @@ class CapabilitiesTest extends TestCase {
|
||||||
'logo' => 'http://localhost/logo5',
|
'logo' => 'http://localhost/logo5',
|
||||||
'background' => 'http://localhost/background6',
|
'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
|
* @param string[] $expected
|
||||||
*/
|
*/
|
||||||
public function testGetCapabilities($name, $url, $slogan, $color, $logo, $background, $baseUrl, array $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())
|
$this->theming->expects($this->once())
|
||||||
->method('getName')
|
->method('getName')
|
||||||
->willReturn($name);
|
->willReturn($name);
|
||||||
|
@ -105,21 +108,29 @@ class CapabilitiesTest extends TestCase {
|
||||||
$this->theming->expects($this->once())
|
$this->theming->expects($this->once())
|
||||||
->method('getSlogan')
|
->method('getSlogan')
|
||||||
->willReturn($slogan);
|
->willReturn($slogan);
|
||||||
$this->theming->expects($this->once())
|
$this->theming->expects($this->atLeast(1))
|
||||||
->method('getColorPrimary')
|
->method('getColorPrimary')
|
||||||
->willReturn($color);
|
->willReturn($color);
|
||||||
$this->theming->expects($this->once())
|
$this->theming->expects($this->once())
|
||||||
->method('getLogo')
|
->method('getLogo')
|
||||||
->willReturn($logo);
|
->willReturn($logo);
|
||||||
$this->theming->expects($this->once())
|
|
||||||
->method('getBackground')
|
|
||||||
->willReturn($background);
|
|
||||||
|
|
||||||
$this->url->expects($this->exactly(2))
|
if($background !== 'backgroundColor') {
|
||||||
->method('getAbsoluteURL')
|
$this->theming->expects($this->once())
|
||||||
->willReturnCallback(function($url) use($baseUrl) {
|
->method('getBackground')
|
||||||
return $baseUrl . $url;
|
->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());
|
$this->assertEquals(['theming' => $expected], $this->capabilities->getCapabilities());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue