ThemingDefaultsTest.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Bjoern Schiessle <bjoern@schiessle.org>
  7. * @author Jan-Christoph Borchardt <hey@jancborchardt.net>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author Julius Haertl <jus@bitgrid.net>
  10. * @author Julius Härtl <jus@bitgrid.net>
  11. * @author Lukas Reschke <lukas@statuscode.ch>
  12. * @author Morris Jobke <hey@morrisjobke.de>
  13. *
  14. * @license GNU AGPL version 3 or any later version
  15. *
  16. * This program is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License as
  18. * published by the Free Software Foundation, either version 3 of the
  19. * License, or (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. *
  29. */
  30. namespace OCA\Theming\Tests;
  31. use OCA\Theming\ImageManager;
  32. use OCA\Theming\ThemingDefaults;
  33. use OCP\App\IAppManager;
  34. use OCP\Files\IAppData;
  35. use OCA\Theming\Util;
  36. use OCP\Files\NotFoundException;
  37. use OCP\Files\SimpleFS\ISimpleFile;
  38. use OCP\Files\SimpleFS\ISimpleFolder;
  39. use OCP\ICache;
  40. use OCP\ICacheFactory;
  41. use OCP\IConfig;
  42. use OCP\IL10N;
  43. use OCP\IURLGenerator;
  44. use Test\TestCase;
  45. class ThemingDefaultsTest extends TestCase {
  46. /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
  47. private $config;
  48. /** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
  49. private $l10n;
  50. /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
  51. private $urlGenerator;
  52. /** @var \OC_Defaults|\PHPUnit_Framework_MockObject_MockObject */
  53. private $defaults;
  54. /** @var IAppData|\PHPUnit_Framework_MockObject_MockObject */
  55. private $appData;
  56. /** @var ICacheFactory|\PHPUnit_Framework_MockObject_MockObject */
  57. private $cacheFactory;
  58. /** @var ThemingDefaults */
  59. private $template;
  60. /** @var Util|\PHPUnit_Framework_MockObject_MockObject */
  61. private $util;
  62. /** @var ICache|\PHPUnit_Framework_MockObject_MockObject */
  63. private $cache;
  64. /** @var IAppManager|\PHPUnit_Framework_MockObject_MockObject */
  65. private $appManager;
  66. /** @var ImageManager|\PHPUnit_Framework_MockObject_MockObject */
  67. private $imageManager;
  68. public function setUp() {
  69. parent::setUp();
  70. $this->config = $this->createMock(IConfig::class);
  71. $this->l10n = $this->createMock(IL10N::class);
  72. $this->urlGenerator = $this->createMock(IURLGenerator::class);
  73. $this->cacheFactory = $this->createMock(ICacheFactory::class);
  74. $this->cache = $this->createMock(ICache::class);
  75. $this->util = $this->createMock(Util::class);
  76. $this->imageManager = $this->createMock(ImageManager::class);
  77. $this->appManager = $this->createMock(IAppManager::class);
  78. $this->defaults = new \OC_Defaults();
  79. $this->urlGenerator
  80. ->expects($this->any())
  81. ->method('getBaseUrl')
  82. ->willReturn('');
  83. $this->template = new ThemingDefaults(
  84. $this->config,
  85. $this->l10n,
  86. $this->urlGenerator,
  87. $this->cacheFactory,
  88. $this->util,
  89. $this->imageManager,
  90. $this->appManager
  91. );
  92. }
  93. public function testGetNameWithDefault() {
  94. $this->config
  95. ->expects($this->once())
  96. ->method('getAppValue')
  97. ->with('theming', 'name', 'Nextcloud')
  98. ->willReturn('Nextcloud');
  99. $this->assertEquals('Nextcloud', $this->template->getName());
  100. }
  101. public function testGetNameWithCustom() {
  102. $this->config
  103. ->expects($this->once())
  104. ->method('getAppValue')
  105. ->with('theming', 'name', 'Nextcloud')
  106. ->willReturn('MyCustomCloud');
  107. $this->assertEquals('MyCustomCloud', $this->template->getName());
  108. }
  109. public function testGetHTMLNameWithDefault() {
  110. $this->config
  111. ->expects($this->once())
  112. ->method('getAppValue')
  113. ->with('theming', 'name', 'Nextcloud')
  114. ->willReturn('Nextcloud');
  115. $this->assertEquals('Nextcloud', $this->template->getHTMLName());
  116. }
  117. public function testGetHTMLNameWithCustom() {
  118. $this->config
  119. ->expects($this->once())
  120. ->method('getAppValue')
  121. ->with('theming', 'name', 'Nextcloud')
  122. ->willReturn('MyCustomCloud');
  123. $this->assertEquals('MyCustomCloud', $this->template->getHTMLName());
  124. }
  125. public function testGetTitleWithDefault() {
  126. $this->config
  127. ->expects($this->once())
  128. ->method('getAppValue')
  129. ->with('theming', 'name', 'Nextcloud')
  130. ->willReturn('Nextcloud');
  131. $this->assertEquals('Nextcloud', $this->template->getTitle());
  132. }
  133. public function testGetTitleWithCustom() {
  134. $this->config
  135. ->expects($this->once())
  136. ->method('getAppValue')
  137. ->with('theming', 'name', 'Nextcloud')
  138. ->willReturn('MyCustomCloud');
  139. $this->assertEquals('MyCustomCloud', $this->template->getTitle());
  140. }
  141. public function testGetEntityWithDefault() {
  142. $this->config
  143. ->expects($this->once())
  144. ->method('getAppValue')
  145. ->with('theming', 'name', 'Nextcloud')
  146. ->willReturn('Nextcloud');
  147. $this->assertEquals('Nextcloud', $this->template->getEntity());
  148. }
  149. public function testGetEntityWithCustom() {
  150. $this->config
  151. ->expects($this->once())
  152. ->method('getAppValue')
  153. ->with('theming', 'name', 'Nextcloud')
  154. ->willReturn('MyCustomCloud');
  155. $this->assertEquals('MyCustomCloud', $this->template->getEntity());
  156. }
  157. public function testGetBaseUrlWithDefault() {
  158. $this->config
  159. ->expects($this->once())
  160. ->method('getAppValue')
  161. ->with('theming', 'url', $this->defaults->getBaseUrl())
  162. ->willReturn($this->defaults->getBaseUrl());
  163. $this->assertEquals($this->defaults->getBaseUrl(), $this->template->getBaseUrl());
  164. }
  165. public function testGetBaseUrlWithCustom() {
  166. $this->config
  167. ->expects($this->once())
  168. ->method('getAppValue')
  169. ->with('theming', 'url', $this->defaults->getBaseUrl())
  170. ->willReturn('https://example.com/');
  171. $this->assertEquals('https://example.com/', $this->template->getBaseUrl());
  172. }
  173. public function imprintUrlProvider() {
  174. return [
  175. [ '' ],
  176. [ 'https://example.com/imprint.html']
  177. ];
  178. }
  179. /**
  180. * @param $imprintUrl
  181. * @dataProvider imprintUrlProvider
  182. */
  183. public function testGetImprintURL($imprintUrl) {
  184. $this->config
  185. ->expects($this->once())
  186. ->method('getAppValue')
  187. ->with('theming', 'imprintUrl', '')
  188. ->willReturn($imprintUrl);
  189. $this->assertEquals($imprintUrl, $this->template->getImprintUrl());
  190. }
  191. public function testGetSloganWithDefault() {
  192. $this->config
  193. ->expects($this->once())
  194. ->method('getAppValue')
  195. ->with('theming', 'slogan', $this->defaults->getSlogan())
  196. ->willReturn($this->defaults->getSlogan());
  197. $this->assertEquals($this->defaults->getSlogan(), $this->template->getSlogan());
  198. }
  199. public function testGetSloganWithCustom() {
  200. $this->config
  201. ->expects($this->once())
  202. ->method('getAppValue')
  203. ->with('theming', 'slogan', $this->defaults->getSlogan())
  204. ->willReturn('My custom Slogan');
  205. $this->assertEquals('My custom Slogan', $this->template->getSlogan());
  206. }
  207. public function testGetShortFooter() {
  208. $this->config
  209. ->expects($this->exactly(4))
  210. ->method('getAppValue')
  211. ->willReturnMap([
  212. ['theming', 'url', $this->defaults->getBaseUrl(), 'url'],
  213. ['theming', 'name', 'Nextcloud', 'Name'],
  214. ['theming', 'slogan', $this->defaults->getSlogan(), 'Slogan'],
  215. ['theming', 'imprintUrl', '', ''],
  216. ]);
  217. $this->assertEquals('<a href="url" target="_blank" rel="noreferrer noopener">Name</a> – Slogan', $this->template->getShortFooter());
  218. }
  219. public function testGetShortFooterEmptySlogan() {
  220. $this->config
  221. ->expects($this->exactly(4))
  222. ->method('getAppValue')
  223. ->willReturnMap([
  224. ['theming', 'url', $this->defaults->getBaseUrl(), 'url'],
  225. ['theming', 'name', 'Nextcloud', 'Name'],
  226. ['theming', 'slogan', $this->defaults->getSlogan(), ''],
  227. ['theming', 'imprintUrl', '', ''],
  228. ]);
  229. $this->assertEquals('<a href="url" target="_blank" rel="noreferrer noopener">Name</a>', $this->template->getShortFooter());
  230. }
  231. public function testGetShortFooterImprint() {
  232. $this->config
  233. ->expects($this->exactly(4))
  234. ->method('getAppValue')
  235. ->willReturnMap([
  236. ['theming', 'url', $this->defaults->getBaseUrl(), 'url'],
  237. ['theming', 'name', 'Nextcloud', 'Name'],
  238. ['theming', 'slogan', $this->defaults->getSlogan(), 'Slogan'],
  239. ['theming', 'imprintUrl', '', 'https://example.com/imprint'],
  240. ]);
  241. $this->l10n
  242. ->expects($this->any())
  243. ->method('t')
  244. ->willReturnArgument(0);
  245. $this->assertEquals('<a href="url" target="_blank" rel="noreferrer noopener">Name</a> – Slogan<br/><a href="https://example.com/imprint" class="legal" target="_blank" rel="noreferrer noopener">Legal notice</a>', $this->template->getShortFooter());
  246. }
  247. public function invalidImprintUrlProvider() {
  248. return [
  249. ['example.com/imprint'], # missing scheme
  250. ['https:///imprint'], # missing host
  251. ];
  252. }
  253. /**
  254. * @param $invalidImprintUrl
  255. * @dataProvider invalidImprintUrlProvider
  256. */
  257. public function testGetShortFooterInvalidImprint($invalidImprintUrl) {
  258. $this->config
  259. ->expects($this->exactly(4))
  260. ->method('getAppValue')
  261. ->willReturnMap([
  262. ['theming', 'url', $this->defaults->getBaseUrl(), 'url'],
  263. ['theming', 'name', 'Nextcloud', 'Name'],
  264. ['theming', 'slogan', $this->defaults->getSlogan(), 'Slogan'],
  265. ['theming', 'imprintUrl', '', $invalidImprintUrl],
  266. ]);
  267. $this->assertEquals('<a href="url" target="_blank" rel="noreferrer noopener">Name</a> – Slogan', $this->template->getShortFooter());
  268. }
  269. public function testgetColorPrimaryWithDefault() {
  270. $this->config
  271. ->expects($this->once())
  272. ->method('getAppValue')
  273. ->with('theming', 'color', $this->defaults->getColorPrimary())
  274. ->willReturn($this->defaults->getColorPrimary());
  275. $this->assertEquals($this->defaults->getColorPrimary(), $this->template->getColorPrimary());
  276. }
  277. public function testgetColorPrimaryWithCustom() {
  278. $this->config
  279. ->expects($this->once())
  280. ->method('getAppValue')
  281. ->with('theming', 'color', $this->defaults->getColorPrimary())
  282. ->willReturn('#fff');
  283. $this->assertEquals('#fff', $this->template->getColorPrimary());
  284. }
  285. public function testSet() {
  286. $this->config
  287. ->expects($this->at(0))
  288. ->method('setAppValue')
  289. ->with('theming', 'MySetting', 'MyValue');
  290. $this->config
  291. ->expects($this->at(1))
  292. ->method('getAppValue')
  293. ->with('theming', 'cachebuster', '0')
  294. ->willReturn('15');
  295. $this->config
  296. ->expects($this->at(2))
  297. ->method('setAppValue')
  298. ->with('theming', 'cachebuster', 16);
  299. $this->cacheFactory
  300. ->expects($this->at(0))
  301. ->method('createDistributed')
  302. ->with('theming-')
  303. ->willReturn($this->cache);
  304. $this->cacheFactory
  305. ->expects($this->at(1))
  306. ->method('createDistributed')
  307. ->with('imagePath')
  308. ->willReturn($this->cache);
  309. $this->cache
  310. ->expects($this->any())
  311. ->method('clear')
  312. ->with('');
  313. $this->template->set('MySetting', 'MyValue');
  314. }
  315. public function testUndoName() {
  316. $this->config
  317. ->expects($this->at(0))
  318. ->method('deleteAppValue')
  319. ->with('theming', 'name');
  320. $this->config
  321. ->expects($this->at(1))
  322. ->method('getAppValue')
  323. ->with('theming', 'cachebuster', '0')
  324. ->willReturn('15');
  325. $this->config
  326. ->expects($this->at(2))
  327. ->method('setAppValue')
  328. ->with('theming', 'cachebuster', 16);
  329. $this->config
  330. ->expects($this->at(3))
  331. ->method('getAppValue')
  332. ->with('theming', 'name', 'Nextcloud')
  333. ->willReturn('Nextcloud');
  334. $this->assertSame('Nextcloud', $this->template->undo('name'));
  335. }
  336. public function testUndoBaseUrl() {
  337. $this->config
  338. ->expects($this->at(0))
  339. ->method('deleteAppValue')
  340. ->with('theming', 'url');
  341. $this->config
  342. ->expects($this->at(1))
  343. ->method('getAppValue')
  344. ->with('theming', 'cachebuster', '0')
  345. ->willReturn('15');
  346. $this->config
  347. ->expects($this->at(2))
  348. ->method('setAppValue')
  349. ->with('theming', 'cachebuster', 16);
  350. $this->config
  351. ->expects($this->at(3))
  352. ->method('getAppValue')
  353. ->with('theming', 'url', $this->defaults->getBaseUrl())
  354. ->willReturn($this->defaults->getBaseUrl());
  355. $this->assertSame($this->defaults->getBaseUrl(), $this->template->undo('url'));
  356. }
  357. public function testUndoSlogan() {
  358. $this->config
  359. ->expects($this->at(0))
  360. ->method('deleteAppValue')
  361. ->with('theming', 'slogan');
  362. $this->config
  363. ->expects($this->at(1))
  364. ->method('getAppValue')
  365. ->with('theming', 'cachebuster', '0')
  366. ->willReturn('15');
  367. $this->config
  368. ->expects($this->at(2))
  369. ->method('setAppValue')
  370. ->with('theming', 'cachebuster', 16);
  371. $this->config
  372. ->expects($this->at(3))
  373. ->method('getAppValue')
  374. ->with('theming', 'slogan', $this->defaults->getSlogan())
  375. ->willReturn($this->defaults->getSlogan());
  376. $this->assertSame($this->defaults->getSlogan(), $this->template->undo('slogan'));
  377. }
  378. public function testUndoColor() {
  379. $this->config
  380. ->expects($this->at(0))
  381. ->method('deleteAppValue')
  382. ->with('theming', 'color');
  383. $this->config
  384. ->expects($this->at(1))
  385. ->method('getAppValue')
  386. ->with('theming', 'cachebuster', '0')
  387. ->willReturn('15');
  388. $this->config
  389. ->expects($this->at(2))
  390. ->method('setAppValue')
  391. ->with('theming', 'cachebuster', 16);
  392. $this->config
  393. ->expects($this->at(3))
  394. ->method('getAppValue')
  395. ->with('theming', 'color', $this->defaults->getColorPrimary())
  396. ->willReturn($this->defaults->getColorPrimary());
  397. $this->assertSame($this->defaults->getColorPrimary(), $this->template->undo('color'));
  398. }
  399. public function testUndoDefaultAction() {
  400. $this->config
  401. ->expects($this->at(0))
  402. ->method('deleteAppValue')
  403. ->with('theming', 'defaultitem');
  404. $this->config
  405. ->expects($this->at(1))
  406. ->method('getAppValue')
  407. ->with('theming', 'cachebuster', '0')
  408. ->willReturn('15');
  409. $this->config
  410. ->expects($this->at(2))
  411. ->method('setAppValue')
  412. ->with('theming', 'cachebuster', 16);
  413. $this->assertSame('', $this->template->undo('defaultitem'));
  414. }
  415. public function testGetBackground() {
  416. $this->imageManager
  417. ->expects($this->once())
  418. ->method('getImageUrl')
  419. ->with('background')
  420. ->willReturn('custom-background?v=0');
  421. $this->assertEquals('custom-background?v=0', $this->template->getBackground());
  422. }
  423. private function getLogoHelper($withName, $useSvg) {
  424. $this->imageManager->expects($this->any())
  425. ->method('getImage')
  426. ->with('logo')
  427. ->willThrowException(new NotFoundException());
  428. $this->config
  429. ->expects($this->at(0))
  430. ->method('getAppValue')
  431. ->with('theming', 'logoMime')
  432. ->willReturn('');
  433. $this->config
  434. ->expects($this->at(1))
  435. ->method('getAppValue')
  436. ->with('theming', 'cachebuster', '0')
  437. ->willReturn('0');
  438. $this->urlGenerator->expects($this->once())
  439. ->method('imagePath')
  440. ->with('core', $withName)
  441. ->willReturn('core-logo');
  442. $this->assertEquals('core-logo?v=0', $this->template->getLogo($useSvg));
  443. }
  444. public function testGetLogoDefaultWithSvg() {
  445. $this->getLogoHelper('logo.svg', true);
  446. }
  447. public function testGetLogoDefaultWithoutSvg() {
  448. $this->getLogoHelper('logo.png', false);
  449. }
  450. public function testGetLogoCustom() {
  451. $file = $this->createMock(ISimpleFile::class);
  452. $this->imageManager->expects($this->once())
  453. ->method('getImage')
  454. ->with('logo')
  455. ->willReturn($file);
  456. $this->config
  457. ->expects($this->at(0))
  458. ->method('getAppValue')
  459. ->with('theming', 'logoMime', false)
  460. ->willReturn('image/svg+xml');
  461. $this->config
  462. ->expects($this->at(1))
  463. ->method('getAppValue')
  464. ->with('theming', 'cachebuster', '0')
  465. ->willReturn('0');
  466. $this->urlGenerator->expects($this->once())
  467. ->method('linkToRoute')
  468. ->with('theming.Theming.getImage')
  469. ->willReturn('custom-logo');
  470. $this->assertEquals('custom-logo' . '?v=0', $this->template->getLogo());
  471. }
  472. public function testGetScssVariablesCached() {
  473. $this->cacheFactory->expects($this->once())
  474. ->method('createDistributed')
  475. ->with('theming-')
  476. ->willReturn($this->cache);
  477. $this->cache->expects($this->once())->method('get')->with('getScssVariables')->willReturn(['foo'=>'bar']);
  478. $this->assertEquals(['foo'=>'bar'], $this->template->getScssVariables());
  479. }
  480. public function testGetScssVariables() {
  481. $this->config->expects($this->at(0))->method('getAppValue')->with('theming', 'cachebuster', '0')->willReturn('0');
  482. $this->config->expects($this->at(1))->method('getAppValue')->with('theming', 'logoMime', false)->willReturn('jpeg');
  483. $this->config->expects($this->at(2))->method('getAppValue')->with('theming', 'backgroundMime', false)->willReturn('jpeg');
  484. $this->config->expects($this->at(3))->method('getAppValue')->with('theming', 'logoheaderMime', false)->willReturn('jpeg');
  485. $this->config->expects($this->at(4))->method('getAppValue')->with('theming', 'faviconMime', false)->willReturn('jpeg');
  486. $this->config->expects($this->at(5))->method('getAppValue')->with('theming', 'color', null)->willReturn($this->defaults->getColorPrimary());
  487. $this->config->expects($this->at(6))->method('getAppValue')->with('theming', 'color', $this->defaults->getColorPrimary())->willReturn($this->defaults->getColorPrimary());
  488. $this->config->expects($this->at(7))->method('getAppValue')->with('theming', 'color', $this->defaults->getColorPrimary())->willReturn($this->defaults->getColorPrimary());
  489. $this->config->expects($this->at(8))->method('getAppValue')->with('theming', 'color', $this->defaults->getColorPrimary())->willReturn($this->defaults->getColorPrimary());
  490. $this->util->expects($this->any())->method('invertTextColor')->with($this->defaults->getColorPrimary())->willReturn(false);
  491. $this->util->expects($this->any())->method('elementColor')->with($this->defaults->getColorPrimary())->willReturn('#aaaaaa');
  492. $this->cacheFactory->expects($this->once())
  493. ->method('createDistributed')
  494. ->with('theming-')
  495. ->willReturn($this->cache);
  496. $this->cache->expects($this->once())->method('get')->with('getScssVariables')->willReturn(null);
  497. $this->imageManager->expects($this->at(0))->method('getImageUrl')->with('logo')->willReturn('custom-logo?v=0');
  498. $this->imageManager->expects($this->at(1))->method('getImageUrl')->with('logoheader')->willReturn('custom-logoheader?v=0');
  499. $this->imageManager->expects($this->at(2))->method('getImageUrl')->with('favicon')->willReturn('custom-favicon?v=0');
  500. $this->imageManager->expects($this->at(3))->method('getImageUrl')->with('background')->willReturn('custom-background?v=0');
  501. $expected = [
  502. 'theming-cachebuster' => '\'0\'',
  503. 'theming-logo-mime' => '\'jpeg\'',
  504. 'theming-background-mime' => '\'jpeg\'',
  505. 'image-logo' => "'custom-logo?v=0'",
  506. 'image-login-background' => "'custom-background?v=0'",
  507. 'color-primary' => $this->defaults->getColorPrimary(),
  508. 'color-primary-text' => '#ffffff',
  509. 'image-login-plain' => 'false',
  510. 'color-primary-element' => '#aaaaaa',
  511. 'theming-logoheader-mime' => '\'jpeg\'',
  512. 'theming-favicon-mime' => '\'jpeg\'',
  513. 'image-logoheader' => '\'custom-logoheader?v=0\'',
  514. 'image-favicon' => '\'custom-favicon?v=0\''
  515. ];
  516. $this->assertEquals($expected, $this->template->getScssVariables());
  517. }
  518. public function testGetDefaultAndroidURL() {
  519. $this->config
  520. ->expects($this->once())
  521. ->method('getAppValue')
  522. ->with('theming', 'AndroidClientUrl', 'https://play.google.com/store/apps/details?id=com.nextcloud.client')
  523. ->willReturn('https://play.google.com/store/apps/details?id=com.nextcloud.client');
  524. $this->assertEquals('https://play.google.com/store/apps/details?id=com.nextcloud.client', $this->template->getAndroidClientUrl());
  525. }
  526. public function testGetCustomAndroidURL() {
  527. $this->config
  528. ->expects($this->once())
  529. ->method('getAppValue')
  530. ->with('theming', 'AndroidClientUrl', 'https://play.google.com/store/apps/details?id=com.nextcloud.client')
  531. ->willReturn('https://play.google.com/store/apps/details?id=com.mycloud.client');
  532. $this->assertEquals('https://play.google.com/store/apps/details?id=com.mycloud.client', $this->template->getAndroidClientUrl());
  533. }
  534. public function testGetDefaultiOSURL() {
  535. $this->config
  536. ->expects($this->once())
  537. ->method('getAppValue')
  538. ->with('theming', 'iOSClientUrl', 'https://geo.itunes.apple.com/us/app/nextcloud/id1125420102?mt=8')
  539. ->willReturn('https://geo.itunes.apple.com/us/app/nextcloud/id1125420102?mt=8');
  540. $this->assertEquals('https://geo.itunes.apple.com/us/app/nextcloud/id1125420102?mt=8', $this->template->getiOSClientUrl());
  541. }
  542. public function testGetCustomiOSURL() {
  543. $this->config
  544. ->expects($this->once())
  545. ->method('getAppValue')
  546. ->with('theming', 'iOSClientUrl', 'https://geo.itunes.apple.com/us/app/nextcloud/id1125420102?mt=8')
  547. ->willReturn('https://geo.itunes.apple.com/us/app/nextcloud/id1234567890?mt=8');
  548. $this->assertEquals('https://geo.itunes.apple.com/us/app/nextcloud/id1234567890?mt=8', $this->template->getiOSClientUrl());
  549. }
  550. public function testGetDefaultiTunesAppId() {
  551. $this->config
  552. ->expects($this->once())
  553. ->method('getAppValue')
  554. ->with('theming', 'iTunesAppId', '1125420102')
  555. ->willReturn('1125420102');
  556. $this->assertEquals('1125420102', $this->template->getiTunesAppId());
  557. }
  558. public function testGetCustomiTunesAppId() {
  559. $this->config
  560. ->expects($this->once())
  561. ->method('getAppValue')
  562. ->with('theming', 'iTunesAppId', '1125420102')
  563. ->willReturn('1234567890');
  564. $this->assertEquals('1234567890', $this->template->getiTunesAppId());
  565. }
  566. public function dataReplaceImagePath() {
  567. return [
  568. ['core', 'test.png', false],
  569. ['core', 'manifest.json'],
  570. ['core', 'favicon.ico'],
  571. ['core', 'favicon-touch.png']
  572. ];
  573. }
  574. /** @dataProvider dataReplaceImagePath */
  575. public function testReplaceImagePath($app, $image, $result = 'themingRoute?v=0') {
  576. $this->cache->expects($this->any())
  577. ->method('get')
  578. ->with('shouldReplaceIcons')
  579. ->willReturn(true);
  580. $this->config
  581. ->expects($this->any())
  582. ->method('getAppValue')
  583. ->with('theming', 'cachebuster', '0')
  584. ->willReturn('0');
  585. $this->urlGenerator
  586. ->expects($this->any())
  587. ->method('linkToRoute')
  588. ->willReturn('themingRoute');
  589. $this->assertEquals($result, $this->template->replaceImagePath($app, $image));
  590. }
  591. }