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.

194 lines
5.6 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  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\IConfig;
  35. use OCP\IL10N;
  36. use OCP\IURLGenerator;
  37. use Test\TestCase;
  38. class AdminTest extends TestCase {
  39. /** @var Admin */
  40. private $admin;
  41. /** @var IConfig */
  42. private $config;
  43. /** @var ThemingDefaults */
  44. private $themingDefaults;
  45. /** @var IURLGenerator */
  46. private $urlGenerator;
  47. /** @var ImageManager */
  48. private $imageManager;
  49. /** @var IL10N */
  50. private $l10n;
  51. protected function setUp(): void {
  52. parent::setUp();
  53. $this->config = $this->createMock(IConfig::class);
  54. $this->l10n = $this->createMock(IL10N::class);
  55. $this->themingDefaults = $this->createMock(ThemingDefaults::class);
  56. $this->urlGenerator = $this->createMock(IURLGenerator::class);
  57. $this->imageManager = $this->createMock(ImageManager::class);
  58. $this->admin = new Admin(
  59. Application::APP_ID,
  60. $this->config,
  61. $this->l10n,
  62. $this->themingDefaults,
  63. $this->urlGenerator,
  64. $this->imageManager
  65. );
  66. }
  67. public function testGetFormNoErrors() {
  68. $this->config
  69. ->expects($this->once())
  70. ->method('getSystemValue')
  71. ->with('theme', '')
  72. ->willReturn('');
  73. $this->themingDefaults
  74. ->expects($this->once())
  75. ->method('getEntity')
  76. ->willReturn('MyEntity');
  77. $this->themingDefaults
  78. ->expects($this->once())
  79. ->method('getBaseUrl')
  80. ->willReturn('https://example.com');
  81. $this->themingDefaults
  82. ->expects($this->once())
  83. ->method('getImprintUrl')
  84. ->willReturn('');
  85. $this->themingDefaults
  86. ->expects($this->once())
  87. ->method('getPrivacyUrl')
  88. ->willReturn('');
  89. $this->themingDefaults
  90. ->expects($this->once())
  91. ->method('getSlogan')
  92. ->willReturn('MySlogan');
  93. $this->themingDefaults
  94. ->expects($this->once())
  95. ->method('getDefaultColorPrimary')
  96. ->willReturn('#fff');
  97. $this->urlGenerator
  98. ->expects($this->once())
  99. ->method('linkToRoute')
  100. ->with('theming.Theming.uploadImage')
  101. ->willReturn('/my/route');
  102. $params = [
  103. 'themable' => true,
  104. 'errorMessage' => '',
  105. 'name' => 'MyEntity',
  106. 'url' => 'https://example.com',
  107. 'slogan' => 'MySlogan',
  108. 'color' => '#fff',
  109. 'uploadLogoRoute' => '/my/route',
  110. 'canThemeIcons' => null,
  111. 'iconDocs' => null,
  112. 'images' => [],
  113. 'imprintUrl' => '',
  114. 'privacyUrl' => '',
  115. 'userThemingDisabled' => false,
  116. ];
  117. $expected = new TemplateResponse('theming', 'settings-admin', $params, '');
  118. $this->assertEquals($expected, $this->admin->getForm());
  119. }
  120. public function testGetFormWithErrors() {
  121. $this->config
  122. ->expects($this->once())
  123. ->method('getSystemValue')
  124. ->with('theme', '')
  125. ->willReturn('MyCustomTheme');
  126. $this->l10n
  127. ->expects($this->once())
  128. ->method('t')
  129. ->with('You are already using a custom theme. Theming app settings might be overwritten by that.')
  130. ->willReturn('You are already using a custom theme. Theming app settings might be overwritten by that.');
  131. $this->themingDefaults
  132. ->expects($this->once())
  133. ->method('getEntity')
  134. ->willReturn('MyEntity');
  135. $this->themingDefaults
  136. ->expects($this->once())
  137. ->method('getBaseUrl')
  138. ->willReturn('https://example.com');
  139. $this->themingDefaults
  140. ->expects($this->once())
  141. ->method('getImprintUrl')
  142. ->willReturn('');
  143. $this->themingDefaults
  144. ->expects($this->once())
  145. ->method('getPrivacyUrl')
  146. ->willReturn('');
  147. $this->themingDefaults
  148. ->expects($this->once())
  149. ->method('getSlogan')
  150. ->willReturn('MySlogan');
  151. $this->themingDefaults
  152. ->expects($this->once())
  153. ->method('getDefaultColorPrimary')
  154. ->willReturn('#fff');
  155. $this->urlGenerator
  156. ->expects($this->once())
  157. ->method('linkToRoute')
  158. ->with('theming.Theming.uploadImage')
  159. ->willReturn('/my/route');
  160. $params = [
  161. 'themable' => false,
  162. 'errorMessage' => 'You are already using a custom theme. Theming app settings might be overwritten by that.',
  163. 'name' => 'MyEntity',
  164. 'url' => 'https://example.com',
  165. 'slogan' => 'MySlogan',
  166. 'color' => '#fff',
  167. 'uploadLogoRoute' => '/my/route',
  168. 'canThemeIcons' => null,
  169. 'iconDocs' => '',
  170. 'images' => [],
  171. 'imprintUrl' => '',
  172. 'privacyUrl' => '',
  173. 'userThemingDisabled' => false
  174. ];
  175. $expected = new TemplateResponse('theming', 'settings-admin', $params, '');
  176. $this->assertEquals($expected, $this->admin->getForm());
  177. }
  178. public function testGetSection() {
  179. $this->assertSame('theming', $this->admin->getSection());
  180. }
  181. public function testGetPriority() {
  182. $this->assertSame(5, $this->admin->getPriority());
  183. }
  184. }