2016-06-21 19:21:46 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
|
|
|
|
*
|
2017-11-06 14:56:42 +00: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 14:49:16 +00:00
|
|
|
* @author Julius Haertl <jus@bitgrid.net>
|
2017-11-06 14:56:42 +00:00
|
|
|
* @author Julius Härtl <jus@bitgrid.net>
|
2016-07-21 14:49:16 +00:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2017-11-06 14:56:42 +00:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2016-07-21 14:49:16 +00:00
|
|
|
*
|
2016-06-21 19:21:46 +00: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 15:42:07 +00:00
|
|
|
use OC\Files\AppData\Factory;
|
2017-02-09 16:12:00 +00:00
|
|
|
use OC\L10N\L10N;
|
2017-02-17 15:42:07 +00:00
|
|
|
use OC\Template\SCSSCacher;
|
2016-06-21 19:21:46 +00:00
|
|
|
use OCA\Theming\Controller\ThemingController;
|
2018-03-28 12:56:31 +00:00
|
|
|
use OCA\Theming\ImageManager;
|
2016-07-25 15:32:11 +00:00
|
|
|
use OCA\Theming\Util;
|
2016-11-18 09:49:03 +00:00
|
|
|
use OCP\App\IAppManager;
|
2016-06-21 19:21:46 +00:00
|
|
|
use OCP\AppFramework\Http;
|
|
|
|
use OCP\AppFramework\Http\DataResponse;
|
2017-02-09 16:12:00 +00:00
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
2017-02-09 10:38:45 +00:00
|
|
|
use OCP\Files\IAppData;
|
2016-06-27 08:47:44 +00:00
|
|
|
use OCP\Files\IRootFolder;
|
2016-11-08 18:46:09 +00:00
|
|
|
use OCP\Files\NotFoundException;
|
2017-02-09 16:12:00 +00:00
|
|
|
use OCP\Files\SimpleFS\ISimpleFile;
|
|
|
|
use OCP\Files\SimpleFS\ISimpleFolder;
|
2016-06-21 19:21:46 +00:00
|
|
|
use OCP\IConfig;
|
|
|
|
use OCP\IL10N;
|
2017-02-17 15:42:07 +00:00
|
|
|
use OCP\ILogger;
|
2016-06-21 19:21:46 +00:00
|
|
|
use OCP\IRequest;
|
2016-08-27 19:38:41 +00:00
|
|
|
use OCP\ITempManager;
|
2017-02-17 15:42:07 +00:00
|
|
|
use OCP\IURLGenerator;
|
2016-06-21 19:21:46 +00:00
|
|
|
use Test\TestCase;
|
2016-08-15 14:24:56 +00:00
|
|
|
use OCA\Theming\ThemingDefaults;
|
2016-06-21 19:21:46 +00:00
|
|
|
|
|
|
|
class ThemingControllerTest extends TestCase {
|
2016-08-01 07:37:12 +00:00
|
|
|
/** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
|
2016-06-21 19:21:46 +00:00
|
|
|
private $request;
|
2016-08-01 07:37:12 +00:00
|
|
|
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
2016-06-21 19:21:46 +00:00
|
|
|
private $config;
|
2016-08-12 14:58:59 +00:00
|
|
|
/** @var ThemingDefaults|\PHPUnit_Framework_MockObject_MockObject */
|
2017-02-17 15:42:07 +00:00
|
|
|
private $themingDefaults;
|
2016-07-28 14:07:23 +00:00
|
|
|
/** @var Util */
|
|
|
|
private $util;
|
|
|
|
/** @var \OCP\AppFramework\Utility\ITimeFactory */
|
|
|
|
private $timeFactory;
|
2016-08-01 07:37:12 +00:00
|
|
|
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
|
2016-06-21 19:21:46 +00:00
|
|
|
private $l10n;
|
|
|
|
/** @var ThemingController */
|
|
|
|
private $themingController;
|
2016-08-27 19:38:41 +00:00
|
|
|
/** @var ITempManager */
|
|
|
|
private $tempManager;
|
2017-02-09 10:38:45 +00:00
|
|
|
/** @var IAppManager|\PHPUnit_Framework_MockObject_MockObject */
|
2016-11-18 09:49:03 +00:00
|
|
|
private $appManager;
|
2017-02-09 10:38:45 +00:00
|
|
|
/** @var IAppData|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $appData;
|
2018-03-28 12:56:31 +00:00
|
|
|
/** @var ImageManager|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $imageManager;
|
2017-02-17 15:42:07 +00:00
|
|
|
/** @var SCSSCacher */
|
|
|
|
private $scssCacher;
|
2017-08-10 09:33:12 +00:00
|
|
|
/** @var IURLGenerator */
|
|
|
|
private $urlGenerator;
|
2016-06-21 19:21:46 +00:00
|
|
|
|
|
|
|
public function setUp() {
|
2017-02-09 21:51:05 +00:00
|
|
|
$this->request = $this->createMock(IRequest::class);
|
|
|
|
$this->config = $this->createMock(IConfig::class);
|
2017-02-17 15:42:07 +00:00
|
|
|
$this->themingDefaults = $this->createMock(ThemingDefaults::class);
|
2017-02-09 21:51:05 +00:00
|
|
|
$this->l10n = $this->createMock(L10N::class);
|
2017-05-17 08:16:59 +00:00
|
|
|
$this->appData = $this->createMock(IAppData::class);
|
2017-02-09 21:51:05 +00:00
|
|
|
$this->appManager = $this->createMock(IAppManager::class);
|
2017-05-17 08:16:59 +00:00
|
|
|
$this->util = new Util($this->config, $this->appManager, $this->appData);
|
2016-08-27 19:38:41 +00:00
|
|
|
$this->tempManager = \OC::$server->getTempManager();
|
2017-02-17 15:42:07 +00:00
|
|
|
$this->scssCacher = $this->createMock(SCSSCacher::class);
|
2017-08-10 09:33:12 +00:00
|
|
|
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
2018-03-28 12:56:31 +00:00
|
|
|
$this->imageManager = $this->createMock(ImageManager::class);
|
2016-07-28 14:07:23 +00:00
|
|
|
|
2018-06-07 09:42:21 +00: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 19:21:46 +00:00
|
|
|
$this->themingController = new ThemingController(
|
|
|
|
'theming',
|
|
|
|
$this->request,
|
|
|
|
$this->config,
|
2017-02-17 15:42:07 +00:00
|
|
|
$this->themingDefaults,
|
2016-07-28 14:07:23 +00:00
|
|
|
$this->util,
|
2016-06-27 08:47:44 +00:00
|
|
|
$this->l10n,
|
2017-02-09 10:38:45 +00:00
|
|
|
$this->tempManager,
|
2017-02-17 15:42:07 +00:00
|
|
|
$this->appData,
|
2017-08-10 09:33:12 +00:00
|
|
|
$this->scssCacher,
|
2018-02-24 16:16:42 +00:00
|
|
|
$this->urlGenerator,
|
2018-03-28 12:56:31 +00:00
|
|
|
$this->appManager,
|
|
|
|
$this->imageManager
|
2016-06-21 19:21:46 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return parent::setUp();
|
|
|
|
}
|
|
|
|
|
2017-08-10 09:21:43 +00:00
|
|
|
public function dataUpdateStylesheetSuccess() {
|
2016-08-01 07:37:12 +00:00
|
|
|
return [
|
2017-08-10 09:21:43 +00: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 07:37:12 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-08-10 09:21:43 +00:00
|
|
|
* @dataProvider dataUpdateStylesheetSuccess
|
2016-08-01 07:37:12 +00:00
|
|
|
*
|
|
|
|
* @param string $setting
|
|
|
|
* @param string $value
|
|
|
|
* @param string $message
|
|
|
|
*/
|
2017-08-10 09:21:43 +00:00
|
|
|
public function testUpdateStylesheetSuccess($setting, $value, $message) {
|
2017-02-17 15:42:07 +00:00
|
|
|
$this->themingDefaults
|
2017-08-10 09:21:43 +00:00
|
|
|
->expects($this->once())
|
|
|
|
->method('set')
|
|
|
|
->with($setting, $value);
|
|
|
|
$this->l10n
|
|
|
|
->expects($this->once())
|
|
|
|
->method('t')
|
2017-09-20 10:32:41 +00:00
|
|
|
->will($this->returnCallback(function($str) {
|
|
|
|
return $str;
|
|
|
|
}));
|
2017-08-10 09:33:12 +00: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 09:21:43 +00:00
|
|
|
|
|
|
|
$expected = new DataResponse(
|
|
|
|
[
|
|
|
|
'data' =>
|
|
|
|
[
|
|
|
|
'message' => $message,
|
2017-08-10 09:33:12 +00:00
|
|
|
'serverCssUrl' => '/nextcloudWebroot/core/css/someHash-server.scss',
|
2017-08-10 09:21:43 +00: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 19:21:46 +00:00
|
|
|
->method('set')
|
2016-08-01 07:37:12 +00:00
|
|
|
->with($setting, $value);
|
2016-06-21 19:21:46 +00:00
|
|
|
$this->l10n
|
|
|
|
->expects($this->once())
|
|
|
|
->method('t')
|
2017-09-20 10:32:41 +00:00
|
|
|
->will($this->returnCallback(function($str) {
|
|
|
|
return $str;
|
|
|
|
}));
|
2016-06-21 19:21:46 +00:00
|
|
|
|
2017-08-10 10:31:30 +00:00
|
|
|
$expected = new DataResponse(
|
|
|
|
[
|
|
|
|
'data' =>
|
|
|
|
[
|
|
|
|
'message' => $message,
|
|
|
|
],
|
2017-08-10 09:21:43 +00:00
|
|
|
'status' => 'error',
|
2017-08-10 10:31:30 +00:00
|
|
|
]
|
|
|
|
);
|
2016-08-01 07:37:12 +00:00
|
|
|
$this->assertEquals($expected, $this->themingController->updateStylesheet($setting, $value));
|
2016-06-21 19:21:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateLogoNoData() {
|
|
|
|
$this->request
|
|
|
|
->expects($this->at(0))
|
2017-05-01 08:42:19 +00:00
|
|
|
->method('getParam')
|
2018-03-28 12:56:31 +00:00
|
|
|
->with('key')
|
|
|
|
->willReturn('logo');
|
2017-05-01 08:42:19 +00:00
|
|
|
$this->request
|
|
|
|
->expects($this->at(1))
|
2016-06-21 19:21:46 +00:00
|
|
|
->method('getUploadedFile')
|
2018-03-28 12:56:31 +00:00
|
|
|
->with('image')
|
2016-06-21 19:21:46 +00:00
|
|
|
->willReturn(null);
|
|
|
|
$this->l10n
|
2017-09-20 10:32:41 +00:00
|
|
|
->expects($this->any())
|
2016-06-21 19:21:46 +00:00
|
|
|
->method('t')
|
2017-09-20 10:32:41 +00:00
|
|
|
->will($this->returnCallback(function($str) {
|
|
|
|
return $str;
|
|
|
|
}));
|
2016-06-21 19:21:46 +00:00
|
|
|
|
|
|
|
$expected = new DataResponse(
|
|
|
|
[
|
|
|
|
'data' =>
|
|
|
|
[
|
|
|
|
'message' => 'No file uploaded',
|
|
|
|
],
|
2017-09-21 09:36:27 +00:00
|
|
|
'status' => 'failure',
|
|
|
|
],
|
|
|
|
Http::STATUS_UNPROCESSABLE_ENTITY
|
|
|
|
);
|
|
|
|
|
2018-03-28 12:56:31 +00:00
|
|
|
$this->assertEquals($expected, $this->themingController->uploadImage());
|
2017-09-21 09:36:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateLogoInvalidMimeType() {
|
|
|
|
$this->request
|
|
|
|
->expects($this->at(0))
|
|
|
|
->method('getParam')
|
2018-03-28 12:56:31 +00:00
|
|
|
->with('key')
|
|
|
|
->willReturn('logo');
|
2017-09-21 09:36:27 +00:00
|
|
|
$this->request
|
|
|
|
->expects($this->at(1))
|
|
|
|
->method('getUploadedFile')
|
2018-03-28 12:56:31 +00:00
|
|
|
->with('image')
|
2017-09-21 09:36:27 +00:00
|
|
|
->willReturn([
|
2018-05-17 09:24:19 +00:00
|
|
|
'tmp_name' => __DIR__ . '/../../../../tests/data/lorem.txt',
|
2017-09-21 09:36:27 +00:00
|
|
|
'type' => 'application/pdf',
|
|
|
|
'name' => 'logo.pdf',
|
|
|
|
'error' => 0,
|
|
|
|
]);
|
|
|
|
$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 19:21:46 +00:00
|
|
|
],
|
|
|
|
Http::STATUS_UNPROCESSABLE_ENTITY
|
|
|
|
);
|
|
|
|
|
2018-03-28 12:56:31 +00:00
|
|
|
$this->assertEquals($expected, $this->themingController->uploadImage());
|
2017-05-01 08:42:19 +00:00
|
|
|
}
|
|
|
|
|
2017-02-16 14:13:19 +00:00
|
|
|
public function dataUpdateImages() {
|
|
|
|
return [
|
2017-09-21 09:36:27 +00:00
|
|
|
['image/jpeg', false],
|
|
|
|
['image/jpeg', true],
|
|
|
|
['image/gif'],
|
|
|
|
['image/png'],
|
|
|
|
['image/svg+xml'],
|
2018-05-17 09:24:19 +00:00
|
|
|
['image/svg']
|
2017-02-16 14:13:19 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @dataProvider dataUpdateImages */
|
2017-09-21 09:36:27 +00:00
|
|
|
public function testUpdateLogoNormalLogoUpload($mimeType, $folderExists=true) {
|
2016-06-21 19:21:46 +00:00
|
|
|
$tmpLogo = \OC::$server->getTempManager()->getTemporaryFolder() . '/logo.svg';
|
|
|
|
$destination = \OC::$server->getTempManager()->getTemporaryFolder();
|
|
|
|
|
|
|
|
touch($tmpLogo);
|
2018-05-17 09:46:28 +00:00
|
|
|
copy(__DIR__ . '/../../../../tests/data/testimage.png', $tmpLogo);
|
2016-06-21 19:21:46 +00:00
|
|
|
$this->request
|
|
|
|
->expects($this->at(0))
|
2017-05-01 08:42:19 +00:00
|
|
|
->method('getParam')
|
2018-03-28 12:56:31 +00:00
|
|
|
->with('key')
|
|
|
|
->willReturn('logo');
|
2017-05-01 08:42:19 +00:00
|
|
|
$this->request
|
|
|
|
->expects($this->at(1))
|
2016-06-21 19:21:46 +00:00
|
|
|
->method('getUploadedFile')
|
2018-03-28 12:56:31 +00:00
|
|
|
->with('image')
|
2016-06-21 19:21:46 +00:00
|
|
|
->willReturn([
|
|
|
|
'tmp_name' => $tmpLogo,
|
2017-09-21 09:36:27 +00:00
|
|
|
'type' => $mimeType,
|
2016-06-21 19:21:46 +00:00
|
|
|
'name' => 'logo.svg',
|
2017-09-20 10:32:41 +00:00
|
|
|
'error' => 0,
|
2016-06-21 19:21:46 +00:00
|
|
|
]);
|
|
|
|
$this->l10n
|
2017-09-20 10:32:41 +00:00
|
|
|
->expects($this->any())
|
2016-06-21 19:21:46 +00:00
|
|
|
->method('t')
|
2017-09-20 10:32:41 +00:00
|
|
|
->will($this->returnCallback(function($str) {
|
|
|
|
return $str;
|
|
|
|
}));
|
2017-02-09 10:38:45 +00:00
|
|
|
|
|
|
|
|
2017-02-09 21:51:05 +00:00
|
|
|
$file = $this->createMock(ISimpleFile::class);
|
|
|
|
$folder = $this->createMock(ISimpleFolder::class);
|
2017-02-16 14:13:19 +00: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 10:38:45 +00:00
|
|
|
$folder->expects($this->once())
|
2016-06-27 08:47:44 +00:00
|
|
|
->method('newFile')
|
2017-02-09 10:38:45 +00:00
|
|
|
->with('logo')
|
2016-06-27 08:47:44 +00:00
|
|
|
->willReturn($file);
|
2018-03-28 12:56:31 +00:00
|
|
|
$this->urlGenerator->expects($this->once())
|
|
|
|
->method('linkTo')
|
|
|
|
->willReturn('serverCss');
|
|
|
|
$this->imageManager->expects($this->once())
|
|
|
|
->method('getImageUrl')
|
|
|
|
->with('logo')
|
|
|
|
->willReturn('imageUrl');
|
2016-06-21 19:21:46 +00:00
|
|
|
$expected = new DataResponse(
|
|
|
|
[
|
|
|
|
'data' =>
|
|
|
|
[
|
|
|
|
'name' => 'logo.svg',
|
|
|
|
'message' => 'Saved',
|
2018-03-28 12:56:31 +00:00
|
|
|
'url' => 'imageUrl',
|
|
|
|
'serverCssUrl' => 'serverCss'
|
2016-06-21 19:21:46 +00:00
|
|
|
],
|
|
|
|
'status' => 'success'
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2018-03-28 12:56:31 +00:00
|
|
|
$this->assertEquals($expected, $this->themingController->uploadImage());
|
2016-06-21 19:21:46 +00:00
|
|
|
}
|
|
|
|
|
2017-02-16 14:13:19 +00:00
|
|
|
/** @dataProvider dataUpdateImages */
|
|
|
|
public function testUpdateLogoLoginScreenUpload($folderExists) {
|
2018-05-17 09:24:19 +00:00
|
|
|
$tmpLogo = \OC::$server->getTempManager()->getTemporaryFolder() . 'logo.png';
|
2016-06-21 19:21:46 +00:00
|
|
|
|
|
|
|
touch($tmpLogo);
|
2018-05-17 09:24:19 +00:00
|
|
|
copy(__DIR__ . '/../../../../tests/data/desktopapp.png', $tmpLogo);
|
2016-06-21 19:21:46 +00:00
|
|
|
$this->request
|
|
|
|
->expects($this->at(0))
|
2017-05-01 08:42:19 +00:00
|
|
|
->method('getParam')
|
2018-03-28 12:56:31 +00:00
|
|
|
->with('key')
|
|
|
|
->willReturn('background');
|
2017-05-01 08:42:19 +00:00
|
|
|
$this->request
|
|
|
|
->expects($this->at(1))
|
2016-06-21 19:21:46 +00:00
|
|
|
->method('getUploadedFile')
|
2018-03-28 12:56:31 +00:00
|
|
|
->with('image')
|
2016-06-21 19:21:46 +00:00
|
|
|
->willReturn([
|
|
|
|
'tmp_name' => $tmpLogo,
|
2018-05-17 09:24:19 +00:00
|
|
|
'type' => 'image/svg+xml',
|
2016-06-21 19:21:46 +00:00
|
|
|
'name' => 'logo.svg',
|
2017-09-20 10:32:41 +00:00
|
|
|
'error' => 0,
|
2016-06-21 19:21:46 +00:00
|
|
|
]);
|
|
|
|
$this->l10n
|
2017-09-20 10:32:41 +00:00
|
|
|
->expects($this->any())
|
2016-06-21 19:21:46 +00:00
|
|
|
->method('t')
|
2017-09-20 10:32:41 +00:00
|
|
|
->will($this->returnCallback(function($str) {
|
|
|
|
return $str;
|
|
|
|
}));
|
2017-02-09 10:38:45 +00:00
|
|
|
|
2017-02-09 21:51:05 +00:00
|
|
|
$file = $this->createMock(ISimpleFile::class);
|
|
|
|
$folder = $this->createMock(ISimpleFolder::class);
|
2017-02-16 14:13:19 +00: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 10:38:45 +00:00
|
|
|
$folder->expects($this->once())
|
2016-06-27 08:47:44 +00:00
|
|
|
->method('newFile')
|
2017-02-09 10:38:45 +00:00
|
|
|
->with('background')
|
2016-06-27 08:47:44 +00:00
|
|
|
->willReturn($file);
|
2016-06-21 19:21:46 +00:00
|
|
|
|
2018-03-28 12:56:31 +00:00
|
|
|
$this->urlGenerator->expects($this->once())
|
|
|
|
->method('linkTo')
|
|
|
|
->willReturn('serverCss');
|
|
|
|
$this->imageManager->expects($this->once())
|
|
|
|
->method('getImageUrl')
|
|
|
|
->with('background')
|
|
|
|
->willReturn('imageUrl');
|
2016-06-21 19:21:46 +00:00
|
|
|
$expected = new DataResponse(
|
|
|
|
[
|
|
|
|
'data' =>
|
|
|
|
[
|
|
|
|
'name' => 'logo.svg',
|
|
|
|
'message' => 'Saved',
|
2018-03-28 12:56:31 +00:00
|
|
|
'url' => 'imageUrl',
|
|
|
|
'serverCssUrl' => 'serverCss'
|
2016-06-21 19:21:46 +00:00
|
|
|
],
|
|
|
|
'status' => 'success'
|
|
|
|
]
|
|
|
|
);
|
2018-03-28 12:56:31 +00:00
|
|
|
$this->assertEquals($expected, $this->themingController->uploadImage());
|
2016-06-21 19:21:46 +00:00
|
|
|
}
|
|
|
|
|
2016-08-27 10:38:15 +00: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 08:42:19 +00:00
|
|
|
->method('getParam')
|
2018-03-28 12:56:31 +00:00
|
|
|
->with('key')
|
|
|
|
->willReturn('logo');
|
2017-05-01 08:42:19 +00:00
|
|
|
$this->request
|
|
|
|
->expects($this->at(1))
|
2016-08-27 10:38:15 +00:00
|
|
|
->method('getUploadedFile')
|
2018-03-28 12:56:31 +00:00
|
|
|
->with('image')
|
2016-08-27 10:38:15 +00:00
|
|
|
->willReturn([
|
|
|
|
'tmp_name' => $tmpLogo,
|
2018-03-28 12:56:31 +00:00
|
|
|
'type' => 'foobar',
|
2016-08-27 10:38:15 +00:00
|
|
|
'name' => 'logo.svg',
|
2017-09-20 10:32:41 +00:00
|
|
|
'error' => 0,
|
2016-08-27 10:38:15 +00:00
|
|
|
]);
|
|
|
|
$this->l10n
|
2017-09-20 10:32:41 +00:00
|
|
|
->expects($this->any())
|
2016-08-27 10:38:15 +00:00
|
|
|
->method('t')
|
2017-09-20 10:32:41 +00:00
|
|
|
->will($this->returnCallback(function($str) {
|
|
|
|
return $str;
|
|
|
|
}));
|
2017-02-09 10:38:45 +00:00
|
|
|
|
2017-02-09 21:51:05 +00:00
|
|
|
$folder = $this->createMock(ISimpleFolder::class);
|
2017-02-09 10:38:45 +00:00
|
|
|
$this->appData
|
2016-08-27 10:38:15 +00:00
|
|
|
->expects($this->once())
|
2017-02-09 10:38:45 +00:00
|
|
|
->method('getFolder')
|
|
|
|
->with('images')
|
|
|
|
->willReturn($folder);
|
|
|
|
|
2016-08-27 10:38:15 +00:00
|
|
|
$expected = new DataResponse(
|
|
|
|
[
|
|
|
|
'data' =>
|
|
|
|
[
|
|
|
|
'message' => 'Unsupported image type',
|
|
|
|
],
|
|
|
|
'status' => 'failure'
|
|
|
|
],
|
|
|
|
Http::STATUS_UNPROCESSABLE_ENTITY
|
|
|
|
);
|
2018-03-28 12:56:31 +00:00
|
|
|
$this->assertEquals($expected, $this->themingController->uploadImage());
|
2016-08-27 10:38:15 +00:00
|
|
|
}
|
|
|
|
|
2017-09-21 09:36:27 +00: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 14:55:32 +00:00
|
|
|
[UPLOAD_ERR_PARTIAL, 'The file was only partially uploaded'],
|
2017-09-21 09:36:27 +00:00
|
|
|
[UPLOAD_ERR_NO_FILE, 'No file was uploaded'],
|
|
|
|
[UPLOAD_ERR_NO_TMP_DIR, 'Missing a temporary folder'],
|
2018-03-19 14:07:49 +00:00
|
|
|
[UPLOAD_ERR_CANT_WRITE, 'Could not write file to disk'],
|
|
|
|
[UPLOAD_ERR_EXTENSION, 'A PHP extension stopped the file upload'],
|
2017-09-21 09:36:27 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataPhpUploadErrors
|
|
|
|
*/
|
|
|
|
public function testUpdateLogoLoginScreenUploadWithInvalidImageUpload($error, $expectedErrorMessage) {
|
|
|
|
$this->request
|
|
|
|
->expects($this->at(0))
|
|
|
|
->method('getParam')
|
2018-03-28 12:56:31 +00:00
|
|
|
->with('key')
|
|
|
|
->willReturn('background');
|
2017-09-21 09:36:27 +00:00
|
|
|
$this->request
|
|
|
|
->expects($this->at(1))
|
|
|
|
->method('getUploadedFile')
|
2018-03-28 12:56:31 +00:00
|
|
|
->with('image')
|
2017-09-21 09:36:27 +00:00
|
|
|
->willReturn([
|
|
|
|
'tmp_name' => '',
|
2018-05-17 09:24:19 +00:00
|
|
|
'type' => 'image/svg+xml',
|
2017-09-21 09:36:27 +00:00
|
|
|
'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
|
|
|
|
);
|
2018-03-28 12:56:31 +00:00
|
|
|
$this->assertEquals($expected, $this->themingController->uploadImage());
|
2017-09-21 09:36:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataPhpUploadErrors
|
|
|
|
*/
|
|
|
|
public function testUpdateLogoUploadWithInvalidImageUpload($error, $expectedErrorMessage) {
|
|
|
|
$this->request
|
|
|
|
->expects($this->at(0))
|
|
|
|
->method('getParam')
|
2018-03-28 12:56:31 +00:00
|
|
|
->with('key')
|
|
|
|
->willReturn('background');
|
2017-09-21 09:36:27 +00:00
|
|
|
$this->request
|
|
|
|
->expects($this->at(1))
|
|
|
|
->method('getUploadedFile')
|
2018-03-28 12:56:31 +00:00
|
|
|
->with('image')
|
2017-09-21 09:36:27 +00:00
|
|
|
->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
|
|
|
|
);
|
2018-03-28 12:56:31 +00:00
|
|
|
$this->assertEquals($expected, $this->themingController->uploadImage());
|
2017-09-21 09:36:27 +00:00
|
|
|
}
|
|
|
|
|
2016-06-21 19:21:46 +00:00
|
|
|
public function testUndo() {
|
|
|
|
$this->l10n
|
|
|
|
->expects($this->once())
|
|
|
|
->method('t')
|
|
|
|
->with('Saved')
|
|
|
|
->willReturn('Saved');
|
2017-02-17 15:42:07 +00:00
|
|
|
$this->themingDefaults
|
2016-06-21 19:21:46 +00:00
|
|
|
->expects($this->once())
|
|
|
|
->method('undo')
|
|
|
|
->with('MySetting')
|
|
|
|
->willReturn('MyValue');
|
2017-08-10 09:33:12 +00: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 19:21:46 +00:00
|
|
|
|
|
|
|
$expected = new DataResponse(
|
|
|
|
[
|
|
|
|
'data' =>
|
|
|
|
[
|
|
|
|
'value' => 'MyValue',
|
|
|
|
'message' => 'Saved',
|
2017-08-10 09:33:12 +00:00
|
|
|
'serverCssUrl' => '/nextcloudWebroot/core/css/someHash-server.scss',
|
2016-06-21 19:21:46 +00:00
|
|
|
],
|
|
|
|
'status' => 'success'
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $this->themingController->undo('MySetting'));
|
|
|
|
}
|
|
|
|
|
2017-04-29 09:22:34 +00: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 09:33:12 +00: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');
|
2018-03-28 12:56:31 +00:00
|
|
|
$this->imageManager->expects($this->once())
|
|
|
|
->method('delete')
|
|
|
|
->with($filename);
|
2017-04-29 09:22:34 +00:00
|
|
|
|
|
|
|
$expected = new DataResponse(
|
|
|
|
[
|
|
|
|
'data' =>
|
|
|
|
[
|
|
|
|
'value' => $value,
|
|
|
|
'message' => 'Saved',
|
2017-08-10 09:33:12 +00:00
|
|
|
'serverCssUrl' => '/nextcloudWebroot/core/css/someHash-server.scss',
|
2017-04-29 09:22:34 +00:00
|
|
|
],
|
|
|
|
'status' => 'success'
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $this->themingController->undo($value));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-06-21 19:21:46 +00:00
|
|
|
public function testGetLogoNotExistent() {
|
2018-03-28 12:56:31 +00:00
|
|
|
$this->imageManager->method('getImage')
|
|
|
|
->with($this->equalTo('logo'))
|
2016-11-08 18:46:09 +00:00
|
|
|
->willThrowException(new NotFoundException());
|
|
|
|
|
|
|
|
$expected = new Http\NotFoundResponse();
|
2018-03-28 12:56:31 +00:00
|
|
|
$this->assertEquals($expected, $this->themingController->getImage('logo'));
|
2016-06-21 19:21:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetLogo() {
|
2017-02-09 21:51:05 +00:00
|
|
|
$file = $this->createMock(ISimpleFile::class);
|
2018-03-28 12:56:31 +00:00
|
|
|
$this->imageManager->expects($this->once())
|
|
|
|
->method('getImage')
|
2016-11-08 18:46:09 +00:00
|
|
|
->willReturn($file);
|
2016-06-21 19:21:46 +00:00
|
|
|
$this->config
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getAppValue')
|
|
|
|
->with('theming', 'logoMime', '')
|
|
|
|
->willReturn('text/svg');
|
|
|
|
|
2017-02-09 10:38:45 +00:00
|
|
|
@$expected = new Http\FileDisplayResponse($file);
|
2016-06-21 19:21:46 +00:00
|
|
|
$expected->cacheFor(3600);
|
2017-02-09 10:38:45 +00:00
|
|
|
$expected->addHeader('Content-Type', 'text/svg');
|
2018-05-17 09:46:28 +00:00
|
|
|
$expected->addHeader('Content-Disposition', 'attachment; filename="logo"');
|
2018-03-28 12:56:31 +00:00
|
|
|
@$this->assertEquals($expected, $this->themingController->getImage('logo'));
|
2016-06-21 19:21:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testGetLoginBackgroundNotExistent() {
|
2018-03-28 12:56:31 +00:00
|
|
|
$this->imageManager->method('getImage')
|
|
|
|
->with($this->equalTo('background'))
|
2016-11-08 18:46:09 +00:00
|
|
|
->willThrowException(new NotFoundException());
|
|
|
|
$expected = new Http\NotFoundResponse();
|
2018-03-28 12:56:31 +00:00
|
|
|
$this->assertEquals($expected, $this->themingController->getImage('background'));
|
2016-06-21 19:21:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetLoginBackground() {
|
2017-02-09 21:51:05 +00:00
|
|
|
$file = $this->createMock(ISimpleFile::class);
|
2018-03-28 12:56:31 +00:00
|
|
|
$this->imageManager->expects($this->once())
|
|
|
|
->method('getImage')
|
2016-11-08 18:46:09 +00:00
|
|
|
->willReturn($file);
|
|
|
|
|
2016-06-21 19:21:46 +00:00
|
|
|
$this->config
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getAppValue')
|
|
|
|
->with('theming', 'backgroundMime', '')
|
|
|
|
->willReturn('image/png');
|
|
|
|
|
2017-02-09 10:38:45 +00:00
|
|
|
@$expected = new Http\FileDisplayResponse($file);
|
2016-06-21 19:21:46 +00:00
|
|
|
$expected->cacheFor(3600);
|
2017-02-09 10:38:45 +00:00
|
|
|
$expected->addHeader('Content-Type', 'image/png');
|
2018-05-17 09:46:28 +00:00
|
|
|
$expected->addHeader('Content-Disposition', 'attachment; filename="background"');
|
2018-03-28 12:56:31 +00:00
|
|
|
@$this->assertEquals($expected, $this->themingController->getImage('background'));
|
2016-06-21 19:21:46 +00:00
|
|
|
}
|
|
|
|
|
2016-07-28 09:45:42 +00:00
|
|
|
|
2017-02-17 15:42:07 +00:00
|
|
|
public function testGetStylesheet() {
|
2018-02-24 16:16:42 +00:00
|
|
|
$this->appManager->expects($this->once())->method('getAppPath')->with('theming')->willReturn(\OC::$SERVERROOT . '/theming');
|
2017-02-17 15:42:07 +00: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 09:45:42 +00:00
|
|
|
|
2017-02-17 15:42:07 +00:00
|
|
|
$response = new Http\FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => 'text/css']);
|
|
|
|
$response->cacheFor(86400);
|
2016-07-19 12:39:53 +00:00
|
|
|
|
2017-02-17 15:42:07 +00:00
|
|
|
$actual = $this->themingController->getStylesheet();
|
|
|
|
$this->assertEquals($response, $actual);
|
2016-06-21 19:21:46 +00:00
|
|
|
}
|
2016-07-28 09:45:42 +00:00
|
|
|
|
2017-02-17 15:42:07 +00:00
|
|
|
public function testGetStylesheetFails() {
|
2018-02-24 16:16:42 +00:00
|
|
|
$this->appManager->expects($this->once())->method('getAppPath')->with('theming')->willReturn(\OC::$SERVERROOT . '/theming');
|
2017-02-17 15:42:07 +00: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 12:04:19 +00:00
|
|
|
}
|
2016-08-10 09:53:33 +00:00
|
|
|
|
2018-02-21 06:44:37 +00: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 09:53:33 +00:00
|
|
|
public function testGetJavascript() {
|
2017-02-17 15:42:07 +00:00
|
|
|
$this->themingDefaults
|
2016-08-10 09:53:33 +00:00
|
|
|
->expects($this->at(0))
|
|
|
|
->method('getName')
|
|
|
|
->willReturn("");
|
2017-02-17 15:42:07 +00:00
|
|
|
$this->themingDefaults
|
2016-08-10 09:53:33 +00:00
|
|
|
->expects($this->at(1))
|
|
|
|
->method('getBaseUrl')
|
|
|
|
->willReturn("");
|
2017-02-17 15:42:07 +00:00
|
|
|
$this->themingDefaults
|
2016-08-10 09:53:33 +00:00
|
|
|
->expects($this->at(2))
|
|
|
|
->method('getSlogan')
|
|
|
|
->willReturn("");
|
2017-02-17 15:42:07 +00:00
|
|
|
$this->themingDefaults
|
2016-08-10 09:53:33 +00:00
|
|
|
->expects($this->at(3))
|
2017-03-27 23:37:47 +00:00
|
|
|
->method('getColorPrimary')
|
2016-08-10 09:53:33 +00:00
|
|
|
->willReturn("#000");
|
|
|
|
|
|
|
|
|
|
|
|
$expectedResponse = '(function() {
|
|
|
|
OCA.Theming = {
|
|
|
|
name: "",
|
|
|
|
url: "",
|
|
|
|
slogan: "",
|
|
|
|
color: "#000",
|
2018-05-11 13:11:09 +00:00
|
|
|
imprintUrl: null,
|
2018-05-24 12:45:49 +00:00
|
|
|
privacyUrl: null,
|
2016-08-10 09:53:33 +00:00
|
|
|
inverted: false,
|
2016-08-30 09:51:48 +00:00
|
|
|
cacheBuster: null
|
2016-08-10 09:53:33 +00:00
|
|
|
};
|
|
|
|
})();';
|
2017-01-18 16:00:09 +00:00
|
|
|
$expected = new Http\DataDownloadResponse($expectedResponse, 'javascript', 'text/javascript');
|
2016-08-10 09:53:33 +00:00
|
|
|
$expected->cacheFor(3600);
|
|
|
|
@$this->assertEquals($expected, $this->themingController->getJavascript());
|
|
|
|
}
|
|
|
|
public function testGetJavascriptInverted() {
|
2017-02-17 15:42:07 +00:00
|
|
|
$this->themingDefaults
|
2016-08-10 09:53:33 +00:00
|
|
|
->expects($this->at(0))
|
|
|
|
->method('getName')
|
|
|
|
->willReturn("Nextcloud");
|
2017-02-17 15:42:07 +00:00
|
|
|
$this->themingDefaults
|
2016-08-10 09:53:33 +00:00
|
|
|
->expects($this->at(1))
|
|
|
|
->method('getBaseUrl')
|
|
|
|
->willReturn("nextcloudurl");
|
2017-02-17 15:42:07 +00:00
|
|
|
$this->themingDefaults
|
2016-08-10 09:53:33 +00:00
|
|
|
->expects($this->at(2))
|
|
|
|
->method('getSlogan')
|
|
|
|
->willReturn("awesome");
|
2017-02-17 15:42:07 +00:00
|
|
|
$this->themingDefaults
|
2016-08-10 09:53:33 +00:00
|
|
|
->expects($this->any())
|
2017-03-27 23:37:47 +00:00
|
|
|
->method('getColorPrimary')
|
2016-08-10 09:53:33 +00:00
|
|
|
->willReturn("#ffffff");
|
|
|
|
|
|
|
|
$expectedResponse = '(function() {
|
|
|
|
OCA.Theming = {
|
|
|
|
name: "Nextcloud",
|
|
|
|
url: "nextcloudurl",
|
|
|
|
slogan: "awesome",
|
|
|
|
color: "#ffffff",
|
2018-05-11 13:11:09 +00:00
|
|
|
imprintUrl: null,
|
2018-05-24 12:45:49 +00:00
|
|
|
privacyUrl: null,
|
2016-08-10 09:53:33 +00:00
|
|
|
inverted: true,
|
2016-08-30 09:51:48 +00:00
|
|
|
cacheBuster: null
|
2016-08-10 09:53:33 +00:00
|
|
|
};
|
|
|
|
})();';
|
2017-01-18 16:00:09 +00:00
|
|
|
$expected = new Http\DataDownloadResponse($expectedResponse, 'javascript', 'text/javascript');
|
2016-08-10 09:53:33 +00:00
|
|
|
$expected->cacheFor(3600);
|
|
|
|
@$this->assertEquals($expected, $this->themingController->getJavascript());
|
|
|
|
}
|
2017-09-11 13:04:26 +00: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 19:21:46 +00:00
|
|
|
}
|