diff options
author | Morris Jobke <hey@morrisjobke.de> | 2017-05-17 10:42:41 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-17 10:42:41 -0500 |
commit | 2ec616323b9ce83a8b8a0347b069991696198aeb (patch) | |
tree | a6f9741a134459a001d015f67b9cf7a06062ef7f /apps/theming | |
parent | e3322634a2ddd96ae454d1796fcaf46769a885ec (diff) | |
parent | 81847c01b014bf609e7d5597b2d81efe5973b0a5 (diff) | |
download | nextcloud-server-2ec616323b9ce83a8b8a0347b069991696198aeb.tar.gz nextcloud-server-2ec616323b9ce83a8b8a0347b069991696198aeb.zip |
Merge pull request #4918 from nextcloud/theming-capabilities-plain-background
OCS Return color when theming uses no background image
Diffstat (limited to 'apps/theming')
-rw-r--r-- | apps/theming/lib/Capabilities.php | 15 | ||||
-rw-r--r-- | apps/theming/tests/CapabilitiesTest.php | 61 |
2 files changed, 48 insertions, 28 deletions
diff --git a/apps/theming/lib/Capabilities.php b/apps/theming/lib/Capabilities.php index 2a9e9a3c6cf..6e098940ff1 100644 --- a/apps/theming/lib/Capabilities.php +++ b/apps/theming/lib/Capabilities.php @@ -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()), ], ]; } diff --git a/apps/theming/tests/CapabilitiesTest.php b/apps/theming/tests/CapabilitiesTest.php index 1c379797736..55f40cb788a 100644 --- a/apps/theming/tests/CapabilitiesTest.php +++ b/apps/theming/tests/CapabilitiesTest.php @@ -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()); } |