CapabilitiesTest.php 5.8 KB

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