aboutsummaryrefslogtreecommitdiffstats
path: root/apps/theming/tests/Themes
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2023-12-16 14:04:53 +0100
committerEduardo Morales <emoral435@gmail.com>2023-12-19 10:20:33 -0600
commit74f6995bdb6fa85426048ac87cea7ed94902686f (patch)
treed5942987822f11324d1de2f93e13ff0c201ab8bf /apps/theming/tests/Themes
parent94a5e6c7b37765a4e8079ad945801a0a892dba04 (diff)
downloadnextcloud-server-74f6995bdb6fa85426048ac87cea7ed94902686f.tar.gz
nextcloud-server-74f6995bdb6fa85426048ac87cea7ed94902686f.zip
fix(theming): Adjust dark high contrast to fulfill WCAG 2.1 AAA contrast
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'apps/theming/tests/Themes')
-rw-r--r--apps/theming/tests/Themes/AccessibleThemeTestCase.php35
-rw-r--r--apps/theming/tests/Themes/DarkHighContrastThemeTest.php142
2 files changed, 169 insertions, 8 deletions
diff --git a/apps/theming/tests/Themes/AccessibleThemeTestCase.php b/apps/theming/tests/Themes/AccessibleThemeTestCase.php
index fbd0722552d..84121dd41b0 100644
--- a/apps/theming/tests/Themes/AccessibleThemeTestCase.php
+++ b/apps/theming/tests/Themes/AccessibleThemeTestCase.php
@@ -30,7 +30,15 @@ class AccessibleThemeTestCase extends TestCase {
protected ITheme $theme;
protected Util $util;
+ /**
+ * Set to true to check for WCAG AAA level accessibility
+ */
+ protected bool $WCAGaaa = false;
+
public function dataAccessibilityPairs() {
+ $textContrast = $this->WCAGaaa ? 7.0 : 4.5;
+ $elementContrast = 3.0;
+
return [
'primary-element on background' => [
[
@@ -44,7 +52,7 @@ class AccessibleThemeTestCase extends TestCase {
'--color-background-darker',
'--color-main-background-blur',
],
- 3.0,
+ $elementContrast,
],
'status color elements on background' => [
[
@@ -64,7 +72,18 @@ class AccessibleThemeTestCase extends TestCase {
'--color-background-darker',
'--color-main-background-blur',
],
- 3.0,
+ $elementContrast,
+ ],
+ // Those two colors are used for borders which will be `color-main-text` on focussed state, thus need 3:1 contrast to it
+ 'success-error-border-colors' => [
+ [
+ '--color-error',
+ '--color-success',
+ ],
+ [
+ '--color-main-text',
+ ],
+ $elementContrast,
],
'primary-element-text' => [
[
@@ -75,7 +94,7 @@ class AccessibleThemeTestCase extends TestCase {
'--color-primary-element',
'--color-primary-element-hover',
],
- 4.5,
+ $textContrast,
],
'primary-element-light-text' => [
['--color-primary-element-light-text'],
@@ -83,7 +102,7 @@ class AccessibleThemeTestCase extends TestCase {
'--color-primary-element-light',
'--color-primary-element-light-hover',
],
- 4.5,
+ $textContrast,
],
'main-text' => [
['--color-main-text'],
@@ -94,7 +113,7 @@ class AccessibleThemeTestCase extends TestCase {
'--color-background-darker',
'--color-main-background-blur',
],
- 4.5,
+ $textContrast,
],
'max-contrast-text' => [
['--color-text-maxcontrast'],
@@ -103,14 +122,14 @@ class AccessibleThemeTestCase extends TestCase {
'--color-background-hover',
'--color-background-dark',
],
- 4.5,
+ $textContrast,
],
'max-contrast text-on blur' => [
['--color-text-maxcontrast-background-blur'],
[
'--color-main-background-blur',
],
- 4.5,
+ $textContrast,
],
'status-text' => [
[
@@ -125,7 +144,7 @@ class AccessibleThemeTestCase extends TestCase {
'--color-background-dark',
'--color-main-background-blur',
],
- 4.5,
+ $textContrast,
],
];
}
diff --git a/apps/theming/tests/Themes/DarkHighContrastThemeTest.php b/apps/theming/tests/Themes/DarkHighContrastThemeTest.php
new file mode 100644
index 00000000000..d3a357bcfe7
--- /dev/null
+++ b/apps/theming/tests/Themes/DarkHighContrastThemeTest.php
@@ -0,0 +1,142 @@
+<?php
+/**
+ * @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
+ *
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
+ *
+ * @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\Themes;
+
+use OCA\Theming\AppInfo\Application;
+use OCA\Theming\ImageManager;
+use OCA\Theming\ITheme;
+use OCA\Theming\Service\BackgroundService;
+use OCA\Theming\Themes\DarkHighContrastTheme;
+use OCA\Theming\ThemingDefaults;
+use OCA\Theming\Util;
+use OCP\App\IAppManager;
+use OCP\Files\IAppData;
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+use OCP\IUserSession;
+use PHPUnit\Framework\MockObject\MockObject;
+
+class DarkHighContrastThemeTest extends AccessibleThemeTestCase {
+ /** @var ThemingDefaults|MockObject */
+ private $themingDefaults;
+ /** @var IUserSession|MockObject */
+ private $userSession;
+ /** @var IURLGenerator|MockObject */
+ private $urlGenerator;
+ /** @var ImageManager|MockObject */
+ private $imageManager;
+ /** @var IConfig|MockObject */
+ private $config;
+ /** @var IL10N|MockObject */
+ private $l10n;
+ /** @var IAppManager|MockObject */
+ private $appManager;
+
+ // !! important: Enable WCAG AAA tests
+ protected bool $WCAGaaa = true;
+
+ protected function setUp(): void {
+ $this->themingDefaults = $this->createMock(ThemingDefaults::class);
+ $this->userSession = $this->createMock(IUserSession::class);
+ $this->urlGenerator = $this->createMock(IURLGenerator::class);
+ $this->imageManager = $this->createMock(ImageManager::class);
+ $this->config = $this->createMock(IConfig::class);
+ $this->l10n = $this->createMock(IL10N::class);
+ $this->appManager = $this->createMock(IAppManager::class);
+
+ $this->util = new Util(
+ $this->config,
+ $this->appManager,
+ $this->createMock(IAppData::class),
+ $this->imageManager
+ );
+
+ $this->themingDefaults
+ ->expects($this->any())
+ ->method('getColorPrimary')
+ ->willReturn('#0082c9');
+
+ $this->themingDefaults
+ ->expects($this->any())
+ ->method('getDefaultColorPrimary')
+ ->willReturn('#0082c9');
+
+ $this->themingDefaults
+ ->expects($this->any())
+ ->method('getBackground')
+ ->willReturn('/apps/' . Application::APP_ID . '/img/background/' . BackgroundService::DEFAULT_BACKGROUND_IMAGE);
+
+ $this->l10n
+ ->expects($this->any())
+ ->method('t')
+ ->willReturnCallback(function ($text, $parameters = []) {
+ return vsprintf($text, $parameters);
+ });
+
+ $this->urlGenerator
+ ->expects($this->any())
+ ->method('imagePath')
+ ->willReturnCallback(function ($app = 'core', $filename = '') {
+ return "/$app/img/$filename";
+ });
+
+ $this->theme = new DarkHighContrastTheme(
+ $this->util,
+ $this->themingDefaults,
+ $this->userSession,
+ $this->urlGenerator,
+ $this->imageManager,
+ $this->config,
+ $this->l10n,
+ $this->appManager,
+ );
+
+ parent::setUp();
+ }
+
+
+ public function testGetId() {
+ $this->assertEquals('dark-highcontrast', $this->theme->getId());
+ }
+
+ public function testGetType() {
+ $this->assertEquals(ITheme::TYPE_THEME, $this->theme->getType());
+ }
+
+ public function testGetTitle() {
+ $this->assertEquals('Dark theme with high contrast mode', $this->theme->getTitle());
+ }
+
+ public function testGetEnableLabel() {
+ $this->assertEquals('Enable dark high contrast mode', $this->theme->getEnableLabel());
+ }
+
+ public function testGetDescription() {
+ $this->assertEquals('Similar to the high contrast mode, but with dark colours.', $this->theme->getDescription());
+ }
+
+ public function testGetMediaQuery() {
+ $this->assertEquals('(prefers-color-scheme: dark) and (prefers-contrast: more)', $this->theme->getMediaQuery());
+ }
+}