1
0

DarkThemeTest.php 4.1 KB

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