ThemingDefaultsTest.php 26 KB

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