Skip to content

Commit

Permalink
Merge pull request #1026 from nextcloud/theming-extend-defaults
Browse files Browse the repository at this point in the history
Theming: Add logo and background to ThemingDefaults
  • Loading branch information
rullzer authored Aug 26, 2016
2 parents ad4cab1 + c7c53ae commit 044d7c3
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 12 deletions.
39 changes: 35 additions & 4 deletions apps/theming/lib/ThemingDefaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@
namespace OCA\Theming;




use OCP\IConfig;
use OCP\IL10N;
use OCP\IURLGenerator;

use OCP\Files\IRootFolder;

class ThemingDefaults extends \OC_Defaults {

Expand All @@ -38,6 +36,8 @@ class ThemingDefaults extends \OC_Defaults {
private $l;
/** @var IURLGenerator */
private $urlGenerator;
/** @var IRootFolder */
private $rootFolder;
/** @var string */
private $name;
/** @var string */
Expand All @@ -54,16 +54,19 @@ class ThemingDefaults extends \OC_Defaults {
* @param IL10N $l
* @param IURLGenerator $urlGenerator
* @param \OC_Defaults $defaults
* @param IRootFolder $rootFolder
*/
public function __construct(IConfig $config,
IL10N $l,
IURLGenerator $urlGenerator,
\OC_Defaults $defaults
\OC_Defaults $defaults,
IRootFolder $rootFolder
) {
parent::__construct();
$this->config = $config;
$this->l = $l;
$this->urlGenerator = $urlGenerator;
$this->rootFolder = $rootFolder;

$this->name = $defaults->getName();
$this->url = $defaults->getBaseUrl();
Expand Down Expand Up @@ -113,6 +116,34 @@ public function getMailHeaderColor() {
return $this->config->getAppValue('theming', 'color', $this->color);
}

/**
* Themed logo url
*
* @return string
*/
public function getLogo() {
$logo = $this->config->getAppValue('theming', 'logoMime');
if(!$logo || !$this->rootFolder->nodeExists('/themedinstancelogo')) {
return $this->urlGenerator->imagePath('core','logo.svg');
} else {
return $this->urlGenerator->linkToRoute('theming.Theming.getLogo');
}
}

/**
* Themed background image url
*
* @return string
*/
public function getBackground() {
$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime');
if(!$backgroundLogo || !$this->rootFolder->nodeExists('/themedbackgroundlogo')) {
return $this->urlGenerator->imagePath('core','background.jpg');
} else {
return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground');
}
}

/**
* Increases the cache buster key
*/
Expand Down
52 changes: 49 additions & 3 deletions apps/theming/tests/ThemingDefaultsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use OCP\IConfig;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\Files\IRootFolder;
use Test\TestCase;

class ThemingDefaultsTest extends TestCase {
Expand All @@ -40,11 +41,17 @@ class ThemingDefaultsTest extends TestCase {
private $defaults;
/** @var ThemingDefaults */
private $template;
/** @var IRootFolder */
private $rootFolder;

public function setUp() {
parent::setUp();
$this->config = $this->getMock('\\OCP\\IConfig');
$this->l10n = $this->getMock('\\OCP\\IL10N');
$this->urlGenerator = $this->getMock('\\OCP\\IURLGenerator');
$this->rootFolder = $this->getMockBuilder('OCP\Files\IRootFolder')
->disableOriginalConstructor()
->getMock();
$this->defaults = $this->getMockBuilder('\\OC_Defaults')
->disableOriginalConstructor()
->getMock();
Expand All @@ -68,10 +75,9 @@ public function setUp() {
$this->config,
$this->l10n,
$this->urlGenerator,
$this->defaults
$this->defaults,
$this->rootFolder
);

return parent::setUp();
}

public function testGetNameWithDefault() {
Expand Down Expand Up @@ -368,4 +374,44 @@ public function testUndoDefaultAction() {

$this->assertSame('', $this->template->undo('defaultitem'));
}

public function testGetBackgroundDefault() {
$this->config
->expects($this->once())
->method('getAppValue')
->with('theming', 'backgroundMime')
->willReturn('');
$expected = $this->urlGenerator->imagePath('core','background.jpg');
$this->assertEquals($expected, $this->template->getBackground());
}

public function testGetBackgroundCustom() {
$this->config
->expects($this->once())
->method('getAppValue')
->with('theming', 'backgroundMime')
->willReturn('image/svg+xml');
$expected = $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground');
$this->assertEquals($expected, $this->template->getBackground());
}

public function testGetLogoDefault() {
$this->config
->expects($this->once())
->method('getAppValue')
->with('theming', 'logoMime')
->willReturn('');
$expected = $this->urlGenerator->imagePath('core','logo.svg');
$this->assertEquals($expected, $this->template->getLogo());
}

public function testGetLogoCustom() {
$this->config
->expects($this->once())
->method('getAppValue')
->with('theming', 'logoMime')
->willReturn('image/svg+xml');
$expected = $this->urlGenerator->linkToRoute('theming.Theming.getLogo');
$this->assertEquals($expected, $this->template->getLogo());
}
}
11 changes: 6 additions & 5 deletions lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -656,12 +656,13 @@ public function __construct($webRoot, \OC\Config $config) {
$classExists = false;
}

if ($classExists && $this->getConfig()->getSystemValue('installed', false) && $this->getAppManager()->isInstalled('theming')) {
if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming')) {
return new ThemingDefaults(
$this->getConfig(),
$this->getL10N('theming'),
$this->getURLGenerator(),
new \OC_Defaults()
$c->getConfig(),
$c->getL10N('theming'),
$c->getURLGenerator(),
new \OC_Defaults(),
$c->getLazyRootFolder()
);
}
return new \OC_Defaults();
Expand Down

0 comments on commit 044d7c3

Please sign in to comment.