aboutsummaryrefslogtreecommitdiffstats
path: root/apps/theming/tests
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2023-12-14 17:53:18 +0100
committerFerdinand Thiessen <opensource@fthiessen.de>2023-12-15 21:09:14 +0100
commit141d1e90260ca63f415d65060752f4c9d3e8eb28 (patch)
treedf37f6769f5fb67fec417ba7aea95e153188e8f4 /apps/theming/tests
parent2a205511c7002b7980a7c6db980f002013c7be7b (diff)
downloadnextcloud-server-141d1e90260ca63f415d65060752f4c9d3e8eb28.tar.gz
nextcloud-server-141d1e90260ca63f415d65060752f4c9d3e8eb28.zip
enh(theming): Adjust color utils to work as specified by WCAG (color contrast and luma calculation)
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'apps/theming/tests')
-rw-r--r--apps/theming/tests/UtilTest.php29
1 files changed, 24 insertions, 5 deletions
diff --git a/apps/theming/tests/UtilTest.php b/apps/theming/tests/UtilTest.php
index 0d986a2b112..857e9fff6a5 100644
--- a/apps/theming/tests/UtilTest.php
+++ b/apps/theming/tests/UtilTest.php
@@ -35,19 +35,20 @@ use OCP\Files\NotFoundException;
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\Files\SimpleFS\ISimpleFolder;
use OCP\IConfig;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class UtilTest extends TestCase {
/** @var Util */
protected $util;
- /** @var IConfig */
+ /** @var IConfig|MockObject */
protected $config;
- /** @var IAppData */
+ /** @var IAppData|MockObject */
protected $appData;
- /** @var IAppManager */
+ /** @var IAppManager|MockObject */
protected $appManager;
- /** @var ImageManager */
+ /** @var ImageManager|MockObject */
protected $imageManager;
protected function setUp(): void {
@@ -59,11 +60,29 @@ class UtilTest extends TestCase {
$this->util = new Util($this->config, $this->appManager, $this->appData, $this->imageManager);
}
+ public function dataColorContrast() {
+ return [
+ ['#ffffff', '#FFFFFF', 1],
+ ['#000000', '#000000', 1],
+ ['#ffffff', '#000000', 21],
+ ['#000000', '#FFFFFF', 21],
+ ['#9E9E9E', '#353535', 4.578],
+ ['#353535', '#9E9E9E', 4.578],
+ ];
+ }
+
+ /**
+ * @dataProvider dataColorContrast
+ */
+ public function testColorContrast(string $color1, string $color2, $contrast) {
+ $this->assertEqualsWithDelta($contrast, $this->util->colorContrast($color1, $color2), .001);
+ }
+
public function dataInvertTextColor() {
return [
['#ffffff', true],
['#000000', false],
- ['#0082C9', false],
+ ['#00679e', false],
['#ffff00', true],
];
}