DarkHighContrastThemeTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\Theming\Tests\Themes;
  7. use OCA\Theming\AppInfo\Application;
  8. use OCA\Theming\ImageManager;
  9. use OCA\Theming\ITheme;
  10. use OCA\Theming\Service\BackgroundService;
  11. use OCA\Theming\Themes\DarkHighContrastTheme;
  12. use OCA\Theming\ThemingDefaults;
  13. use OCA\Theming\Util;
  14. use OCP\App\IAppManager;
  15. use OCP\Files\IAppData;
  16. use OCP\IConfig;
  17. use OCP\IL10N;
  18. use OCP\IURLGenerator;
  19. use OCP\IUserSession;
  20. use OCP\ServerVersion;
  21. use PHPUnit\Framework\MockObject\MockObject;
  22. class DarkHighContrastThemeTest extends AccessibleThemeTestCase {
  23. /** @var ThemingDefaults|MockObject */
  24. private $themingDefaults;
  25. /** @var IUserSession|MockObject */
  26. private $userSession;
  27. /** @var IURLGenerator|MockObject */
  28. private $urlGenerator;
  29. /** @var ImageManager|MockObject */
  30. private $imageManager;
  31. /** @var IConfig|MockObject */
  32. private $config;
  33. /** @var IL10N|MockObject */
  34. private $l10n;
  35. /** @var IAppManager|MockObject */
  36. private $appManager;
  37. // !! important: Enable WCAG AAA tests
  38. protected bool $WCAGaaa = true;
  39. protected function setUp(): void {
  40. $this->themingDefaults = $this->createMock(ThemingDefaults::class);
  41. $this->userSession = $this->createMock(IUserSession::class);
  42. $this->urlGenerator = $this->createMock(IURLGenerator::class);
  43. $this->imageManager = $this->createMock(ImageManager::class);
  44. $this->config = $this->createMock(IConfig::class);
  45. $this->l10n = $this->createMock(IL10N::class);
  46. $this->appManager = $this->createMock(IAppManager::class);
  47. $this->util = new Util(
  48. $this->createMock(ServerVersion::class),
  49. $this->config,
  50. $this->appManager,
  51. $this->createMock(IAppData::class),
  52. $this->imageManager
  53. );
  54. $this->themingDefaults
  55. ->expects($this->any())
  56. ->method('getColorPrimary')
  57. ->willReturn('#0082c9');
  58. $this->themingDefaults
  59. ->expects($this->any())
  60. ->method('getDefaultColorPrimary')
  61. ->willReturn('#0082c9');
  62. $this->themingDefaults
  63. ->expects($this->any())
  64. ->method('getColorBackground')
  65. ->willReturn('#0082c9');
  66. $this->themingDefaults
  67. ->expects($this->any())
  68. ->method('getDefaultColorBackground')
  69. ->willReturn('#0082c9');
  70. $this->themingDefaults
  71. ->expects($this->any())
  72. ->method('getBackground')
  73. ->willReturn('/apps/' . Application::APP_ID . '/img/background/' . BackgroundService::DEFAULT_BACKGROUND_IMAGE);
  74. $this->l10n
  75. ->expects($this->any())
  76. ->method('t')
  77. ->willReturnCallback(function ($text, $parameters = []) {
  78. return vsprintf($text, $parameters);
  79. });
  80. $this->urlGenerator
  81. ->expects($this->any())
  82. ->method('imagePath')
  83. ->willReturnCallback(function ($app = 'core', $filename = '') {
  84. return "/$app/img/$filename";
  85. });
  86. $this->theme = new DarkHighContrastTheme(
  87. $this->util,
  88. $this->themingDefaults,
  89. $this->userSession,
  90. $this->urlGenerator,
  91. $this->imageManager,
  92. $this->config,
  93. $this->l10n,
  94. $this->appManager,
  95. null,
  96. );
  97. parent::setUp();
  98. }
  99. public function testGetId(): void {
  100. $this->assertEquals('dark-highcontrast', $this->theme->getId());
  101. }
  102. public function testGetType(): void {
  103. $this->assertEquals(ITheme::TYPE_THEME, $this->theme->getType());
  104. }
  105. public function testGetTitle(): void {
  106. $this->assertEquals('Dark theme with high contrast mode', $this->theme->getTitle());
  107. }
  108. public function testGetEnableLabel(): void {
  109. $this->assertEquals('Enable dark high contrast mode', $this->theme->getEnableLabel());
  110. }
  111. public function testGetDescription(): void {
  112. $this->assertEquals('Similar to the high contrast mode, but with dark colours.', $this->theme->getDescription());
  113. }
  114. public function testGetMediaQuery(): void {
  115. $this->assertEquals('(prefers-color-scheme: dark) and (prefers-contrast: more)', $this->theme->getMediaQuery());
  116. }
  117. }