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