2016-06-21 22:21:46 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
|
|
|
|
*
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
|
|
|
* @author Bjoern Schiessle <bjoern@schiessle.org>
|
|
|
|
* @author Daniel Calviño Sánchez <danxuliu@gmail.com>
|
|
|
|
* @author Jan-Christoph Borchardt <hey@jancborchardt.net>
|
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Julius Haertl <jus@bitgrid.net>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Julius Härtl <jus@bitgrid.net>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2016-07-21 17:49:16 +03:00
|
|
|
*
|
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,
|
2018-02-24 19:16:42 +03:00
|
|
|
$this->urlGenerator,
|
|
|
|
$this->appManager
|
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')
|
2017-09-20 13:32:41 +03:00
|
|
|
->will($this->returnCallback(function($str) {
|
|
|
|
return $str;
|
|
|
|
}));
|
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')
|
2017-09-20 13:32:41 +03:00
|
|
|
->will($this->returnCallback(function($str) {
|
|
|
|
return $str;
|
|
|
|
}));
|
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
|
2017-09-20 13:32:41 +03:00
|
|
|
->expects($this->any())
|
2016-06-21 22:21:46 +03:00
|
|
|
->method('t')
|
2017-09-20 13:32:41 +03:00
|
|
|
->will($this->returnCallback(function($str) {
|
|
|
|
return $str;
|
|
|
|
}));
|
2016-06-21 22:21:46 +03:00
|
|
|
|
|
|
|
$expected = new DataResponse(
|
|
|
|
[
|
|
|
|
'data' =>
|
|
|
|
[
|
|
|
|
'message' => 'No file uploaded',
|
|
|
|
],
|
2017-09-21 12:36:27 +03:00
|
|
|
'status' => 'failure',
|
|
|
|
],
|
|
|
|
Http::STATUS_UNPROCESSABLE_ENTITY
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $this->themingController->updateLogo());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateLogoInvalidMimeType() {
|
|
|
|
$this->request
|
|
|
|
->expects($this->at(0))
|
|
|
|
->method('getParam')
|
|
|
|
->with('backgroundColor')
|
|
|
|
->willReturn(false);
|
|
|
|
$this->request
|
|
|
|
->expects($this->at(1))
|
|
|
|
->method('getUploadedFile')
|
|
|
|
->with('uploadlogo')
|
|
|
|
->willReturn([
|
|
|
|
'tmp_name' => 'logo.pdf',
|
|
|
|
'type' => 'application/pdf',
|
|
|
|
'name' => 'logo.pdf',
|
|
|
|
'error' => 0,
|
|
|
|
]);
|
|
|
|
$this->request
|
|
|
|
->expects($this->at(2))
|
|
|
|
->method('getUploadedFile')
|
|
|
|
->with('upload-login-background')
|
|
|
|
->willReturn(null);
|
|
|
|
$this->l10n
|
|
|
|
->expects($this->any())
|
|
|
|
->method('t')
|
|
|
|
->will($this->returnCallback(function($str) {
|
|
|
|
return $str;
|
|
|
|
}));
|
|
|
|
|
|
|
|
$folder = $this->createMock(ISimpleFolder::class);
|
|
|
|
$this->appData
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getFolder')
|
|
|
|
->with('images')
|
|
|
|
->willReturn($folder);
|
|
|
|
|
|
|
|
$expected = new DataResponse(
|
|
|
|
[
|
|
|
|
'data' =>
|
|
|
|
[
|
|
|
|
'message' => 'Unsupported image type',
|
|
|
|
],
|
|
|
|
'status' => 'failure'
|
2016-06-21 22:21:46 +03:00
|
|
|
],
|
|
|
|
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 [
|
2017-09-21 12:36:27 +03:00
|
|
|
['image/jpeg', false],
|
|
|
|
['image/jpeg', true],
|
|
|
|
['image/gif'],
|
|
|
|
['image/png'],
|
|
|
|
['image/svg+xml'],
|
|
|
|
['text/svg'],
|
2017-02-16 17:13:19 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @dataProvider dataUpdateImages */
|
2017-09-21 12:36:27 +03:00
|
|
|
public function testUpdateLogoNormalLogoUpload($mimeType, $folderExists=true) {
|
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,
|
2017-09-21 12:36:27 +03:00
|
|
|
'type' => $mimeType,
|
2016-06-21 22:21:46 +03:00
|
|
|
'name' => 'logo.svg',
|
2017-09-20 13:32:41 +03:00
|
|
|
'error' => 0,
|
2016-06-21 22:21:46 +03:00
|
|
|
]);
|
|
|
|
$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
|
2017-09-20 13:32:41 +03:00
|
|
|
->expects($this->any())
|
2016-06-21 22:21:46 +03:00
|
|
|
->method('t')
|
2017-09-20 13:32:41 +03:00
|
|
|
->will($this->returnCallback(function($str) {
|
|
|
|
return $str;
|
|
|
|
}));
|
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',
|
2017-09-20 13:32:41 +03:00
|
|
|
'error' => 0,
|
2016-06-21 22:21:46 +03:00
|
|
|
]);
|
|
|
|
$this->l10n
|
2017-09-20 13:32:41 +03:00
|
|
|
->expects($this->any())
|
2016-06-21 22:21:46 +03:00
|
|
|
->method('t')
|
2017-09-20 13:32:41 +03:00
|
|
|
->will($this->returnCallback(function($str) {
|
|
|
|
return $str;
|
|
|
|
}));
|
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',
|
2017-09-20 13:32:41 +03:00
|
|
|
'error' => 0,
|
2016-08-27 13:38:15 +03:00
|
|
|
]);
|
|
|
|
$this->l10n
|
2017-09-20 13:32:41 +03:00
|
|
|
->expects($this->any())
|
2016-08-27 13:38:15 +03:00
|
|
|
->method('t')
|
2017-09-20 13:32:41 +03:00
|
|
|
->will($this->returnCallback(function($str) {
|
|
|
|
return $str;
|
|
|
|
}));
|
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());
|
|
|
|
}
|
|
|
|
|
2017-09-21 12:36:27 +03:00
|
|
|
public function dataPhpUploadErrors() {
|
|
|
|
return [
|
|
|
|
[UPLOAD_ERR_INI_SIZE, 'The uploaded file exceeds the upload_max_filesize directive in php.ini'],
|
|
|
|
[UPLOAD_ERR_FORM_SIZE, 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'],
|
2018-03-03 17:55:32 +03:00
|
|
|
[UPLOAD_ERR_PARTIAL, 'The file was only partially uploaded'],
|
2017-09-21 12:36:27 +03:00
|
|
|
[UPLOAD_ERR_NO_FILE, 'No file was uploaded'],
|
|
|
|
[UPLOAD_ERR_NO_TMP_DIR, 'Missing a temporary folder'],
|
2018-03-19 17:07:49 +03:00
|
|
|
[UPLOAD_ERR_CANT_WRITE, 'Could not write file to disk'],
|
|
|
|
[UPLOAD_ERR_EXTENSION, 'A PHP extension stopped the file upload'],
|
2017-09-21 12:36:27 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataPhpUploadErrors
|
|
|
|
*/
|
|
|
|
public function testUpdateLogoLoginScreenUploadWithInvalidImageUpload($error, $expectedErrorMessage) {
|
|
|
|
$this->request
|
|
|
|
->expects($this->at(0))
|
|
|
|
->method('getParam')
|
|
|
|
->with('backgroundColor')
|
|
|
|
->willReturn(false);
|
|
|
|
$this->request
|
|
|
|
->expects($this->at(1))
|
|
|
|
->method('getUploadedFile')
|
|
|
|
->with('uploadlogo')
|
|
|
|
->willReturn(null);
|
|
|
|
$this->request
|
|
|
|
->expects($this->at(2))
|
|
|
|
->method('getUploadedFile')
|
|
|
|
->with('upload-login-background')
|
|
|
|
->willReturn([
|
|
|
|
'tmp_name' => '',
|
|
|
|
'type' => 'text/svg',
|
|
|
|
'name' => 'logo.svg',
|
|
|
|
'error' => $error,
|
|
|
|
]);
|
|
|
|
$this->l10n
|
|
|
|
->expects($this->any())
|
|
|
|
->method('t')
|
|
|
|
->will($this->returnCallback(function($str) {
|
|
|
|
return $str;
|
|
|
|
}));
|
|
|
|
|
|
|
|
$expected = new DataResponse(
|
|
|
|
[
|
|
|
|
'data' =>
|
|
|
|
[
|
|
|
|
'message' => $expectedErrorMessage,
|
|
|
|
],
|
|
|
|
'status' => 'failure'
|
|
|
|
],
|
|
|
|
Http::STATUS_UNPROCESSABLE_ENTITY
|
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $this->themingController->updateLogo());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataPhpUploadErrors
|
|
|
|
*/
|
|
|
|
public function testUpdateLogoUploadWithInvalidImageUpload($error, $expectedErrorMessage) {
|
|
|
|
$this->request
|
|
|
|
->expects($this->at(0))
|
|
|
|
->method('getParam')
|
|
|
|
->with('backgroundColor')
|
|
|
|
->willReturn(false);
|
|
|
|
$this->request
|
|
|
|
->expects($this->at(1))
|
|
|
|
->method('getUploadedFile')
|
|
|
|
->with('uploadlogo')
|
|
|
|
->willReturn([
|
|
|
|
'tmp_name' => '',
|
|
|
|
'type' => 'text/svg',
|
|
|
|
'name' => 'logo.svg',
|
|
|
|
'error' => $error,
|
|
|
|
]);
|
|
|
|
$this->request
|
|
|
|
->expects($this->at(2))
|
|
|
|
->method('getUploadedFile')
|
|
|
|
->with('upload-login-background')
|
|
|
|
->willReturn(null);
|
|
|
|
$this->l10n
|
|
|
|
->expects($this->any())
|
|
|
|
->method('t')
|
|
|
|
->will($this->returnCallback(function($str) {
|
|
|
|
return $str;
|
|
|
|
}));
|
|
|
|
|
|
|
|
$expected = new DataResponse(
|
|
|
|
[
|
|
|
|
'data' =>
|
|
|
|
[
|
|
|
|
'message' => $expectedErrorMessage
|
|
|
|
],
|
|
|
|
'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() {
|
2018-02-24 19:16:42 +03:00
|
|
|
$this->appManager->expects($this->once())->method('getAppPath')->with('theming')->willReturn(\OC::$SERVERROOT . '/theming');
|
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() {
|
2018-02-24 19:16:42 +03:00
|
|
|
$this->appManager->expects($this->once())->method('getAppPath')->with('theming')->willReturn(\OC::$SERVERROOT . '/theming');
|
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')->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
|
|
|
|
2018-02-21 09:44:37 +03:00
|
|
|
public function testGetStylesheetOutsideServerroot() {
|
|
|
|
$this->appManager->expects($this->once())->method('getAppPath')->with('theming')->willReturn('/outside/serverroot/theming');
|
|
|
|
$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')->with('/outside/serverroot/theming', 'css/theming.scss', 'theming')->willReturn(true);
|
|
|
|
$this->scssCacher->expects($this->once())->method('getCachedCSS')->willReturn($file);
|
|
|
|
|
|
|
|
$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');
|
|
|
|
|
|
|
|
$actual = $this->themingController->getStylesheet();
|
|
|
|
$this->assertEquals($response, $actual);
|
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
}
|
2017-09-11 16:04:26 +03:00
|
|
|
|
|
|
|
public function testGetManifest() {
|
|
|
|
$this->config
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getAppValue')
|
|
|
|
->with('theming', 'cachebuster', '0')
|
|
|
|
->willReturn('0');
|
|
|
|
$this->themingDefaults
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getName')
|
|
|
|
->willReturn('Nextcloud');
|
|
|
|
$this->urlGenerator
|
|
|
|
->expects($this->at(0))
|
|
|
|
->method('getBaseUrl')
|
|
|
|
->willReturn('localhost');
|
|
|
|
$this->urlGenerator
|
|
|
|
->expects($this->at(1))
|
|
|
|
->method('linkToRoute')
|
|
|
|
->with('theming.Icon.getTouchIcon', ['app' => 'core'])
|
|
|
|
->willReturn('touchicon');
|
|
|
|
$this->urlGenerator
|
|
|
|
->expects($this->at(2))
|
|
|
|
->method('linkToRoute')
|
|
|
|
->with('theming.Icon.getFavicon', ['app' => 'core'])
|
|
|
|
->willReturn('favicon');
|
|
|
|
$response = new Http\JSONResponse([
|
|
|
|
'name' => 'Nextcloud',
|
|
|
|
'start_url' => 'localhost',
|
|
|
|
'icons' =>
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'src' => 'touchicon?v=0',
|
|
|
|
'type'=> 'image/png',
|
|
|
|
'sizes'=> '128x128'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'src' => 'favicon?v=0',
|
|
|
|
'type' => 'image/svg+xml',
|
|
|
|
'sizes' => '16x16'
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'display' => 'standalone'
|
|
|
|
]);
|
|
|
|
$response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime()));
|
|
|
|
$response->addHeader('Pragma', 'cache');
|
|
|
|
$response->cacheFor(3600);
|
|
|
|
$this->assertEquals($response, $this->themingController->getManifest('core'));
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:21:46 +03:00
|
|
|
}
|