1
0

AdminTest.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
  4. *
  5. * @author iamfool <praveenraonp@gmail.com>
  6. * @author Jan-Christoph Borchardt <hey@jancborchardt.net>
  7. * @author Julius Haertl <jus@bitgrid.net>
  8. * @author Lukas Reschke <lukas@statuscode.ch>
  9. * @author Morris Jobke <hey@morrisjobke.de>
  10. *
  11. * @license GNU AGPL version 3 or any later version
  12. *
  13. * This program is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License as
  15. * published by the Free Software Foundation, either version 3 of the
  16. * License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  25. *
  26. */
  27. namespace OCA\Theming\Tests\Settings;
  28. use OCA\Theming\Settings\Admin;
  29. use OCA\Theming\ThemingDefaults;
  30. use OCP\AppFramework\Http\TemplateResponse;
  31. use OCP\IConfig;
  32. use OCP\IL10N;
  33. use OCP\IURLGenerator;
  34. use Test\TestCase;
  35. class AdminTest extends TestCase {
  36. /** @var Admin */
  37. private $admin;
  38. /** @var IConfig */
  39. private $config;
  40. /** @var ThemingDefaults */
  41. private $themingDefaults;
  42. /** @var IURLGenerator */
  43. private $urlGenerator;
  44. /** @var IL10N */
  45. private $l10n;
  46. public function setUp() {
  47. parent::setUp();
  48. $this->config = $this->getMockBuilder(IConfig::class)->getMock();
  49. $this->l10n = $this->getMockBuilder(IL10N::class)->getMock();
  50. $this->themingDefaults = $this->getMockBuilder('\OCA\Theming\ThemingDefaults')->disableOriginalConstructor()->getMock();
  51. $this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)->getMock();
  52. $this->admin = new Admin(
  53. $this->config,
  54. $this->l10n,
  55. $this->themingDefaults,
  56. $this->urlGenerator
  57. );
  58. }
  59. public function testGetFormNoErrors() {
  60. $this->config
  61. ->expects($this->once())
  62. ->method('getSystemValue')
  63. ->with('theme', '')
  64. ->willReturn('');
  65. $this->themingDefaults
  66. ->expects($this->once())
  67. ->method('getEntity')
  68. ->willReturn('MyEntity');
  69. $this->themingDefaults
  70. ->expects($this->once())
  71. ->method('getBaseUrl')
  72. ->willReturn('https://example.com');
  73. $this->themingDefaults
  74. ->expects($this->once())
  75. ->method('getImprintUrl')
  76. ->willReturn('');
  77. $this->themingDefaults
  78. ->expects($this->once())
  79. ->method('getPrivacyUrl')
  80. ->willReturn('');
  81. $this->themingDefaults
  82. ->expects($this->once())
  83. ->method('getSlogan')
  84. ->willReturn('MySlogan');
  85. $this->themingDefaults
  86. ->expects($this->once())
  87. ->method('getColorPrimary')
  88. ->willReturn('#fff');
  89. $this->urlGenerator
  90. ->expects($this->once())
  91. ->method('linkToRoute')
  92. ->with('theming.Theming.updateLogo')
  93. ->willReturn('/my/route');
  94. $params = [
  95. 'themable' => true,
  96. 'errorMessage' => '',
  97. 'name' => 'MyEntity',
  98. 'url' => 'https://example.com',
  99. 'slogan' => 'MySlogan',
  100. 'color' => '#fff',
  101. 'uploadLogoRoute' => '/my/route',
  102. 'logo' => null,
  103. 'logoMime' => null,
  104. 'background' => null,
  105. 'backgroundMime' => null,
  106. 'canThemeIcons' => null,
  107. 'iconDocs' => null,
  108. 'imprintUrl' => '',
  109. 'privacyUrl' => '',
  110. ];
  111. $expected = new TemplateResponse('theming', 'settings-admin', $params, '');
  112. $this->assertEquals($expected, $this->admin->getForm());
  113. }
  114. public function testGetFormWithErrors() {
  115. $this->config
  116. ->expects($this->once())
  117. ->method('getSystemValue')
  118. ->with('theme', '')
  119. ->willReturn('MyCustomTheme');
  120. $this->l10n
  121. ->expects($this->once())
  122. ->method('t')
  123. ->with('You are already using a custom theme')
  124. ->willReturn('You are already using a custom theme');
  125. $this->themingDefaults
  126. ->expects($this->once())
  127. ->method('getEntity')
  128. ->willReturn('MyEntity');
  129. $this->themingDefaults
  130. ->expects($this->once())
  131. ->method('getBaseUrl')
  132. ->willReturn('https://example.com');
  133. $this->themingDefaults
  134. ->expects($this->once())
  135. ->method('getImprintUrl')
  136. ->willReturn('');
  137. $this->themingDefaults
  138. ->expects($this->once())
  139. ->method('getPrivacyUrl')
  140. ->willReturn('');
  141. $this->themingDefaults
  142. ->expects($this->once())
  143. ->method('getSlogan')
  144. ->willReturn('MySlogan');
  145. $this->themingDefaults
  146. ->expects($this->once())
  147. ->method('getColorPrimary')
  148. ->willReturn('#fff');
  149. $this->urlGenerator
  150. ->expects($this->once())
  151. ->method('linkToRoute')
  152. ->with('theming.Theming.updateLogo')
  153. ->willReturn('/my/route');
  154. $params = [
  155. 'themable' => false,
  156. 'errorMessage' => 'You are already using a custom theme',
  157. 'name' => 'MyEntity',
  158. 'url' => 'https://example.com',
  159. 'slogan' => 'MySlogan',
  160. 'color' => '#fff',
  161. 'uploadLogoRoute' => '/my/route',
  162. 'logo' => null,
  163. 'logoMime' => null,
  164. 'background' => null,
  165. 'backgroundMime' => null,
  166. 'canThemeIcons' => null,
  167. 'iconDocs' => null,
  168. 'imprintUrl' => '',
  169. 'privacyUrl' => '',
  170. ];
  171. $expected = new TemplateResponse('theming', 'settings-admin', $params, '');
  172. $this->assertEquals($expected, $this->admin->getForm());
  173. }
  174. public function testGetSection() {
  175. $this->assertSame('theming', $this->admin->getSection());
  176. }
  177. public function testGetPriority() {
  178. $this->assertSame(5, $this->admin->getPriority());
  179. }
  180. }