DarkThemeTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 PHPUnit\Framework\MockObject\MockObject;
  21. class DarkThemeTest 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. protected function setUp(): void {
  37. $this->themingDefaults = $this->createMock(ThemingDefaults::class);
  38. $this->userSession = $this->createMock(IUserSession::class);
  39. $this->urlGenerator = $this->createMock(IURLGenerator::class);
  40. $this->imageManager = $this->createMock(ImageManager::class);
  41. $this->config = $this->createMock(IConfig::class);
  42. $this->l10n = $this->createMock(IL10N::class);
  43. $this->appManager = $this->createMock(IAppManager::class);
  44. $this->util = new Util(
  45. $this->config,
  46. $this->appManager,
  47. $this->createMock(IAppData::class),
  48. $this->imageManager
  49. );
  50. $this->themingDefaults
  51. ->expects($this->any())
  52. ->method('getColorPrimary')
  53. ->willReturn('#0082c9');
  54. $this->themingDefaults
  55. ->expects($this->any())
  56. ->method('getDefaultColorPrimary')
  57. ->willReturn('#0082c9');
  58. $this->themingDefaults
  59. ->expects($this->any())
  60. ->method('getColorBackground')
  61. ->willReturn('#0082c9');
  62. $this->themingDefaults
  63. ->expects($this->any())
  64. ->method('getDefaultColorBackground')
  65. ->willReturn('#0082c9');
  66. $this->themingDefaults
  67. ->expects($this->any())
  68. ->method('getBackground')
  69. ->willReturn('/apps/' . Application::APP_ID . '/img/background/' . BackgroundService::DEFAULT_BACKGROUND_IMAGE);
  70. $this->l10n
  71. ->expects($this->any())
  72. ->method('t')
  73. ->willReturnCallback(function ($text, $parameters = []) {
  74. return vsprintf($text, $parameters);
  75. });
  76. $this->urlGenerator
  77. ->expects($this->any())
  78. ->method('imagePath')
  79. ->willReturnCallback(function ($app = 'core', $filename = '') {
  80. return "/$app/img/$filename";
  81. });
  82. $this->theme = new DarkTheme(
  83. $this->util,
  84. $this->themingDefaults,
  85. $this->userSession,
  86. $this->urlGenerator,
  87. $this->imageManager,
  88. $this->config,
  89. $this->l10n,
  90. $this->appManager,
  91. null,
  92. );
  93. parent::setUp();
  94. }
  95. public function testGetId(): void {
  96. $this->assertEquals('dark', $this->theme->getId());
  97. }
  98. public function testGetType(): void {
  99. $this->assertEquals(ITheme::TYPE_THEME, $this->theme->getType());
  100. }
  101. public function testGetTitle(): void {
  102. $this->assertEquals('Dark theme', $this->theme->getTitle());
  103. }
  104. public function testGetEnableLabel(): void {
  105. $this->assertEquals('Enable dark theme', $this->theme->getEnableLabel());
  106. }
  107. public function testGetDescription(): void {
  108. $this->assertEquals('A dark theme to ease your eyes by reducing the overall luminosity and brightness.', $this->theme->getDescription());
  109. }
  110. public function testGetMediaQuery(): void {
  111. $this->assertEquals('(prefers-color-scheme: dark)', $this->theme->getMediaQuery());
  112. }
  113. public function testGetCustomCss(): void {
  114. $this->assertEquals('', $this->theme->getCustomCss());
  115. }
  116. }