2016-06-21 22:21:46 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
|
|
|
|
*
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Julius Haertl <jus@bitgrid.net>
|
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
|
|
|
* @author oparoz <owncloud@interfasys.ch>
|
|
|
|
*
|
2016-06-21 22:21:46 +03:00
|
|
|
* @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;
|
|
|
|
|
2017-02-17 18:42:07 +03:00
|
|
|
use OC\Files\AppData\Factory;
|
2017-02-09 19:12:00 +03:00
|
|
|
use OC\L10N\L10N;
|
2017-02-17 18:42:07 +03:00
|
|
|
use OC\Template\SCSSCacher;
|
2016-06-21 22:21:46 +03:00
|
|
|
use OCA\Theming\Controller\ThemingController;
|
2016-07-25 18:32:11 +03:00
|
|
|
use OCA\Theming\Util;
|
2016-11-18 12:49:03 +03:00
|
|
|
use OCP\App\IAppManager;
|
2016-06-21 22:21:46 +03:00
|
|
|
use OCP\AppFramework\Http;
|
|
|
|
use OCP\AppFramework\Http\DataResponse;
|
2017-02-09 19:12:00 +03:00
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
2017-02-09 13:38:45 +03:00
|
|
|
use OCP\Files\IAppData;
|
2016-06-27 11:47:44 +03:00
|
|
|
use OCP\Files\IRootFolder;
|
2016-11-08 21:46:09 +03:00
|
|
|
use OCP\Files\NotFoundException;
|
2017-02-09 19:12:00 +03:00
|
|
|
use OCP\Files\SimpleFS\ISimpleFile;
|
|
|
|
use OCP\Files\SimpleFS\ISimpleFolder;
|
2016-06-21 22:21:46 +03:00
|
|
|
use OCP\IConfig;
|
|
|
|
use OCP\IL10N;
|
2017-02-17 18:42:07 +03:00
|
|
|
use OCP\ILogger;
|
2016-06-21 22:21:46 +03:00
|
|
|
use OCP\IRequest;
|
2016-08-27 22:38:41 +03:00
|
|
|
use OCP\ITempManager;
|
2017-02-17 18:42:07 +03:00
|
|
|
use OCP\IURLGenerator;
|
2016-06-21 22:21:46 +03:00
|
|
|
use Test\TestCase;
|
2016-08-15 17:24:56 +03:00
|
|
|
use OCA\Theming\ThemingDefaults;
|
2016-06-21 22:21:46 +03:00
|
|
|
|
|
|
|
class ThemingControllerTest extends TestCase {
|
2016-08-01 10:37:12 +03:00
|
|
|
/** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
|
2016-06-21 22:21:46 +03:00
|
|
|
private $request;
|
2016-08-01 10:37:12 +03:00
|
|
|
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
2016-06-21 22:21:46 +03:00
|
|
|
private $config;
|
2016-08-12 17:58:59 +03:00
|
|
|
/** @var ThemingDefaults|\PHPUnit_Framework_MockObject_MockObject */
|
2017-02-17 18:42:07 +03:00
|
|
|
private $themingDefaults;
|
2016-07-28 17:07:23 +03:00
|
|
|
/** @var Util */
|
|
|
|
private $util;
|
|
|
|
/** @var \OCP\AppFramework\Utility\ITimeFactory */
|
|
|
|
private $timeFactory;
|
2016-08-01 10:37:12 +03:00
|
|
|
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
|
2016-06-21 22:21:46 +03:00
|
|
|
private $l10n;
|
|
|
|
/** @var ThemingController */
|
|
|
|
private $themingController;
|
2016-08-27 22:38:41 +03:00
|
|
|
/** @var ITempManager */
|
|
|
|
private $tempManager;
|
2017-02-09 13:38:45 +03:00
|
|
|
/** @var IAppManager|\PHPUnit_Framework_MockObject_MockObject */
|
2016-11-18 12:49:03 +03:00
|
|
|
private $appManager;
|
2017-02-09 13:38:45 +03:00
|
|
|
/** @var IAppData|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $appData;
|
2017-02-17 18:42:07 +03:00
|
|
|
/** @var SCSSCacher */
|
|
|
|
private $scssCacher;
|
2017-08-10 12:33:12 +03:00
|
|
|
/** @var IURLGenerator */
|
|
|
|
private $urlGenerator;
|
2016-06-21 22:21:46 +03:00
|
|
|
|
|
|
|
public function setUp() {
|
2017-02-10 00:51:05 +03:00
|
|
|
$this->request = $this->createMock(IRequest::class);
|
|
|
|
$this->config = $this->createMock(IConfig::class);
|
2017-02-17 18:42:07 +03:00
|
|
|
$this->themingDefaults = $this->createMock(ThemingDefaults::class);
|
2017-02-10 00:51:05 +03:00
|
|
|
$this->timeFactory = $this->createMock(ITimeFactory::class);
|
|
|
|
$this->l10n = $this->createMock(L10N::class);
|
2017-05-17 11:16:59 +03:00
|
|
|
$this->appData = $this->createMock(IAppData::class);
|
2017-02-10 00:51:05 +03:00
|
|
|
$this->appManager = $this->createMock(IAppManager::class);
|
2017-05-17 11:16:59 +03:00
|
|
|
$this->util = new Util($this->config, $this->appManager, $this->appData);
|
2016-07-28 17:07:23 +03:00
|
|
|
$this->timeFactory->expects($this->any())
|
|
|
|
->method('getTime')
|
|
|
|
->willReturn(123);
|
2016-08-27 22:38:41 +03:00
|
|
|
$this->tempManager = \OC::$server->getTempManager();
|
2017-02-17 18:42:07 +03:00
|
|
|
$this->scssCacher = $this->createMock(SCSSCacher::class);
|
2017-08-10 12:33:12 +03:00
|
|
|
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
2016-07-28 17:07:23 +03:00
|
|
|
|
2016-06-21 22:21:46 +03:00
|
|
|
$this->themingController = new ThemingController(
|
|
|
|
'theming',
|
|
|
|
$this->request,
|
|
|
|
$this->config,
|
2017-02-17 18:42:07 +03:00
|
|
|
$this->themingDefaults,
|
2016-07-28 17:07:23 +03:00
|
|
|
$this->util,
|
|
|
|
$this->timeFactory,
|
2016-06-27 11:47:44 +03:00
|
|
|
$this->l10n,
|
2017-02-09 13:38:45 +03:00
|
|
|
$this->tempManager,
|
2017-02-17 18:42:07 +03:00
|
|
|
$this->appData,
|
2017-08-10 12:33:12 +03:00
|
|
|
$this->scssCacher,
|
|
|
|
$this->urlGenerator
|
2016-06-21 22:21:46 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
return parent::setUp();
|
|
|
|
}
|
|
|
|
|
2017-08-10 12:21:43 +03:00
|
|
|
public function dataUpdateStylesheetSuccess() {
|
2016-08-01 10:37:12 +03:00
|
|
|
return [
|
2017-08-10 12:21:43 +03:00
|
|
|
['name', str_repeat('a', 250), 'Saved'],
|
|
|
|
['url', str_repeat('a', 500), 'Saved'],
|
|
|
|
['slogan', str_repeat('a', 500), 'Saved'],
|
|
|
|
['color', '#0082c9', 'Saved'],
|
|
|
|
['color', '#0082C9', 'Saved'],
|
2016-08-01 10:37:12 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-08-10 12:21:43 +03:00
|
|
|
* @dataProvider dataUpdateStylesheetSuccess
|
2016-08-01 10:37:12 +03:00
|
|
|
*
|
|
|
|
* @param string $setting
|
|
|
|
* @param string $value
|
|
|
|
* @param string $message
|
|
|
|
*/
|
2017-08-10 12:21:43 +03:00
|
|
|
public function testUpdateStylesheetSuccess($setting, $value, $message) {
|
2017-02-17 18:42:07 +03:00
|
|
|
$this->themingDefaults
|
2017-08-10 12:21:43 +03:00
|
|
|
->expects($this->once())
|
|
|
|
->method('set')
|
|
|
|
->with($setting, $value);
|
|
|
|
$this->l10n
|
|
|
|
->expects($this->once())
|
|
|
|
->method('t')
|
|
|
|
->with($message)
|
|
|
|
->willReturn($message);
|
2017-08-10 12:33:12 +03:00
|
|
|
$this->scssCacher
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getCachedSCSS')
|
|
|
|
->with('core', '/core/css/server.scss')
|
|
|
|
->willReturn('/core/css/someHash-server.scss');
|
|
|
|
$this->urlGenerator
|
|
|
|
->expects($this->once())
|
|
|
|
->method('linkTo')
|
|
|
|
->with('', '/core/css/someHash-server.scss')
|
|
|
|
->willReturn('/nextcloudWebroot/core/css/someHash-server.scss');
|
2017-08-10 12:21:43 +03:00
|
|
|
|
|
|
|
$expected = new DataResponse(
|
|
|
|
[
|
|
|
|
'data' =>
|
|
|
|
[
|
|
|
|
'message' => $message,
|
2017-08-10 12:33:12 +03:00
|
|
|
'serverCssUrl' => '/nextcloudWebroot/core/css/someHash-server.scss',
|
2017-08-10 12:21:43 +03:00
|
|
|
],
|
|
|
|
'status' => 'success',
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $this->themingController->updateStylesheet($setting, $value));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function dataUpdateStylesheetError() {
|
|
|
|
return [
|
|
|
|
['name', str_repeat('a', 251), 'The given name is too long'],
|
|
|
|
['url', str_repeat('a', 501), 'The given web address is too long'],
|
|
|
|
['slogan', str_repeat('a', 501), 'The given slogan is too long'],
|
|
|
|
['color', '0082C9', 'The given color is invalid'],
|
|
|
|
['color', '#0082Z9', 'The given color is invalid'],
|
|
|
|
['color', 'Nextcloud', 'The given color is invalid'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataUpdateStylesheetError
|
|
|
|
*
|
|
|
|
* @param string $setting
|
|
|
|
* @param string $value
|
|
|
|
* @param string $message
|
|
|
|
*/
|
|
|
|
public function testUpdateStylesheetError($setting, $value, $message) {
|
|
|
|
$this->themingDefaults
|
|
|
|
->expects($this->never())
|
2016-06-21 22:21:46 +03:00
|
|
|
->method('set')
|
2016-08-01 10:37:12 +03:00
|
|
|
->with($setting, $value);
|
2016-06-21 22:21:46 +03:00
|
|
|
$this->l10n
|
|
|
|
->expects($this->once())
|
|
|
|
->method('t')
|
2016-08-01 10:37:12 +03:00
|
|
|
->with($message)
|
|
|
|
->willReturn($message);
|
2016-06-21 22:21:46 +03:00
|
|
|
|
2017-08-10 13:31:30 +03:00
|
|
|
$expected = new DataResponse(
|
|
|
|
[
|
|
|
|
'data' =>
|
|
|
|
[
|
|
|
|
'message' => $message,
|
|
|
|
],
|
2017-08-10 12:21:43 +03:00
|
|
|
'status' => 'error',
|
2017-08-10 13:31:30 +03:00
|
|
|
]
|
|
|
|
);
|
2016-08-01 10:37:12 +03:00
|
|
|
$this->assertEquals($expected, $this->themingController->updateStylesheet($setting, $value));
|
2016-06-21 22:21:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateLogoNoData() {
|
|
|
|
$this->request
|
|
|
|
->expects($this->at(0))
|
2017-05-01 11:42:19 +03:00
|
|
|
->method('getParam')
|
|
|
|
->with('backgroundColor')
|
|
|
|
->willReturn(false);
|
|
|
|
$this->request
|
|
|
|
->expects($this->at(1))
|
2016-06-21 22:21:46 +03:00
|
|
|
->method('getUploadedFile')
|
|
|
|
->with('uploadlogo')
|
|
|
|
->willReturn(null);
|
|
|
|
$this->request
|
2017-05-01 11:42:19 +03:00
|
|
|
->expects($this->at(2))
|
2016-06-21 22:21:46 +03:00
|
|
|
->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());
|
|
|
|
}
|
|
|
|
|
2017-05-01 11:42:19 +03:00
|
|
|
public function testUpdateBackgroundColor() {
|
|
|
|
$this->request
|
|
|
|
->expects($this->at(0))
|
|
|
|
->method('getParam')
|
|
|
|
->with('backgroundColor')
|
|
|
|
->willReturn(true);
|
|
|
|
$this->themingDefaults
|
|
|
|
->expects($this->once())
|
|
|
|
->method('set')
|
|
|
|
->with('backgroundMime', 'backgroundColor');
|
|
|
|
$expected = new DataResponse(
|
|
|
|
[
|
|
|
|
'data' =>
|
|
|
|
[
|
|
|
|
'name' => 'backgroundColor',
|
|
|
|
'message' => $this->l10n->t('Saved')
|
|
|
|
],
|
|
|
|
'status' => 'success'
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $this->themingController->updateLogo());
|
|
|
|
}
|
|
|
|
|
2017-02-16 17:13:19 +03:00
|
|
|
public function dataUpdateImages() {
|
|
|
|
return [
|
|
|
|
[false],
|
|
|
|
[true]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @dataProvider dataUpdateImages */
|
|
|
|
public function testUpdateLogoNormalLogoUpload($folderExists) {
|
2016-06-21 22:21:46 +03:00
|
|
|
$tmpLogo = \OC::$server->getTempManager()->getTemporaryFolder() . '/logo.svg';
|
|
|
|
$destination = \OC::$server->getTempManager()->getTemporaryFolder();
|
|
|
|
|
|
|
|
touch($tmpLogo);
|
|
|
|
$this->request
|
|
|
|
->expects($this->at(0))
|
2017-05-01 11:42:19 +03:00
|
|
|
->method('getParam')
|
|
|
|
->with('backgroundColor')
|
|
|
|
->willReturn(false);
|
|
|
|
$this->request
|
|
|
|
->expects($this->at(1))
|
2016-06-21 22:21:46 +03:00
|
|
|
->method('getUploadedFile')
|
|
|
|
->with('uploadlogo')
|
|
|
|
->willReturn([
|
|
|
|
'tmp_name' => $tmpLogo,
|
|
|
|
'type' => 'text/svg',
|
|
|
|
'name' => 'logo.svg',
|
|
|
|
]);
|
|
|
|
$this->request
|
2017-05-01 11:42:19 +03:00
|
|
|
->expects($this->at(2))
|
2016-06-21 22:21:46 +03:00
|
|
|
->method('getUploadedFile')
|
|
|
|
->with('upload-login-background')
|
|
|
|
->willReturn(null);
|
|
|
|
$this->l10n
|
|
|
|
->expects($this->once())
|
|
|
|
->method('t')
|
|
|
|
->with('Saved')
|
|
|
|
->willReturn('Saved');
|
2017-02-09 13:38:45 +03:00
|
|
|
|
|
|
|
|
2017-02-10 00:51:05 +03:00
|
|
|
$file = $this->createMock(ISimpleFile::class);
|
|
|
|
$folder = $this->createMock(ISimpleFolder::class);
|
2017-02-16 17:13:19 +03:00
|
|
|
if($folderExists) {
|
|
|
|
$this->appData
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getFolder')
|
|
|
|
->with('images')
|
|
|
|
->willReturn($folder);
|
|
|
|
} else {
|
|
|
|
$this->appData
|
|
|
|
->expects($this->at(0))
|
|
|
|
->method('getFolder')
|
|
|
|
->with('images')
|
|
|
|
->willThrowException(new NotFoundException());
|
|
|
|
$this->appData
|
|
|
|
->expects($this->at(1))
|
|
|
|
->method('newFolder')
|
|
|
|
->with('images')
|
|
|
|
->willReturn($folder);
|
|
|
|
}
|
2017-02-09 13:38:45 +03:00
|
|
|
$folder->expects($this->once())
|
2016-06-27 11:47:44 +03:00
|
|
|
->method('newFile')
|
2017-02-09 13:38:45 +03:00
|
|
|
->with('logo')
|
2016-06-27 11:47:44 +03:00
|
|
|
->willReturn($file);
|
2016-06-21 22:21:46 +03:00
|
|
|
$expected = new DataResponse(
|
|
|
|
[
|
|
|
|
'data' =>
|
|
|
|
[
|
|
|
|
'name' => 'logo.svg',
|
|
|
|
'message' => 'Saved',
|
|
|
|
],
|
|
|
|
'status' => 'success'
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $this->themingController->updateLogo());
|
|
|
|
}
|
|
|
|
|
2017-02-16 17:13:19 +03:00
|
|
|
/** @dataProvider dataUpdateImages */
|
|
|
|
public function testUpdateLogoLoginScreenUpload($folderExists) {
|
2016-06-21 22:21:46 +03:00
|
|
|
$tmpLogo = \OC::$server->getTempManager()->getTemporaryFolder() . '/logo.svg';
|
|
|
|
|
|
|
|
touch($tmpLogo);
|
2016-08-27 13:38:15 +03:00
|
|
|
file_put_contents($tmpLogo, file_get_contents(__DIR__ . '/../../../../tests/data/desktopapp.png'));
|
2016-06-21 22:21:46 +03:00
|
|
|
$this->request
|
|
|
|
->expects($this->at(0))
|
2017-05-01 11:42:19 +03:00
|
|
|
->method('getParam')
|
|
|
|
->with('backgroundColor')
|
|
|
|
->willReturn(false);
|
|
|
|
$this->request
|
|
|
|
->expects($this->at(1))
|
2016-06-21 22:21:46 +03:00
|
|
|
->method('getUploadedFile')
|
|
|
|
->with('uploadlogo')
|
|
|
|
->willReturn(null);
|
|
|
|
$this->request
|
2017-05-01 11:42:19 +03:00
|
|
|
->expects($this->at(2))
|
2016-06-21 22:21:46 +03:00
|
|
|
->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');
|
2017-02-09 13:38:45 +03:00
|
|
|
|
2017-02-10 00:51:05 +03:00
|
|
|
$file = $this->createMock(ISimpleFile::class);
|
|
|
|
$folder = $this->createMock(ISimpleFolder::class);
|
2017-02-16 17:13:19 +03:00
|
|
|
if($folderExists) {
|
|
|
|
$this->appData
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getFolder')
|
|
|
|
->with('images')
|
|
|
|
->willReturn($folder);
|
|
|
|
} else {
|
|
|
|
$this->appData
|
|
|
|
->expects($this->at(0))
|
|
|
|
->method('getFolder')
|
|
|
|
->with('images')
|
|
|
|
->willThrowException(new NotFoundException());
|
|
|
|
$this->appData
|
|
|
|
->expects($this->at(1))
|
|
|
|
->method('newFolder')
|
|
|
|
->with('images')
|
|
|
|
->willReturn($folder);
|
|
|
|
}
|
2017-02-09 13:38:45 +03:00
|
|
|
$folder->expects($this->once())
|
2016-06-27 11:47:44 +03:00
|
|
|
->method('newFile')
|
2017-02-09 13:38:45 +03:00
|
|
|
->with('background')
|
2016-06-27 11:47:44 +03:00
|
|
|
->willReturn($file);
|
2016-06-21 22:21:46 +03:00
|
|
|
|
|
|
|
$expected = new DataResponse(
|
|
|
|
[
|
|
|
|
'data' =>
|
|
|
|
[
|
|
|
|
'name' => 'logo.svg',
|
|
|
|
'message' => 'Saved',
|
|
|
|
],
|
|
|
|
'status' => 'success'
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $this->themingController->updateLogo());
|
|
|
|
}
|
|
|
|
|
2016-08-27 13:38:15 +03:00
|
|
|
public function testUpdateLogoLoginScreenUploadWithInvalidImage() {
|
|
|
|
$tmpLogo = \OC::$server->getTempManager()->getTemporaryFolder() . '/logo.svg';
|
|
|
|
|
|
|
|
touch($tmpLogo);
|
|
|
|
file_put_contents($tmpLogo, file_get_contents(__DIR__ . '/../../../../tests/data/data.zip'));
|
|
|
|
$this->request
|
|
|
|
->expects($this->at(0))
|
2017-05-01 11:42:19 +03:00
|
|
|
->method('getParam')
|
|
|
|
->with('backgroundColor')
|
|
|
|
->willReturn(false);
|
|
|
|
$this->request
|
|
|
|
->expects($this->at(1))
|
2016-08-27 13:38:15 +03:00
|
|
|
->method('getUploadedFile')
|
|
|
|
->with('uploadlogo')
|
|
|
|
->willReturn(null);
|
|
|
|
$this->request
|
2017-05-01 11:42:19 +03:00
|
|
|
->expects($this->at(2))
|
2016-08-27 13:38:15 +03:00
|
|
|
->method('getUploadedFile')
|
|
|
|
->with('upload-login-background')
|
|
|
|
->willReturn([
|
|
|
|
'tmp_name' => $tmpLogo,
|
|
|
|
'type' => 'text/svg',
|
|
|
|
'name' => 'logo.svg',
|
|
|
|
]);
|
|
|
|
$this->l10n
|
|
|
|
->expects($this->once())
|
|
|
|
->method('t')
|
|
|
|
->with('Unsupported image type')
|
|
|
|
->willReturn('Unsupported image type');
|
2017-02-09 13:38:45 +03:00
|
|
|
|
2017-02-10 00:51:05 +03:00
|
|
|
$folder = $this->createMock(ISimpleFolder::class);
|
2017-02-09 13:38:45 +03:00
|
|
|
$this->appData
|
2016-08-27 13:38:15 +03:00
|
|
|
->expects($this->once())
|
2017-02-09 13:38:45 +03:00
|
|
|
->method('getFolder')
|
|
|
|
->with('images')
|
|
|
|
->willReturn($folder);
|
|
|
|
|
2016-08-27 13:38:15 +03:00
|
|
|
$expected = new DataResponse(
|
|
|
|
[
|
|
|
|
'data' =>
|
|
|
|
[
|
|
|
|
'message' => 'Unsupported image type',
|
|
|
|
],
|
|
|
|
'status' => 'failure'
|
|
|
|
],
|
|
|
|
Http::STATUS_UNPROCESSABLE_ENTITY
|
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $this->themingController->updateLogo());
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:21:46 +03:00
|
|
|
public function testUndo() {
|
|
|
|
$this->l10n
|
|
|
|
->expects($this->once())
|
|
|
|
->method('t')
|
|
|
|
->with('Saved')
|
|
|
|
->willReturn('Saved');
|
2017-02-17 18:42:07 +03:00
|
|
|
$this->themingDefaults
|
2016-06-21 22:21:46 +03:00
|
|
|
->expects($this->once())
|
|
|
|
->method('undo')
|
|
|
|
->with('MySetting')
|
|
|
|
->willReturn('MyValue');
|
2017-08-10 12:33:12 +03:00
|
|
|
$this->scssCacher
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getCachedSCSS')
|
|
|
|
->with('core', '/core/css/server.scss')
|
|
|
|
->willReturn('/core/css/someHash-server.scss');
|
|
|
|
$this->urlGenerator
|
|
|
|
->expects($this->once())
|
|
|
|
->method('linkTo')
|
|
|
|
->with('', '/core/css/someHash-server.scss')
|
|
|
|
->willReturn('/nextcloudWebroot/core/css/someHash-server.scss');
|
2016-06-21 22:21:46 +03:00
|
|
|
|
|
|
|
$expected = new DataResponse(
|
|
|
|
[
|
|
|
|
'data' =>
|
|
|
|
[
|
|
|
|
'value' => 'MyValue',
|
|
|
|
'message' => 'Saved',
|
2017-08-10 12:33:12 +03:00
|
|
|
'serverCssUrl' => '/nextcloudWebroot/core/css/someHash-server.scss',
|
2016-06-21 22:21:46 +03:00
|
|
|
],
|
|
|
|
'status' => 'success'
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $this->themingController->undo('MySetting'));
|
|
|
|
}
|
|
|
|
|
2017-04-29 12:22:34 +03:00
|
|
|
public function dataUndoDelete() {
|
|
|
|
return [
|
|
|
|
[ 'backgroundMime', 'background' ],
|
|
|
|
[ 'logoMime', 'logo' ]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @dataProvider dataUndoDelete */
|
|
|
|
public function testUndoDelete($value, $filename) {
|
|
|
|
$this->l10n
|
|
|
|
->expects($this->once())
|
|
|
|
->method('t')
|
|
|
|
->with('Saved')
|
|
|
|
->willReturn('Saved');
|
|
|
|
$this->themingDefaults
|
|
|
|
->expects($this->once())
|
|
|
|
->method('undo')
|
|
|
|
->with($value)
|
|
|
|
->willReturn($value);
|
2017-08-10 12:33:12 +03:00
|
|
|
$this->scssCacher
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getCachedSCSS')
|
|
|
|
->with('core', '/core/css/server.scss')
|
|
|
|
->willReturn('/core/css/someHash-server.scss');
|
|
|
|
$this->urlGenerator
|
|
|
|
->expects($this->once())
|
|
|
|
->method('linkTo')
|
|
|
|
->with('', '/core/css/someHash-server.scss')
|
|
|
|
->willReturn('/nextcloudWebroot/core/css/someHash-server.scss');
|
2017-04-29 12:22:34 +03:00
|
|
|
$folder = $this->createMock(ISimpleFolder::class);
|
|
|
|
$file = $this->createMock(ISimpleFile::class);
|
|
|
|
$this->appData
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getFolder')
|
|
|
|
->with('images')
|
|
|
|
->willReturn($folder);
|
|
|
|
$folder
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getFile')
|
|
|
|
->with($filename)
|
|
|
|
->willReturn($file);
|
|
|
|
$file
|
|
|
|
->expects($this->once())
|
|
|
|
->method('delete');
|
|
|
|
|
|
|
|
$expected = new DataResponse(
|
|
|
|
[
|
|
|
|
'data' =>
|
|
|
|
[
|
|
|
|
'value' => $value,
|
|
|
|
'message' => 'Saved',
|
2017-08-10 12:33:12 +03:00
|
|
|
'serverCssUrl' => '/nextcloudWebroot/core/css/someHash-server.scss',
|
2017-04-29 12:22:34 +03:00
|
|
|
],
|
|
|
|
'status' => 'success'
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $this->themingController->undo($value));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-06-21 22:21:46 +03:00
|
|
|
public function testGetLogoNotExistent() {
|
2017-02-09 13:38:45 +03:00
|
|
|
$this->appData->method('getFolder')
|
|
|
|
->with($this->equalTo('images'))
|
2016-11-08 21:46:09 +03:00
|
|
|
->willThrowException(new NotFoundException());
|
|
|
|
|
|
|
|
$expected = new Http\NotFoundResponse();
|
2016-06-21 22:21:46 +03:00
|
|
|
$this->assertEquals($expected, $this->themingController->getLogo());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetLogo() {
|
2017-02-10 00:51:05 +03:00
|
|
|
$file = $this->createMock(ISimpleFile::class);
|
|
|
|
$folder = $this->createMock(ISimpleFolder::class);
|
2017-02-09 13:38:45 +03:00
|
|
|
$this->appData
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getFolder')
|
|
|
|
->with('images')
|
|
|
|
->willReturn($folder);
|
|
|
|
$folder->expects($this->once())
|
|
|
|
->method('getFile')
|
|
|
|
->with('logo')
|
2016-11-08 21:46:09 +03:00
|
|
|
->willReturn($file);
|
|
|
|
|
2016-06-21 22:21:46 +03:00
|
|
|
$this->config
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getAppValue')
|
|
|
|
->with('theming', 'logoMime', '')
|
|
|
|
->willReturn('text/svg');
|
|
|
|
|
2017-02-09 13:38:45 +03:00
|
|
|
@$expected = new Http\FileDisplayResponse($file);
|
2016-06-21 22:21:46 +03:00
|
|
|
$expected->cacheFor(3600);
|
2017-02-09 13:38:45 +03:00
|
|
|
$expires = new \DateTime();
|
|
|
|
$expires->setTimestamp($this->timeFactory->getTime());
|
|
|
|
$expires->add(new \DateInterval('PT24H'));
|
|
|
|
$expected->addHeader('Expires', $expires->format(\DateTime::RFC2822));
|
2016-08-27 13:38:15 +03:00
|
|
|
$expected->addHeader('Pragma', 'cache');
|
2017-02-09 13:38:45 +03:00
|
|
|
$expected->addHeader('Content-Type', 'text/svg');
|
2016-06-21 22:21:46 +03:00
|
|
|
@$this->assertEquals($expected, $this->themingController->getLogo());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testGetLoginBackgroundNotExistent() {
|
2017-02-09 13:38:45 +03:00
|
|
|
$this->appData->method('getFolder')
|
|
|
|
->with($this->equalTo('images'))
|
2016-11-08 21:46:09 +03:00
|
|
|
->willThrowException(new NotFoundException());
|
|
|
|
$expected = new Http\NotFoundResponse();
|
2016-06-21 22:21:46 +03:00
|
|
|
$this->assertEquals($expected, $this->themingController->getLoginBackground());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetLoginBackground() {
|
2017-02-10 00:51:05 +03:00
|
|
|
$file = $this->createMock(ISimpleFile::class);
|
|
|
|
$folder = $this->createMock(ISimpleFolder::class);
|
2017-02-09 13:38:45 +03:00
|
|
|
$this->appData
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getFolder')
|
|
|
|
->with('images')
|
|
|
|
->willReturn($folder);
|
|
|
|
$folder->expects($this->once())
|
|
|
|
->method('getFile')
|
|
|
|
->with('background')
|
2016-11-08 21:46:09 +03:00
|
|
|
->willReturn($file);
|
|
|
|
|
2016-06-21 22:21:46 +03:00
|
|
|
$this->config
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getAppValue')
|
|
|
|
->with('theming', 'backgroundMime', '')
|
|
|
|
->willReturn('image/png');
|
|
|
|
|
2017-02-09 13:38:45 +03:00
|
|
|
@$expected = new Http\FileDisplayResponse($file);
|
2016-06-21 22:21:46 +03:00
|
|
|
$expected->cacheFor(3600);
|
2017-02-09 13:38:45 +03:00
|
|
|
$expires = new \DateTime();
|
|
|
|
$expires->setTimestamp($this->timeFactory->getTime());
|
|
|
|
$expires->add(new \DateInterval('PT24H'));
|
|
|
|
$expected->addHeader('Expires', $expires->format(\DateTime::RFC2822));
|
2016-08-27 13:38:15 +03:00
|
|
|
$expected->addHeader('Pragma', 'cache');
|
2017-02-09 13:38:45 +03:00
|
|
|
$expected->addHeader('Content-Type', 'image/png');
|
2016-06-21 22:21:46 +03:00
|
|
|
@$this->assertEquals($expected, $this->themingController->getLoginBackground());
|
|
|
|
}
|
|
|
|
|
2016-07-28 12:45:42 +03:00
|
|
|
|
2017-02-17 18:42:07 +03:00
|
|
|
public function testGetStylesheet() {
|
2016-07-28 12:45:42 +03:00
|
|
|
|
2017-02-17 18:42:07 +03:00
|
|
|
$file = $this->createMock(ISimpleFile::class);
|
|
|
|
$file->expects($this->any())->method('getName')->willReturn('theming.css');
|
|
|
|
$file->expects($this->any())->method('getContent')->willReturn('compiled');
|
|
|
|
$this->scssCacher->expects($this->once())->method('process')->willReturn(true);
|
|
|
|
$this->scssCacher->expects($this->once())->method('getCachedCSS')->willReturn($file);
|
2016-07-28 12:45:42 +03:00
|
|
|
|
2017-02-17 18:42:07 +03:00
|
|
|
$response = new Http\FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => 'text/css']);
|
|
|
|
$response->cacheFor(86400);
|
|
|
|
$expires = new \DateTime();
|
|
|
|
$expires->setTimestamp($this->timeFactory->getTime());
|
|
|
|
$expires->add(new \DateInterval('PT24H'));
|
|
|
|
$response->addHeader('Expires', $expires->format(\DateTime::RFC1123));
|
|
|
|
$response->addHeader('Pragma', 'cache');
|
2016-07-19 15:39:53 +03:00
|
|
|
|
2017-02-17 18:42:07 +03:00
|
|
|
$actual = $this->themingController->getStylesheet();
|
|
|
|
$this->assertEquals($response, $actual);
|
2016-06-21 22:21:46 +03:00
|
|
|
}
|
2016-07-28 12:45:42 +03:00
|
|
|
|
2017-02-17 18:42:07 +03:00
|
|
|
public function testGetStylesheetFails() {
|
|
|
|
$file = $this->createMock(ISimpleFile::class);
|
|
|
|
$file->expects($this->any())->method('getName')->willReturn('theming.css');
|
|
|
|
$file->expects($this->any())->method('getContent')->willReturn('compiled');
|
|
|
|
$this->scssCacher->expects($this->once())->method('process')->willReturn(true);
|
|
|
|
$this->scssCacher->expects($this->once())->method('getCachedCSS')->willThrowException(new NotFoundException());
|
|
|
|
$response = new Http\NotFoundResponse();
|
|
|
|
|
|
|
|
$actual = $this->themingController->getStylesheet();
|
|
|
|
$this->assertEquals($response, $actual);
|
2016-07-15 15:04:19 +03:00
|
|
|
}
|
2016-08-10 12:53:33 +03:00
|
|
|
|
|
|
|
public function testGetJavascript() {
|
2017-02-17 18:42:07 +03:00
|
|
|
$this->themingDefaults
|
2016-08-10 12:53:33 +03:00
|
|
|
->expects($this->at(0))
|
|
|
|
->method('getName')
|
|
|
|
->willReturn("");
|
2017-02-17 18:42:07 +03:00
|
|
|
$this->themingDefaults
|
2016-08-10 12:53:33 +03:00
|
|
|
->expects($this->at(1))
|
|
|
|
->method('getBaseUrl')
|
|
|
|
->willReturn("");
|
2017-02-17 18:42:07 +03:00
|
|
|
$this->themingDefaults
|
2016-08-10 12:53:33 +03:00
|
|
|
->expects($this->at(2))
|
|
|
|
->method('getSlogan')
|
|
|
|
->willReturn("");
|
2017-02-17 18:42:07 +03:00
|
|
|
$this->themingDefaults
|
2016-08-10 12:53:33 +03:00
|
|
|
->expects($this->at(3))
|
2017-03-28 02:37:47 +03:00
|
|
|
->method('getColorPrimary')
|
2016-08-10 12:53:33 +03:00
|
|
|
->willReturn("#000");
|
|
|
|
|
|
|
|
|
|
|
|
$expectedResponse = '(function() {
|
|
|
|
OCA.Theming = {
|
|
|
|
name: "",
|
|
|
|
url: "",
|
|
|
|
slogan: "",
|
|
|
|
color: "#000",
|
|
|
|
inverted: false,
|
2016-08-30 12:51:48 +03:00
|
|
|
cacheBuster: null
|
2016-08-10 12:53:33 +03:00
|
|
|
};
|
|
|
|
})();';
|
2017-01-18 19:00:09 +03:00
|
|
|
$expected = new Http\DataDownloadResponse($expectedResponse, 'javascript', 'text/javascript');
|
2016-08-10 12:53:33 +03:00
|
|
|
$expected->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime()));
|
2016-08-27 13:38:15 +03:00
|
|
|
$expected->addHeader('Pragma', 'cache');
|
2016-08-10 12:53:33 +03:00
|
|
|
$expected->cacheFor(3600);
|
|
|
|
@$this->assertEquals($expected, $this->themingController->getJavascript());
|
|
|
|
}
|
|
|
|
public function testGetJavascriptInverted() {
|
2017-02-17 18:42:07 +03:00
|
|
|
$this->themingDefaults
|
2016-08-10 12:53:33 +03:00
|
|
|
->expects($this->at(0))
|
|
|
|
->method('getName')
|
|
|
|
->willReturn("Nextcloud");
|
2017-02-17 18:42:07 +03:00
|
|
|
$this->themingDefaults
|
2016-08-10 12:53:33 +03:00
|
|
|
->expects($this->at(1))
|
|
|
|
->method('getBaseUrl')
|
|
|
|
->willReturn("nextcloudurl");
|
2017-02-17 18:42:07 +03:00
|
|
|
$this->themingDefaults
|
2016-08-10 12:53:33 +03:00
|
|
|
->expects($this->at(2))
|
|
|
|
->method('getSlogan')
|
|
|
|
->willReturn("awesome");
|
2017-02-17 18:42:07 +03:00
|
|
|
$this->themingDefaults
|
2016-08-10 12:53:33 +03:00
|
|
|
->expects($this->any())
|
2017-03-28 02:37:47 +03:00
|
|
|
->method('getColorPrimary')
|
2016-08-10 12:53:33 +03:00
|
|
|
->willReturn("#ffffff");
|
|
|
|
|
|
|
|
$expectedResponse = '(function() {
|
|
|
|
OCA.Theming = {
|
|
|
|
name: "Nextcloud",
|
|
|
|
url: "nextcloudurl",
|
|
|
|
slogan: "awesome",
|
|
|
|
color: "#ffffff",
|
|
|
|
inverted: true,
|
2016-08-30 12:51:48 +03:00
|
|
|
cacheBuster: null
|
2016-08-10 12:53:33 +03:00
|
|
|
};
|
|
|
|
})();';
|
2017-01-18 19:00:09 +03:00
|
|
|
$expected = new Http\DataDownloadResponse($expectedResponse, 'javascript', 'text/javascript');
|
2016-08-10 12:53:33 +03:00
|
|
|
$expected->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime()));
|
2016-08-27 13:38:15 +03:00
|
|
|
$expected->addHeader('Pragma', 'cache');
|
2016-08-10 12:53:33 +03:00
|
|
|
$expected->cacheFor(3600);
|
|
|
|
@$this->assertEquals($expected, $this->themingController->getJavascript());
|
|
|
|
}
|
2016-06-21 22:21:46 +03:00
|
|
|
}
|