Also adds support for having custom login backgroundspull/350/head
parent
cc321bc140
commit
27b699bdbc
@ -1,23 +1,38 @@ |
||||
<?php |
||||
/** |
||||
* @author Björn Schießle <bjoern@schiessle.org> |
||||
* @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org> |
||||
* @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch> |
||||
* |
||||
* @copyright Copyright (c) 2016, Bjoern Schiessle |
||||
* @license AGPL-3.0 |
||||
* @license GNU AGPL version 3 or any later version |
||||
* |
||||
* This code is free software: you can redistribute it and/or modify |
||||
* 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 opinion) any later version. |
||||
* 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 |
||||
* 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/> |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
* |
||||
*/ |
||||
|
||||
\OCP\App::registerAdmin('theming', 'settings/settings-admin'); |
||||
|
||||
$linkToCSS = \OC::$server->getURLGenerator()->linkToRoute( |
||||
'theming.Theming.getStylesheet', |
||||
[ |
||||
'v' => \OC::$server->getConfig()->getAppValue('theming', 'cachebuster', '0'), |
||||
] |
||||
); |
||||
\OC_Util::addHeader( |
||||
'link', |
||||
[ |
||||
'rel' => 'stylesheet', |
||||
'href' => $linkToCSS, |
||||
] |
||||
); |
||||
|
||||
|
@ -1,94 +0,0 @@ |
||||
<?php |
||||
/** |
||||
* @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org> |
||||
* |
||||
* @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\App\ManagerEvent; |
||||
use OCP\IConfig; |
||||
use OCP\ILogger; |
||||
|
||||
/** |
||||
* Class Init |
||||
* |
||||
* Initialize the app and make sure that all directories and files exists |
||||
* |
||||
* @package OCA\Theming |
||||
*/ |
||||
class Init { |
||||
|
||||
/** @var IConfig */ |
||||
private $config; |
||||
|
||||
/** @var ILogger */ |
||||
private $logger; |
||||
|
||||
/** |
||||
* Init constructor. |
||||
* |
||||
* @param IConfig $config |
||||
* @param ILogger $logger |
||||
*/ |
||||
public function __construct(IConfig $config, ILogger $logger) { |
||||
$this->config = $config; |
||||
$this->logger = $logger; |
||||
} |
||||
|
||||
/** |
||||
* prepare folders with the theming app and add the default values to it |
||||
*/ |
||||
public function prepareThemeFolder() { |
||||
|
||||
if ($this->config->getSystemValue('theme', 'default') === 'theming-app') { |
||||
return; |
||||
} |
||||
|
||||
if (!is_writable(\OC::$SERVERROOT . '/themes')) { |
||||
$this->logger->warning('Themes folder is read only, can not prepare the theming-app folder', |
||||
['app' => 'theming'] |
||||
); |
||||
} |
||||
|
||||
$this->config->setSystemValue('theme', 'theming-app'); |
||||
|
||||
if(!file_exists(\OC::$SERVERROOT . '/themes/theming-app')) { |
||||
mkdir(\OC::$SERVERROOT . '/themes/theming-app'); |
||||
} |
||||
|
||||
if(!file_exists(\OC::$SERVERROOT . '/themes/theming-app/core')) { |
||||
mkdir(\OC::$SERVERROOT . '/themes/theming-app/core'); |
||||
} |
||||
|
||||
if(!file_exists(\OC::$SERVERROOT . '/themes/theming-app/core/img')) { |
||||
mkdir(\OC::$SERVERROOT . '/themes/theming-app/core/img'); |
||||
} |
||||
|
||||
if(!file_exists(\OC::$SERVERROOT . '/themes/theming-app/core/css')) { |
||||
mkdir(\OC::$SERVERROOT . '/themes/theming-app/core/css'); |
||||
} |
||||
|
||||
if(!file_exists(\OC::$SERVERROOT . '/themes/theming-app/core/img/logo-icon.svg')) { |
||||
copy(\OC::$SERVERROOT . '/core/img/logo-icon.svg' ,\OC::$SERVERROOT . '/themes/theming-app/core/img/logo-icon.svg'); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,301 @@ |
||||
<?php |
||||
/** |
||||
* @copyright Copyright (c) 2016 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 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 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')); |
||||
} |
||||
} |
@ -0,0 +1,405 @@ |
||||
<?php |
||||
/** |
||||
* @copyright Copyright (c) 2016 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\Controller; |
||||
|
||||
use OCA\Theming\Controller\ThemingController; |
||||
use OCA\Theming\Template; |
||||
use OCP\AppFramework\Http; |
||||
use OCP\AppFramework\Http\DataResponse; |
||||
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; |
||||
|
||||
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->themingController = new ThemingController( |
||||
'theming', |
||||
$this->request, |
||||
$this->config, |
||||
$this->template, |
||||
$this->l10n |
||||
); |
||||
|
||||
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->config |
||||
->expects($this->at(0)) |
||||
->method('getSystemValue') |
||||
->with('datadirectory', \OC::$SERVERROOT . '/data') |
||||
->willReturn($destination); |
||||
$this->l10n |
||||
->expects($this->once()) |
||||
->method('t') |
||||
->with('Saved') |
||||
->willReturn('Saved'); |
||||
|
||||
$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->config |
||||
->expects($this->at(0)) |
||||
->method('getSystemValue') |
||||
->with('datadirectory', \OC::$SERVERROOT . '/data') |
||||
->willReturn($destination); |
||||
$this->l10n |
||||
->expects($this->once()) |
||||
->method('t') |
||||
->with('Saved') |
||||
->willReturn('Saved'); |
||||
|
||||
$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() { |
||||
$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(''); |
||||
$this->config |
||||
->expects($this->at(3)) |
||||
->method('getAppValue') |
||||
->with('theming', 'backgroundMime', '') |
||||
->willReturn(''); |
||||
|
||||
$expected = new Http\DataDownloadResponse('#body-user #header,#body-settings #header,#body-public #header {background-color: #fff}', 'style.css', '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(''); |
||||
|
||||
$expected = new Http\DataDownloadResponse('#header .logo { |
||||
background-image: url(\'./logo?v=0\'); |
||||
} |
||||
#header .logo-icon { |
||||
background-image: url(\'./logo?v=0\'); |
||||
background-size: 62px 34px; |
||||
}', 'style.css', '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'); |
||||
|
||||
$expected = new Http\DataDownloadResponse('#body-login { |
||||
background-image: url(\'./loginbackground?v=0\'); |
||||
}', 'style.css', 'text/css'); |
||||
$expected->cacheFor(3600); |
||||
@$this->assertEquals($expected, $this->themingController->getStylesheet()); |
||||
} |
||||
|
||||
public function testGetStylesheetWithAllCombined() { |
||||
$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('#abc'); |
||||
$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'); |
||||
|
||||
$expected = new Http\DataDownloadResponse('#body-user #header,#body-settings #header,#body-public #header {background-color: #abc}#header .logo { |
||||
background-image: url(\'./logo?v=0\'); |
||||
} |
||||
#header .logo-icon { |
||||
background-image: url(\'./logo?v=0\'); |
||||
background-size: 62px 34px; |
||||
}#body-login { |
||||
background-image: url(\'./loginbackground?v=0\'); |
||||
}', 'style.css', 'text/css'); |
||||
$expected->cacheFor(3600); |
||||
@$this->assertEquals($expected, $this->themingController->getStylesheet()); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue