You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PersonalTest.php 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Jan-Christoph Borchardt <hey@jancborchardt.net>
  7. * @author Julius Härtl <jus@bitgrid.net>
  8. * @author Lukas Reschke <lukas@statuscode.ch>
  9. * @author Morris Jobke <hey@morrisjobke.de>
  10. * @author Roeland Jago Douma <roeland@famdouma.nl>
  11. *
  12. * @license GNU AGPL version 3 or any later version
  13. *
  14. * This program is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License as
  16. * published by the Free Software Foundation, either version 3 of the
  17. * License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU Affero General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Affero General Public License
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  26. *
  27. */
  28. namespace OCA\Theming\Tests\Settings;
  29. use OCA\Theming\AppInfo\Application;
  30. use OCA\Theming\ImageManager;
  31. use OCA\Theming\Service\ThemesService;
  32. use OCA\Theming\Settings\Personal;
  33. use OCA\Theming\Themes\DarkHighContrastTheme;
  34. use OCA\Theming\Themes\DarkTheme;
  35. use OCA\Theming\Themes\DefaultTheme;
  36. use OCA\Theming\Themes\DyslexiaFont;
  37. use OCA\Theming\Themes\HighContrastTheme;
  38. use OCA\Theming\Themes\LightTheme;
  39. use OCA\Theming\ThemingDefaults;
  40. use OCA\Theming\Util;
  41. use OCA\Theming\ITheme;
  42. use OCP\App\IAppManager;
  43. use OCP\AppFramework\Http\TemplateResponse;
  44. use OCP\AppFramework\Services\IInitialState;
  45. use OCP\IConfig;
  46. use OCP\IL10N;
  47. use OCP\IURLGenerator;
  48. use OCP\IUserSession;
  49. use Test\TestCase;
  50. class PersonalTest extends TestCase {
  51. private IConfig $config;
  52. private ThemesService $themesService;
  53. private IInitialState $initialStateService;
  54. private ThemingDefaults $themingDefaults;
  55. private IAppManager $appManager;
  56. private Personal $admin;
  57. /** @var ITheme[] */
  58. private $themes;
  59. protected function setUp(): void {
  60. parent::setUp();
  61. $this->config = $this->createMock(IConfig::class);
  62. $this->themesService = $this->createMock(ThemesService::class);
  63. $this->initialStateService = $this->createMock(IInitialState::class);
  64. $this->themingDefaults = $this->createMock(ThemingDefaults::class);
  65. $this->appManager = $this->createMock(IAppManager::class);
  66. $this->initThemes();
  67. $this->themesService
  68. ->expects($this->any())
  69. ->method('getThemes')
  70. ->willReturn($this->themes);
  71. $this->admin = new Personal(
  72. Application::APP_ID,
  73. 'admin',
  74. $this->config,
  75. $this->themesService,
  76. $this->initialStateService,
  77. $this->themingDefaults,
  78. $this->appManager,
  79. );
  80. }
  81. public function dataTestGetForm() {
  82. return [
  83. ['', [
  84. $this->formatThemeForm('default'),
  85. $this->formatThemeForm('light'),
  86. $this->formatThemeForm('dark'),
  87. $this->formatThemeForm('light-highcontrast'),
  88. $this->formatThemeForm('dark-highcontrast'),
  89. $this->formatThemeForm('opendyslexic'),
  90. ]],
  91. ['dark', [
  92. $this->formatThemeForm('dark'),
  93. $this->formatThemeForm('opendyslexic'),
  94. ]],
  95. ];
  96. }
  97. /**
  98. * @dataProvider dataTestGetForm
  99. *
  100. * @param string $toEnable
  101. * @param string[] $enabledThemes
  102. */
  103. public function testGetForm(string $enforcedTheme, $themesState) {
  104. $this->config->expects($this->once())
  105. ->method('getSystemValueString')
  106. ->with('enforce_theme', '')
  107. ->willReturn($enforcedTheme);
  108. $this->appManager->expects($this->once())
  109. ->method('getDefaultAppForUser')
  110. ->willReturn('forcedapp');
  111. $this->initialStateService->expects($this->exactly(4))
  112. ->method('provideInitialState')
  113. ->withConsecutive(
  114. ['themes', $themesState],
  115. ['enforceTheme', $enforcedTheme],
  116. ['isUserThemingDisabled', false],
  117. ['enforcedDefaultApp', 'forcedapp'],
  118. );
  119. $expected = new TemplateResponse('theming', 'settings-personal');
  120. $this->assertEquals($expected, $this->admin->getForm());
  121. }
  122. public function testGetSection() {
  123. $this->assertSame('theming', $this->admin->getSection());
  124. }
  125. public function testGetPriority() {
  126. $this->assertSame(40, $this->admin->getPriority());
  127. }
  128. private function initThemes() {
  129. $util = $this->createMock(Util::class);
  130. $themingDefaults = $this->createMock(ThemingDefaults::class);
  131. $userSession = $this->createMock(IUserSession::class);
  132. $urlGenerator = $this->createMock(IURLGenerator::class);
  133. $imageManager = $this->createMock(ImageManager::class);
  134. $config = $this->createMock(IConfig::class);
  135. $l10n = $this->createMock(IL10N::class);
  136. $appManager = $this->createMock(IAppManager::class);
  137. $themingDefaults->expects($this->any())
  138. ->method('getColorPrimary')
  139. ->willReturn('#0082c9');
  140. $themingDefaults->expects($this->any())
  141. ->method('getDefaultColorPrimary')
  142. ->willReturn('#0082c9');
  143. $this->themes = [
  144. 'default' => new DefaultTheme(
  145. $util,
  146. $themingDefaults,
  147. $userSession,
  148. $urlGenerator,
  149. $imageManager,
  150. $config,
  151. $l10n,
  152. $appManager,
  153. ),
  154. 'light' => new LightTheme(
  155. $util,
  156. $themingDefaults,
  157. $userSession,
  158. $urlGenerator,
  159. $imageManager,
  160. $config,
  161. $l10n,
  162. $appManager,
  163. ),
  164. 'dark' => new DarkTheme(
  165. $util,
  166. $themingDefaults,
  167. $userSession,
  168. $urlGenerator,
  169. $imageManager,
  170. $config,
  171. $l10n,
  172. $appManager,
  173. ),
  174. 'light-highcontrast' => new HighContrastTheme(
  175. $util,
  176. $themingDefaults,
  177. $userSession,
  178. $urlGenerator,
  179. $imageManager,
  180. $config,
  181. $l10n,
  182. $appManager,
  183. ),
  184. 'dark-highcontrast' => new DarkHighContrastTheme(
  185. $util,
  186. $themingDefaults,
  187. $userSession,
  188. $urlGenerator,
  189. $imageManager,
  190. $config,
  191. $l10n,
  192. $appManager,
  193. ),
  194. 'opendyslexic' => new DyslexiaFont(
  195. $util,
  196. $themingDefaults,
  197. $userSession,
  198. $urlGenerator,
  199. $imageManager,
  200. $config,
  201. $l10n,
  202. $appManager,
  203. ),
  204. ];
  205. }
  206. private function formatThemeForm(string $themeId): array {
  207. $this->initThemes();
  208. $theme = $this->themes[$themeId];
  209. return [
  210. 'id' => $theme->getId(),
  211. 'type' => $theme->getType(),
  212. 'title' => $theme->getTitle(),
  213. 'enableLabel' => $theme->getEnableLabel(),
  214. 'description' => $theme->getDescription(),
  215. 'enabled' => false,
  216. ];
  217. }
  218. }