From b73e46f4715c84a553171e3f4e99d9d43299998e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 15 Jul 2016 08:45:55 +0200 Subject: [PATCH 1/4] Better handling of empty slogan --- apps/theming/lib/template.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/apps/theming/lib/template.php b/apps/theming/lib/template.php index a09a854ca69fc..436dfe86a038d 100644 --- a/apps/theming/lib/template.php +++ b/apps/theming/lib/template.php @@ -77,6 +77,10 @@ public function getName() { return $this->config->getAppValue('theming', 'name', $this->name); } + public function getHTMLName() { + return $this->config->getAppValue('theming', 'name', $this->name); + } + public function getTitle() { return $this->config->getAppValue('theming', 'name', $this->name); } @@ -93,6 +97,15 @@ public function getSlogan() { return $this->config->getAppValue('theming', 'slogan', $this->slogan); } + public function getShortFooter() { + $slogan = $this->getSlogan(); + $footer = '' .$this->getEntity() . ''. + ($slogan !== '' ? ' – ' . $slogan : ''); + + return $footer; + } + /** * Color that is used for the header as well as for mail headers * From 06ac822b710acf473a7baad363aa08faacbda5ab Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 15 Jul 2016 09:22:44 +0200 Subject: [PATCH 2/4] Use the themed Defaults everywhere --- apps/dav/lib/connector/sabre/serverfactory.php | 2 +- core/application.php | 4 ++-- core/command/maintenance/install.php | 2 +- lib/base.php | 2 +- lib/private/console/application.php | 2 +- lib/private/server.php | 2 +- lib/private/setup.php | 2 +- lib/private/urlgenerator.php | 2 +- lib/private/util.php | 2 +- lib/public/defaults.php | 2 +- settings/application.php | 2 +- settings/personal.php | 2 +- 12 files changed, 13 insertions(+), 13 deletions(-) diff --git a/apps/dav/lib/connector/sabre/serverfactory.php b/apps/dav/lib/connector/sabre/serverfactory.php index 8462f624552c4..47400caeae7e1 100644 --- a/apps/dav/lib/connector/sabre/serverfactory.php +++ b/apps/dav/lib/connector/sabre/serverfactory.php @@ -98,7 +98,7 @@ public function createServer($baseUri, $server->setBaseUri($baseUri); // Load plugins - $defaults = new \OC_Defaults(); + $defaults = new \OCP\Defaults(); $server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin($this->config)); $server->addPlugin(new \OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin($this->config)); $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, $defaults->getName())); diff --git a/core/application.php b/core/application.php index 30376ee4f2e0f..f0748b06ba526 100644 --- a/core/application.php +++ b/core/application.php @@ -123,8 +123,8 @@ public function __construct(array $urlParams=array()){ $container->registerService('UserFolder', function(SimpleContainer $c) { return $c->query('ServerContainer')->getUserFolder(); }); - $container->registerService('Defaults', function() { - return new \OC_Defaults; + $container->registerService('Defaults', function(SimpleContainer $c) { + return $c->query('ServerContainer')->getThemingDefaults(); }); $container->registerService('Mailer', function(SimpleContainer $c) { return $c->query('ServerContainer')->getMailer(); diff --git a/core/command/maintenance/install.php b/core/command/maintenance/install.php index 266b50a3feaf5..fd04d4db53d42 100644 --- a/core/command/maintenance/install.php +++ b/core/command/maintenance/install.php @@ -63,7 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { // validate the environment $server = \OC::$server; $setupHelper = new Setup($this->config, $server->getIniWrapper(), - $server->getL10N('lib'), new \OC_Defaults(), $server->getLogger(), + $server->getL10N('lib'), $server->getThemingDefaults(), $server->getLogger(), $server->getSecureRandom()); $sysInfo = $setupHelper->getSystemInfo(true); $errors = $sysInfo['errors']; diff --git a/lib/base.php b/lib/base.php index 2ad453189d0e7..18765c1735322 100644 --- a/lib/base.php +++ b/lib/base.php @@ -911,7 +911,7 @@ public static function handleRequest() { if (!$systemConfig->getValue('installed', false)) { \OC::$server->getSession()->clear(); $setupHelper = new OC\Setup(\OC::$server->getConfig(), \OC::$server->getIniWrapper(), - \OC::$server->getL10N('lib'), new \OC_Defaults(), \OC::$server->getLogger(), + \OC::$server->getL10N('lib'), \OC::$server->getThemingDefaults(), \OC::$server->getLogger(), \OC::$server->getSecureRandom()); $controller = new OC\Core\Controller\SetupController($setupHelper); $controller->run($_POST); diff --git a/lib/private/console/application.php b/lib/private/console/application.php index d23f41f487e49..cea9719da80d8 100644 --- a/lib/private/console/application.php +++ b/lib/private/console/application.php @@ -51,7 +51,7 @@ class Application { * @param IRequest $request */ public function __construct(IConfig $config, EventDispatcherInterface $dispatcher, IRequest $request) { - $defaults = new OC_Defaults; + $defaults = \OC::$server->getThemingDefaults(); $this->config = $config; $this->application = new SymfonyApplication($defaults->getName(), \OC_Util::getVersionString()); $this->dispatcher = $dispatcher; diff --git a/lib/private/server.php b/lib/private/server.php index 0731239e88421..407026696db8b 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -510,7 +510,7 @@ public function __construct($webRoot, \OC\Config $config) { return new Mailer( $c->getConfig(), $c->getLogger(), - new \OC_Defaults() + $c->getThemingDefaults() ); }); $this->registerService('OcsClient', function (Server $c) { diff --git a/lib/private/setup.php b/lib/private/setup.php index b74e34309dc40..fc9189493e0aa 100644 --- a/lib/private/setup.php +++ b/lib/private/setup.php @@ -415,7 +415,7 @@ public static function updateHtaccess() { } $setupHelper = new \OC\Setup($config, \OC::$server->getIniWrapper(), - \OC::$server->getL10N('lib'), new \OC_Defaults(), \OC::$server->getLogger(), + \OC::$server->getL10N('lib'), \OC::$server->getThemingDefaults(), \OC::$server->getLogger(), \OC::$server->getSecureRandom()); $htaccessContent = file_get_contents($setupHelper->pathToHtaccess()); diff --git a/lib/private/urlgenerator.php b/lib/private/urlgenerator.php index 327c0c32dfe4f..b0e3c3c31296c 100644 --- a/lib/private/urlgenerator.php +++ b/lib/private/urlgenerator.php @@ -218,7 +218,7 @@ public function getAbsoluteURL($url) { * @return string url to the online documentation */ public function linkToDocs($key) { - $theme = new OC_Defaults(); + $theme = \OC::$server->getThemingDefaults(); return $theme->buildDocLinkToKey($key); } } diff --git a/lib/private/util.php b/lib/private/util.php index 74a944e085051..92bafc2d7b94e 100644 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -625,7 +625,7 @@ public static function checkServer(\OCP\IConfig $config) { $webServerRestart = false; $setup = new \OC\Setup($config, \OC::$server->getIniWrapper(), \OC::$server->getL10N('lib'), - new \OC_Defaults(), \OC::$server->getLogger(), \OC::$server->getSecureRandom()); + \OC::$server->getThemingDefaults(), \OC::$server->getLogger(), \OC::$server->getSecureRandom()); $urlGenerator = \OC::$server->getURLGenerator(); diff --git a/lib/public/defaults.php b/lib/public/defaults.php index 58b25d5914a8a..29ce167a65dcc 100644 --- a/lib/public/defaults.php +++ b/lib/public/defaults.php @@ -51,7 +51,7 @@ class Defaults { * @since 6.0.0 */ function __construct() { - $this->defaults = new \OC_Defaults(); + $this->defaults = \OC::$server->getThemingDefaults(); } /** diff --git a/settings/application.php b/settings/application.php index 5b84d028abf19..0ac42879f28e1 100644 --- a/settings/application.php +++ b/settings/application.php @@ -214,7 +214,7 @@ public function __construct(array $urlParams=[]){ return $c->query('ServerContainer')->getMailer(); }); $container->registerService('Defaults', function(IContainer $c) { - return new \OC_Defaults; + return $c->query('ServerContainer')->getThemingDefaults(); }); $container->registerService('DefaultMailAddress', function(IContainer $c) { return Util::getDefaultEmailAddress('no-reply'); diff --git a/settings/personal.php b/settings/personal.php index 244cd7eb581c0..cc7151943d402 100644 --- a/settings/personal.php +++ b/settings/personal.php @@ -36,7 +36,7 @@ OC_Util::checkLoggedIn(); -$defaults = new OC_Defaults(); // initialize themable default strings and urls +$defaults = \OC::$server->getThemingDefaults(); $certificateManager = \OC::$server->getCertificateManager(); $config = \OC::$server->getConfig(); $urlGenerator = \OC::$server->getURLGenerator(); From e6ddf775f61543110c8af7758df0129825824f32 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 15 Jul 2016 08:47:35 +0200 Subject: [PATCH 3/4] Also load the theming app on CLI --- apps/theming/appinfo/info.xml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/theming/appinfo/info.xml b/apps/theming/appinfo/info.xml index 58c839f2758a7..6db66632a457c 100644 --- a/apps/theming/appinfo/info.xml +++ b/apps/theming/appinfo/info.xml @@ -5,11 +5,17 @@ Adjust the Nextcloud theme AGPL Nextcloud - 0.1.0 + 0.2.0 Theming other + + + + + + From 3cdd10b9d7aa1f40be5e73414d99e420c897c21f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 15 Jul 2016 11:54:47 +0200 Subject: [PATCH 4/4] Add unit tests --- apps/theming/tests/lib/TemplateTest.php | 46 +++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/apps/theming/tests/lib/TemplateTest.php b/apps/theming/tests/lib/TemplateTest.php index 1ee860f93c464..cd7115d2086ec 100644 --- a/apps/theming/tests/lib/TemplateTest.php +++ b/apps/theming/tests/lib/TemplateTest.php @@ -91,6 +91,26 @@ public function testGetNameWithCustom() { $this->assertEquals('MyCustomCloud', $this->template->getName()); } + public function testGetHTMLNameWithDefault() { + $this->config + ->expects($this->once()) + ->method('getAppValue') + ->with('theming', 'name', 'Nextcloud') + ->willReturn('Nextcloud'); + + $this->assertEquals('Nextcloud', $this->template->getHTMLName()); + } + + public function testGetHTMLNameWithCustom() { + $this->config + ->expects($this->once()) + ->method('getAppValue') + ->with('theming', 'name', 'Nextcloud') + ->willReturn('MyCustomCloud'); + + $this->assertEquals('MyCustomCloud', $this->template->getHTMLName()); + } + public function testGetTitleWithDefault() { $this->config ->expects($this->once()) @@ -172,6 +192,32 @@ public function testGetSloganWithCustom() { $this->assertEquals('My custom Slogan', $this->template->getSlogan()); } + public function testGetShortFooter() { + $this->config + ->expects($this->exactly(3)) + ->method('getAppValue') + ->willReturnMap([ + ['theming', 'url', 'https://nextcloud.com/', 'url'], + ['theming', 'name', 'Nextcloud', 'Name'], + ['theming', 'slogan', 'Safe Data', 'Slogan'], + ]); + + $this->assertEquals('Name – Slogan', $this->template->getShortFooter()); + } + + public function testGetShortFooterEmptySlogan() { + $this->config + ->expects($this->exactly(3)) + ->method('getAppValue') + ->willReturnMap([ + ['theming', 'url', 'https://nextcloud.com/', 'url'], + ['theming', 'name', 'Nextcloud', 'Name'], + ['theming', 'slogan', 'Safe Data', ''], + ]); + + $this->assertEquals('Name', $this->template->getShortFooter()); + } + public function testGetMailHeaderColorWithDefault() { $this->config ->expects($this->once())