HighContrastThemeTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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\HighContrastTheme;
  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 PHPUnit\Framework\MockObject\MockObject;
  21. class HighContrastThemeTest extends AccessibleThemeTestCase {
  22. /** @var ThemingDefaults|MockObject */
  23. private $themingDefaults;
  24. /** @var IUserSession|MockObject */
  25. private $userSession;
  26. /** @var IURLGenerator|MockObject */
  27. private $urlGenerator;
  28. /** @var ImageManager|MockObject */
  29. private $imageManager;
  30. /** @var IConfig|MockObject */
  31. private $config;
  32. /** @var IL10N|MockObject */
  33. private $l10n;
  34. /** @var IAppManager|MockObject */
  35. private $appManager;
  36. // !! important: Enable WCAG AAA tests
  37. protected bool $WCAGaaa = true;
  38. protected function setUp(): void {
  39. $this->themingDefaults = $this->createMock(ThemingDefaults::class);
  40. $this->userSession = $this->createMock(IUserSession::class);
  41. $this->urlGenerator = $this->createMock(IURLGenerator::class);
  42. $this->imageManager = $this->createMock(ImageManager::class);
  43. $this->config = $this->createMock(IConfig::class);
  44. $this->l10n = $this->createMock(IL10N::class);
  45. $this->appManager = $this->createMock(IAppManager::class);
  46. $this->util = new Util(
  47. $this->config,
  48. $this->appManager,
  49. $this->createMock(IAppData::class),
  50. $this->imageManager
  51. );
  52. $this->themingDefaults
  53. ->expects($this->any())
  54. ->method('getColorPrimary')
  55. ->willReturn('#0082c9');
  56. $this->themingDefaults
  57. ->expects($this->any())
  58. ->method('getDefaultColorPrimary')
  59. ->willReturn('#0082c9');
  60. $this->themingDefaults
  61. ->expects($this->any())
  62. ->method('getColorBackground')
  63. ->willReturn('#0082c9');
  64. $this->themingDefaults
  65. ->expects($this->any())
  66. ->method('getDefaultColorBackground')
  67. ->willReturn('#0082c9');
  68. $this->themingDefaults
  69. ->expects($this->any())
  70. ->method('getBackground')
  71. ->willReturn('/apps/' . Application::APP_ID . '/img/background/' . BackgroundService::DEFAULT_BACKGROUND_IMAGE);
  72. $this->l10n
  73. ->expects($this->any())
  74. ->method('t')
  75. ->willReturnCallback(function ($text, $parameters = []) {
  76. return vsprintf($text, $parameters);
  77. });
  78. $this->urlGenerator
  79. ->expects($this->any())
  80. ->method('imagePath')
  81. ->willReturnCallback(function ($app = 'core', $filename = '') {
  82. return "/$app/img/$filename";
  83. });
  84. $this->theme = new HighContrastTheme(
  85. $this->util,
  86. $this->themingDefaults,
  87. $this->userSession,
  88. $this->urlGenerator,
  89. $this->imageManager,
  90. $this->config,
  91. $this->l10n,
  92. $this->appManager,
  93. null,
  94. );
  95. parent::setUp();
  96. }
  97. public function testGetId(): void {
  98. $this->assertEquals('light-highcontrast', $this->theme->getId());
  99. }
  100. public function testGetType(): void {
  101. $this->assertEquals(ITheme::TYPE_THEME, $this->theme->getType());
  102. }
  103. public function testGetTitle(): void {
  104. $this->assertEquals('High contrast mode', $this->theme->getTitle());
  105. }
  106. public function testGetEnableLabel(): void {
  107. $this->assertEquals('Enable high contrast mode', $this->theme->getEnableLabel());
  108. }
  109. public function testGetDescription(): void {
  110. $this->assertEquals('A high contrast mode to ease your navigation. Visual quality will be reduced but clarity will be increased.', $this->theme->getDescription());
  111. }
  112. public function testGetMediaQuery(): void {
  113. $this->assertEquals('(prefers-contrast: more)', $this->theme->getMediaQuery());
  114. }
  115. }