CapabilitiesTest.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. 'logo' => 'http://absolute/logo',
  72. 'background' => 'http://absolute/background',
  73. 'background-plain' => false,
  74. 'background-default' => false,
  75. 'logoheader' => 'http://absolute/logo',
  76. 'favicon' => 'http://absolute/logo',
  77. ]],
  78. ['name1', 'url2', 'slogan3', '#01e4a0', '#ffffff', 'logo5', 'background6', 'http://localhost/', false, [
  79. 'name' => 'name1',
  80. 'url' => 'url2',
  81. 'slogan' => 'slogan3',
  82. 'color' => '#01e4a0',
  83. 'color-text' => '#ffffff',
  84. 'color-element' => '#01e4a0',
  85. 'logo' => 'http://localhost/logo5',
  86. 'background' => 'http://localhost/background6',
  87. 'background-plain' => false,
  88. 'background-default' => true,
  89. 'logoheader' => 'http://localhost/logo5',
  90. 'favicon' => 'http://localhost/logo5',
  91. ]],
  92. ['name1', 'url2', 'slogan3', '#000000', '#ffffff', 'logo5', 'backgroundColor', 'http://localhost/', true, [
  93. 'name' => 'name1',
  94. 'url' => 'url2',
  95. 'slogan' => 'slogan3',
  96. 'color' => '#000000',
  97. 'color-text' => '#ffffff',
  98. 'color-element' => '#000000',
  99. 'logo' => 'http://localhost/logo5',
  100. 'background' => '#000000',
  101. 'background-plain' => true,
  102. 'background-default' => false,
  103. 'logoheader' => 'http://localhost/logo5',
  104. 'favicon' => 'http://localhost/logo5',
  105. ]],
  106. ['name1', 'url2', 'slogan3', '#000000', '#ffffff', 'logo5', 'backgroundColor', 'http://localhost/', false, [
  107. 'name' => 'name1',
  108. 'url' => 'url2',
  109. 'slogan' => 'slogan3',
  110. 'color' => '#000000',
  111. 'color-text' => '#ffffff',
  112. 'color-element' => '#000000',
  113. 'logo' => 'http://localhost/logo5',
  114. 'background' => '#000000',
  115. 'background-plain' => true,
  116. 'background-default' => true,
  117. 'logoheader' => 'http://localhost/logo5',
  118. 'favicon' => 'http://localhost/logo5',
  119. ]],
  120. ];
  121. }
  122. /**
  123. * @dataProvider dataGetCapabilities
  124. * @param string $name
  125. * @param string $url
  126. * @param string $slogan
  127. * @param string $color
  128. * @param string $textColor
  129. * @param string $logo
  130. * @param string $background
  131. * @param string $baseUrl
  132. * @param bool $backgroundThemed
  133. * @param string[] $expected
  134. */
  135. public function testGetCapabilities($name, $url, $slogan, $color, $textColor, $logo, $background, $baseUrl, $backgroundThemed, array $expected) {
  136. $this->config->expects($this->once())
  137. ->method('getAppValue')
  138. ->willReturn($background);
  139. $this->theming->expects($this->once())
  140. ->method('getName')
  141. ->willReturn($name);
  142. $this->theming->expects($this->once())
  143. ->method('getBaseUrl')
  144. ->willReturn($url);
  145. $this->theming->expects($this->once())
  146. ->method('getSlogan')
  147. ->willReturn($slogan);
  148. $this->theming->expects($this->atLeast(1))
  149. ->method('getColorPrimary')
  150. ->willReturn($color);
  151. $this->theming->expects($this->exactly(3))
  152. ->method('getLogo')
  153. ->willReturn($logo);
  154. $this->theming->expects($this->once())
  155. ->method('getTextColorPrimary')
  156. ->willReturn($textColor);
  157. $util = new Util($this->config, $this->createMock(IAppManager::class), $this->createMock(IAppData::class));
  158. $this->util->expects($this->once())
  159. ->method('elementColor')
  160. ->with($color)
  161. ->willReturn($util->elementColor($color));
  162. $this->util->expects($this->once())
  163. ->method('isBackgroundThemed')
  164. ->willReturn($backgroundThemed);
  165. if ($background !== 'backgroundColor') {
  166. $this->theming->expects($this->once())
  167. ->method('getBackground')
  168. ->willReturn($background);
  169. $this->url->expects($this->exactly(4))
  170. ->method('getAbsoluteURL')
  171. ->willReturnCallback(function ($url) use ($baseUrl) {
  172. return $baseUrl . $url;
  173. });
  174. } else {
  175. $this->url->expects($this->exactly(3))
  176. ->method('getAbsoluteURL')
  177. ->willReturnCallback(function ($url) use ($baseUrl) {
  178. return $baseUrl . $url;
  179. });
  180. }
  181. $this->assertEquals(['theming' => $expected], $this->capabilities->getCapabilities());
  182. }
  183. }