Merge pull request #4918 from nextcloud/theming-capabilities-plain-background

OCS Return color when theming uses no background image
This commit is contained in:
Morris Jobke 2017-05-17 10:42:41 -05:00 committed by GitHub
commit 2ec616323b
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());
}