DarkThemeTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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\DarkTheme;
  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 DarkThemeTest 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. protected function setUp(): void {
  38. $this->themingDefaults = $this->createMock(ThemingDefaults::class);
  39. $this->userSession = $this->createMock(IUserSession::class);
  40. $this->urlGenerator = $this->createMock(IURLGenerator::class);
  41. $this->imageManager = $this->createMock(ImageManager::class);
  42. $this->config = $this->createMock(IConfig::class);
  43. $this->l10n = $this->createMock(IL10N::class);
  44. $this->appManager = $this->createMock(IAppManager::class);
  45. $this->util = new Util(
  46. $this->createMock(ServerVersion::class),
  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 DarkTheme(
  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('dark', $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('Dark theme', $this->theme->getTitle());
  105. }
  106. public function testGetEnableLabel(): void {
  107. $this->assertEquals('Enable dark theme', $this->theme->getEnableLabel());
  108. }
  109. public function testGetDescription(): void {
  110. $this->assertEquals('A dark theme to ease your eyes by reducing the overall luminosity and brightness.', $this->theme->getDescription());
  111. }
  112. public function testGetMediaQuery(): void {
  113. $this->assertEquals('(prefers-color-scheme: dark)', $this->theme->getMediaQuery());
  114. }
  115. public function testGetCustomCss(): void {
  116. $this->assertEquals('', $this->theme->getCustomCss());
  117. }
  118. }