1
0

CapabilitiesTest.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 Test\TestCase;
  39. /**
  40. * Class CapabilitiesTest
  41. *
  42. * @package OCA\Theming\Tests
  43. */
  44. class CapabilitiesTest extends TestCase {
  45. /** @var ThemingDefaults|\PHPUnit\Framework\MockObject\MockObject */
  46. protected $theming;
  47. /** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
  48. protected $url;
  49. /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
  50. protected $config;
  51. /** @var Util|\PHPUnit\Framework\MockObject\MockObject */
  52. protected $util;
  53. /** @var Capabilities */
  54. protected $capabilities;
  55. protected function setUp(): void {
  56. parent::setUp();
  57. $this->theming = $this->createMock(ThemingDefaults::class);
  58. $this->url = $this->getMockBuilder(IURLGenerator::class)->getMock();
  59. $this->config = $this->createMock(IConfig::class);
  60. $this->util = $this->createMock(Util::class);
  61. $this->capabilities = new Capabilities($this->theming, $this->util, $this->url, $this->config);
  62. }
  63. public function dataGetCapabilities() {
  64. return [
  65. ['name', 'url', 'slogan', '#FFFFFF', '#000000', 'logo', 'background', 'http://absolute/', true, [
  66. 'name' => 'name',
  67. 'url' => 'url',
  68. 'slogan' => 'slogan',
  69. 'color' => '#FFFFFF',
  70. 'color-text' => '#000000',
  71. 'color-element' => '#b3b3b3',
  72. 'color-element-bright' => '#b3b3b3',
  73. 'color-element-dark' => '#FFFFFF',
  74. 'logo' => 'http://absolute/logo',
  75. 'background' => 'http://absolute/background',
  76. 'background-plain' => false,
  77. 'background-default' => false,
  78. 'logoheader' => 'http://absolute/logo',
  79. 'favicon' => 'http://absolute/logo',
  80. ]],
  81. ['name1', 'url2', 'slogan3', '#01e4a0', '#ffffff', 'logo5', 'background6', 'http://localhost/', false, [
  82. 'name' => 'name1',
  83. 'url' => 'url2',
  84. 'slogan' => 'slogan3',
  85. 'color' => '#01e4a0',
  86. 'color-text' => '#ffffff',
  87. 'color-element' => '#01e4a0',
  88. 'color-element-bright' => '#01e4a0',
  89. 'color-element-dark' => '#01e4a0',
  90. 'logo' => 'http://localhost/logo5',
  91. 'background' => 'http://localhost/background6',
  92. 'background-plain' => false,
  93. 'background-default' => true,
  94. 'logoheader' => 'http://localhost/logo5',
  95. 'favicon' => 'http://localhost/logo5',
  96. ]],
  97. ['name1', 'url2', 'slogan3', '#000000', '#ffffff', 'logo5', 'backgroundColor', 'http://localhost/', true, [
  98. 'name' => 'name1',
  99. 'url' => 'url2',
  100. 'slogan' => 'slogan3',
  101. 'color' => '#000000',
  102. 'color-text' => '#ffffff',
  103. 'color-element' => '#4d4d4d',
  104. 'color-element-bright' => '#4d4d4d',
  105. 'color-element-dark' => '#4d4d4d',
  106. 'logo' => 'http://localhost/logo5',
  107. 'background' => '#000000',
  108. 'background-plain' => true,
  109. 'background-default' => false,
  110. 'logoheader' => 'http://localhost/logo5',
  111. 'favicon' => 'http://localhost/logo5',
  112. ]],
  113. ['name1', 'url2', 'slogan3', '#000000', '#ffffff', 'logo5', 'backgroundColor', 'http://localhost/', false, [
  114. 'name' => 'name1',
  115. 'url' => 'url2',
  116. 'slogan' => 'slogan3',
  117. 'color' => '#000000',
  118. 'color-text' => '#ffffff',
  119. 'color-element' => '#4d4d4d',
  120. 'color-element-bright' => '#4d4d4d',
  121. 'color-element-dark' => '#4d4d4d',
  122. 'logo' => 'http://localhost/logo5',
  123. 'background' => '#000000',
  124. 'background-plain' => true,
  125. 'background-default' => true,
  126. 'logoheader' => 'http://localhost/logo5',
  127. 'favicon' => 'http://localhost/logo5',
  128. ]],
  129. ];
  130. }
  131. /**
  132. * @dataProvider dataGetCapabilities
  133. * @param string $name
  134. * @param string $url
  135. * @param string $slogan
  136. * @param string $color
  137. * @param string $textColor
  138. * @param string $logo
  139. * @param string $background
  140. * @param string $baseUrl
  141. * @param bool $backgroundThemed
  142. * @param string[] $expected
  143. */
  144. public function testGetCapabilities($name, $url, $slogan, $color, $textColor, $logo, $background, $baseUrl, $backgroundThemed, array $expected) {
  145. $this->config->expects($this->once())
  146. ->method('getAppValue')
  147. ->willReturn($background);
  148. $this->theming->expects($this->once())
  149. ->method('getName')
  150. ->willReturn($name);
  151. $this->theming->expects($this->once())
  152. ->method('getBaseUrl')
  153. ->willReturn($url);
  154. $this->theming->expects($this->once())
  155. ->method('getSlogan')
  156. ->willReturn($slogan);
  157. $this->theming->expects($this->atLeast(1))
  158. ->method('getColorPrimary')
  159. ->willReturn($color);
  160. $this->theming->expects($this->exactly(3))
  161. ->method('getLogo')
  162. ->willReturn($logo);
  163. $this->theming->expects($this->once())
  164. ->method('getTextColorPrimary')
  165. ->willReturn($textColor);
  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->once())
  174. ->method('isBackgroundThemed')
  175. ->willReturn($backgroundThemed);
  176. if ($background !== 'backgroundColor') {
  177. $this->theming->expects($this->once())
  178. ->method('getBackground')
  179. ->willReturn($background);
  180. $this->url->expects($this->exactly(4))
  181. ->method('getAbsoluteURL')
  182. ->willReturnCallback(function ($url) use ($baseUrl) {
  183. return $baseUrl . $url;
  184. });
  185. } else {
  186. $this->url->expects($this->exactly(3))
  187. ->method('getAbsoluteURL')
  188. ->willReturnCallback(function ($url) use ($baseUrl) {
  189. return $baseUrl . $url;
  190. });
  191. }
  192. $this->assertEquals(['theming' => $expected], $this->capabilities->getCapabilities());
  193. }
  194. }