AdminTest.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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\Settings\Admin;
  32. use OCA\Theming\ThemingDefaults;
  33. use OCP\AppFramework\Http\TemplateResponse;
  34. use OCP\AppFramework\Services\IInitialState;
  35. use OCP\IConfig;
  36. use OCP\IL10N;
  37. use OCP\IURLGenerator;
  38. use Test\TestCase;
  39. class AdminTest extends TestCase {
  40. private Admin $admin;
  41. private IConfig $config;
  42. private ThemingDefaults $themingDefaults;
  43. private IInitialState $initialState;
  44. private IURLGenerator $urlGenerator;
  45. private ImageManager $imageManager;
  46. private IL10N $l10n;
  47. protected function setUp(): void {
  48. parent::setUp();
  49. $this->config = $this->createMock(IConfig::class);
  50. $this->l10n = $this->createMock(IL10N::class);
  51. $this->themingDefaults = $this->createMock(ThemingDefaults::class);
  52. $this->initialState = $this->createMock(IInitialState::class);
  53. $this->urlGenerator = $this->createMock(IURLGenerator::class);
  54. $this->imageManager = $this->createMock(ImageManager::class);
  55. $this->admin = new Admin(
  56. Application::APP_ID,
  57. $this->config,
  58. $this->l10n,
  59. $this->themingDefaults,
  60. $this->initialState,
  61. $this->urlGenerator,
  62. $this->imageManager
  63. );
  64. }
  65. public function testGetFormNoErrors() {
  66. $this->config
  67. ->expects($this->once())
  68. ->method('getSystemValue')
  69. ->with('theme', '')
  70. ->willReturn('');
  71. $this->themingDefaults
  72. ->expects($this->once())
  73. ->method('getEntity')
  74. ->willReturn('MyEntity');
  75. $this->themingDefaults
  76. ->expects($this->once())
  77. ->method('getBaseUrl')
  78. ->willReturn('https://example.com');
  79. $this->themingDefaults
  80. ->expects($this->once())
  81. ->method('getImprintUrl')
  82. ->willReturn('');
  83. $this->themingDefaults
  84. ->expects($this->once())
  85. ->method('getPrivacyUrl')
  86. ->willReturn('');
  87. $this->themingDefaults
  88. ->expects($this->once())
  89. ->method('getSlogan')
  90. ->willReturn('MySlogan');
  91. $this->themingDefaults
  92. ->expects($this->once())
  93. ->method('getDefaultColorPrimary')
  94. ->willReturn('#fff');
  95. $expected = new TemplateResponse('theming', 'settings-admin');
  96. $this->assertEquals($expected, $this->admin->getForm());
  97. }
  98. public function testGetFormWithErrors() {
  99. $this->config
  100. ->expects($this->once())
  101. ->method('getSystemValue')
  102. ->with('theme', '')
  103. ->willReturn('MyCustomTheme');
  104. $this->l10n
  105. ->expects($this->once())
  106. ->method('t')
  107. ->with('You are already using a custom theme. Theming app settings might be overwritten by that.')
  108. ->willReturn('You are already using a custom theme. Theming app settings might be overwritten by that.');
  109. $this->themingDefaults
  110. ->expects($this->once())
  111. ->method('getEntity')
  112. ->willReturn('MyEntity');
  113. $this->themingDefaults
  114. ->expects($this->once())
  115. ->method('getBaseUrl')
  116. ->willReturn('https://example.com');
  117. $this->themingDefaults
  118. ->expects($this->once())
  119. ->method('getImprintUrl')
  120. ->willReturn('');
  121. $this->themingDefaults
  122. ->expects($this->once())
  123. ->method('getPrivacyUrl')
  124. ->willReturn('');
  125. $this->themingDefaults
  126. ->expects($this->once())
  127. ->method('getSlogan')
  128. ->willReturn('MySlogan');
  129. $this->themingDefaults
  130. ->expects($this->once())
  131. ->method('getDefaultColorPrimary')
  132. ->willReturn('#fff');
  133. $expected = new TemplateResponse('theming', 'settings-admin');
  134. $this->assertEquals($expected, $this->admin->getForm());
  135. }
  136. public function testGetSection() {
  137. $this->assertSame('theming', $this->admin->getSection());
  138. }
  139. public function testGetPriority() {
  140. $this->assertSame(5, $this->admin->getPriority());
  141. }
  142. }