AdminTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\Theming\Tests\Settings;
  7. use OCA\Theming\AppInfo\Application;
  8. use OCA\Theming\ImageManager;
  9. use OCA\Theming\Settings\Admin;
  10. use OCA\Theming\ThemingDefaults;
  11. use OCP\AppFramework\Http\TemplateResponse;
  12. use OCP\AppFramework\Services\IInitialState;
  13. use OCP\IConfig;
  14. use OCP\IL10N;
  15. use OCP\INavigationManager;
  16. use OCP\IURLGenerator;
  17. use Test\TestCase;
  18. class AdminTest extends TestCase {
  19. private Admin $admin;
  20. private IConfig $config;
  21. private ThemingDefaults $themingDefaults;
  22. private IInitialState $initialState;
  23. private IURLGenerator $urlGenerator;
  24. private ImageManager $imageManager;
  25. private IL10N $l10n;
  26. private INavigationManager $navigationManager;
  27. protected function setUp(): void {
  28. parent::setUp();
  29. $this->config = $this->createMock(IConfig::class);
  30. $this->l10n = $this->createMock(IL10N::class);
  31. $this->themingDefaults = $this->createMock(ThemingDefaults::class);
  32. $this->initialState = $this->createMock(IInitialState::class);
  33. $this->urlGenerator = $this->createMock(IURLGenerator::class);
  34. $this->imageManager = $this->createMock(ImageManager::class);
  35. $this->navigationManager = $this->createMock(INavigationManager::class);
  36. $this->admin = new Admin(
  37. Application::APP_ID,
  38. $this->config,
  39. $this->l10n,
  40. $this->themingDefaults,
  41. $this->initialState,
  42. $this->urlGenerator,
  43. $this->imageManager,
  44. $this->navigationManager,
  45. );
  46. }
  47. public function testGetFormNoErrors(): void {
  48. $this->config
  49. ->expects($this->once())
  50. ->method('getSystemValue')
  51. ->with('theme', '')
  52. ->willReturn('');
  53. $this->themingDefaults
  54. ->expects($this->once())
  55. ->method('getEntity')
  56. ->willReturn('MyEntity');
  57. $this->themingDefaults
  58. ->expects($this->once())
  59. ->method('getBaseUrl')
  60. ->willReturn('https://example.com');
  61. $this->themingDefaults
  62. ->expects($this->once())
  63. ->method('getImprintUrl')
  64. ->willReturn('');
  65. $this->themingDefaults
  66. ->expects($this->once())
  67. ->method('getPrivacyUrl')
  68. ->willReturn('');
  69. $this->themingDefaults
  70. ->expects($this->once())
  71. ->method('getSlogan')
  72. ->willReturn('MySlogan');
  73. $this->themingDefaults
  74. ->expects($this->once())
  75. ->method('getDefaultColorPrimary')
  76. ->willReturn('#fff');
  77. $expected = new TemplateResponse('theming', 'settings-admin');
  78. $this->assertEquals($expected, $this->admin->getForm());
  79. }
  80. public function testGetFormWithErrors(): void {
  81. $this->config
  82. ->expects($this->once())
  83. ->method('getSystemValue')
  84. ->with('theme', '')
  85. ->willReturn('MyCustomTheme');
  86. $this->l10n
  87. ->expects($this->once())
  88. ->method('t')
  89. ->with('You are already using a custom theme. Theming app settings might be overwritten by that.')
  90. ->willReturn('You are already using a custom theme. Theming app settings might be overwritten by that.');
  91. $this->themingDefaults
  92. ->expects($this->once())
  93. ->method('getEntity')
  94. ->willReturn('MyEntity');
  95. $this->themingDefaults
  96. ->expects($this->once())
  97. ->method('getBaseUrl')
  98. ->willReturn('https://example.com');
  99. $this->themingDefaults
  100. ->expects($this->once())
  101. ->method('getImprintUrl')
  102. ->willReturn('');
  103. $this->themingDefaults
  104. ->expects($this->once())
  105. ->method('getPrivacyUrl')
  106. ->willReturn('');
  107. $this->themingDefaults
  108. ->expects($this->once())
  109. ->method('getSlogan')
  110. ->willReturn('MySlogan');
  111. $this->themingDefaults
  112. ->expects($this->once())
  113. ->method('getDefaultColorPrimary')
  114. ->willReturn('#fff');
  115. $expected = new TemplateResponse('theming', 'settings-admin');
  116. $this->assertEquals($expected, $this->admin->getForm());
  117. }
  118. public function testGetSection(): void {
  119. $this->assertSame('theming', $this->admin->getSection());
  120. }
  121. public function testGetPriority(): void {
  122. $this->assertSame(5, $this->admin->getPriority());
  123. }
  124. }