You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

780 lines
26 KiB

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