--- /dev/null
+<?php
+/**
+ * @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org>
+ * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
+ *
+ * @author Bjoern Schiessle <bjoern@schiessle.org>
+ * @author Julius Haertl <jus@bitgrid.net>
+ * @author Lukas Reschke <lukas@statuscode.ch>
+ * @author oparoz <owncloud@interfasys.ch>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Theming\Controller;
+
+use OCA\Theming\Template;
+use OCP\AppFramework\Controller;
+use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\DataResponse;
+use OCP\Files\IRootFolder;
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\IRequest;
+use OCA\Theming\Util;
+
+/**
+ * Class ThemingController
+ *
+ * handle ajax requests to update the theme
+ *
+ * @package OCA\Theming\Controller
+ */
+class ThemingController extends Controller {
+ /** @var Template */
+ private $template;
+ /** @var IL10N */
+ private $l;
+ /** @var IConfig */
+ private $config;
+ /** @var IRootFolder */
+ private $rootFolder;
+
+ /**
+ * ThemingController constructor.
+ *
+ * @param string $appName
+ * @param IRequest $request
+ * @param IConfig $config
+ * @param Template $template
+ * @param IL10N $l
+ * @param IRootFolder $rootFolder
+ */
+ public function __construct(
+ $appName,
+ IRequest $request,
+ IConfig $config,
+ Template $template,
+ IL10N $l,
+ IRootFolder $rootFolder
+ ) {
+ parent::__construct($appName, $request);
+
+ $this->template = $template;
+ $this->l = $l;
+ $this->config = $config;
+ $this->rootFolder = $rootFolder;
+ }
+
+ /**
+ * @param string $setting
+ * @param string $value
+ * @return DataResponse
+ * @internal param string $color
+ */
+ public function updateStylesheet($setting, $value) {
+ $this->template->set($setting, $value);
+ return new DataResponse(
+ [
+ 'data' =>
+ [
+ 'message' => $this->l->t('Saved')
+ ],
+ 'status' => 'success'
+ ]
+ );
+ }
+
+ /**
+ * Update the logos and background image
+ *
+ * @return DataResponse
+ */
+ public function updateLogo() {
+ $newLogo = $this->request->getUploadedFile('uploadlogo');
+ $newBackgroundLogo = $this->request->getUploadedFile('upload-login-background');
+ if (empty($newLogo) && empty($newBackgroundLogo)) {
+ return new DataResponse(
+ [
+ 'data' => [
+ 'message' => $this->l->t('No file uploaded')
+ ]
+ ],
+ Http::STATUS_UNPROCESSABLE_ENTITY);
+ }
+ $name = '';
+ if(!empty($newLogo)) {
+ $target = $this->rootFolder->newFile('themedinstancelogo');
+ stream_copy_to_stream(fopen($newLogo['tmp_name'], 'r'), $target->fopen('w'));
+ $this->template->set('logoMime', $newLogo['type']);
+ $name = $newLogo['name'];
+ }
+ if(!empty($newBackgroundLogo)) {
+ $target = $this->rootFolder->newFile('themedbackgroundlogo');
+ stream_copy_to_stream(fopen($newBackgroundLogo['tmp_name'], 'r'), $target->fopen('w'));
+ $this->template->set('backgroundMime', $newBackgroundLogo['type']);
+ $name = $newBackgroundLogo['name'];
+ }
+
+ return new DataResponse(
+ [
+ 'data' =>
+ [
+ 'name' => $name,
+ 'message' => $this->l->t('Saved')
+ ],
+ 'status' => 'success'
+ ]
+ );
+ }
+
+ /**
+ * Revert setting to default value
+ *
+ * @param string $setting setting which should be reverted
+ * @return DataResponse
+ */
+ public function undo($setting) {
+ $value = $this->template->undo($setting);
+ return new DataResponse(
+ [
+ 'data' =>
+ [
+ 'value' => $value,
+ 'message' => $this->l->t('Saved')
+ ],
+ 'status' => 'success'
+ ]
+ );
+ }
+
+ /**
+ * @PublicPage
+ * @NoCSRFRequired
+ *
+ * @return Http\StreamResponse
+ */
+ public function getLogo() {
+ $pathToLogo = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data/') . '/themedinstancelogo';
+ if(!file_exists($pathToLogo)) {
+ return new DataResponse();
+ }
+
+ \OC_Response::setExpiresHeader(gmdate('D, d M Y H:i:s', time() + (60*60*24*45)) . ' GMT');
+ \OC_Response::enableCaching();
+ $response = new Http\StreamResponse($pathToLogo);
+ $response->cacheFor(3600);
+ $response->addHeader('Content-Disposition', 'attachment');
+ $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, 'logoMime', ''));
+ return $response;
+ }
+
+ /**
+ * @PublicPage
+ * @NoCSRFRequired
+ *
+ * @return Http\StreamResponse
+ */
+ public function getLoginBackground() {
+ $pathToLogo = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data/') . '/themedbackgroundlogo';
+ if(!file_exists($pathToLogo)) {
+ return new DataResponse();
+ }
+
+ \OC_Response::setExpiresHeader(gmdate('D, d M Y H:i:s', time() + (60*60*24*45)) . ' GMT');
+ \OC_Response::enableCaching();
+ $response = new Http\StreamResponse($pathToLogo);
+ $response->cacheFor(3600);
+ $response->addHeader('Content-Disposition', 'attachment');
+ $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, 'backgroundMime', ''));
+ return $response;
+ }
+
+ /**
+ * @NoCSRFRequired
+ * @PublicPage
+ *
+ * @return Http\DataDownloadResponse
+ */
+ public function getStylesheet() {
+ $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0');
+ $responseCss = '';
+ $color = $this->config->getAppValue($this->appName, 'color');
+ $elementColor = Util::elementColor($color);
+ if($color !== '') {
+ $responseCss .= sprintf(
+ '#body-user #header,#body-settings #header,#body-public #header,#body-login,.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid {background-color: %s}' . "\n",
+ $color
+ );
+ $responseCss .= sprintf('input[type="checkbox"].checkbox:checked:enabled:not(.checkbox--white) + label:before {' .
+ 'background-image:url(\'%s/core/img/actions/checkmark-white.svg\');' .
+ 'background-color: %s; background-position: center center; background-size:contain;' .
+ 'width:12px; height:12px; padding:0; margin:2px 6px 6px 2px; border-radius:1px;' .
+ "}\n",
+ \OC::$WEBROOT,
+ $elementColor
+ );
+ $responseCss .= 'input[type="radio"].radio:checked:not(.radio--white):not(:disabled) + label:before {' .
+ 'background-image: url(\'data:image/svg+xml;base64,'.Util::generateRadioButton($elementColor).'\');' .
+ "}\n";
+ $responseCss .= '
+ #firstrunwizard .firstrunwizard-header {
+ background-color: ' . $color . ';
+ }
+ #firstrunwizard p a {
+ color: ' . $color . ';
+ }
+ ';
+
+ }
+ $logo = $this->config->getAppValue($this->appName, 'logoMime');
+ if($logo !== '') {
+ $responseCss .= sprintf(
+ '#header .logo {' .
+ 'background-image: url(\'./logo?v='.$cacheBusterValue.'\');' .
+ 'background-size: contain;' .
+ '}' . "\n" .
+ '#header .logo-icon {' .
+ 'background-image: url(\'./logo?v='.$cacheBusterValue.'\');' .
+ 'background-size: contain;' .
+ '}' . "\n" .
+ '#firstrunwizard .firstrunwizard-header .logo {' .
+ 'background-image: url(\'./logo?v='.$cacheBusterValue.'\');' .
+ 'background-size: contain;' .
+ '}' . "\n"
+ );
+ }
+ $backgroundLogo = $this->config->getAppValue($this->appName, 'backgroundMime');
+ if($backgroundLogo !== '') {
+ $responseCss .= '#body-login {background-image: url(\'./loginbackground?v='.$cacheBusterValue.'\');}' . "\n";
+ $responseCss .= '#firstrunwizard .firstrunwizard-header {' .
+ 'background-image: url(\'./loginbackground?v='.$cacheBusterValue.'\');' .
+ '}' . "\n";
+ }
+ if(Util::invertTextColor($color)) {
+ $responseCss .= '#header .header-appname, #expandDisplayName { color: #000000; }' . "\n";
+ $responseCss .= '#header .icon-caret { background-image: url(\'' . \OC::$WEBROOT . '/core/img/actions/caret-dark.svg\'); }' . "\n";
+ $responseCss .= '.searchbox input[type="search"] { background: transparent url(\'' . \OC::$WEBROOT . '/core/img/actions/search.svg\') no-repeat 6px center; color: #000; }' . "\n";
+ $responseCss .= '.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid { color: #000; border: 1px solid rgba(0, 0, 0, .5); }' . "\n";
+ }
+
+ \OC_Response::setExpiresHeader(gmdate('D, d M Y H:i:s', time() + (60*60*24*45)) . ' GMT');
+ \OC_Response::enableCaching();
+ $response = new Http\DataDownloadResponse($responseCss, 'style', 'text/css');
+ $response->cacheFor(3600);
+ return $response;
+ }
+}
--- /dev/null
+<?php
+/**
+ * @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org>
+ * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
+ *
+ * @author Bjoern Schiessle <bjoern@schiessle.org>
+ * @author Joas Schilling <coding@schilljs.com>
+ * @author Lukas Reschke <lukas@statuscode.ch>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Theming;
+
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+
+/**
+ * Class Template
+ *
+ * Handle all the values which can be modified by this app
+ *
+ * @package OCA\Theming
+ */
+class Template extends \OC_Defaults {
+ /** @var IConfig */
+ private $config;
+ /** @var IL10N */
+ private $l;
+ /** @var IURLGenerator */
+ private $urlGenerator;
+ /** @var string */
+ private $name;
+ /** @var string */
+ private $url;
+ /** @var string */
+ private $slogan;
+ /** @var string */
+ private $color;
+
+ /**
+ * Template constructor.
+ *
+ * @param IConfig $config
+ * @param IL10N $l
+ * @param IURLGenerator $urlGenerator
+ * @param \OC_Defaults $defaults
+ */
+ public function __construct(IConfig $config,
+ IL10N $l,
+ IURLGenerator $urlGenerator,
+ \OC_Defaults $defaults
+ ) {
+ parent::__construct();
+ $this->config = $config;
+ $this->l = $l;
+ $this->urlGenerator = $urlGenerator;
+
+ $this->name = $defaults->getName();
+ $this->url = $defaults->getBaseUrl();
+ $this->slogan = $defaults->getSlogan();
+ $this->color = $defaults->getMailHeaderColor();
+ }
+
+ 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);
+ }
+
+ public function getEntity() {
+ return $this->config->getAppValue('theming', 'name', $this->name);
+ }
+
+ public function getBaseUrl() {
+ return $this->config->getAppValue('theming', 'url', $this->url);
+ }
+
+ public function getSlogan() {
+ return $this->config->getAppValue('theming', 'slogan', $this->slogan);
+ }
+
+ public function getShortFooter() {
+ $slogan = $this->getSlogan();
+ $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' .
+ ' rel="noreferrer">' .$this->getEntity() . '</a>'.
+ ($slogan !== '' ? ' – ' . $slogan : '');
+
+ return $footer;
+ }
+
+ /**
+ * Color that is used for the header as well as for mail headers
+ *
+ * @return string
+ */
+ public function getMailHeaderColor() {
+ return $this->config->getAppValue('theming', 'color', $this->color);
+ }
+
+ /**
+ * Increases the cache buster key
+ */
+ private function increaseCacheBuster() {
+ $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');
+ $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1);
+ }
+
+ /**
+ * Update setting in the database
+ *
+ * @param string $setting
+ * @param string $value
+ */
+ public function set($setting, $value) {
+ $this->config->setAppValue('theming', $setting, $value);
+ $this->increaseCacheBuster();
+ }
+
+ /**
+ * Revert settings to the default value
+ *
+ * @param string $setting setting which should be reverted
+ * @return string default value
+ */
+ public function undo($setting) {
+ $this->config->deleteAppValue('theming', $setting);
+ $this->increaseCacheBuster();
+
+ switch ($setting) {
+ case 'name':
+ $returnValue = $this->getEntity();
+ break;
+ case 'url':
+ $returnValue = $this->getBaseUrl();
+ break;
+ case 'slogan':
+ $returnValue = $this->getSlogan();
+ break;
+ case 'color':
+ $returnValue = $this->getMailHeaderColor();
+ break;
+ default:
+ $returnValue = '';
+ break;
+ }
+
+ return $returnValue;
+ }
+}
--- /dev/null
+<?php
+/**
+ * @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
+ *
+ * @author Julius Haertl <jus@bitgrid.net>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Theming;
+
+class Util {
+
+ /**
+ * @param string $color rgb color value
+ * @return bool
+ */
+ public static function invertTextColor($color) {
+ $l = self::calculateLuminance($color);
+ if($l>0.5) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * get color for on-page elements:
+ * theme color by default, grey if theme color is to bright
+ * @param $color
+ * @return string
+ */
+ public static function elementColor($color) {
+ $l = self::calculateLuminance($color);
+ if($l>0.8) {
+ return '#555555';
+ } else {
+ return $color;
+ }
+ }
+
+ /**
+ * @param string $color rgb color value
+ * @return float
+ */
+ public static function calculateLuminance($color) {
+ $hex = preg_replace("/[^0-9A-Fa-f]/", '', $color);
+ if (strlen($hex) === 3) {
+ $hex = $hex{0} . $hex{0} . $hex{1} . $hex{1} . $hex{2} . $hex{2};
+ }
+ if (strlen($hex) !== 6) {
+ return 0;
+ }
+ $r = hexdec(substr($hex, 0, 2));
+ $g = hexdec(substr($hex, 2, 2));
+ $b = hexdec(substr($hex, 4, 2));
+ return (0.299 * $r + 0.587 * $g + 0.114 * $b)/255;
+ }
+
+ /**
+ * @param $color
+ * @return string base64 encoded radio button svg
+ */
+ public static function generateRadioButton($color) {
+ $radioButtonIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16">' .
+ '<path d="M8 1a7 7 0 0 0-7 7 7 7 0 0 0 7 7 7 7 0 0 0 7-7 7 7 0 0 0-7-7zm0 1a6 6 0 0 1 6 6 6 6 0 0 1-6 6 6 6 0 0 1-6-6 6 6 0 0 1 6-6zm0 2a4 4 0 1 0 0 8 4 4 0 0 0 0-8z" fill="'.$color.'"/></svg>';
+ return base64_encode($radioButtonIcon);
+ }
+
+}
+++ /dev/null
-<?php
-/**
- * @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org>
- * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
- *
- * @author Bjoern Schiessle <bjoern@schiessle.org>
- * @author Julius Haertl <jus@bitgrid.net>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author oparoz <owncloud@interfasys.ch>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-namespace OCA\Theming\Controller;
-
-use OCA\Theming\Template;
-use OCP\AppFramework\Controller;
-use OCP\AppFramework\Http;
-use OCP\AppFramework\Http\DataResponse;
-use OCP\Files\IRootFolder;
-use OCP\IConfig;
-use OCP\IL10N;
-use OCP\IRequest;
-use OCA\Theming\Util;
-
-/**
- * Class ThemingController
- *
- * handle ajax requests to update the theme
- *
- * @package OCA\Theming\Controller
- */
-class ThemingController extends Controller {
- /** @var Template */
- private $template;
- /** @var IL10N */
- private $l;
- /** @var IConfig */
- private $config;
- /** @var IRootFolder */
- private $rootFolder;
-
- /**
- * ThemingController constructor.
- *
- * @param string $appName
- * @param IRequest $request
- * @param IConfig $config
- * @param Template $template
- * @param IL10N $l
- * @param IRootFolder $rootFolder
- */
- public function __construct(
- $appName,
- IRequest $request,
- IConfig $config,
- Template $template,
- IL10N $l,
- IRootFolder $rootFolder
- ) {
- parent::__construct($appName, $request);
-
- $this->template = $template;
- $this->l = $l;
- $this->config = $config;
- $this->rootFolder = $rootFolder;
- }
-
- /**
- * @param string $setting
- * @param string $value
- * @return DataResponse
- * @internal param string $color
- */
- public function updateStylesheet($setting, $value) {
- $this->template->set($setting, $value);
- return new DataResponse(
- [
- 'data' =>
- [
- 'message' => $this->l->t('Saved')
- ],
- 'status' => 'success'
- ]
- );
- }
-
- /**
- * Update the logos and background image
- *
- * @return DataResponse
- */
- public function updateLogo() {
- $newLogo = $this->request->getUploadedFile('uploadlogo');
- $newBackgroundLogo = $this->request->getUploadedFile('upload-login-background');
- if (empty($newLogo) && empty($newBackgroundLogo)) {
- return new DataResponse(
- [
- 'data' => [
- 'message' => $this->l->t('No file uploaded')
- ]
- ],
- Http::STATUS_UNPROCESSABLE_ENTITY);
- }
- $name = '';
- if(!empty($newLogo)) {
- $target = $this->rootFolder->newFile('themedinstancelogo');
- stream_copy_to_stream(fopen($newLogo['tmp_name'], 'r'), $target->fopen('w'));
- $this->template->set('logoMime', $newLogo['type']);
- $name = $newLogo['name'];
- }
- if(!empty($newBackgroundLogo)) {
- $target = $this->rootFolder->newFile('themedbackgroundlogo');
- stream_copy_to_stream(fopen($newBackgroundLogo['tmp_name'], 'r'), $target->fopen('w'));
- $this->template->set('backgroundMime', $newBackgroundLogo['type']);
- $name = $newBackgroundLogo['name'];
- }
-
- return new DataResponse(
- [
- 'data' =>
- [
- 'name' => $name,
- 'message' => $this->l->t('Saved')
- ],
- 'status' => 'success'
- ]
- );
- }
-
- /**
- * Revert setting to default value
- *
- * @param string $setting setting which should be reverted
- * @return DataResponse
- */
- public function undo($setting) {
- $value = $this->template->undo($setting);
- return new DataResponse(
- [
- 'data' =>
- [
- 'value' => $value,
- 'message' => $this->l->t('Saved')
- ],
- 'status' => 'success'
- ]
- );
- }
-
- /**
- * @PublicPage
- * @NoCSRFRequired
- *
- * @return Http\StreamResponse
- */
- public function getLogo() {
- $pathToLogo = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data/') . '/themedinstancelogo';
- if(!file_exists($pathToLogo)) {
- return new DataResponse();
- }
-
- \OC_Response::setExpiresHeader(gmdate('D, d M Y H:i:s', time() + (60*60*24*45)) . ' GMT');
- \OC_Response::enableCaching();
- $response = new Http\StreamResponse($pathToLogo);
- $response->cacheFor(3600);
- $response->addHeader('Content-Disposition', 'attachment');
- $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, 'logoMime', ''));
- return $response;
- }
-
- /**
- * @PublicPage
- * @NoCSRFRequired
- *
- * @return Http\StreamResponse
- */
- public function getLoginBackground() {
- $pathToLogo = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data/') . '/themedbackgroundlogo';
- if(!file_exists($pathToLogo)) {
- return new DataResponse();
- }
-
- \OC_Response::setExpiresHeader(gmdate('D, d M Y H:i:s', time() + (60*60*24*45)) . ' GMT');
- \OC_Response::enableCaching();
- $response = new Http\StreamResponse($pathToLogo);
- $response->cacheFor(3600);
- $response->addHeader('Content-Disposition', 'attachment');
- $response->addHeader('Content-Type', $this->config->getAppValue($this->appName, 'backgroundMime', ''));
- return $response;
- }
-
- /**
- * @NoCSRFRequired
- * @PublicPage
- *
- * @return Http\DataDownloadResponse
- */
- public function getStylesheet() {
- $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0');
- $responseCss = '';
- $color = $this->config->getAppValue($this->appName, 'color');
- $elementColor = Util::elementColor($color);
- if($color !== '') {
- $responseCss .= sprintf(
- '#body-user #header,#body-settings #header,#body-public #header,#body-login,.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid {background-color: %s}' . "\n",
- $color
- );
- $responseCss .= sprintf('input[type="checkbox"].checkbox:checked:enabled:not(.checkbox--white) + label:before {' .
- 'background-image:url(\'%s/core/img/actions/checkmark-white.svg\');' .
- 'background-color: %s; background-position: center center; background-size:contain;' .
- 'width:12px; height:12px; padding:0; margin:2px 6px 6px 2px; border-radius:1px;' .
- "}\n",
- \OC::$WEBROOT,
- $elementColor
- );
- $responseCss .= 'input[type="radio"].radio:checked:not(.radio--white):not(:disabled) + label:before {' .
- 'background-image: url(\'data:image/svg+xml;base64,'.Util::generateRadioButton($elementColor).'\');' .
- "}\n";
- $responseCss .= '
- #firstrunwizard .firstrunwizard-header {
- background-color: ' . $color . ';
- }
- #firstrunwizard p a {
- color: ' . $color . ';
- }
- ';
-
- }
- $logo = $this->config->getAppValue($this->appName, 'logoMime');
- if($logo !== '') {
- $responseCss .= sprintf(
- '#header .logo {' .
- 'background-image: url(\'./logo?v='.$cacheBusterValue.'\');' .
- 'background-size: contain;' .
- '}' . "\n" .
- '#header .logo-icon {' .
- 'background-image: url(\'./logo?v='.$cacheBusterValue.'\');' .
- 'background-size: contain;' .
- '}' . "\n" .
- '#firstrunwizard .firstrunwizard-header .logo {' .
- 'background-image: url(\'./logo?v='.$cacheBusterValue.'\');' .
- 'background-size: contain;' .
- '}' . "\n"
- );
- }
- $backgroundLogo = $this->config->getAppValue($this->appName, 'backgroundMime');
- if($backgroundLogo !== '') {
- $responseCss .= '#body-login {background-image: url(\'./loginbackground?v='.$cacheBusterValue.'\');}' . "\n";
- $responseCss .= '#firstrunwizard .firstrunwizard-header {' .
- 'background-image: url(\'./loginbackground?v='.$cacheBusterValue.'\');' .
- '}' . "\n";
- }
- if(Util::invertTextColor($color)) {
- $responseCss .= '#header .header-appname, #expandDisplayName { color: #000000; }' . "\n";
- $responseCss .= '#header .icon-caret { background-image: url(\'' . \OC::$WEBROOT . '/core/img/actions/caret-dark.svg\'); }' . "\n";
- $responseCss .= '.searchbox input[type="search"] { background: transparent url(\'' . \OC::$WEBROOT . '/core/img/actions/search.svg\') no-repeat 6px center; color: #000; }' . "\n";
- $responseCss .= '.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid { color: #000; border: 1px solid rgba(0, 0, 0, .5); }' . "\n";
- }
-
- \OC_Response::setExpiresHeader(gmdate('D, d M Y H:i:s', time() + (60*60*24*45)) . ' GMT');
- \OC_Response::enableCaching();
- $response = new Http\DataDownloadResponse($responseCss, 'style', 'text/css');
- $response->cacheFor(3600);
- return $response;
- }
-}
+++ /dev/null
-<?php
-/**
- * @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org>
- * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
- *
- * @author Bjoern Schiessle <bjoern@schiessle.org>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Lukas Reschke <lukas@statuscode.ch>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-namespace OCA\Theming;
-
-use OCP\IConfig;
-use OCP\IL10N;
-use OCP\IURLGenerator;
-
-/**
- * Class Template
- *
- * Handle all the values which can be modified by this app
- *
- * @package OCA\Theming
- */
-class Template extends \OC_Defaults {
- /** @var IConfig */
- private $config;
- /** @var IL10N */
- private $l;
- /** @var IURLGenerator */
- private $urlGenerator;
- /** @var string */
- private $name;
- /** @var string */
- private $url;
- /** @var string */
- private $slogan;
- /** @var string */
- private $color;
-
- /**
- * Template constructor.
- *
- * @param IConfig $config
- * @param IL10N $l
- * @param IURLGenerator $urlGenerator
- * @param \OC_Defaults $defaults
- */
- public function __construct(IConfig $config,
- IL10N $l,
- IURLGenerator $urlGenerator,
- \OC_Defaults $defaults
- ) {
- parent::__construct();
- $this->config = $config;
- $this->l = $l;
- $this->urlGenerator = $urlGenerator;
-
- $this->name = $defaults->getName();
- $this->url = $defaults->getBaseUrl();
- $this->slogan = $defaults->getSlogan();
- $this->color = $defaults->getMailHeaderColor();
- }
-
- 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);
- }
-
- public function getEntity() {
- return $this->config->getAppValue('theming', 'name', $this->name);
- }
-
- public function getBaseUrl() {
- return $this->config->getAppValue('theming', 'url', $this->url);
- }
-
- public function getSlogan() {
- return $this->config->getAppValue('theming', 'slogan', $this->slogan);
- }
-
- public function getShortFooter() {
- $slogan = $this->getSlogan();
- $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' .
- ' rel="noreferrer">' .$this->getEntity() . '</a>'.
- ($slogan !== '' ? ' – ' . $slogan : '');
-
- return $footer;
- }
-
- /**
- * Color that is used for the header as well as for mail headers
- *
- * @return string
- */
- public function getMailHeaderColor() {
- return $this->config->getAppValue('theming', 'color', $this->color);
- }
-
- /**
- * Increases the cache buster key
- */
- private function increaseCacheBuster() {
- $cacheBusterKey = $this->config->getAppValue('theming', 'cachebuster', '0');
- $this->config->setAppValue('theming', 'cachebuster', (int)$cacheBusterKey+1);
- }
-
- /**
- * Update setting in the database
- *
- * @param string $setting
- * @param string $value
- */
- public function set($setting, $value) {
- $this->config->setAppValue('theming', $setting, $value);
- $this->increaseCacheBuster();
- }
-
- /**
- * Revert settings to the default value
- *
- * @param string $setting setting which should be reverted
- * @return string default value
- */
- public function undo($setting) {
- $this->config->deleteAppValue('theming', $setting);
- $this->increaseCacheBuster();
-
- switch ($setting) {
- case 'name':
- $returnValue = $this->getEntity();
- break;
- case 'url':
- $returnValue = $this->getBaseUrl();
- break;
- case 'slogan':
- $returnValue = $this->getSlogan();
- break;
- case 'color':
- $returnValue = $this->getMailHeaderColor();
- break;
- default:
- $returnValue = '';
- break;
- }
-
- return $returnValue;
- }
-}
+++ /dev/null
-<?php
-/**
- * @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
- *
- * @author Julius Haertl <jus@bitgrid.net>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-namespace OCA\Theming;
-
-class Util {
-
- /**
- * @param string $color rgb color value
- * @return bool
- */
- public static function invertTextColor($color) {
- $l = self::calculateLuminance($color);
- if($l>0.5) {
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * get color for on-page elements:
- * theme color by default, grey if theme color is to bright
- * @param $color
- * @return string
- */
- public static function elementColor($color) {
- $l = self::calculateLuminance($color);
- if($l>0.8) {
- return '#555555';
- } else {
- return $color;
- }
- }
-
- /**
- * @param string $color rgb color value
- * @return float
- */
- public static function calculateLuminance($color) {
- $hex = preg_replace("/[^0-9A-Fa-f]/", '', $color);
- if (strlen($hex) === 3) {
- $hex = $hex{0} . $hex{0} . $hex{1} . $hex{1} . $hex{2} . $hex{2};
- }
- if (strlen($hex) !== 6) {
- return 0;
- }
- $r = hexdec(substr($hex, 0, 2));
- $g = hexdec(substr($hex, 2, 2));
- $b = hexdec(substr($hex, 4, 2));
- return (0.299 * $r + 0.587 * $g + 0.114 * $b)/255;
- }
-
- /**
- * @param $color
- * @return string base64 encoded radio button svg
- */
- public static function generateRadioButton($color) {
- $radioButtonIcon = '<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16">' .
- '<path d="M8 1a7 7 0 0 0-7 7 7 7 0 0 0 7 7 7 7 0 0 0 7-7 7 7 0 0 0-7-7zm0 1a6 6 0 0 1 6 6 6 6 0 0 1-6 6 6 6 0 0 1-6-6 6 6 0 0 1 6-6zm0 2a4 4 0 1 0 0 8 4 4 0 0 0 0-8z" fill="'.$color.'"/></svg>';
- return base64_encode($radioButtonIcon);
- }
-
-}
--- /dev/null
+<?php
+/**
+ * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
+ *
+ * @author Julius Haertl <jus@bitgrid.net>
+ * @author Lukas Reschke <lukas@statuscode.ch>
+ * @author oparoz <owncloud@interfasys.ch>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+namespace OCA\Theming\Tests\Controller;
+
+use OCA\Theming\Controller\ThemingController;
+use OCA\Theming\Template;
+use OCA\Theming\Util;
+use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\DataResponse;
+use OCP\Files\IRootFolder;
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\IRequest;
+use Test\TestCase;
+
+class ThemingControllerTest extends TestCase {
+ /** @var IRequest */
+ private $request;
+ /** @var IConfig */
+ private $config;
+ /** @var Template */
+ private $template;
+ /** @var IL10N */
+ private $l10n;
+ /** @var ThemingController */
+ private $themingController;
+ /** @var IRootFolder */
+ private $rootFolder;
+
+ public function setUp() {
+ $this->request = $this->getMock('\\OCP\\IRequest');
+ $this->config = $this->getMock('\\OCP\\IConfig');
+ $this->template = $this->getMockBuilder('\\OCA\\Theming\\Template')
+ ->disableOriginalConstructor()->getMock();
+ $this->l10n = $this->getMock('\\OCP\\IL10N');
+ $this->rootFolder = $this->getMock('\\OCP\\Files\\IRootFolder');
+
+ $this->themingController = new ThemingController(
+ 'theming',
+ $this->request,
+ $this->config,
+ $this->template,
+ $this->l10n,
+ $this->rootFolder
+ );
+
+ return parent::setUp();
+ }
+
+ public function testUpdateStylesheet() {
+ $this->template
+ ->expects($this->once())
+ ->method('set')
+ ->with('MySetting', 'MyValue');
+ $this->l10n
+ ->expects($this->once())
+ ->method('t')
+ ->with('Saved')
+ ->willReturn('Saved');
+
+ $expected = new DataResponse(
+ [
+ 'data' =>
+ [
+ 'message' => 'Saved',
+ ],
+ 'status' => 'success'
+ ]
+ );
+ $this->assertEquals($expected, $this->themingController->updateStylesheet('MySetting', 'MyValue'));
+ }
+
+ public function testUpdateLogoNoData() {
+ $this->request
+ ->expects($this->at(0))
+ ->method('getUploadedFile')
+ ->with('uploadlogo')
+ ->willReturn(null);
+ $this->request
+ ->expects($this->at(1))
+ ->method('getUploadedFile')
+ ->with('upload-login-background')
+ ->willReturn(null);
+ $this->l10n
+ ->expects($this->once())
+ ->method('t')
+ ->with('No file uploaded')
+ ->willReturn('No file uploaded');
+
+ $expected = new DataResponse(
+ [
+ 'data' =>
+ [
+ 'message' => 'No file uploaded',
+ ],
+ ],
+ Http::STATUS_UNPROCESSABLE_ENTITY
+ );
+
+ $this->assertEquals($expected, $this->themingController->updateLogo());
+ }
+
+ public function testUpdateLogoNormalLogoUpload() {
+ $tmpLogo = \OC::$server->getTempManager()->getTemporaryFolder() . '/logo.svg';
+ $destination = \OC::$server->getTempManager()->getTemporaryFolder();
+
+ touch($tmpLogo);
+ $this->request
+ ->expects($this->at(0))
+ ->method('getUploadedFile')
+ ->with('uploadlogo')
+ ->willReturn([
+ 'tmp_name' => $tmpLogo,
+ 'type' => 'text/svg',
+ 'name' => 'logo.svg',
+ ]);
+ $this->request
+ ->expects($this->at(1))
+ ->method('getUploadedFile')
+ ->with('upload-login-background')
+ ->willReturn(null);
+ $this->l10n
+ ->expects($this->once())
+ ->method('t')
+ ->with('Saved')
+ ->willReturn('Saved');
+ $file = $this->getMockBuilder('\\OCP\\Files\\File')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->rootFolder
+ ->expects($this->once())
+ ->method('newFile')
+ ->with('themedinstancelogo')
+ ->willReturn($file);
+ $file
+ ->expects($this->once())
+ ->method('fopen')
+ ->with('w')
+ ->willReturn(fopen($destination . '/themedinstancelogo', 'w'));
+
+ $expected = new DataResponse(
+ [
+ 'data' =>
+ [
+ 'name' => 'logo.svg',
+ 'message' => 'Saved',
+ ],
+ 'status' => 'success'
+ ]
+ );
+
+ $this->assertEquals($expected, $this->themingController->updateLogo());
+ }
+
+ public function testUpdateLogoLoginScreenUpload() {
+ $tmpLogo = \OC::$server->getTempManager()->getTemporaryFolder() . '/logo.svg';
+ $destination = \OC::$server->getTempManager()->getTemporaryFolder();
+
+ touch($tmpLogo);
+ $this->request
+ ->expects($this->at(0))
+ ->method('getUploadedFile')
+ ->with('uploadlogo')
+ ->willReturn(null);
+ $this->request
+ ->expects($this->at(1))
+ ->method('getUploadedFile')
+ ->with('upload-login-background')
+ ->willReturn([
+ 'tmp_name' => $tmpLogo,
+ 'type' => 'text/svg',
+ 'name' => 'logo.svg',
+ ]);
+ $this->l10n
+ ->expects($this->once())
+ ->method('t')
+ ->with('Saved')
+ ->willReturn('Saved');
+ $file = $this->getMockBuilder('\\OCP\\Files\\File')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->rootFolder
+ ->expects($this->once())
+ ->method('newFile')
+ ->with('themedbackgroundlogo')
+ ->willReturn($file);
+ $file
+ ->expects($this->once())
+ ->method('fopen')
+ ->with('w')
+ ->willReturn(fopen($destination . '/themedbackgroundlogo', 'w'));
+
+
+ $expected = new DataResponse(
+ [
+ 'data' =>
+ [
+ 'name' => 'logo.svg',
+ 'message' => 'Saved',
+ ],
+ 'status' => 'success'
+ ]
+ );
+ $this->assertEquals($expected, $this->themingController->updateLogo());
+ }
+
+ public function testUndo() {
+ $this->l10n
+ ->expects($this->once())
+ ->method('t')
+ ->with('Saved')
+ ->willReturn('Saved');
+ $this->template
+ ->expects($this->once())
+ ->method('undo')
+ ->with('MySetting')
+ ->willReturn('MyValue');
+
+ $expected = new DataResponse(
+ [
+ 'data' =>
+ [
+ 'value' => 'MyValue',
+ 'message' => 'Saved',
+ ],
+ 'status' => 'success'
+ ]
+ );
+ $this->assertEquals($expected, $this->themingController->undo('MySetting'));
+ }
+
+ public function testGetLogoNotExistent() {
+ $expected = new DataResponse();
+ $this->assertEquals($expected, $this->themingController->getLogo());
+ }
+
+ public function testGetLogo() {
+ $dataFolder = \OC::$server->getTempManager()->getTemporaryFolder();
+ $tmpLogo = $dataFolder . '/themedinstancelogo';
+ touch($tmpLogo);
+ $this->config
+ ->expects($this->once())
+ ->method('getSystemValue')
+ ->with('datadirectory', \OC::$SERVERROOT . '/data/')
+ ->willReturn($dataFolder);
+ $this->config
+ ->expects($this->once())
+ ->method('getAppValue')
+ ->with('theming', 'logoMime', '')
+ ->willReturn('text/svg');
+
+ @$expected = new Http\StreamResponse($tmpLogo);
+ $expected->cacheFor(3600);
+ $expected->addHeader('Content-Disposition', 'attachment');
+ $expected->addHeader('Content-Type', 'text/svg');
+ @$this->assertEquals($expected, $this->themingController->getLogo());
+ }
+
+
+ public function testGetLoginBackgroundNotExistent() {
+ $expected = new DataResponse();
+ $this->assertEquals($expected, $this->themingController->getLoginBackground());
+ }
+
+ public function testGetLoginBackground() {
+ $dataFolder = \OC::$server->getTempManager()->getTemporaryFolder();
+ $tmpLogo = $dataFolder . '/themedbackgroundlogo';
+ touch($tmpLogo);
+ $this->config
+ ->expects($this->once())
+ ->method('getSystemValue')
+ ->with('datadirectory', \OC::$SERVERROOT . '/data/')
+ ->willReturn($dataFolder);
+ $this->config
+ ->expects($this->once())
+ ->method('getAppValue')
+ ->with('theming', 'backgroundMime', '')
+ ->willReturn('image/png');
+
+ @$expected = new Http\StreamResponse($tmpLogo);
+ $expected->cacheFor(3600);
+ $expected->addHeader('Content-Disposition', 'attachment');
+ $expected->addHeader('Content-Type', 'image/png');
+ @$this->assertEquals($expected, $this->themingController->getLoginBackground());
+ }
+
+ public function testGetStylesheetWithOnlyColor() {
+
+ $color = '#000';
+
+ $this->config
+ ->expects($this->at(0))
+ ->method('getAppValue')
+ ->with('theming', 'cachebuster', '0')
+ ->willReturn('0');
+ $this->config
+ ->expects($this->at(1))
+ ->method('getAppValue')
+ ->with('theming', 'color', '')
+ ->willReturn($color);
+ $this->config
+ ->expects($this->at(2))
+ ->method('getAppValue')
+ ->with('theming', 'logoMime', '')
+ ->willReturn('');
+ $this->config
+ ->expects($this->at(3))
+ ->method('getAppValue')
+ ->with('theming', 'backgroundMime', '')
+ ->willReturn('');
+
+ $expectedData = sprintf(
+ '#body-user #header,#body-settings #header,#body-public #header,#body-login,.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid {background-color: %s}' . "\n",
+ $color
+ );
+ $expectedData .= sprintf('input[type="checkbox"].checkbox:checked:enabled:not(.checkbox--white) + label:before {' .
+ 'background-image:url(\'%s/core/img/actions/checkmark-white.svg\');' .
+ 'background-color: %s; background-position: center center; background-size:contain;' .
+ 'width:12px; height:12px; padding:0; margin:2px 6px 6px 2px; border-radius:1px;' .
+ "}\n",
+ \OC::$WEBROOT,
+ $color
+ );
+ $expectedData .= 'input[type="radio"].radio:checked:not(.radio--white):not(:disabled) + label:before {' .
+ 'background-image: url(\'data:image/svg+xml;base64,'.Util::generateRadioButton($color).'\');' .
+ "}\n";
+
+ $expectedData .= '
+ #firstrunwizard .firstrunwizard-header {
+ background-color: ' . $color . ';
+ }
+ #firstrunwizard p a {
+ color: ' . $color . ';
+ }
+ ';
+
+ $expected = new Http\DataDownloadResponse($expectedData, 'style', 'text/css');
+
+ $expected->cacheFor(3600);
+ @$this->assertEquals($expected, $this->themingController->getStylesheet());
+ }
+
+ public function testGetStylesheetWithOnlyColorInvert() {
+
+ $color = '#fff';
+
+ $this->config
+ ->expects($this->at(0))
+ ->method('getAppValue')
+ ->with('theming', 'cachebuster', '0')
+ ->willReturn('0');
+ $this->config
+ ->expects($this->at(1))
+ ->method('getAppValue')
+ ->with('theming', 'color', '')
+ ->willReturn($color);
+ $this->config
+ ->expects($this->at(2))
+ ->method('getAppValue')
+ ->with('theming', 'logoMime', '')
+ ->willReturn('');
+ $this->config
+ ->expects($this->at(3))
+ ->method('getAppValue')
+ ->with('theming', 'backgroundMime', '')
+ ->willReturn('');
+
+ $expectedData = sprintf(
+ '#body-user #header,#body-settings #header,#body-public #header,#body-login,.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid {background-color: %s}' . "\n",
+ $color
+ );
+ $expectedData .= sprintf('input[type="checkbox"].checkbox:checked:enabled:not(.checkbox--white) + label:before {' .
+ 'background-image:url(\'%s/core/img/actions/checkmark-white.svg\');' .
+ 'background-color: #555555; background-position: center center; background-size:contain;' .
+ 'width:12px; height:12px; padding:0; margin:2px 6px 6px 2px; border-radius:1px;' .
+ "}\n",
+ \OC::$WEBROOT
+ );
+ $expectedData .= 'input[type="radio"].radio:checked:not(.radio--white):not(:disabled) + label:before {' .
+ 'background-image: url(\'data:image/svg+xml;base64,'.Util::generateRadioButton('#555555').'\');' .
+ "}\n";
+
+ $expectedData .= '
+ #firstrunwizard .firstrunwizard-header {
+ background-color: ' . $color . ';
+ }
+ #firstrunwizard p a {
+ color: ' . $color . ';
+ }
+ ';
+ $expectedData .= '#header .header-appname, #expandDisplayName { color: #000000; }' . "\n";
+ $expectedData .= '#header .icon-caret { background-image: url(\'' . \OC::$WEBROOT . '/core/img/actions/caret-dark.svg\'); }' . "\n";
+ $expectedData .= '.searchbox input[type="search"] { background: transparent url(\'' . \OC::$WEBROOT . '/core/img/actions/search.svg\') no-repeat 6px center; color: #000; }' . "\n";
+ $expectedData .= '.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid { color: #000; border: 1px solid rgba(0, 0, 0, .5); }' . "\n";
+
+
+ $expected = new Http\DataDownloadResponse($expectedData, 'style', 'text/css');
+
+ $expected->cacheFor(3600);
+ @$this->assertEquals($expected, $this->themingController->getStylesheet());
+ }
+
+ public function testGetStylesheetWithOnlyHeaderLogo() {
+ $this->config
+ ->expects($this->at(0))
+ ->method('getAppValue')
+ ->with('theming', 'cachebuster', '0')
+ ->willReturn('0');
+ $this->config
+ ->expects($this->at(1))
+ ->method('getAppValue')
+ ->with('theming', 'color', '')
+ ->willReturn('');
+ $this->config
+ ->expects($this->at(2))
+ ->method('getAppValue')
+ ->with('theming', 'logoMime', '')
+ ->willReturn('image/png');
+ $this->config
+ ->expects($this->at(3))
+ ->method('getAppValue')
+ ->with('theming', 'backgroundMime', '')
+ ->willReturn('');
+
+ $expectedData = '#header .logo {' .
+ 'background-image: url(\'./logo?v=0\');' .
+ 'background-size: contain;' .
+ '}' . "\n" .
+ '#header .logo-icon {' .
+ 'background-image: url(\'./logo?v=0\');' .
+ 'background-size: contain;' .
+ '}' . "\n" .
+ '#firstrunwizard .firstrunwizard-header .logo {' .
+ 'background-image: url(\'./logo?v=0\');' .
+ 'background-size: contain;' .
+ '}' . "\n";
+
+ $expected = new Http\DataDownloadResponse($expectedData, 'style', 'text/css');
+
+ $expected->cacheFor(3600);
+ @$this->assertEquals($expected, $this->themingController->getStylesheet());
+ }
+
+ public function testGetStylesheetWithOnlyBackgroundLogin() {
+ $this->config
+ ->expects($this->at(0))
+ ->method('getAppValue')
+ ->with('theming', 'cachebuster', '0')
+ ->willReturn('0');
+ $this->config
+ ->expects($this->at(1))
+ ->method('getAppValue')
+ ->with('theming', 'color', '')
+ ->willReturn('');
+ $this->config
+ ->expects($this->at(2))
+ ->method('getAppValue')
+ ->with('theming', 'logoMime', '')
+ ->willReturn('');
+ $this->config
+ ->expects($this->at(3))
+ ->method('getAppValue')
+ ->with('theming', 'backgroundMime', '')
+ ->willReturn('text/svg');
+
+ $expectedData = '#body-login {background-image: url(\'./loginbackground?v=0\');}' . "\n";
+ $expectedData .= '#firstrunwizard .firstrunwizard-header {' .
+ 'background-image: url(\'./loginbackground?v=0\');' .
+ '}' . "\n";
+
+ $expected = new Http\DataDownloadResponse($expectedData, 'style', 'text/css');
+
+ $expected->cacheFor(3600);
+ @$this->assertEquals($expected, $this->themingController->getStylesheet());
+ }
+
+ public function testGetStylesheetWithAllCombined() {
+
+ $color = '#000';
+
+ $this->config
+ ->expects($this->at(0))
+ ->method('getAppValue')
+ ->with('theming', 'cachebuster', '0')
+ ->willReturn('0');
+ $this->config
+ ->expects($this->at(1))
+ ->method('getAppValue')
+ ->with('theming', 'color', '')
+ ->willReturn($color);
+ $this->config
+ ->expects($this->at(2))
+ ->method('getAppValue')
+ ->with('theming', 'logoMime', '')
+ ->willReturn('text/svg');
+ $this->config
+ ->expects($this->at(3))
+ ->method('getAppValue')
+ ->with('theming', 'backgroundMime', '')
+ ->willReturn('image/png');
+
+ $expectedData = sprintf(
+ '#body-user #header,#body-settings #header,#body-public #header,#body-login,.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid {background-color: %s}' . "\n",
+ $color);
+
+ $expectedData .= sprintf('input[type="checkbox"].checkbox:checked:enabled:not(.checkbox--white) + label:before {' .
+ 'background-image:url(\'%s/core/img/actions/checkmark-white.svg\');' .
+ 'background-color: %s; background-position: center center; background-size:contain;' .
+ 'width:12px; height:12px; padding:0; margin:2px 6px 6px 2px; border-radius:1px;' .
+ "}\n",
+ \OC::$WEBROOT,
+ $color
+ );
+ $expectedData .= 'input[type="radio"].radio:checked:not(.radio--white):not(:disabled) + label:before {' .
+ 'background-image: url(\'data:image/svg+xml;base64,'.Util::generateRadioButton($color).'\');' .
+ "}\n";
+ $expectedData .= '
+ #firstrunwizard .firstrunwizard-header {
+ background-color: ' . $color . ';
+ }
+ #firstrunwizard p a {
+ color: ' . $color . ';
+ }
+ ';
+ $expectedData .= sprintf(
+ '#header .logo {' .
+ 'background-image: url(\'./logo?v=0\');' .
+ 'background-size: contain;' .
+ '}' . "\n" .
+ '#header .logo-icon {' .
+ 'background-image: url(\'./logo?v=0\');' .
+ 'background-size: contain;' .
+ '}' . "\n" .
+ '#firstrunwizard .firstrunwizard-header .logo {' .
+ 'background-image: url(\'./logo?v=0\');' .
+ 'background-size: contain;' .
+ '}' . "\n"
+ );
+ $expectedData .= '#body-login {background-image: url(\'./loginbackground?v=0\');}' . "\n";
+ $expectedData .= '#firstrunwizard .firstrunwizard-header {' .
+ 'background-image: url(\'./loginbackground?v=0\');' .
+ '}' . "\n";
+ $expected = new Http\DataDownloadResponse($expectedData, 'style', 'text/css');
+
+ $expected->cacheFor(3600);
+ @$this->assertEquals($expected, $this->themingController->getStylesheet());
+ }
+
+ public function testGetStylesheetWithAllCombinedInverted() {
+
+ $color = '#fff';
+
+ $this->config
+ ->expects($this->at(0))
+ ->method('getAppValue')
+ ->with('theming', 'cachebuster', '0')
+ ->willReturn('0');
+ $this->config
+ ->expects($this->at(1))
+ ->method('getAppValue')
+ ->with('theming', 'color', '')
+ ->willReturn('#fff');
+ $this->config
+ ->expects($this->at(2))
+ ->method('getAppValue')
+ ->with('theming', 'logoMime', '')
+ ->willReturn('text/svg');
+ $this->config
+ ->expects($this->at(3))
+ ->method('getAppValue')
+ ->with('theming', 'backgroundMime', '')
+ ->willReturn('image/png');
+
+
+ $expectedData = sprintf(
+ '#body-user #header,#body-settings #header,#body-public #header,#body-login,.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid {background-color: %s}' . "\n",
+ $color);
+
+ $expectedData .= sprintf('input[type="checkbox"].checkbox:checked:enabled:not(.checkbox--white) + label:before {' .
+ 'background-image:url(\'%s/core/img/actions/checkmark-white.svg\');' .
+ 'background-color: #555555; background-position: center center; background-size:contain;' .
+ 'width:12px; height:12px; padding:0; margin:2px 6px 6px 2px; border-radius:1px;' .
+ "}\n",
+ \OC::$WEBROOT
+ );
+ $expectedData .= 'input[type="radio"].radio:checked:not(.radio--white):not(:disabled) + label:before {' .
+ 'background-image: url(\'data:image/svg+xml;base64,'.Util::generateRadioButton('#555555').'\');' .
+ "}\n";
+ $expectedData .= '
+ #firstrunwizard .firstrunwizard-header {
+ background-color: ' . $color . ';
+ }
+ #firstrunwizard p a {
+ color: ' . $color . ';
+ }
+ ';
+ $expectedData .= sprintf(
+ '#header .logo {' .
+ 'background-image: url(\'./logo?v=0\');' .
+ 'background-size: contain;' .
+ '}' . "\n" .
+ '#header .logo-icon {' .
+ 'background-image: url(\'./logo?v=0\');' .
+ 'background-size: contain;' .
+ '}' . "\n" .
+ '#firstrunwizard .firstrunwizard-header .logo {' .
+ 'background-image: url(\'./logo?v=0\');' .
+ 'background-size: contain;' .
+ '}' . "\n"
+ );
+ $expectedData .= '#body-login {background-image: url(\'./loginbackground?v=0\');}' . "\n";
+ $expectedData .= '#firstrunwizard .firstrunwizard-header {' .
+ 'background-image: url(\'./loginbackground?v=0\');' .
+ '}' . "\n";
+ $expectedData .= '#header .header-appname, #expandDisplayName { color: #000000; }' . "\n";
+ $expectedData .= '#header .icon-caret { background-image: url(\'' . \OC::$WEBROOT . '/core/img/actions/caret-dark.svg\'); }' . "\n";
+ $expectedData .= '.searchbox input[type="search"] { background: transparent url(\'' . \OC::$WEBROOT . '/core/img/actions/search.svg\') no-repeat 6px center; color: #000; }' . "\n";
+ $expectedData .= '.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid { color: #000; border: 1px solid rgba(0, 0, 0, .5); }' . "\n";
+ $expected = new Http\DataDownloadResponse($expectedData, 'style', 'text/css');
+
+ $expected->cacheFor(3600);
+ @$this->assertEquals($expected, $this->themingController->getStylesheet());
+ }
+
+}
--- /dev/null
+<?php
+/**
+ * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
+ *
+ * @author Joas Schilling <coding@schilljs.com>
+ * @author Lukas Reschke <lukas@statuscode.ch>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+namespace OCA\Theming\Tests;
+
+use OCA\Theming\Template;
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+use Test\TestCase;
+
+class TemplateTest extends TestCase {
+ /** @var IConfig */
+ private $config;
+ /** @var IL10N */
+ private $l10n;
+ /** @var IURLGenerator */
+ private $urlGenerator;
+ /** @var \OC_Defaults */
+ private $defaults;
+ /** @var Template */
+ private $template;
+
+ public function setUp() {
+ $this->config = $this->getMock('\\OCP\\IConfig');
+ $this->l10n = $this->getMock('\\OCP\\IL10N');
+ $this->urlGenerator = $this->getMock('\\OCP\\IURLGenerator');
+ $this->defaults = $this->getMockBuilder('\\OC_Defaults')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->defaults
+ ->expects($this->at(0))
+ ->method('getName')
+ ->willReturn('Nextcloud');
+ $this->defaults
+ ->expects($this->at(1))
+ ->method('getBaseUrl')
+ ->willReturn('https://nextcloud.com/');
+ $this->defaults
+ ->expects($this->at(2))
+ ->method('getSlogan')
+ ->willReturn('Safe Data');
+ $this->defaults
+ ->expects($this->at(3))
+ ->method('getMailHeaderColor')
+ ->willReturn('#000');
+ $this->template = new Template(
+ $this->config,
+ $this->l10n,
+ $this->urlGenerator,
+ $this->defaults
+ );
+
+ return parent::setUp();
+ }
+
+ public function testGetNameWithDefault() {
+ $this->config
+ ->expects($this->once())
+ ->method('getAppValue')
+ ->with('theming', 'name', 'Nextcloud')
+ ->willReturn('Nextcloud');
+
+ $this->assertEquals('Nextcloud', $this->template->getName());
+ }
+
+ public function testGetNameWithCustom() {
+ $this->config
+ ->expects($this->once())
+ ->method('getAppValue')
+ ->with('theming', 'name', 'Nextcloud')
+ ->willReturn('MyCustomCloud');
+
+ $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())
+ ->method('getAppValue')
+ ->with('theming', 'name', 'Nextcloud')
+ ->willReturn('Nextcloud');
+
+ $this->assertEquals('Nextcloud', $this->template->getTitle());
+ }
+
+ public function testGetTitleWithCustom() {
+ $this->config
+ ->expects($this->once())
+ ->method('getAppValue')
+ ->with('theming', 'name', 'Nextcloud')
+ ->willReturn('MyCustomCloud');
+
+ $this->assertEquals('MyCustomCloud', $this->template->getTitle());
+ }
+
+
+ public function testGetEntityWithDefault() {
+ $this->config
+ ->expects($this->once())
+ ->method('getAppValue')
+ ->with('theming', 'name', 'Nextcloud')
+ ->willReturn('Nextcloud');
+
+ $this->assertEquals('Nextcloud', $this->template->getEntity());
+ }
+
+ public function testGetEntityWithCustom() {
+ $this->config
+ ->expects($this->once())
+ ->method('getAppValue')
+ ->with('theming', 'name', 'Nextcloud')
+ ->willReturn('MyCustomCloud');
+
+ $this->assertEquals('MyCustomCloud', $this->template->getEntity());
+ }
+
+ public function testGetBaseUrlWithDefault() {
+ $this->config
+ ->expects($this->once())
+ ->method('getAppValue')
+ ->with('theming', 'url', 'https://nextcloud.com/')
+ ->willReturn('https://nextcloud.com/');
+
+ $this->assertEquals('https://nextcloud.com/', $this->template->getBaseUrl());
+ }
+
+ public function testGetBaseUrlWithCustom() {
+ $this->config
+ ->expects($this->once())
+ ->method('getAppValue')
+ ->with('theming', 'url', 'https://nextcloud.com/')
+ ->willReturn('https://example.com/');
+
+ $this->assertEquals('https://example.com/', $this->template->getBaseUrl());
+ }
+
+ public function testGetSloganWithDefault() {
+ $this->config
+ ->expects($this->once())
+ ->method('getAppValue')
+ ->with('theming', 'slogan', 'Safe Data')
+ ->willReturn('Safe Data');
+
+ $this->assertEquals('Safe Data', $this->template->getSlogan());
+ }
+
+ public function testGetSloganWithCustom() {
+ $this->config
+ ->expects($this->once())
+ ->method('getAppValue')
+ ->with('theming', 'slogan', 'Safe Data')
+ ->willReturn('My custom Slogan');
+
+ $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('<a href="url" target="_blank" rel="noreferrer">Name</a> – 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('<a href="url" target="_blank" rel="noreferrer">Name</a>', $this->template->getShortFooter());
+ }
+
+ public function testGetMailHeaderColorWithDefault() {
+ $this->config
+ ->expects($this->once())
+ ->method('getAppValue')
+ ->with('theming', 'color', '#000')
+ ->willReturn('#000');
+
+ $this->assertEquals('#000', $this->template->getMailHeaderColor());
+ }
+
+ public function testGetMailHeaderColorWithCustom() {
+ $this->config
+ ->expects($this->once())
+ ->method('getAppValue')
+ ->with('theming', 'color', '#000')
+ ->willReturn('#fff');
+
+ $this->assertEquals('#fff', $this->template->getMailHeaderColor());
+ }
+
+ public function testSet() {
+ $this->config
+ ->expects($this->at(0))
+ ->method('setAppValue')
+ ->with('theming', 'MySetting', 'MyValue');
+ $this->config
+ ->expects($this->at(1))
+ ->method('getAppValue')
+ ->with('theming', 'cachebuster', '0')
+ ->willReturn('15');
+ $this->config
+ ->expects($this->at(2))
+ ->method('setAppValue')
+ ->with('theming', 'cachebuster', 16);
+
+ $this->template->set('MySetting', 'MyValue');
+ }
+
+ public function testUndoName() {
+ $this->config
+ ->expects($this->at(0))
+ ->method('deleteAppValue')
+ ->with('theming', 'name');
+ $this->config
+ ->expects($this->at(1))
+ ->method('getAppValue')
+ ->with('theming', 'cachebuster', '0')
+ ->willReturn('15');
+ $this->config
+ ->expects($this->at(2))
+ ->method('setAppValue')
+ ->with('theming', 'cachebuster', 16);
+ $this->config
+ ->expects($this->at(3))
+ ->method('getAppValue')
+ ->with('theming', 'name', 'Nextcloud')
+ ->willReturn('Nextcloud');
+
+ $this->assertSame('Nextcloud', $this->template->undo('name'));
+ }
+
+ public function testUndoBaseUrl() {
+ $this->config
+ ->expects($this->at(0))
+ ->method('deleteAppValue')
+ ->with('theming', 'url');
+ $this->config
+ ->expects($this->at(1))
+ ->method('getAppValue')
+ ->with('theming', 'cachebuster', '0')
+ ->willReturn('15');
+ $this->config
+ ->expects($this->at(2))
+ ->method('setAppValue')
+ ->with('theming', 'cachebuster', 16);
+ $this->config
+ ->expects($this->at(3))
+ ->method('getAppValue')
+ ->with('theming', 'url', 'https://nextcloud.com/')
+ ->willReturn('https://nextcloud.com/');
+
+ $this->assertSame('https://nextcloud.com/', $this->template->undo('url'));
+ }
+
+ public function testUndoSlogan() {
+ $this->config
+ ->expects($this->at(0))
+ ->method('deleteAppValue')
+ ->with('theming', 'slogan');
+ $this->config
+ ->expects($this->at(1))
+ ->method('getAppValue')
+ ->with('theming', 'cachebuster', '0')
+ ->willReturn('15');
+ $this->config
+ ->expects($this->at(2))
+ ->method('setAppValue')
+ ->with('theming', 'cachebuster', 16);
+ $this->config
+ ->expects($this->at(3))
+ ->method('getAppValue')
+ ->with('theming', 'slogan', 'Safe Data')
+ ->willReturn('Safe Data');
+
+ $this->assertSame('Safe Data', $this->template->undo('slogan'));
+ }
+
+ public function testUndoColor() {
+ $this->config
+ ->expects($this->at(0))
+ ->method('deleteAppValue')
+ ->with('theming', 'color');
+ $this->config
+ ->expects($this->at(1))
+ ->method('getAppValue')
+ ->with('theming', 'cachebuster', '0')
+ ->willReturn('15');
+ $this->config
+ ->expects($this->at(2))
+ ->method('setAppValue')
+ ->with('theming', 'cachebuster', 16);
+ $this->config
+ ->expects($this->at(3))
+ ->method('getAppValue')
+ ->with('theming', 'color', '#000')
+ ->willReturn('#000');
+
+ $this->assertSame('#000', $this->template->undo('color'));
+ }
+
+ public function testUndoDefaultAction() {
+ $this->config
+ ->expects($this->at(0))
+ ->method('deleteAppValue')
+ ->with('theming', 'defaultitem');
+ $this->config
+ ->expects($this->at(1))
+ ->method('getAppValue')
+ ->with('theming', 'cachebuster', '0')
+ ->willReturn('15');
+ $this->config
+ ->expects($this->at(2))
+ ->method('setAppValue')
+ ->with('theming', 'cachebuster', 16);
+
+ $this->assertSame('', $this->template->undo('defaultitem'));
+ }
+}
--- /dev/null
+<?php
+/**
+ * @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
+ *
+ * @author Julius Haertl <jus@bitgrid.net>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+namespace OCA\Theming\Tests;
+
+use OCA\Theming\Util;
+use Test\TestCase;
+
+class UtilTest extends TestCase {
+
+ public function testInvertTextColorLight() {
+ $invert = Util::invertTextColor('#ffffff');
+ $this->assertEquals(true, $invert);
+ }
+
+ public function testInvertTextColorDark() {
+ $invert = Util::invertTextColor('#000000');
+ $this->assertEquals(false, $invert);
+ }
+
+ public function testCalculateLuminanceLight() {
+ $luminance = Util::calculateLuminance('#ffffff');
+ $this->assertEquals(1, $luminance);
+ }
+
+ public function testCalculateLuminanceDark() {
+ $luminance = Util::calculateLuminance('#000000');
+ $this->assertEquals(0, $luminance);
+ }
+
+ public function testCalculateLuminanceLightShorthand() {
+ $luminance = Util::calculateLuminance('#fff');
+ $this->assertEquals(1, $luminance);
+ }
+
+ public function testCalculateLuminanceDarkShorthand() {
+ $luminance = Util::calculateLuminance('#000');
+ $this->assertEquals(0, $luminance);
+ }
+ public function testInvertTextColorInvalid() {
+ $invert = Util::invertTextColor('aaabbbcccddd123');
+ $this->assertEquals(false, $invert);
+ }
+
+ public function testInvertTextColorEmpty() {
+ $invert = Util::invertTextColor('');
+ $this->assertEquals(false, $invert);
+ }
+
+ public function testElementColorDefault() {
+ $elementColor = Util::elementColor("#000000");
+ $this->assertEquals('#000000', $elementColor);
+ }
+
+ public function testElementColorOnBrightBackground() {
+ $elementColor = Util::elementColor('#ffffff');
+ $this->assertEquals('#555555', $elementColor);
+ }
+
+ public function testGenerateRadioButtonWhite() {
+ $button = Util::generateRadioButton('#ffffff');
+ $expected = 'PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMTYiIHdpZHRoPSIxNiI+PHBhdGggZD0iTTggMWE3IDcgMCAwIDAtNyA3IDcgNyAwIDAgMCA3IDcgNyA3IDAgMCAwIDctNyA3IDcgMCAwIDAtNy03em0wIDFhNiA2IDAgMCAxIDYgNiA2IDYgMCAwIDEtNiA2IDYgNiAwIDAgMS02LTYgNiA2IDAgMCAxIDYtNnptMCAyYTQgNCAwIDEgMCAwIDggNCA0IDAgMCAwIDAtOHoiIGZpbGw9IiNmZmZmZmYiLz48L3N2Zz4=';
+ $this->assertEquals($expected, $button);
+ }
+ public function testGenerateRadioButtonBlack() {
+ $button = Util::generateRadioButton('#000000');
+ $expected = 'PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMTYiIHdpZHRoPSIxNiI+PHBhdGggZD0iTTggMWE3IDcgMCAwIDAtNyA3IDcgNyAwIDAgMCA3IDcgNyA3IDAgMCAwIDctNyA3IDcgMCAwIDAtNy03em0wIDFhNiA2IDAgMCAxIDYgNiA2IDYgMCAwIDEtNiA2IDYgNiAwIDAgMS02LTYgNiA2IDAgMCAxIDYtNnptMCAyYTQgNCAwIDEgMCAwIDggNCA0IDAgMCAwIDAtOHoiIGZpbGw9IiMwMDAwMDAiLz48L3N2Zz4=';
+ $this->assertEquals($expected, $button);
+ }
+}
+++ /dev/null
-<?php
-/**
- * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
- *
- * @author Joas Schilling <coding@schilljs.com>
- * @author Lukas Reschke <lukas@statuscode.ch>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-namespace OCA\Theming\Tests;
-
-use OCA\Theming\Template;
-use OCP\IConfig;
-use OCP\IL10N;
-use OCP\IURLGenerator;
-use Test\TestCase;
-
-class TemplateTest extends TestCase {
- /** @var IConfig */
- private $config;
- /** @var IL10N */
- private $l10n;
- /** @var IURLGenerator */
- private $urlGenerator;
- /** @var \OC_Defaults */
- private $defaults;
- /** @var Template */
- private $template;
-
- public function setUp() {
- $this->config = $this->getMock('\\OCP\\IConfig');
- $this->l10n = $this->getMock('\\OCP\\IL10N');
- $this->urlGenerator = $this->getMock('\\OCP\\IURLGenerator');
- $this->defaults = $this->getMockBuilder('\\OC_Defaults')
- ->disableOriginalConstructor()
- ->getMock();
- $this->defaults
- ->expects($this->at(0))
- ->method('getName')
- ->willReturn('Nextcloud');
- $this->defaults
- ->expects($this->at(1))
- ->method('getBaseUrl')
- ->willReturn('https://nextcloud.com/');
- $this->defaults
- ->expects($this->at(2))
- ->method('getSlogan')
- ->willReturn('Safe Data');
- $this->defaults
- ->expects($this->at(3))
- ->method('getMailHeaderColor')
- ->willReturn('#000');
- $this->template = new Template(
- $this->config,
- $this->l10n,
- $this->urlGenerator,
- $this->defaults
- );
-
- return parent::setUp();
- }
-
- public function testGetNameWithDefault() {
- $this->config
- ->expects($this->once())
- ->method('getAppValue')
- ->with('theming', 'name', 'Nextcloud')
- ->willReturn('Nextcloud');
-
- $this->assertEquals('Nextcloud', $this->template->getName());
- }
-
- public function testGetNameWithCustom() {
- $this->config
- ->expects($this->once())
- ->method('getAppValue')
- ->with('theming', 'name', 'Nextcloud')
- ->willReturn('MyCustomCloud');
-
- $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())
- ->method('getAppValue')
- ->with('theming', 'name', 'Nextcloud')
- ->willReturn('Nextcloud');
-
- $this->assertEquals('Nextcloud', $this->template->getTitle());
- }
-
- public function testGetTitleWithCustom() {
- $this->config
- ->expects($this->once())
- ->method('getAppValue')
- ->with('theming', 'name', 'Nextcloud')
- ->willReturn('MyCustomCloud');
-
- $this->assertEquals('MyCustomCloud', $this->template->getTitle());
- }
-
-
- public function testGetEntityWithDefault() {
- $this->config
- ->expects($this->once())
- ->method('getAppValue')
- ->with('theming', 'name', 'Nextcloud')
- ->willReturn('Nextcloud');
-
- $this->assertEquals('Nextcloud', $this->template->getEntity());
- }
-
- public function testGetEntityWithCustom() {
- $this->config
- ->expects($this->once())
- ->method('getAppValue')
- ->with('theming', 'name', 'Nextcloud')
- ->willReturn('MyCustomCloud');
-
- $this->assertEquals('MyCustomCloud', $this->template->getEntity());
- }
-
- public function testGetBaseUrlWithDefault() {
- $this->config
- ->expects($this->once())
- ->method('getAppValue')
- ->with('theming', 'url', 'https://nextcloud.com/')
- ->willReturn('https://nextcloud.com/');
-
- $this->assertEquals('https://nextcloud.com/', $this->template->getBaseUrl());
- }
-
- public function testGetBaseUrlWithCustom() {
- $this->config
- ->expects($this->once())
- ->method('getAppValue')
- ->with('theming', 'url', 'https://nextcloud.com/')
- ->willReturn('https://example.com/');
-
- $this->assertEquals('https://example.com/', $this->template->getBaseUrl());
- }
-
- public function testGetSloganWithDefault() {
- $this->config
- ->expects($this->once())
- ->method('getAppValue')
- ->with('theming', 'slogan', 'Safe Data')
- ->willReturn('Safe Data');
-
- $this->assertEquals('Safe Data', $this->template->getSlogan());
- }
-
- public function testGetSloganWithCustom() {
- $this->config
- ->expects($this->once())
- ->method('getAppValue')
- ->with('theming', 'slogan', 'Safe Data')
- ->willReturn('My custom Slogan');
-
- $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('<a href="url" target="_blank" rel="noreferrer">Name</a> – 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('<a href="url" target="_blank" rel="noreferrer">Name</a>', $this->template->getShortFooter());
- }
-
- public function testGetMailHeaderColorWithDefault() {
- $this->config
- ->expects($this->once())
- ->method('getAppValue')
- ->with('theming', 'color', '#000')
- ->willReturn('#000');
-
- $this->assertEquals('#000', $this->template->getMailHeaderColor());
- }
-
- public function testGetMailHeaderColorWithCustom() {
- $this->config
- ->expects($this->once())
- ->method('getAppValue')
- ->with('theming', 'color', '#000')
- ->willReturn('#fff');
-
- $this->assertEquals('#fff', $this->template->getMailHeaderColor());
- }
-
- public function testSet() {
- $this->config
- ->expects($this->at(0))
- ->method('setAppValue')
- ->with('theming', 'MySetting', 'MyValue');
- $this->config
- ->expects($this->at(1))
- ->method('getAppValue')
- ->with('theming', 'cachebuster', '0')
- ->willReturn('15');
- $this->config
- ->expects($this->at(2))
- ->method('setAppValue')
- ->with('theming', 'cachebuster', 16);
-
- $this->template->set('MySetting', 'MyValue');
- }
-
- public function testUndoName() {
- $this->config
- ->expects($this->at(0))
- ->method('deleteAppValue')
- ->with('theming', 'name');
- $this->config
- ->expects($this->at(1))
- ->method('getAppValue')
- ->with('theming', 'cachebuster', '0')
- ->willReturn('15');
- $this->config
- ->expects($this->at(2))
- ->method('setAppValue')
- ->with('theming', 'cachebuster', 16);
- $this->config
- ->expects($this->at(3))
- ->method('getAppValue')
- ->with('theming', 'name', 'Nextcloud')
- ->willReturn('Nextcloud');
-
- $this->assertSame('Nextcloud', $this->template->undo('name'));
- }
-
- public function testUndoBaseUrl() {
- $this->config
- ->expects($this->at(0))
- ->method('deleteAppValue')
- ->with('theming', 'url');
- $this->config
- ->expects($this->at(1))
- ->method('getAppValue')
- ->with('theming', 'cachebuster', '0')
- ->willReturn('15');
- $this->config
- ->expects($this->at(2))
- ->method('setAppValue')
- ->with('theming', 'cachebuster', 16);
- $this->config
- ->expects($this->at(3))
- ->method('getAppValue')
- ->with('theming', 'url', 'https://nextcloud.com/')
- ->willReturn('https://nextcloud.com/');
-
- $this->assertSame('https://nextcloud.com/', $this->template->undo('url'));
- }
-
- public function testUndoSlogan() {
- $this->config
- ->expects($this->at(0))
- ->method('deleteAppValue')
- ->with('theming', 'slogan');
- $this->config
- ->expects($this->at(1))
- ->method('getAppValue')
- ->with('theming', 'cachebuster', '0')
- ->willReturn('15');
- $this->config
- ->expects($this->at(2))
- ->method('setAppValue')
- ->with('theming', 'cachebuster', 16);
- $this->config
- ->expects($this->at(3))
- ->method('getAppValue')
- ->with('theming', 'slogan', 'Safe Data')
- ->willReturn('Safe Data');
-
- $this->assertSame('Safe Data', $this->template->undo('slogan'));
- }
-
- public function testUndoColor() {
- $this->config
- ->expects($this->at(0))
- ->method('deleteAppValue')
- ->with('theming', 'color');
- $this->config
- ->expects($this->at(1))
- ->method('getAppValue')
- ->with('theming', 'cachebuster', '0')
- ->willReturn('15');
- $this->config
- ->expects($this->at(2))
- ->method('setAppValue')
- ->with('theming', 'cachebuster', 16);
- $this->config
- ->expects($this->at(3))
- ->method('getAppValue')
- ->with('theming', 'color', '#000')
- ->willReturn('#000');
-
- $this->assertSame('#000', $this->template->undo('color'));
- }
-
- public function testUndoDefaultAction() {
- $this->config
- ->expects($this->at(0))
- ->method('deleteAppValue')
- ->with('theming', 'defaultitem');
- $this->config
- ->expects($this->at(1))
- ->method('getAppValue')
- ->with('theming', 'cachebuster', '0')
- ->willReturn('15');
- $this->config
- ->expects($this->at(2))
- ->method('setAppValue')
- ->with('theming', 'cachebuster', 16);
-
- $this->assertSame('', $this->template->undo('defaultitem'));
- }
-}
+++ /dev/null
-<?php
-/**
- * @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
- *
- * @author Julius Haertl <jus@bitgrid.net>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-namespace OCA\Theming\Tests;
-
-use OCA\Theming\Util;
-use Test\TestCase;
-
-class UtilTest extends TestCase {
-
- public function testInvertTextColorLight() {
- $invert = Util::invertTextColor('#ffffff');
- $this->assertEquals(true, $invert);
- }
-
- public function testInvertTextColorDark() {
- $invert = Util::invertTextColor('#000000');
- $this->assertEquals(false, $invert);
- }
-
- public function testCalculateLuminanceLight() {
- $luminance = Util::calculateLuminance('#ffffff');
- $this->assertEquals(1, $luminance);
- }
-
- public function testCalculateLuminanceDark() {
- $luminance = Util::calculateLuminance('#000000');
- $this->assertEquals(0, $luminance);
- }
-
- public function testCalculateLuminanceLightShorthand() {
- $luminance = Util::calculateLuminance('#fff');
- $this->assertEquals(1, $luminance);
- }
-
- public function testCalculateLuminanceDarkShorthand() {
- $luminance = Util::calculateLuminance('#000');
- $this->assertEquals(0, $luminance);
- }
- public function testInvertTextColorInvalid() {
- $invert = Util::invertTextColor('aaabbbcccddd123');
- $this->assertEquals(false, $invert);
- }
-
- public function testInvertTextColorEmpty() {
- $invert = Util::invertTextColor('');
- $this->assertEquals(false, $invert);
- }
-
- public function testElementColorDefault() {
- $elementColor = Util::elementColor("#000000");
- $this->assertEquals('#000000', $elementColor);
- }
-
- public function testElementColorOnBrightBackground() {
- $elementColor = Util::elementColor('#ffffff');
- $this->assertEquals('#555555', $elementColor);
- }
-
- public function testGenerateRadioButtonWhite() {
- $button = Util::generateRadioButton('#ffffff');
- $expected = 'PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMTYiIHdpZHRoPSIxNiI+PHBhdGggZD0iTTggMWE3IDcgMCAwIDAtNyA3IDcgNyAwIDAgMCA3IDcgNyA3IDAgMCAwIDctNyA3IDcgMCAwIDAtNy03em0wIDFhNiA2IDAgMCAxIDYgNiA2IDYgMCAwIDEtNiA2IDYgNiAwIDAgMS02LTYgNiA2IDAgMCAxIDYtNnptMCAyYTQgNCAwIDEgMCAwIDggNCA0IDAgMCAwIDAtOHoiIGZpbGw9IiNmZmZmZmYiLz48L3N2Zz4=';
- $this->assertEquals($expected, $button);
- }
- public function testGenerateRadioButtonBlack() {
- $button = Util::generateRadioButton('#000000');
- $expected = 'PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMTYiIHdpZHRoPSIxNiI+PHBhdGggZD0iTTggMWE3IDcgMCAwIDAtNyA3IDcgNyAwIDAgMCA3IDcgNyA3IDAgMCAwIDctNyA3IDcgMCAwIDAtNy03em0wIDFhNiA2IDAgMCAxIDYgNiA2IDYgMCAwIDEtNiA2IDYgNiAwIDAgMS02LTYgNiA2IDAgMCAxIDYtNnptMCAyYTQgNCAwIDEgMCAwIDggNCA0IDAgMCAwIDAtOHoiIGZpbGw9IiMwMDAwMDAiLz48L3N2Zz4=';
- $this->assertEquals($expected, $button);
- }
-}
+++ /dev/null
-<?php
-/**
- * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
- *
- * @author Julius Haertl <jus@bitgrid.net>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author oparoz <owncloud@interfasys.ch>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-namespace OCA\Theming\Tests\Controller;
-
-use OCA\Theming\Controller\ThemingController;
-use OCA\Theming\Template;
-use OCA\Theming\Util;
-use OCP\AppFramework\Http;
-use OCP\AppFramework\Http\DataResponse;
-use OCP\Files\IRootFolder;
-use OCP\IConfig;
-use OCP\IL10N;
-use OCP\IRequest;
-use Test\TestCase;
-
-class ThemingControllerTest extends TestCase {
- /** @var IRequest */
- private $request;
- /** @var IConfig */
- private $config;
- /** @var Template */
- private $template;
- /** @var IL10N */
- private $l10n;
- /** @var ThemingController */
- private $themingController;
- /** @var IRootFolder */
- private $rootFolder;
-
- public function setUp() {
- $this->request = $this->getMock('\\OCP\\IRequest');
- $this->config = $this->getMock('\\OCP\\IConfig');
- $this->template = $this->getMockBuilder('\\OCA\\Theming\\Template')
- ->disableOriginalConstructor()->getMock();
- $this->l10n = $this->getMock('\\OCP\\IL10N');
- $this->rootFolder = $this->getMock('\\OCP\\Files\\IRootFolder');
-
- $this->themingController = new ThemingController(
- 'theming',
- $this->request,
- $this->config,
- $this->template,
- $this->l10n,
- $this->rootFolder
- );
-
- return parent::setUp();
- }
-
- public function testUpdateStylesheet() {
- $this->template
- ->expects($this->once())
- ->method('set')
- ->with('MySetting', 'MyValue');
- $this->l10n
- ->expects($this->once())
- ->method('t')
- ->with('Saved')
- ->willReturn('Saved');
-
- $expected = new DataResponse(
- [
- 'data' =>
- [
- 'message' => 'Saved',
- ],
- 'status' => 'success'
- ]
- );
- $this->assertEquals($expected, $this->themingController->updateStylesheet('MySetting', 'MyValue'));
- }
-
- public function testUpdateLogoNoData() {
- $this->request
- ->expects($this->at(0))
- ->method('getUploadedFile')
- ->with('uploadlogo')
- ->willReturn(null);
- $this->request
- ->expects($this->at(1))
- ->method('getUploadedFile')
- ->with('upload-login-background')
- ->willReturn(null);
- $this->l10n
- ->expects($this->once())
- ->method('t')
- ->with('No file uploaded')
- ->willReturn('No file uploaded');
-
- $expected = new DataResponse(
- [
- 'data' =>
- [
- 'message' => 'No file uploaded',
- ],
- ],
- Http::STATUS_UNPROCESSABLE_ENTITY
- );
-
- $this->assertEquals($expected, $this->themingController->updateLogo());
- }
-
- public function testUpdateLogoNormalLogoUpload() {
- $tmpLogo = \OC::$server->getTempManager()->getTemporaryFolder() . '/logo.svg';
- $destination = \OC::$server->getTempManager()->getTemporaryFolder();
-
- touch($tmpLogo);
- $this->request
- ->expects($this->at(0))
- ->method('getUploadedFile')
- ->with('uploadlogo')
- ->willReturn([
- 'tmp_name' => $tmpLogo,
- 'type' => 'text/svg',
- 'name' => 'logo.svg',
- ]);
- $this->request
- ->expects($this->at(1))
- ->method('getUploadedFile')
- ->with('upload-login-background')
- ->willReturn(null);
- $this->l10n
- ->expects($this->once())
- ->method('t')
- ->with('Saved')
- ->willReturn('Saved');
- $file = $this->getMockBuilder('\\OCP\\Files\\File')
- ->disableOriginalConstructor()
- ->getMock();
- $this->rootFolder
- ->expects($this->once())
- ->method('newFile')
- ->with('themedinstancelogo')
- ->willReturn($file);
- $file
- ->expects($this->once())
- ->method('fopen')
- ->with('w')
- ->willReturn(fopen($destination . '/themedinstancelogo', 'w'));
-
- $expected = new DataResponse(
- [
- 'data' =>
- [
- 'name' => 'logo.svg',
- 'message' => 'Saved',
- ],
- 'status' => 'success'
- ]
- );
-
- $this->assertEquals($expected, $this->themingController->updateLogo());
- }
-
- public function testUpdateLogoLoginScreenUpload() {
- $tmpLogo = \OC::$server->getTempManager()->getTemporaryFolder() . '/logo.svg';
- $destination = \OC::$server->getTempManager()->getTemporaryFolder();
-
- touch($tmpLogo);
- $this->request
- ->expects($this->at(0))
- ->method('getUploadedFile')
- ->with('uploadlogo')
- ->willReturn(null);
- $this->request
- ->expects($this->at(1))
- ->method('getUploadedFile')
- ->with('upload-login-background')
- ->willReturn([
- 'tmp_name' => $tmpLogo,
- 'type' => 'text/svg',
- 'name' => 'logo.svg',
- ]);
- $this->l10n
- ->expects($this->once())
- ->method('t')
- ->with('Saved')
- ->willReturn('Saved');
- $file = $this->getMockBuilder('\\OCP\\Files\\File')
- ->disableOriginalConstructor()
- ->getMock();
- $this->rootFolder
- ->expects($this->once())
- ->method('newFile')
- ->with('themedbackgroundlogo')
- ->willReturn($file);
- $file
- ->expects($this->once())
- ->method('fopen')
- ->with('w')
- ->willReturn(fopen($destination . '/themedbackgroundlogo', 'w'));
-
-
- $expected = new DataResponse(
- [
- 'data' =>
- [
- 'name' => 'logo.svg',
- 'message' => 'Saved',
- ],
- 'status' => 'success'
- ]
- );
- $this->assertEquals($expected, $this->themingController->updateLogo());
- }
-
- public function testUndo() {
- $this->l10n
- ->expects($this->once())
- ->method('t')
- ->with('Saved')
- ->willReturn('Saved');
- $this->template
- ->expects($this->once())
- ->method('undo')
- ->with('MySetting')
- ->willReturn('MyValue');
-
- $expected = new DataResponse(
- [
- 'data' =>
- [
- 'value' => 'MyValue',
- 'message' => 'Saved',
- ],
- 'status' => 'success'
- ]
- );
- $this->assertEquals($expected, $this->themingController->undo('MySetting'));
- }
-
- public function testGetLogoNotExistent() {
- $expected = new DataResponse();
- $this->assertEquals($expected, $this->themingController->getLogo());
- }
-
- public function testGetLogo() {
- $dataFolder = \OC::$server->getTempManager()->getTemporaryFolder();
- $tmpLogo = $dataFolder . '/themedinstancelogo';
- touch($tmpLogo);
- $this->config
- ->expects($this->once())
- ->method('getSystemValue')
- ->with('datadirectory', \OC::$SERVERROOT . '/data/')
- ->willReturn($dataFolder);
- $this->config
- ->expects($this->once())
- ->method('getAppValue')
- ->with('theming', 'logoMime', '')
- ->willReturn('text/svg');
-
- @$expected = new Http\StreamResponse($tmpLogo);
- $expected->cacheFor(3600);
- $expected->addHeader('Content-Disposition', 'attachment');
- $expected->addHeader('Content-Type', 'text/svg');
- @$this->assertEquals($expected, $this->themingController->getLogo());
- }
-
-
- public function testGetLoginBackgroundNotExistent() {
- $expected = new DataResponse();
- $this->assertEquals($expected, $this->themingController->getLoginBackground());
- }
-
- public function testGetLoginBackground() {
- $dataFolder = \OC::$server->getTempManager()->getTemporaryFolder();
- $tmpLogo = $dataFolder . '/themedbackgroundlogo';
- touch($tmpLogo);
- $this->config
- ->expects($this->once())
- ->method('getSystemValue')
- ->with('datadirectory', \OC::$SERVERROOT . '/data/')
- ->willReturn($dataFolder);
- $this->config
- ->expects($this->once())
- ->method('getAppValue')
- ->with('theming', 'backgroundMime', '')
- ->willReturn('image/png');
-
- @$expected = new Http\StreamResponse($tmpLogo);
- $expected->cacheFor(3600);
- $expected->addHeader('Content-Disposition', 'attachment');
- $expected->addHeader('Content-Type', 'image/png');
- @$this->assertEquals($expected, $this->themingController->getLoginBackground());
- }
-
- public function testGetStylesheetWithOnlyColor() {
-
- $color = '#000';
-
- $this->config
- ->expects($this->at(0))
- ->method('getAppValue')
- ->with('theming', 'cachebuster', '0')
- ->willReturn('0');
- $this->config
- ->expects($this->at(1))
- ->method('getAppValue')
- ->with('theming', 'color', '')
- ->willReturn($color);
- $this->config
- ->expects($this->at(2))
- ->method('getAppValue')
- ->with('theming', 'logoMime', '')
- ->willReturn('');
- $this->config
- ->expects($this->at(3))
- ->method('getAppValue')
- ->with('theming', 'backgroundMime', '')
- ->willReturn('');
-
- $expectedData = sprintf(
- '#body-user #header,#body-settings #header,#body-public #header,#body-login,.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid {background-color: %s}' . "\n",
- $color
- );
- $expectedData .= sprintf('input[type="checkbox"].checkbox:checked:enabled:not(.checkbox--white) + label:before {' .
- 'background-image:url(\'%s/core/img/actions/checkmark-white.svg\');' .
- 'background-color: %s; background-position: center center; background-size:contain;' .
- 'width:12px; height:12px; padding:0; margin:2px 6px 6px 2px; border-radius:1px;' .
- "}\n",
- \OC::$WEBROOT,
- $color
- );
- $expectedData .= 'input[type="radio"].radio:checked:not(.radio--white):not(:disabled) + label:before {' .
- 'background-image: url(\'data:image/svg+xml;base64,'.Util::generateRadioButton($color).'\');' .
- "}\n";
-
- $expectedData .= '
- #firstrunwizard .firstrunwizard-header {
- background-color: ' . $color . ';
- }
- #firstrunwizard p a {
- color: ' . $color . ';
- }
- ';
-
- $expected = new Http\DataDownloadResponse($expectedData, 'style', 'text/css');
-
- $expected->cacheFor(3600);
- @$this->assertEquals($expected, $this->themingController->getStylesheet());
- }
-
- public function testGetStylesheetWithOnlyColorInvert() {
-
- $color = '#fff';
-
- $this->config
- ->expects($this->at(0))
- ->method('getAppValue')
- ->with('theming', 'cachebuster', '0')
- ->willReturn('0');
- $this->config
- ->expects($this->at(1))
- ->method('getAppValue')
- ->with('theming', 'color', '')
- ->willReturn($color);
- $this->config
- ->expects($this->at(2))
- ->method('getAppValue')
- ->with('theming', 'logoMime', '')
- ->willReturn('');
- $this->config
- ->expects($this->at(3))
- ->method('getAppValue')
- ->with('theming', 'backgroundMime', '')
- ->willReturn('');
-
- $expectedData = sprintf(
- '#body-user #header,#body-settings #header,#body-public #header,#body-login,.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid {background-color: %s}' . "\n",
- $color
- );
- $expectedData .= sprintf('input[type="checkbox"].checkbox:checked:enabled:not(.checkbox--white) + label:before {' .
- 'background-image:url(\'%s/core/img/actions/checkmark-white.svg\');' .
- 'background-color: #555555; background-position: center center; background-size:contain;' .
- 'width:12px; height:12px; padding:0; margin:2px 6px 6px 2px; border-radius:1px;' .
- "}\n",
- \OC::$WEBROOT
- );
- $expectedData .= 'input[type="radio"].radio:checked:not(.radio--white):not(:disabled) + label:before {' .
- 'background-image: url(\'data:image/svg+xml;base64,'.Util::generateRadioButton('#555555').'\');' .
- "}\n";
-
- $expectedData .= '
- #firstrunwizard .firstrunwizard-header {
- background-color: ' . $color . ';
- }
- #firstrunwizard p a {
- color: ' . $color . ';
- }
- ';
- $expectedData .= '#header .header-appname, #expandDisplayName { color: #000000; }' . "\n";
- $expectedData .= '#header .icon-caret { background-image: url(\'' . \OC::$WEBROOT . '/core/img/actions/caret-dark.svg\'); }' . "\n";
- $expectedData .= '.searchbox input[type="search"] { background: transparent url(\'' . \OC::$WEBROOT . '/core/img/actions/search.svg\') no-repeat 6px center; color: #000; }' . "\n";
- $expectedData .= '.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid { color: #000; border: 1px solid rgba(0, 0, 0, .5); }' . "\n";
-
-
- $expected = new Http\DataDownloadResponse($expectedData, 'style', 'text/css');
-
- $expected->cacheFor(3600);
- @$this->assertEquals($expected, $this->themingController->getStylesheet());
- }
-
- public function testGetStylesheetWithOnlyHeaderLogo() {
- $this->config
- ->expects($this->at(0))
- ->method('getAppValue')
- ->with('theming', 'cachebuster', '0')
- ->willReturn('0');
- $this->config
- ->expects($this->at(1))
- ->method('getAppValue')
- ->with('theming', 'color', '')
- ->willReturn('');
- $this->config
- ->expects($this->at(2))
- ->method('getAppValue')
- ->with('theming', 'logoMime', '')
- ->willReturn('image/png');
- $this->config
- ->expects($this->at(3))
- ->method('getAppValue')
- ->with('theming', 'backgroundMime', '')
- ->willReturn('');
-
- $expectedData = '#header .logo {' .
- 'background-image: url(\'./logo?v=0\');' .
- 'background-size: contain;' .
- '}' . "\n" .
- '#header .logo-icon {' .
- 'background-image: url(\'./logo?v=0\');' .
- 'background-size: contain;' .
- '}' . "\n" .
- '#firstrunwizard .firstrunwizard-header .logo {' .
- 'background-image: url(\'./logo?v=0\');' .
- 'background-size: contain;' .
- '}' . "\n";
-
- $expected = new Http\DataDownloadResponse($expectedData, 'style', 'text/css');
-
- $expected->cacheFor(3600);
- @$this->assertEquals($expected, $this->themingController->getStylesheet());
- }
-
- public function testGetStylesheetWithOnlyBackgroundLogin() {
- $this->config
- ->expects($this->at(0))
- ->method('getAppValue')
- ->with('theming', 'cachebuster', '0')
- ->willReturn('0');
- $this->config
- ->expects($this->at(1))
- ->method('getAppValue')
- ->with('theming', 'color', '')
- ->willReturn('');
- $this->config
- ->expects($this->at(2))
- ->method('getAppValue')
- ->with('theming', 'logoMime', '')
- ->willReturn('');
- $this->config
- ->expects($this->at(3))
- ->method('getAppValue')
- ->with('theming', 'backgroundMime', '')
- ->willReturn('text/svg');
-
- $expectedData = '#body-login {background-image: url(\'./loginbackground?v=0\');}' . "\n";
- $expectedData .= '#firstrunwizard .firstrunwizard-header {' .
- 'background-image: url(\'./loginbackground?v=0\');' .
- '}' . "\n";
-
- $expected = new Http\DataDownloadResponse($expectedData, 'style', 'text/css');
-
- $expected->cacheFor(3600);
- @$this->assertEquals($expected, $this->themingController->getStylesheet());
- }
-
- public function testGetStylesheetWithAllCombined() {
-
- $color = '#000';
-
- $this->config
- ->expects($this->at(0))
- ->method('getAppValue')
- ->with('theming', 'cachebuster', '0')
- ->willReturn('0');
- $this->config
- ->expects($this->at(1))
- ->method('getAppValue')
- ->with('theming', 'color', '')
- ->willReturn($color);
- $this->config
- ->expects($this->at(2))
- ->method('getAppValue')
- ->with('theming', 'logoMime', '')
- ->willReturn('text/svg');
- $this->config
- ->expects($this->at(3))
- ->method('getAppValue')
- ->with('theming', 'backgroundMime', '')
- ->willReturn('image/png');
-
- $expectedData = sprintf(
- '#body-user #header,#body-settings #header,#body-public #header,#body-login,.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid {background-color: %s}' . "\n",
- $color);
-
- $expectedData .= sprintf('input[type="checkbox"].checkbox:checked:enabled:not(.checkbox--white) + label:before {' .
- 'background-image:url(\'%s/core/img/actions/checkmark-white.svg\');' .
- 'background-color: %s; background-position: center center; background-size:contain;' .
- 'width:12px; height:12px; padding:0; margin:2px 6px 6px 2px; border-radius:1px;' .
- "}\n",
- \OC::$WEBROOT,
- $color
- );
- $expectedData .= 'input[type="radio"].radio:checked:not(.radio--white):not(:disabled) + label:before {' .
- 'background-image: url(\'data:image/svg+xml;base64,'.Util::generateRadioButton($color).'\');' .
- "}\n";
- $expectedData .= '
- #firstrunwizard .firstrunwizard-header {
- background-color: ' . $color . ';
- }
- #firstrunwizard p a {
- color: ' . $color . ';
- }
- ';
- $expectedData .= sprintf(
- '#header .logo {' .
- 'background-image: url(\'./logo?v=0\');' .
- 'background-size: contain;' .
- '}' . "\n" .
- '#header .logo-icon {' .
- 'background-image: url(\'./logo?v=0\');' .
- 'background-size: contain;' .
- '}' . "\n" .
- '#firstrunwizard .firstrunwizard-header .logo {' .
- 'background-image: url(\'./logo?v=0\');' .
- 'background-size: contain;' .
- '}' . "\n"
- );
- $expectedData .= '#body-login {background-image: url(\'./loginbackground?v=0\');}' . "\n";
- $expectedData .= '#firstrunwizard .firstrunwizard-header {' .
- 'background-image: url(\'./loginbackground?v=0\');' .
- '}' . "\n";
- $expected = new Http\DataDownloadResponse($expectedData, 'style', 'text/css');
-
- $expected->cacheFor(3600);
- @$this->assertEquals($expected, $this->themingController->getStylesheet());
- }
-
- public function testGetStylesheetWithAllCombinedInverted() {
-
- $color = '#fff';
-
- $this->config
- ->expects($this->at(0))
- ->method('getAppValue')
- ->with('theming', 'cachebuster', '0')
- ->willReturn('0');
- $this->config
- ->expects($this->at(1))
- ->method('getAppValue')
- ->with('theming', 'color', '')
- ->willReturn('#fff');
- $this->config
- ->expects($this->at(2))
- ->method('getAppValue')
- ->with('theming', 'logoMime', '')
- ->willReturn('text/svg');
- $this->config
- ->expects($this->at(3))
- ->method('getAppValue')
- ->with('theming', 'backgroundMime', '')
- ->willReturn('image/png');
-
-
- $expectedData = sprintf(
- '#body-user #header,#body-settings #header,#body-public #header,#body-login,.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid {background-color: %s}' . "\n",
- $color);
-
- $expectedData .= sprintf('input[type="checkbox"].checkbox:checked:enabled:not(.checkbox--white) + label:before {' .
- 'background-image:url(\'%s/core/img/actions/checkmark-white.svg\');' .
- 'background-color: #555555; background-position: center center; background-size:contain;' .
- 'width:12px; height:12px; padding:0; margin:2px 6px 6px 2px; border-radius:1px;' .
- "}\n",
- \OC::$WEBROOT
- );
- $expectedData .= 'input[type="radio"].radio:checked:not(.radio--white):not(:disabled) + label:before {' .
- 'background-image: url(\'data:image/svg+xml;base64,'.Util::generateRadioButton('#555555').'\');' .
- "}\n";
- $expectedData .= '
- #firstrunwizard .firstrunwizard-header {
- background-color: ' . $color . ';
- }
- #firstrunwizard p a {
- color: ' . $color . ';
- }
- ';
- $expectedData .= sprintf(
- '#header .logo {' .
- 'background-image: url(\'./logo?v=0\');' .
- 'background-size: contain;' .
- '}' . "\n" .
- '#header .logo-icon {' .
- 'background-image: url(\'./logo?v=0\');' .
- 'background-size: contain;' .
- '}' . "\n" .
- '#firstrunwizard .firstrunwizard-header .logo {' .
- 'background-image: url(\'./logo?v=0\');' .
- 'background-size: contain;' .
- '}' . "\n"
- );
- $expectedData .= '#body-login {background-image: url(\'./loginbackground?v=0\');}' . "\n";
- $expectedData .= '#firstrunwizard .firstrunwizard-header {' .
- 'background-image: url(\'./loginbackground?v=0\');' .
- '}' . "\n";
- $expectedData .= '#header .header-appname, #expandDisplayName { color: #000000; }' . "\n";
- $expectedData .= '#header .icon-caret { background-image: url(\'' . \OC::$WEBROOT . '/core/img/actions/caret-dark.svg\'); }' . "\n";
- $expectedData .= '.searchbox input[type="search"] { background: transparent url(\'' . \OC::$WEBROOT . '/core/img/actions/search.svg\') no-repeat 6px center; color: #000; }' . "\n";
- $expectedData .= '.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid { color: #000; border: 1px solid rgba(0, 0, 0, .5); }' . "\n";
- $expected = new Http\DataDownloadResponse($expectedData, 'style', 'text/css');
-
- $expected->cacheFor(3600);
- @$this->assertEquals($expected, $this->themingController->getStylesheet());
- }
-
-}