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>
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Daniel Calviño Sánchez <danxuliu@gmail.com>
|
|
|
|
* @author Jan-Christoph Borchardt <hey@jancborchardt.net>
|
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.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>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Kyle Fazzari <kyrofa@ubuntu.com>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Michael Weimann <mail@michael-weimann.eu>
|
|
|
|
* @author rakekniven <mark.ziegler@rakekniven.de>
|
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
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2016-06-21 22:21:46 +03:00
|
|
|
*
|
|
|
|
*/
|
2019-11-22 22:52:10 +03:00
|
|
|
|
2016-06-21 22:21:46 +03:00
|
|
|
namespace OCA\Theming\Tests\Controller;
|
|
|
|
|
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;
|
2018-03-28 15:56:31 +03:00
|
|
|
use OCA\Theming\ImageManager;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCA\Theming\ThemingDefaults;
|
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-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;
|
|
|
|
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;
|
|
|
|
|
|
|
|
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;
|
2018-03-28 15:56:31 +03:00
|
|
|
/** @var ImageManager|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $imageManager;
|
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
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
protected function setUp(): void {
|
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->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-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);
|
2018-03-28 15:56:31 +03:00
|
|
|
$this->imageManager = $this->createMock(ImageManager::class);
|
2016-07-28 17:07:23 +03:00
|
|
|
|
2018-06-07 12:42:21 +03:00
|
|
|
$this->timeFactory = $this->createMock(ITimeFactory::class);
|
|
|
|
$this->timeFactory->expects($this->any())
|
|
|
|
->method('getTime')
|
|
|
|
->willReturn(123);
|
|
|
|
|
|
|
|
$this->overwriteService(ITimeFactory::class, $this->timeFactory);
|
|
|
|
|
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,
|
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,
|
2018-03-28 15:56:31 +03:00
|
|
|
$this->appManager,
|
|
|
|
$this->imageManager
|
2016-06-21 22:21:46 +03:00
|
|
|
);
|
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
parent::setUp();
|
2016-06-21 22:21:46 +03:00
|
|
|
}
|
|
|
|
|
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'],
|
2019-07-31 11:05:46 +03:00
|
|
|
['url', 'https://nextcloud.com/' . str_repeat('a', 478), 'Saved'],
|
2017-08-10 12:21:43 +03:00
|
|
|
['slogan', str_repeat('a', 500), 'Saved'],
|
|
|
|
['color', '#0082c9', 'Saved'],
|
|
|
|
['color', '#0082C9', 'Saved'],
|
2019-07-31 11:05:46 +03:00
|
|
|
['color', '#0082C9', 'Saved'],
|
|
|
|
['imprintUrl', 'https://nextcloud.com/' . str_repeat('a', 478), 'Saved'],
|
|
|
|
['privacyUrl', 'https://nextcloud.com/' . str_repeat('a', 478), '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')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnCallback(function($str) {
|
2017-09-20 13:32:41 +03:00
|
|
|
return $str;
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2017-08-10 12:33:12 +03:00
|
|
|
$this->scssCacher
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getCachedSCSS')
|
2018-06-14 18:24:43 +03:00
|
|
|
->with('core', '/core/css/css-variables.scss')
|
|
|
|
->willReturn('/core/css/someHash-css-variables.scss');
|
2017-08-10 12:33:12 +03:00
|
|
|
$this->urlGenerator
|
|
|
|
->expects($this->once())
|
|
|
|
->method('linkTo')
|
2018-06-14 18:24:43 +03:00
|
|
|
->with('', '/core/css/someHash-css-variables.scss')
|
|
|
|
->willReturn('/nextcloudWebroot/core/css/someHash-css-variables.scss');
|
2017-08-10 12:21:43 +03:00
|
|
|
|
|
|
|
$expected = new DataResponse(
|
|
|
|
[
|
|
|
|
'data' =>
|
|
|
|
[
|
|
|
|
'message' => $message,
|
2018-06-14 18:24:43 +03:00
|
|
|
'serverCssUrl' => '/nextcloudWebroot/core/css/someHash-css-variables.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'],
|
2019-07-31 11:05:46 +03:00
|
|
|
['url', 'http://example.com/' . str_repeat('a', 501), 'The given web address is too long'],
|
|
|
|
['url', str_repeat('a', 501), 'The given web address is not a valid URL'],
|
|
|
|
['url', 'javascript:alert(1)', 'The given web address is not a valid URL'],
|
2017-08-10 12:21:43 +03:00
|
|
|
['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'],
|
2019-07-31 11:05:46 +03:00
|
|
|
['imprintUrl', '0082C9', 'The given legal notice address is not a valid URL'],
|
|
|
|
['imprintUrl', '0082C9', 'The given legal notice address is not a valid URL'],
|
|
|
|
['imprintUrl', 'javascript:foo', 'The given legal notice address is not a valid URL'],
|
|
|
|
['privacyUrl', '#0082Z9', 'The given privacy policy address is not a valid URL'],
|
2017-08-10 12:21:43 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
2019-07-31 11:05:46 +03:00
|
|
|
->expects($this->any())
|
2016-06-21 22:21:46 +03:00
|
|
|
->method('t')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnCallback(function($str) {
|
2017-09-20 13:32:41 +03:00
|
|
|
return $str;
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
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',
|
2019-07-31 11:05:46 +03:00
|
|
|
],
|
|
|
|
Http::STATUS_BAD_REQUEST
|
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')
|
2018-03-28 15:56:31 +03:00
|
|
|
->with('key')
|
|
|
|
->willReturn('logo');
|
2017-05-01 11:42:19 +03:00
|
|
|
$this->request
|
|
|
|
->expects($this->at(1))
|
2016-06-21 22:21:46 +03:00
|
|
|
->method('getUploadedFile')
|
2018-03-28 15:56:31 +03:00
|
|
|
->with('image')
|
2016-06-21 22:21:46 +03:00
|
|
|
->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')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnCallback(function($str) {
|
2017-09-20 13:32:41 +03:00
|
|
|
return $str;
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
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
|
|
|
|
);
|
|
|
|
|
2018-03-28 15:56:31 +03:00
|
|
|
$this->assertEquals($expected, $this->themingController->uploadImage());
|
2017-09-21 12:36:27 +03:00
|
|
|
}
|
|
|
|
|
2018-09-02 15:17:17 +03:00
|
|
|
/**
|
|
|
|
* Checks that trying to upload an SVG favicon without imagemagick
|
|
|
|
* results in an unsupported media type response.
|
|
|
|
*
|
|
|
|
* @test
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testUploadSVGFaviconWithoutImagemagick() {
|
|
|
|
$this->imageManager
|
|
|
|
->method('shouldReplaceIcons')
|
|
|
|
->willReturn(false);
|
|
|
|
|
|
|
|
$this->request
|
|
|
|
->expects($this->at(0))
|
|
|
|
->method('getParam')
|
|
|
|
->with('key')
|
|
|
|
->willReturn('favicon');
|
|
|
|
$this->request
|
|
|
|
->expects($this->at(1))
|
|
|
|
->method('getUploadedFile')
|
|
|
|
->with('image')
|
|
|
|
->willReturn([
|
|
|
|
'tmp_name' => __DIR__ . '/../../../../tests/data/testimagelarge.svg',
|
|
|
|
'type' => 'image/svg',
|
|
|
|
'name' => 'testimagelarge.svg',
|
|
|
|
'error' => 0,
|
|
|
|
]);
|
|
|
|
$this->l10n
|
|
|
|
->expects($this->any())
|
|
|
|
->method('t')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnCallback(function($str) {
|
2018-09-02 15:17:17 +03:00
|
|
|
return $str;
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2018-09-02 15:17:17 +03:00
|
|
|
|
|
|
|
$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'
|
|
|
|
],
|
|
|
|
Http::STATUS_UNPROCESSABLE_ENTITY
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $this->themingController->uploadImage());
|
|
|
|
}
|
|
|
|
|
2017-09-21 12:36:27 +03:00
|
|
|
public function testUpdateLogoInvalidMimeType() {
|
|
|
|
$this->request
|
|
|
|
->expects($this->at(0))
|
|
|
|
->method('getParam')
|
2018-03-28 15:56:31 +03:00
|
|
|
->with('key')
|
|
|
|
->willReturn('logo');
|
2017-09-21 12:36:27 +03:00
|
|
|
$this->request
|
|
|
|
->expects($this->at(1))
|
|
|
|
->method('getUploadedFile')
|
2018-03-28 15:56:31 +03:00
|
|
|
->with('image')
|
2017-09-21 12:36:27 +03:00
|
|
|
->willReturn([
|
2018-05-17 12:24:19 +03:00
|
|
|
'tmp_name' => __DIR__ . '/../../../../tests/data/lorem.txt',
|
2017-09-21 12:36:27 +03:00
|
|
|
'type' => 'application/pdf',
|
|
|
|
'name' => 'logo.pdf',
|
|
|
|
'error' => 0,
|
|
|
|
]);
|
|
|
|
$this->l10n
|
|
|
|
->expects($this->any())
|
|
|
|
->method('t')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnCallback(function($str) {
|
2017-09-21 12:36:27 +03:00
|
|
|
return $str;
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2017-09-21 12:36:27 +03:00
|
|
|
|
|
|
|
$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
|
|
|
|
);
|
|
|
|
|
2018-03-28 15:56:31 +03:00
|
|
|
$this->assertEquals($expected, $this->themingController->uploadImage());
|
2017-05-01 11:42:19 +03:00
|
|
|
}
|
|
|
|
|
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'],
|
2018-05-17 12:24:19 +03:00
|
|
|
['image/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);
|
2018-05-17 12:46:28 +03:00
|
|
|
copy(__DIR__ . '/../../../../tests/data/testimage.png', $tmpLogo);
|
2016-06-21 22:21:46 +03:00
|
|
|
$this->request
|
|
|
|
->expects($this->at(0))
|
2017-05-01 11:42:19 +03:00
|
|
|
->method('getParam')
|
2018-03-28 15:56:31 +03:00
|
|
|
->with('key')
|
|
|
|
->willReturn('logo');
|
2017-05-01 11:42:19 +03:00
|
|
|
$this->request
|
|
|
|
->expects($this->at(1))
|
2016-06-21 22:21:46 +03:00
|
|
|
->method('getUploadedFile')
|
2018-03-28 15:56:31 +03:00
|
|
|
->with('image')
|
2016-06-21 22:21:46 +03:00
|
|
|
->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->l10n
|
2017-09-20 13:32:41 +03:00
|
|
|
->expects($this->any())
|
2016-06-21 22:21:46 +03:00
|
|
|
->method('t')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnCallback(function($str) {
|
2017-09-20 13:32:41 +03:00
|
|
|
return $str;
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
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);
|
2018-03-28 15:56:31 +03:00
|
|
|
$this->urlGenerator->expects($this->once())
|
|
|
|
->method('linkTo')
|
|
|
|
->willReturn('serverCss');
|
|
|
|
$this->imageManager->expects($this->once())
|
|
|
|
->method('getImageUrl')
|
|
|
|
->with('logo')
|
|
|
|
->willReturn('imageUrl');
|
2016-06-21 22:21:46 +03:00
|
|
|
$expected = new DataResponse(
|
|
|
|
[
|
|
|
|
'data' =>
|
|
|
|
[
|
|
|
|
'name' => 'logo.svg',
|
|
|
|
'message' => 'Saved',
|
2018-03-28 15:56:31 +03:00
|
|
|
'url' => 'imageUrl',
|
|
|
|
'serverCssUrl' => 'serverCss'
|
2016-06-21 22:21:46 +03:00
|
|
|
],
|
|
|
|
'status' => 'success'
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2018-03-28 15:56:31 +03:00
|
|
|
$this->assertEquals($expected, $this->themingController->uploadImage());
|
2016-06-21 22:21:46 +03:00
|
|
|
}
|
|
|
|
|
2017-02-16 17:13:19 +03:00
|
|
|
/** @dataProvider dataUpdateImages */
|
|
|
|
public function testUpdateLogoLoginScreenUpload($folderExists) {
|
2018-05-17 12:24:19 +03:00
|
|
|
$tmpLogo = \OC::$server->getTempManager()->getTemporaryFolder() . 'logo.png';
|
2016-06-21 22:21:46 +03:00
|
|
|
|
|
|
|
touch($tmpLogo);
|
2018-05-17 12:24:19 +03:00
|
|
|
copy(__DIR__ . '/../../../../tests/data/desktopapp.png', $tmpLogo);
|
2016-06-21 22:21:46 +03:00
|
|
|
$this->request
|
|
|
|
->expects($this->at(0))
|
2017-05-01 11:42:19 +03:00
|
|
|
->method('getParam')
|
2018-03-28 15:56:31 +03:00
|
|
|
->with('key')
|
|
|
|
->willReturn('background');
|
2017-05-01 11:42:19 +03:00
|
|
|
$this->request
|
|
|
|
->expects($this->at(1))
|
2016-06-21 22:21:46 +03:00
|
|
|
->method('getUploadedFile')
|
2018-03-28 15:56:31 +03:00
|
|
|
->with('image')
|
2016-06-21 22:21:46 +03:00
|
|
|
->willReturn([
|
|
|
|
'tmp_name' => $tmpLogo,
|
2018-05-17 12:24:19 +03:00
|
|
|
'type' => 'image/svg+xml',
|
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->l10n
|
2017-09-20 13:32:41 +03:00
|
|
|
->expects($this->any())
|
2016-06-21 22:21:46 +03:00
|
|
|
->method('t')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnCallback(function($str) {
|
2017-09-20 13:32:41 +03:00
|
|
|
return $str;
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
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
|
|
|
|
2018-03-28 15:56:31 +03:00
|
|
|
$this->urlGenerator->expects($this->once())
|
|
|
|
->method('linkTo')
|
|
|
|
->willReturn('serverCss');
|
|
|
|
$this->imageManager->expects($this->once())
|
|
|
|
->method('getImageUrl')
|
|
|
|
->with('background')
|
|
|
|
->willReturn('imageUrl');
|
2016-06-21 22:21:46 +03:00
|
|
|
$expected = new DataResponse(
|
|
|
|
[
|
|
|
|
'data' =>
|
|
|
|
[
|
|
|
|
'name' => 'logo.svg',
|
|
|
|
'message' => 'Saved',
|
2018-03-28 15:56:31 +03:00
|
|
|
'url' => 'imageUrl',
|
|
|
|
'serverCssUrl' => 'serverCss'
|
2016-06-21 22:21:46 +03:00
|
|
|
],
|
|
|
|
'status' => 'success'
|
|
|
|
]
|
|
|
|
);
|
2018-03-28 15:56:31 +03:00
|
|
|
$this->assertEquals($expected, $this->themingController->uploadImage());
|
2016-06-21 22:21:46 +03:00
|
|
|
}
|
|
|
|
|
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')
|
2018-03-28 15:56:31 +03:00
|
|
|
->with('key')
|
|
|
|
->willReturn('logo');
|
2017-05-01 11:42:19 +03:00
|
|
|
$this->request
|
|
|
|
->expects($this->at(1))
|
2016-08-27 13:38:15 +03:00
|
|
|
->method('getUploadedFile')
|
2018-03-28 15:56:31 +03:00
|
|
|
->with('image')
|
2016-08-27 13:38:15 +03:00
|
|
|
->willReturn([
|
|
|
|
'tmp_name' => $tmpLogo,
|
2018-03-28 15:56:31 +03:00
|
|
|
'type' => 'foobar',
|
2016-08-27 13:38:15 +03:00
|
|
|
'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')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnCallback(function($str) {
|
2017-09-20 13:32:41 +03:00
|
|
|
return $str;
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
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
|
|
|
|
);
|
2018-03-28 15:56:31 +03:00
|
|
|
$this->assertEquals($expected, $this->themingController->uploadImage());
|
2016-08-27 13:38:15 +03:00
|
|
|
}
|
|
|
|
|
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')
|
2018-03-28 15:56:31 +03:00
|
|
|
->with('key')
|
|
|
|
->willReturn('background');
|
2017-09-21 12:36:27 +03:00
|
|
|
$this->request
|
|
|
|
->expects($this->at(1))
|
|
|
|
->method('getUploadedFile')
|
2018-03-28 15:56:31 +03:00
|
|
|
->with('image')
|
2017-09-21 12:36:27 +03:00
|
|
|
->willReturn([
|
|
|
|
'tmp_name' => '',
|
2018-05-17 12:24:19 +03:00
|
|
|
'type' => 'image/svg+xml',
|
2017-09-21 12:36:27 +03:00
|
|
|
'name' => 'logo.svg',
|
|
|
|
'error' => $error,
|
|
|
|
]);
|
|
|
|
$this->l10n
|
|
|
|
->expects($this->any())
|
|
|
|
->method('t')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnCallback(function($str) {
|
2017-09-21 12:36:27 +03:00
|
|
|
return $str;
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2017-09-21 12:36:27 +03:00
|
|
|
|
|
|
|
$expected = new DataResponse(
|
|
|
|
[
|
|
|
|
'data' =>
|
|
|
|
[
|
|
|
|
'message' => $expectedErrorMessage,
|
|
|
|
],
|
|
|
|
'status' => 'failure'
|
|
|
|
],
|
|
|
|
Http::STATUS_UNPROCESSABLE_ENTITY
|
|
|
|
);
|
2018-03-28 15:56:31 +03:00
|
|
|
$this->assertEquals($expected, $this->themingController->uploadImage());
|
2017-09-21 12:36:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataPhpUploadErrors
|
|
|
|
*/
|
|
|
|
public function testUpdateLogoUploadWithInvalidImageUpload($error, $expectedErrorMessage) {
|
|
|
|
$this->request
|
|
|
|
->expects($this->at(0))
|
|
|
|
->method('getParam')
|
2018-03-28 15:56:31 +03:00
|
|
|
->with('key')
|
|
|
|
->willReturn('background');
|
2017-09-21 12:36:27 +03:00
|
|
|
$this->request
|
|
|
|
->expects($this->at(1))
|
|
|
|
->method('getUploadedFile')
|
2018-03-28 15:56:31 +03:00
|
|
|
->with('image')
|
2017-09-21 12:36:27 +03:00
|
|
|
->willReturn([
|
|
|
|
'tmp_name' => '',
|
|
|
|
'type' => 'text/svg',
|
|
|
|
'name' => 'logo.svg',
|
|
|
|
'error' => $error,
|
|
|
|
]);
|
|
|
|
$this->l10n
|
|
|
|
->expects($this->any())
|
|
|
|
->method('t')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnCallback(function($str) {
|
2017-09-21 12:36:27 +03:00
|
|
|
return $str;
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2017-09-21 12:36:27 +03:00
|
|
|
|
|
|
|
$expected = new DataResponse(
|
|
|
|
[
|
|
|
|
'data' =>
|
|
|
|
[
|
|
|
|
'message' => $expectedErrorMessage
|
|
|
|
],
|
|
|
|
'status' => 'failure'
|
|
|
|
],
|
|
|
|
Http::STATUS_UNPROCESSABLE_ENTITY
|
|
|
|
);
|
2018-03-28 15:56:31 +03:00
|
|
|
$this->assertEquals($expected, $this->themingController->uploadImage());
|
2017-09-21 12:36:27 +03:00
|
|
|
}
|
|
|
|
|
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')
|
2018-06-14 18:24:43 +03:00
|
|
|
->with('core', '/core/css/css-variables.scss')
|
|
|
|
->willReturn('/core/css/someHash-css-variables.scss');
|
2017-08-10 12:33:12 +03:00
|
|
|
$this->urlGenerator
|
|
|
|
->expects($this->once())
|
|
|
|
->method('linkTo')
|
2018-06-14 18:24:43 +03:00
|
|
|
->with('', '/core/css/someHash-css-variables.scss')
|
|
|
|
->willReturn('/nextcloudWebroot/core/css/someHash-css-variables.scss');
|
2016-06-21 22:21:46 +03:00
|
|
|
|
|
|
|
$expected = new DataResponse(
|
|
|
|
[
|
|
|
|
'data' =>
|
|
|
|
[
|
|
|
|
'value' => 'MyValue',
|
|
|
|
'message' => 'Saved',
|
2018-06-14 18:24:43 +03:00
|
|
|
'serverCssUrl' => '/nextcloudWebroot/core/css/someHash-css-variables.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')
|
2018-06-14 18:24:43 +03:00
|
|
|
->with('core', '/core/css/css-variables.scss')
|
|
|
|
->willReturn('/core/css/someHash-css-variables.scss');
|
2017-08-10 12:33:12 +03:00
|
|
|
$this->urlGenerator
|
|
|
|
->expects($this->once())
|
|
|
|
->method('linkTo')
|
2018-06-14 18:24:43 +03:00
|
|
|
->with('', '/core/css/someHash-css-variables.scss')
|
|
|
|
->willReturn('/nextcloudWebroot/core/css/someHash-css-variables.scss');
|
2018-03-28 15:56:31 +03:00
|
|
|
$this->imageManager->expects($this->once())
|
|
|
|
->method('delete')
|
|
|
|
->with($filename);
|
2017-04-29 12:22:34 +03:00
|
|
|
|
|
|
|
$expected = new DataResponse(
|
|
|
|
[
|
|
|
|
'data' =>
|
|
|
|
[
|
|
|
|
'value' => $value,
|
|
|
|
'message' => 'Saved',
|
2018-06-14 18:24:43 +03:00
|
|
|
'serverCssUrl' => '/nextcloudWebroot/core/css/someHash-css-variables.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() {
|
2018-03-28 15:56:31 +03:00
|
|
|
$this->imageManager->method('getImage')
|
|
|
|
->with($this->equalTo('logo'))
|
2016-11-08 21:46:09 +03:00
|
|
|
->willThrowException(new NotFoundException());
|
|
|
|
|
|
|
|
$expected = new Http\NotFoundResponse();
|
2018-03-28 15:56:31 +03:00
|
|
|
$this->assertEquals($expected, $this->themingController->getImage('logo'));
|
2016-06-21 22:21:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetLogo() {
|
2017-02-10 00:51:05 +03:00
|
|
|
$file = $this->createMock(ISimpleFile::class);
|
2018-03-28 15:56:31 +03:00
|
|
|
$this->imageManager->expects($this->once())
|
|
|
|
->method('getImage')
|
2016-11-08 21:46:09 +03:00
|
|
|
->willReturn($file);
|
2016-06-21 22:21:46 +03:00
|
|
|
$this->config
|
2018-06-05 17:59:05 +03:00
|
|
|
->expects($this->any())
|
2016-06-21 22:21:46 +03:00
|
|
|
->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
|
|
|
$expected->addHeader('Content-Type', 'text/svg');
|
2018-05-17 12:46:28 +03:00
|
|
|
$expected->addHeader('Content-Disposition', 'attachment; filename="logo"');
|
2019-12-04 11:07:24 +03:00
|
|
|
$csp = new Http\ContentSecurityPolicy();
|
|
|
|
$csp->allowInlineStyle();
|
|
|
|
$expected->setContentSecurityPolicy($csp);
|
2018-03-28 15:56:31 +03:00
|
|
|
@$this->assertEquals($expected, $this->themingController->getImage('logo'));
|
2016-06-21 22:21:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testGetLoginBackgroundNotExistent() {
|
2018-03-28 15:56:31 +03:00
|
|
|
$this->imageManager->method('getImage')
|
|
|
|
->with($this->equalTo('background'))
|
2016-11-08 21:46:09 +03:00
|
|
|
->willThrowException(new NotFoundException());
|
|
|
|
$expected = new Http\NotFoundResponse();
|
2018-03-28 15:56:31 +03:00
|
|
|
$this->assertEquals($expected, $this->themingController->getImage('background'));
|
2016-06-21 22:21:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetLoginBackground() {
|
2017-02-10 00:51:05 +03:00
|
|
|
$file = $this->createMock(ISimpleFile::class);
|
2018-03-28 15:56:31 +03:00
|
|
|
$this->imageManager->expects($this->once())
|
|
|
|
->method('getImage')
|
2016-11-08 21:46:09 +03:00
|
|
|
->willReturn($file);
|
|
|
|
|
2016-06-21 22:21:46 +03:00
|
|
|
$this->config
|
2018-06-05 17:59:05 +03:00
|
|
|
->expects($this->any())
|
2016-06-21 22:21:46 +03:00
|
|
|
->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
|
|
|
$expected->addHeader('Content-Type', 'image/png');
|
2018-05-17 12:46:28 +03:00
|
|
|
$expected->addHeader('Content-Disposition', 'attachment; filename="background"');
|
2019-12-04 11:07:24 +03:00
|
|
|
$csp = new Http\ContentSecurityPolicy();
|
|
|
|
$csp->allowInlineStyle();
|
|
|
|
$expected->setContentSecurityPolicy($csp);
|
2018-03-28 15:56:31 +03:00
|
|
|
@$this->assertEquals($expected, $this->themingController->getImage('background'));
|
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 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);
|
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);
|
|
|
|
|
|
|
|
$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",
|
2018-05-11 16:11:09 +03:00
|
|
|
imprintUrl: null,
|
2018-05-24 15:45:49 +03:00
|
|
|
privacyUrl: null,
|
2016-08-10 12:53:33 +03:00
|
|
|
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->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",
|
2018-05-11 16:11:09 +03:00
|
|
|
imprintUrl: null,
|
2018-05-24 15:45:49 +03:00
|
|
|
privacyUrl: null,
|
2016-08-10 12:53:33 +03:00
|
|
|
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->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->cacheFor(3600);
|
|
|
|
$this->assertEquals($response, $this->themingController->getManifest('core'));
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:21:46 +03:00
|
|
|
}
|