diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2017-04-07 14:51:05 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2017-04-07 12:03:47 -0500 |
commit | 281ad406e88d36c1492c7aefd8ef28762379f9e3 (patch) | |
tree | 91b81364f1a9244455657b86848025c628fd4089 /apps/theming | |
parent | 1be75e8db8f583476f1cd03498afd608fce6408d (diff) | |
download | nextcloud-server-281ad406e88d36c1492c7aefd8ef28762379f9e3.tar.gz nextcloud-server-281ad406e88d36c1492c7aefd8ef28762379f9e3.zip |
Add support for theming
Add support for theming in generated emails and simplify API
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Diffstat (limited to 'apps/theming')
-rw-r--r-- | apps/theming/lib/ThemingDefaults.php | 51 | ||||
-rw-r--r-- | apps/theming/tests/ThemingDefaultsTest.php | 57 |
2 files changed, 82 insertions, 26 deletions
diff --git a/apps/theming/lib/ThemingDefaults.php b/apps/theming/lib/ThemingDefaults.php index 5a863b1eb22..d4dc56d3ba9 100644 --- a/apps/theming/lib/ThemingDefaults.php +++ b/apps/theming/lib/ThemingDefaults.php @@ -1,6 +1,7 @@ <?php /** * @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org> + * @copyright Copyright (c) 2017 Lukas Reschke <lukas@statuscode.ch> * * @license GNU AGPL version 3 or any later version * @@ -19,15 +20,14 @@ * */ - namespace OCA\Theming; +use OCP\Files\IAppData; use OCP\ICacheFactory; use OCP\IConfig; use OCP\IL10N; use OCP\IURLGenerator; -use OCP\Files\IRootFolder; use OCP\Util; class ThemingDefaults extends \OC_Defaults { @@ -38,8 +38,8 @@ class ThemingDefaults extends \OC_Defaults { private $l; /** @var IURLGenerator */ private $urlGenerator; - /** @var IRootFolder */ - private $rootFolder; + /** @var IAppData */ + private $appData; /** @var ICacheFactory */ private $cacheFactory; /** @var string */ @@ -58,21 +58,21 @@ class ThemingDefaults extends \OC_Defaults { * @param IL10N $l * @param IURLGenerator $urlGenerator * @param \OC_Defaults $defaults - * @param IRootFolder $rootFolder + * @param IAppData $appData * @param ICacheFactory $cacheFactory */ public function __construct(IConfig $config, IL10N $l, IURLGenerator $urlGenerator, \OC_Defaults $defaults, - IRootFolder $rootFolder, + IAppData $appData, ICacheFactory $cacheFactory ) { parent::__construct(); $this->config = $config; $this->l = $l; $this->urlGenerator = $urlGenerator; - $this->rootFolder = $rootFolder; + $this->appData = $appData; $this->cacheFactory = $cacheFactory; $this->name = $defaults->getName(); @@ -130,11 +130,19 @@ class ThemingDefaults extends \OC_Defaults { */ public function getLogo() { $logo = $this->config->getAppValue('theming', 'logoMime'); - if(!$logo || !$this->rootFolder->nodeExists('/themedinstancelogo')) { + + $logoExists = true; + try { + $this->appData->getFolder('images')->getFile('logo'); + } catch (\Exception $e) { + $logoExists = false; + } + + if(!$logo || !$logoExists) { return $this->urlGenerator->imagePath('core','logo.svg'); - } else { - return $this->urlGenerator->linkToRoute('theming.Theming.getLogo'); } + + return $this->urlGenerator->linkToRoute('theming.Theming.getLogo'); } /** @@ -144,11 +152,19 @@ class ThemingDefaults extends \OC_Defaults { */ public function getBackground() { $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime'); - if(!$backgroundLogo || !$this->rootFolder->nodeExists('/themedbackgroundlogo')) { + + $backgroundExists = true; + try { + $this->appData->getFolder('images')->getFile('background'); + } catch (\Exception $e) { + $backgroundExists = false; + } + + if(!$backgroundLogo || !$backgroundExists) { return $this->urlGenerator->imagePath('core','background.jpg'); - } else { - return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground'); } + + return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground'); } /** @@ -175,6 +191,15 @@ class ThemingDefaults extends \OC_Defaults { } /** + * Gets the current cache buster count + * + * @return string + */ + public function getCacheBusterCounter() { + return $this->config->getAppValue('theming', 'cachebuster', '0'); + } + + /** * Increases the cache buster key */ private function increaseCacheBuster() { diff --git a/apps/theming/tests/ThemingDefaultsTest.php b/apps/theming/tests/ThemingDefaultsTest.php index 72ccaa57d77..986b2f34267 100644 --- a/apps/theming/tests/ThemingDefaultsTest.php +++ b/apps/theming/tests/ThemingDefaultsTest.php @@ -24,37 +24,36 @@ namespace OCA\Theming\Tests; use OCA\Theming\ThemingDefaults; +use OCP\Files\IAppData; +use OCP\Files\SimpleFS\ISimpleFolder; use OCP\ICacheFactory; use OCP\IConfig; use OCP\IL10N; use OCP\IURLGenerator; -use OCP\Files\IRootFolder; use Test\TestCase; class ThemingDefaultsTest extends TestCase { - /** @var IConfig */ + /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ private $config; - /** @var IL10N */ + /** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */ private $l10n; - /** @var IURLGenerator */ + /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */ private $urlGenerator; - /** @var \OC_Defaults */ + /** @var \OC_Defaults|\PHPUnit_Framework_MockObject_MockObject */ private $defaults; + /** @var IAppData|\PHPUnit_Framework_MockObject_MockObject */ + private $appData; + /** @var ICacheFactory|\PHPUnit_Framework_MockObject_MockObject */ + private $cacheFactory; /** @var ThemingDefaults */ private $template; - /** @var IRootFolder */ - private $rootFolder; - /** @var ICacheFactory */ - private $cacheFactory; public function setUp() { parent::setUp(); $this->config = $this->getMockBuilder(IConfig::class)->getMock(); $this->l10n = $this->getMockBuilder(IL10N::class)->getMock(); $this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)->getMock(); - $this->rootFolder = $this->getMockBuilder(IRootFolder::class) - ->disableOriginalConstructor() - ->getMock(); + $this->appData = $this->createMock(IAppData::class); $this->cacheFactory = $this->getMockBuilder(ICacheFactory::class)->getMock(); $this->defaults = $this->getMockBuilder(\OC_Defaults::class) ->disableOriginalConstructor() @@ -80,7 +79,7 @@ class ThemingDefaultsTest extends TestCase { $this->l10n, $this->urlGenerator, $this->defaults, - $this->rootFolder, + $this->appData, $this->cacheFactory ); } @@ -386,6 +385,11 @@ class ThemingDefaultsTest extends TestCase { ->method('getAppValue') ->with('theming', 'backgroundMime') ->willReturn(''); + $this->appData + ->expects($this->once()) + ->method('getFolder') + ->with('images') + ->willThrowException(new \Exception()); $expected = $this->urlGenerator->imagePath('core','background.jpg'); $this->assertEquals($expected, $this->template->getBackground()); } @@ -396,6 +400,17 @@ class ThemingDefaultsTest extends TestCase { ->method('getAppValue') ->with('theming', 'backgroundMime') ->willReturn('image/svg+xml'); + $simpleFolder = $this->createMock(ISimpleFolder::class); + $this->appData + ->expects($this->once()) + ->method('getFolder') + ->with('images') + ->willReturn($simpleFolder); + $simpleFolder + ->expects($this->once()) + ->method('getFile') + ->with('background') + ->willReturn(''); $expected = $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground'); $this->assertEquals($expected, $this->template->getBackground()); } @@ -406,6 +421,11 @@ class ThemingDefaultsTest extends TestCase { ->method('getAppValue') ->with('theming', 'logoMime') ->willReturn(''); + $this->appData + ->expects($this->once()) + ->method('getFolder') + ->with('images') + ->willThrowException(new \Exception()); $expected = $this->urlGenerator->imagePath('core','logo.svg'); $this->assertEquals($expected, $this->template->getLogo()); } @@ -416,6 +436,17 @@ class ThemingDefaultsTest extends TestCase { ->method('getAppValue') ->with('theming', 'logoMime') ->willReturn('image/svg+xml'); + $simpleFolder = $this->createMock(ISimpleFolder::class); + $this->appData + ->expects($this->once()) + ->method('getFolder') + ->with('images') + ->willReturn($simpleFolder); + $simpleFolder + ->expects($this->once()) + ->method('getFile') + ->with('logo') + ->willReturn(''); $expected = $this->urlGenerator->linkToRoute('theming.Theming.getLogo'); $this->assertEquals($expected, $this->template->getLogo()); } |