1
0

CapabilitiesTest.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Guillaume COMPAGNON <gcompagnon@outlook.com>
  7. * @author Jan-Christoph Borchardt <hey@jancborchardt.net>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author Julius Härtl <jus@bitgrid.net>
  10. * @author Morris Jobke <hey@morrisjobke.de>
  11. * @author Roeland Jago Douma <roeland@famdouma.nl>
  12. *
  13. * @license GNU AGPL version 3 or any later version
  14. *
  15. * This program is free software: you can redistribute it and/or modify
  16. * it under the terms of the GNU Affero General Public License as
  17. * published by the Free Software Foundation, either version 3 of the
  18. * License, or (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Affero General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Affero General Public License
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  27. *
  28. */
  29. namespace OCA\Theming\Tests;
  30. use OCA\Theming\Capabilities;
  31. use OCA\Theming\ImageManager;
  32. use OCA\Theming\ThemingDefaults;
  33. use OCA\Theming\Util;
  34. use OCP\App\IAppManager;
  35. use OCP\Files\IAppData;
  36. use OCP\IConfig;
  37. use OCP\IURLGenerator;
  38. use OCP\IUserSession;
  39. use Test\TestCase;
  40. /**
  41. * Class CapabilitiesTest
  42. *
  43. * @package OCA\Theming\Tests
  44. */
  45. class CapabilitiesTest extends TestCase {
  46. /** @var ThemingDefaults|\PHPUnit\Framework\MockObject\MockObject */
  47. protected $theming;
  48. /** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
  49. protected $url;
  50. /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
  51. protected $config;
  52. /** @var Util|\PHPUnit\Framework\MockObject\MockObject */
  53. protected $util;
  54. protected IUserSession $userSession;
  55. /** @var Capabilities */
  56. protected $capabilities;
  57. protected function setUp(): void {
  58. parent::setUp();
  59. $this->theming = $this->createMock(ThemingDefaults::class);
  60. $this->url = $this->getMockBuilder(IURLGenerator::class)->getMock();
  61. $this->config = $this->createMock(IConfig::class);
  62. $this->util = $this->createMock(Util::class);
  63. $this->userSession = $this->createMock(IUserSession::class);
  64. $this->capabilities = new Capabilities($this->theming, $this->util, $this->url, $this->config, $this->userSession);
  65. }
  66. public function dataGetCapabilities() {
  67. return [
  68. ['name', 'url', 'slogan', '#FFFFFF', '#000000', 'logo', 'background', 'http://absolute/', true, [
  69. 'name' => 'name',
  70. 'url' => 'url',
  71. 'slogan' => 'slogan',
  72. 'color' => '#FFFFFF',
  73. 'color-text' => '#000000',
  74. 'color-element' => '#b3b3b3',
  75. 'color-element-bright' => '#b3b3b3',
  76. 'color-element-dark' => '#FFFFFF',
  77. 'logo' => 'http://absolute/logo',
  78. 'background' => 'http://absolute/background',
  79. 'background-plain' => false,
  80. 'background-default' => false,
  81. 'logoheader' => 'http://absolute/logo',
  82. 'favicon' => 'http://absolute/logo',
  83. ]],
  84. ['name1', 'url2', 'slogan3', '#01e4a0', '#ffffff', 'logo5', 'background6', 'http://localhost/', false, [
  85. 'name' => 'name1',
  86. 'url' => 'url2',
  87. 'slogan' => 'slogan3',
  88. 'color' => '#01e4a0',
  89. 'color-text' => '#ffffff',
  90. 'color-element' => '#01e4a0',
  91. 'color-element-bright' => '#01e4a0',
  92. 'color-element-dark' => '#01e4a0',
  93. 'logo' => 'http://localhost/logo5',
  94. 'background' => 'http://localhost/background6',
  95. 'background-plain' => false,
  96. 'background-default' => true,
  97. 'logoheader' => 'http://localhost/logo5',
  98. 'favicon' => 'http://localhost/logo5',
  99. ]],
  100. ['name1', 'url2', 'slogan3', '#000000', '#ffffff', 'logo5', 'backgroundColor', 'http://localhost/', true, [
  101. 'name' => 'name1',
  102. 'url' => 'url2',
  103. 'slogan' => 'slogan3',
  104. 'color' => '#000000',
  105. 'color-text' => '#ffffff',
  106. 'color-element' => '#4d4d4d',
  107. 'color-element-bright' => '#4d4d4d',
  108. 'color-element-dark' => '#4d4d4d',
  109. 'logo' => 'http://localhost/logo5',
  110. 'background' => '#000000',
  111. 'background-plain' => true,
  112. 'background-default' => false,
  113. 'logoheader' => 'http://localhost/logo5',
  114. 'favicon' => 'http://localhost/logo5',
  115. ]],
  116. ['name1', 'url2', 'slogan3', '#000000', '#ffffff', 'logo5', 'backgroundColor', 'http://localhost/', false, [
  117. 'name' => 'name1',
  118. 'url' => 'url2',
  119. 'slogan' => 'slogan3',
  120. 'color' => '#000000',
  121. 'color-text' => '#ffffff',
  122. 'color-element' => '#4d4d4d',
  123. 'color-element-bright' => '#4d4d4d',
  124. 'color-element-dark' => '#4d4d4d',
  125. 'logo' => 'http://localhost/logo5',
  126. 'background' => '#000000',
  127. 'background-plain' => true,
  128. 'background-default' => true,
  129. 'logoheader' => 'http://localhost/logo5',
  130. 'favicon' => 'http://localhost/logo5',
  131. ]],
  132. ];
  133. }
  134. /**
  135. * @dataProvider dataGetCapabilities
  136. * @param string $name
  137. * @param string $url
  138. * @param string $slogan
  139. * @param string $color
  140. * @param string $textColor
  141. * @param string $logo
  142. * @param string $background
  143. * @param string $baseUrl
  144. * @param bool $backgroundThemed
  145. * @param string[] $expected
  146. */
  147. public function testGetCapabilities($name, $url, $slogan, $color, $textColor, $logo, $background, $baseUrl, $backgroundThemed, array $expected) {
  148. $this->config->expects($this->once())
  149. ->method('getAppValue')
  150. ->willReturn($background);
  151. $this->theming->expects($this->once())
  152. ->method('getName')
  153. ->willReturn($name);
  154. $this->theming->expects($this->once())
  155. ->method('getBaseUrl')
  156. ->willReturn($url);
  157. $this->theming->expects($this->once())
  158. ->method('getSlogan')
  159. ->willReturn($slogan);
  160. $this->theming->expects($this->atLeast(1))
  161. ->method('getDefaultColorPrimary')
  162. ->willReturn($color);
  163. $this->theming->expects($this->exactly(3))
  164. ->method('getLogo')
  165. ->willReturn($logo);
  166. $util = new Util($this->config, $this->createMock(IAppManager::class), $this->createMock(IAppData::class), $this->createMock(ImageManager::class));
  167. $this->util->expects($this->exactly(3))
  168. ->method('elementColor')
  169. ->with($color)
  170. ->willReturnCallback(static function (string $color, ?bool $brightBackground = null) use ($util) {
  171. return $util->elementColor($color, $brightBackground);
  172. });
  173. $this->util->expects($this->any())
  174. ->method('invertTextColor')
  175. ->willReturnCallback(fn () => $textColor === '#000000');
  176. $this->util->expects($this->once())
  177. ->method('isBackgroundThemed')
  178. ->willReturn($backgroundThemed);
  179. if ($background !== 'backgroundColor') {
  180. $this->theming->expects($this->once())
  181. ->method('getBackground')
  182. ->willReturn($background);
  183. $this->url->expects($this->exactly(4))
  184. ->method('getAbsoluteURL')
  185. ->willReturnCallback(function ($url) use ($baseUrl) {
  186. return $baseUrl . $url;
  187. });
  188. } else {
  189. $this->url->expects($this->exactly(3))
  190. ->method('getAbsoluteURL')
  191. ->willReturnCallback(function ($url) use ($baseUrl) {
  192. return $baseUrl . $url;
  193. });
  194. }
  195. $this->assertEquals(['theming' => $expected], $this->capabilities->getCapabilities());
  196. }
  197. }