|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com> |
| 4 | + * |
| 5 | + * @author John Molakvoæ <skjnldsv@protonmail.com> |
| 6 | + * |
| 7 | + * @license GNU AGPL version 3 or any later version |
| 8 | + * |
| 9 | + * This program is free software: you can redistribute it and/or modify |
| 10 | + * it under the terms of the GNU Affero General Public License as |
| 11 | + * published by the Free Software Foundation, either version 3 of the |
| 12 | + * License, or (at your option) any later version. |
| 13 | + * |
| 14 | + * This program is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + * GNU Affero General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU Affero General Public License |
| 20 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | + * |
| 22 | + */ |
| 23 | +namespace OCA\Theming\Tests\Themes; |
| 24 | + |
| 25 | +use OCA\Theming\AppInfo\Application; |
| 26 | +use OCA\Theming\ImageManager; |
| 27 | +use OCA\Theming\ITheme; |
| 28 | +use OCA\Theming\Service\BackgroundService; |
| 29 | +use OCA\Theming\Themes\DarkHighContrastTheme; |
| 30 | +use OCA\Theming\ThemingDefaults; |
| 31 | +use OCA\Theming\Util; |
| 32 | +use OCP\App\IAppManager; |
| 33 | +use OCP\Files\IAppData; |
| 34 | +use OCP\IConfig; |
| 35 | +use OCP\IL10N; |
| 36 | +use OCP\IURLGenerator; |
| 37 | +use OCP\IUserSession; |
| 38 | +use PHPUnit\Framework\MockObject\MockObject; |
| 39 | + |
| 40 | +class DarkHighContrastThemeTest extends AccessibleThemeTestCase { |
| 41 | + /** @var ThemingDefaults|MockObject */ |
| 42 | + private $themingDefaults; |
| 43 | + /** @var IUserSession|MockObject */ |
| 44 | + private $userSession; |
| 45 | + /** @var IURLGenerator|MockObject */ |
| 46 | + private $urlGenerator; |
| 47 | + /** @var ImageManager|MockObject */ |
| 48 | + private $imageManager; |
| 49 | + /** @var IConfig|MockObject */ |
| 50 | + private $config; |
| 51 | + /** @var IL10N|MockObject */ |
| 52 | + private $l10n; |
| 53 | + /** @var IAppManager|MockObject */ |
| 54 | + private $appManager; |
| 55 | + |
| 56 | + // !! important: Enable WCAG AAA tests |
| 57 | + protected bool $WCAGaaa = true; |
| 58 | + |
| 59 | + protected function setUp(): void { |
| 60 | + $this->themingDefaults = $this->createMock(ThemingDefaults::class); |
| 61 | + $this->userSession = $this->createMock(IUserSession::class); |
| 62 | + $this->urlGenerator = $this->createMock(IURLGenerator::class); |
| 63 | + $this->imageManager = $this->createMock(ImageManager::class); |
| 64 | + $this->config = $this->createMock(IConfig::class); |
| 65 | + $this->l10n = $this->createMock(IL10N::class); |
| 66 | + $this->appManager = $this->createMock(IAppManager::class); |
| 67 | + |
| 68 | + $this->util = new Util( |
| 69 | + $this->config, |
| 70 | + $this->appManager, |
| 71 | + $this->createMock(IAppData::class), |
| 72 | + $this->imageManager |
| 73 | + ); |
| 74 | + |
| 75 | + $this->themingDefaults |
| 76 | + ->expects($this->any()) |
| 77 | + ->method('getColorPrimary') |
| 78 | + ->willReturn('#0082c9'); |
| 79 | + |
| 80 | + $this->themingDefaults |
| 81 | + ->expects($this->any()) |
| 82 | + ->method('getDefaultColorPrimary') |
| 83 | + ->willReturn('#0082c9'); |
| 84 | + |
| 85 | + $this->themingDefaults |
| 86 | + ->expects($this->any()) |
| 87 | + ->method('getBackground') |
| 88 | + ->willReturn('/apps/' . Application::APP_ID . '/img/background/' . BackgroundService::DEFAULT_BACKGROUND_IMAGE); |
| 89 | + |
| 90 | + $this->l10n |
| 91 | + ->expects($this->any()) |
| 92 | + ->method('t') |
| 93 | + ->willReturnCallback(function ($text, $parameters = []) { |
| 94 | + return vsprintf($text, $parameters); |
| 95 | + }); |
| 96 | + |
| 97 | + $this->urlGenerator |
| 98 | + ->expects($this->any()) |
| 99 | + ->method('imagePath') |
| 100 | + ->willReturnCallback(function ($app = 'core', $filename = '') { |
| 101 | + return "/$app/img/$filename"; |
| 102 | + }); |
| 103 | + |
| 104 | + $this->theme = new DarkHighContrastTheme( |
| 105 | + $this->util, |
| 106 | + $this->themingDefaults, |
| 107 | + $this->userSession, |
| 108 | + $this->urlGenerator, |
| 109 | + $this->imageManager, |
| 110 | + $this->config, |
| 111 | + $this->l10n, |
| 112 | + $this->appManager, |
| 113 | + ); |
| 114 | + |
| 115 | + parent::setUp(); |
| 116 | + } |
| 117 | + |
| 118 | + |
| 119 | + public function testGetId() { |
| 120 | + $this->assertEquals('dark-highcontrast', $this->theme->getId()); |
| 121 | + } |
| 122 | + |
| 123 | + public function testGetType() { |
| 124 | + $this->assertEquals(ITheme::TYPE_THEME, $this->theme->getType()); |
| 125 | + } |
| 126 | + |
| 127 | + public function testGetTitle() { |
| 128 | + $this->assertEquals('Dark theme with high contrast mode', $this->theme->getTitle()); |
| 129 | + } |
| 130 | + |
| 131 | + public function testGetEnableLabel() { |
| 132 | + $this->assertEquals('Enable dark high contrast mode', $this->theme->getEnableLabel()); |
| 133 | + } |
| 134 | + |
| 135 | + public function testGetDescription() { |
| 136 | + $this->assertEquals('Similar to the high contrast mode, but with dark colours.', $this->theme->getDescription()); |
| 137 | + } |
| 138 | + |
| 139 | + public function testGetMediaQuery() { |
| 140 | + $this->assertEquals('(prefers-color-scheme: dark) and (prefers-contrast: more)', $this->theme->getMediaQuery()); |
| 141 | + } |
| 142 | +} |
0 commit comments