2016-07-15 15:04:19 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
|
|
|
|
*
|
2020-04-29 12:57:22 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @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>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Michael Weimann <mail@michael-weimann.eu>
|
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2016-07-21 17:49:16 +03:00
|
|
|
*
|
2016-07-15 15:04:19 +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-07-15 15:04:19 +03:00
|
|
|
*
|
|
|
|
*/
|
2019-11-22 22:52:10 +03:00
|
|
|
|
2016-07-15 15:04:19 +03:00
|
|
|
namespace OCA\Theming\Tests;
|
|
|
|
|
|
|
|
use OCA\Theming\Util;
|
2016-11-18 12:49:03 +03:00
|
|
|
use OCP\App\IAppManager;
|
2017-05-15 00:52:14 +03:00
|
|
|
use OCP\Files\IAppData;
|
|
|
|
use OCP\Files\NotFoundException;
|
|
|
|
use OCP\Files\SimpleFS\ISimpleFile;
|
|
|
|
use OCP\Files\SimpleFS\ISimpleFolder;
|
2016-08-29 12:53:44 +03:00
|
|
|
use OCP\IConfig;
|
2016-07-15 15:04:19 +03:00
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
class UtilTest extends TestCase {
|
|
|
|
|
2016-07-28 17:07:23 +03:00
|
|
|
/** @var Util */
|
|
|
|
protected $util;
|
2016-08-29 12:53:44 +03:00
|
|
|
/** @var IConfig */
|
|
|
|
protected $config;
|
2017-05-15 00:52:14 +03:00
|
|
|
/** @var IAppData */
|
|
|
|
protected $appData;
|
2016-11-18 12:49:03 +03:00
|
|
|
/** @var IAppManager */
|
|
|
|
protected $appManager;
|
2016-08-30 12:51:48 +03:00
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
protected function setUp(): void {
|
2016-07-28 17:07:23 +03:00
|
|
|
parent::setUp();
|
2017-05-15 00:52:14 +03:00
|
|
|
$this->config = $this->createMock(IConfig::class);
|
|
|
|
$this->appData = $this->createMock(IAppData::class);
|
|
|
|
$this->appManager = $this->createMock(IAppManager::class);
|
|
|
|
$this->util = new Util($this->config, $this->appManager, $this->appData);
|
2016-07-28 17:07:23 +03:00
|
|
|
}
|
|
|
|
|
2018-01-08 18:50:03 +03:00
|
|
|
public function dataInvertTextColor() {
|
|
|
|
return [
|
|
|
|
['#ffffff', true],
|
|
|
|
['#000000', false],
|
|
|
|
['#0082C9', false],
|
|
|
|
['#ffff00', true],
|
|
|
|
];
|
2016-07-15 15:04:19 +03:00
|
|
|
}
|
2018-01-08 18:50:03 +03:00
|
|
|
/**
|
|
|
|
* @dataProvider dataInvertTextColor
|
|
|
|
*/
|
|
|
|
public function testInvertTextColor($color, $expected) {
|
|
|
|
$invert = $this->util->invertTextColor($color);
|
|
|
|
$this->assertEquals($expected, $invert);
|
2016-07-15 15:04:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testCalculateLuminanceLight() {
|
2016-07-28 17:07:23 +03:00
|
|
|
$luminance = $this->util->calculateLuminance('#ffffff');
|
2016-07-15 15:04:19 +03:00
|
|
|
$this->assertEquals(1, $luminance);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCalculateLuminanceDark() {
|
2016-07-28 17:07:23 +03:00
|
|
|
$luminance = $this->util->calculateLuminance('#000000');
|
2016-07-15 15:04:19 +03:00
|
|
|
$this->assertEquals(0, $luminance);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCalculateLuminanceLightShorthand() {
|
2016-07-28 17:07:23 +03:00
|
|
|
$luminance = $this->util->calculateLuminance('#fff');
|
2016-07-15 15:04:19 +03:00
|
|
|
$this->assertEquals(1, $luminance);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCalculateLuminanceDarkShorthand() {
|
2016-07-28 17:07:23 +03:00
|
|
|
$luminance = $this->util->calculateLuminance('#000');
|
2016-07-15 15:04:19 +03:00
|
|
|
$this->assertEquals(0, $luminance);
|
|
|
|
}
|
|
|
|
public function testInvertTextColorInvalid() {
|
2016-07-28 17:07:23 +03:00
|
|
|
$invert = $this->util->invertTextColor('aaabbbcccddd123');
|
2016-07-15 15:04:19 +03:00
|
|
|
$this->assertEquals(false, $invert);
|
|
|
|
}
|
2018-10-03 20:26:47 +03:00
|
|
|
|
2016-07-15 15:04:19 +03:00
|
|
|
public function testInvertTextColorEmpty() {
|
2016-07-28 17:07:23 +03:00
|
|
|
$invert = $this->util->invertTextColor('');
|
2016-07-15 15:04:19 +03:00
|
|
|
$this->assertEquals(false, $invert);
|
|
|
|
}
|
2016-07-19 15:00:33 +03:00
|
|
|
|
|
|
|
public function testElementColorDefault() {
|
2016-07-28 17:07:23 +03:00
|
|
|
$elementColor = $this->util->elementColor("#000000");
|
2016-07-19 15:00:33 +03:00
|
|
|
$this->assertEquals('#000000', $elementColor);
|
|
|
|
}
|
|
|
|
|
2020-06-26 10:58:45 +03:00
|
|
|
public function testElementColorOnDarkBackground() {
|
|
|
|
$elementColor = $this->util->elementColor("#000000", false);
|
|
|
|
$this->assertEquals('#555555', $elementColor);
|
|
|
|
}
|
|
|
|
|
2016-07-19 15:00:33 +03:00
|
|
|
public function testElementColorOnBrightBackground() {
|
2016-07-28 17:07:23 +03:00
|
|
|
$elementColor = $this->util->elementColor('#ffffff');
|
2019-03-27 18:11:57 +03:00
|
|
|
$this->assertEquals('#aaaaaa', $elementColor);
|
2016-07-19 15:00:33 +03:00
|
|
|
}
|
2016-07-25 18:32:11 +03:00
|
|
|
|
|
|
|
public function testGenerateRadioButtonWhite() {
|
2016-07-28 17:07:23 +03:00
|
|
|
$button = $this->util->generateRadioButton('#ffffff');
|
2016-07-25 18:32:11 +03:00
|
|
|
$expected = 'PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMTYiIHdpZHRoPSIxNiI+PHBhdGggZD0iTTggMWE3IDcgMCAwIDAtNyA3IDcgNyAwIDAgMCA3IDcgNyA3IDAgMCAwIDctNyA3IDcgMCAwIDAtNy03em0wIDFhNiA2IDAgMCAxIDYgNiA2IDYgMCAwIDEtNiA2IDYgNiAwIDAgMS02LTYgNiA2IDAgMCAxIDYtNnptMCAyYTQgNCAwIDEgMCAwIDggNCA0IDAgMCAwIDAtOHoiIGZpbGw9IiNmZmZmZmYiLz48L3N2Zz4=';
|
|
|
|
$this->assertEquals($expected, $button);
|
|
|
|
}
|
2016-11-04 20:55:00 +03:00
|
|
|
|
2016-07-25 18:32:11 +03:00
|
|
|
public function testGenerateRadioButtonBlack() {
|
2016-07-28 17:07:23 +03:00
|
|
|
$button = $this->util->generateRadioButton('#000000');
|
2016-07-25 18:32:11 +03:00
|
|
|
$expected = 'PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMTYiIHdpZHRoPSIxNiI+PHBhdGggZD0iTTggMWE3IDcgMCAwIDAtNyA3IDcgNyAwIDAgMCA3IDcgNyA3IDAgMCAwIDctNyA3IDcgMCAwIDAtNy03em0wIDFhNiA2IDAgMCAxIDYgNiA2IDYgMCAwIDEtNiA2IDYgNiAwIDAgMS02LTYgNiA2IDAgMCAxIDYtNnptMCAyYTQgNCAwIDEgMCAwIDggNCA0IDAgMCAwIDAtOHoiIGZpbGw9IiMwMDAwMDAiLz48L3N2Zz4=';
|
|
|
|
$this->assertEquals($expected, $button);
|
|
|
|
}
|
2016-08-29 12:53:44 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataGetAppIcon
|
|
|
|
*/
|
|
|
|
public function testGetAppIcon($app, $expected) {
|
2017-05-15 00:52:14 +03:00
|
|
|
$this->appData->expects($this->any())
|
|
|
|
->method('getFolder')
|
|
|
|
->with('images')
|
|
|
|
->willThrowException(new NotFoundException());
|
2016-11-18 12:49:03 +03:00
|
|
|
$this->appManager->expects($this->once())
|
|
|
|
->method('getAppPath')
|
|
|
|
->with($app)
|
|
|
|
->willReturn(\OC_App::getAppPath($app));
|
2016-08-29 12:53:44 +03:00
|
|
|
$icon = $this->util->getAppIcon($app);
|
|
|
|
$this->assertEquals($expected, $icon);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function dataGetAppIcon() {
|
|
|
|
return [
|
|
|
|
['user_ldap', \OC_App::getAppPath('user_ldap') . '/img/app.svg'],
|
2018-10-04 21:43:27 +03:00
|
|
|
['noapplikethis', \OC::$SERVERROOT . '/core/img/logo/logo.svg'],
|
2016-08-29 12:53:44 +03:00
|
|
|
['comments', \OC_App::getAppPath('comments') . '/img/comments.svg'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetAppIconThemed() {
|
2017-05-15 00:52:14 +03:00
|
|
|
$file = $this->createMock(ISimpleFile::class);
|
|
|
|
$folder = $this->createMock(ISimpleFolder::class);
|
|
|
|
$folder->expects($this->once())
|
|
|
|
->method('getFile')
|
|
|
|
->with('logo')
|
|
|
|
->willReturn($file);
|
|
|
|
$this->appData->expects($this->once())
|
|
|
|
->method('getFolder')
|
|
|
|
->with('images')
|
|
|
|
->willReturn($folder);
|
2016-08-29 12:53:44 +03:00
|
|
|
$icon = $this->util->getAppIcon('noapplikethis');
|
2017-05-15 00:52:14 +03:00
|
|
|
$this->assertEquals($file, $icon);
|
2016-08-29 12:53:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataGetAppImage
|
|
|
|
*/
|
|
|
|
public function testGetAppImage($app, $image, $expected) {
|
2020-04-10 15:19:56 +03:00
|
|
|
if ($app !== 'core') {
|
2016-11-18 12:49:03 +03:00
|
|
|
$this->appManager->expects($this->once())
|
|
|
|
->method('getAppPath')
|
|
|
|
->with($app)
|
|
|
|
->willReturn(\OC_App::getAppPath($app));
|
|
|
|
}
|
2016-08-29 12:53:44 +03:00
|
|
|
$this->assertEquals($expected, $this->util->getAppImage($app, $image));
|
|
|
|
}
|
2016-11-04 20:55:00 +03:00
|
|
|
|
2016-08-29 12:53:44 +03:00
|
|
|
public function dataGetAppImage() {
|
|
|
|
return [
|
2018-10-03 20:26:47 +03:00
|
|
|
['core', 'logo/logo.svg', \OC::$SERVERROOT . '/core/img/logo/logo.svg'],
|
2016-08-29 12:53:44 +03:00
|
|
|
['files', 'external', \OC::$SERVERROOT . '/apps/files/img/external.svg'],
|
|
|
|
['files', 'external.svg', \OC::$SERVERROOT . '/apps/files/img/external.svg'],
|
|
|
|
['noapplikethis', 'foobar.svg', false],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testColorizeSvg() {
|
|
|
|
$input = "#0082c9 #0082C9 #000000 #FFFFFF";
|
|
|
|
$expected = "#AAAAAA #AAAAAA #000000 #FFFFFF";
|
|
|
|
$result = $this->util->colorizeSvg($input, '#AAAAAA');
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
2017-05-23 16:20:54 +03:00
|
|
|
public function testIsAlreadyThemedFalse() {
|
|
|
|
$this->config->expects($this->once())
|
|
|
|
->method('getSystemValue')
|
|
|
|
->with('theme', '')
|
|
|
|
->willReturn('');
|
|
|
|
$actual = $this->util->isAlreadyThemed();
|
|
|
|
$this->assertFalse($actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIsAlreadyThemedTrue() {
|
|
|
|
$this->config->expects($this->once())
|
|
|
|
->method('getSystemValue')
|
|
|
|
->with('theme', '')
|
|
|
|
->willReturn('example');
|
|
|
|
$actual = $this->util->isAlreadyThemed();
|
|
|
|
$this->assertTrue($actual);
|
|
|
|
}
|
|
|
|
|
2018-01-10 01:11:49 +03:00
|
|
|
public function dataIsBackgroundThemed() {
|
|
|
|
return [
|
2020-11-20 21:28:18 +03:00
|
|
|
['', false],
|
|
|
|
['png', true],
|
|
|
|
['backgroundColor', false],
|
2018-01-10 01:11:49 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @dataProvider dataIsBackgroundThemed
|
|
|
|
*/
|
2020-11-20 21:28:18 +03:00
|
|
|
public function testIsBackgroundThemed($backgroundMime, $expected) {
|
2018-01-10 01:11:49 +03:00
|
|
|
$this->config->expects($this->once())
|
|
|
|
->method('getAppValue')
|
2020-11-20 21:28:18 +03:00
|
|
|
->with('theming', 'backgroundMime', '')
|
2018-01-10 01:11:49 +03:00
|
|
|
->willReturn($backgroundMime);
|
|
|
|
$this->assertEquals($expected, $this->util->isBackgroundThemed());
|
|
|
|
}
|
2016-07-15 15:04:19 +03:00
|
|
|
}
|