aboutsummaryrefslogtreecommitdiffstats
path: root/apps/theming/tests/UtilTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/theming/tests/UtilTest.php')
-rw-r--r--apps/theming/tests/UtilTest.php181
1 files changed, 88 insertions, 93 deletions
diff --git a/apps/theming/tests/UtilTest.php b/apps/theming/tests/UtilTest.php
index 914ad8b073f..1e944027e32 100644
--- a/apps/theming/tests/UtilTest.php
+++ b/apps/theming/tests/UtilTest.php
@@ -1,32 +1,13 @@
<?php
+
+declare(strict_types=1);
/**
- * @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Julius Haertl <jus@bitgrid.net>
- * @author Julius Härtl <jus@bitgrid.net>
- * @author Michael Weimann <mail@michael-weimann.eu>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @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/>.
- *
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Theming\Tests;
+use OCA\Theming\ImageManager;
use OCA\Theming\Util;
use OCP\App\IAppManager;
use OCP\Files\IAppData;
@@ -34,125 +15,149 @@ use OCP\Files\NotFoundException;
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\Files\SimpleFS\ISimpleFolder;
use OCP\IConfig;
+use OCP\Server;
+use OCP\ServerVersion;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class UtilTest extends TestCase {
- /** @var Util */
- protected $util;
- /** @var IConfig */
- protected $config;
- /** @var IAppData */
- protected $appData;
- /** @var IAppManager */
- protected $appManager;
+ protected Util $util;
+ protected IConfig&MockObject $config;
+ protected IAppData&MockObject $appData;
+ protected IAppManager $appManager;
+ protected ImageManager&MockObject $imageManager;
protected function setUp(): void {
parent::setUp();
$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);
+ $this->appManager = Server::get(IAppManager::class);
+ $this->imageManager = $this->createMock(ImageManager::class);
+ $this->util = new Util($this->createMock(ServerVersion::class), $this->config, $this->appManager, $this->appData, $this->imageManager);
+ }
+
+ public static function dataColorContrast(): array {
+ return [
+ ['#ffffff', '#FFFFFF', 1],
+ ['#000000', '#000000', 1],
+ ['#ffffff', '#000000', 21],
+ ['#000000', '#FFFFFF', 21],
+ ['#9E9E9E', '#353535', 4.578],
+ ['#353535', '#9E9E9E', 4.578],
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataColorContrast')]
+ public function testColorContrast(string $color1, string $color2, int|float $contrast): void {
+ $this->assertEqualsWithDelta($contrast, $this->util->colorContrast($color1, $color2), .001);
}
- public function dataInvertTextColor() {
+ public static function dataInvertTextColor(): array {
return [
['#ffffff', true],
['#000000', false],
- ['#0082C9', false],
+ ['#00679e', false],
['#ffff00', true],
];
}
- /**
- * @dataProvider dataInvertTextColor
- */
- public function testInvertTextColor($color, $expected) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataInvertTextColor')]
+ public function testInvertTextColor(string $color, bool $expected): void {
$invert = $this->util->invertTextColor($color);
$this->assertEquals($expected, $invert);
}
- public function testCalculateLuminanceLight() {
+ public function testCalculateLuminanceLight(): void {
$luminance = $this->util->calculateLuminance('#ffffff');
$this->assertEquals(1, $luminance);
}
- public function testCalculateLuminanceDark() {
+ public function testCalculateLuminanceDark(): void {
$luminance = $this->util->calculateLuminance('#000000');
$this->assertEquals(0, $luminance);
}
- public function testCalculateLuminanceLightShorthand() {
+ public function testCalculateLuminanceLightShorthand(): void {
$luminance = $this->util->calculateLuminance('#fff');
$this->assertEquals(1, $luminance);
}
- public function testCalculateLuminanceDarkShorthand() {
+ public function testCalculateLuminanceDarkShorthand(): void {
$luminance = $this->util->calculateLuminance('#000');
$this->assertEquals(0, $luminance);
}
- public function testInvertTextColorInvalid() {
+ public function testInvertTextColorInvalid(): void {
$this->expectException(\Exception::class);
$this->util->invertTextColor('aaabbbcccddd123');
}
- public function testInvertTextColorEmpty() {
+ public function testInvertTextColorEmpty(): void {
$this->expectException(\Exception::class);
$this->util->invertTextColor('');
}
- public function testElementColorDefault() {
- $elementColor = $this->util->elementColor("#000000");
+ public function testElementColorDefaultBlack(): void {
+ $elementColor = $this->util->elementColor('#000000');
+ $this->assertEquals('#4d4d4d', $elementColor);
+ }
+
+ public function testElementColorDefaultWhite(): void {
+ $elementColor = $this->util->elementColor('#ffffff');
+ $this->assertEquals('#b3b3b3', $elementColor);
+ }
+
+ public function testElementColorBlackOnDarkBackground(): void {
+ $elementColor = $this->util->elementColor('#000000', false);
+ $this->assertEquals('#4d4d4d', $elementColor);
+ }
+
+ public function testElementColorBlackOnBrightBackground(): void {
+ $elementColor = $this->util->elementColor('#000000', true);
$this->assertEquals('#000000', $elementColor);
}
- public function testElementColorOnDarkBackground() {
- $elementColor = $this->util->elementColor("#000000", false);
- $this->assertEquals('#555555', $elementColor);
+ public function testElementColorWhiteOnBrightBackground(): void {
+ $elementColor = $this->util->elementColor('#ffffff', true);
+ $this->assertEquals('#b3b3b3', $elementColor);
}
- public function testElementColorOnBrightBackground() {
- $elementColor = $this->util->elementColor('#ffffff');
- $this->assertEquals('#aaaaaa', $elementColor);
+ public function testElementColorWhiteOnDarkBackground(): void {
+ $elementColor = $this->util->elementColor('#ffffff', false);
+ $this->assertEquals('#ffffff', $elementColor);
}
- public function testGenerateRadioButtonWhite() {
+ public function testGenerateRadioButtonWhite(): void {
$button = $this->util->generateRadioButton('#ffffff');
$expected = 'PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMTYiIHdpZHRoPSIxNiI+PHBhdGggZD0iTTggMWE3IDcgMCAwIDAtNyA3IDcgNyAwIDAgMCA3IDcgNyA3IDAgMCAwIDctNyA3IDcgMCAwIDAtNy03em0wIDFhNiA2IDAgMCAxIDYgNiA2IDYgMCAwIDEtNiA2IDYgNiAwIDAgMS02LTYgNiA2IDAgMCAxIDYtNnptMCAyYTQgNCAwIDEgMCAwIDggNCA0IDAgMCAwIDAtOHoiIGZpbGw9IiNmZmZmZmYiLz48L3N2Zz4=';
$this->assertEquals($expected, $button);
}
- public function testGenerateRadioButtonBlack() {
+ public function testGenerateRadioButtonBlack(): void {
$button = $this->util->generateRadioButton('#000000');
$expected = 'PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMTYiIHdpZHRoPSIxNiI+PHBhdGggZD0iTTggMWE3IDcgMCAwIDAtNyA3IDcgNyAwIDAgMCA3IDcgNyA3IDAgMCAwIDctNyA3IDcgMCAwIDAtNy03em0wIDFhNiA2IDAgMCAxIDYgNiA2IDYgMCAwIDEtNiA2IDYgNiAwIDAgMS02LTYgNiA2IDAgMCAxIDYtNnptMCAyYTQgNCAwIDEgMCAwIDggNCA0IDAgMCAwIDAtOHoiIGZpbGw9IiMwMDAwMDAiLz48L3N2Zz4=';
$this->assertEquals($expected, $button);
}
- /**
- * @dataProvider dataGetAppIcon
- */
- public function testGetAppIcon($app, $expected) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetAppIcon')]
+ public function testGetAppIcon(string $app, string $expected): void {
$this->appData->expects($this->any())
->method('getFolder')
- ->with('images')
+ ->with('global/images')
->willThrowException(new NotFoundException());
- $this->appManager->expects($this->once())
- ->method('getAppPath')
- ->with($app)
- ->willReturn(\OC_App::getAppPath($app));
$icon = $this->util->getAppIcon($app);
$this->assertEquals($expected, $icon);
}
- public function dataGetAppIcon() {
+ public static function dataGetAppIcon(): array {
return [
- ['user_ldap', \OC_App::getAppPath('user_ldap') . '/img/app.svg'],
+ ['user_ldap', Server::get(IAppManager::class)->getAppPath('user_ldap') . '/img/app.svg'],
['noapplikethis', \OC::$SERVERROOT . '/core/img/logo/logo.svg'],
- ['comments', \OC_App::getAppPath('comments') . '/img/comments.svg'],
+ ['comments', Server::get(IAppManager::class)->getAppPath('comments') . '/img/comments.svg'],
];
}
- public function testGetAppIconThemed() {
+ public function testGetAppIconThemed(): void {
$file = $this->createMock(ISimpleFile::class);
$folder = $this->createMock(ISimpleFolder::class);
$folder->expects($this->once())
@@ -161,42 +166,34 @@ class UtilTest extends TestCase {
->willReturn($file);
$this->appData->expects($this->once())
->method('getFolder')
- ->with('images')
+ ->with('global/images')
->willReturn($folder);
$icon = $this->util->getAppIcon('noapplikethis');
$this->assertEquals($file, $icon);
}
- /**
- * @dataProvider dataGetAppImage
- */
- public function testGetAppImage($app, $image, $expected) {
- if ($app !== 'core') {
- $this->appManager->expects($this->once())
- ->method('getAppPath')
- ->with($app)
- ->willReturn(\OC_App::getAppPath($app));
- }
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetAppImage')]
+ public function testGetAppImage(string $app, string $image, string|bool $expected): void {
$this->assertEquals($expected, $this->util->getAppImage($app, $image));
}
- public function dataGetAppImage() {
+ public static function dataGetAppImage(): array {
return [
['core', 'logo/logo.svg', \OC::$SERVERROOT . '/core/img/logo/logo.svg'],
- ['files', 'external', \OC::$SERVERROOT . '/apps/files/img/external.svg'],
- ['files', 'external.svg', \OC::$SERVERROOT . '/apps/files/img/external.svg'],
+ ['files', 'folder', \OC::$SERVERROOT . '/apps/files/img/folder.svg'],
+ ['files', 'folder.svg', \OC::$SERVERROOT . '/apps/files/img/folder.svg'],
['noapplikethis', 'foobar.svg', false],
];
}
- public function testColorizeSvg() {
- $input = "#0082c9 #0082C9 #000000 #FFFFFF";
- $expected = "#AAAAAA #AAAAAA #000000 #FFFFFF";
+ public function testColorizeSvg(): void {
+ $input = '#0082c9 #0082C9 #000000 #FFFFFF';
+ $expected = '#AAAAAA #AAAAAA #000000 #FFFFFF';
$result = $this->util->colorizeSvg($input, '#AAAAAA');
$this->assertEquals($expected, $result);
}
- public function testIsAlreadyThemedFalse() {
+ public function testIsAlreadyThemedFalse(): void {
$this->config->expects($this->once())
->method('getSystemValue')
->with('theme', '')
@@ -205,7 +202,7 @@ class UtilTest extends TestCase {
$this->assertFalse($actual);
}
- public function testIsAlreadyThemedTrue() {
+ public function testIsAlreadyThemedTrue(): void {
$this->config->expects($this->once())
->method('getSystemValue')
->with('theme', '')
@@ -214,17 +211,15 @@ class UtilTest extends TestCase {
$this->assertTrue($actual);
}
- public function dataIsBackgroundThemed() {
+ public static function dataIsBackgroundThemed(): array {
return [
['', false],
['png', true],
['backgroundColor', false],
];
}
- /**
- * @dataProvider dataIsBackgroundThemed
- */
- public function testIsBackgroundThemed($backgroundMime, $expected) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataIsBackgroundThemed')]
+ public function testIsBackgroundThemed(string $backgroundMime, bool $expected): void {
$this->config->expects($this->once())
->method('getAppValue')
->with('theming', 'backgroundMime', '')