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 Christoph Wurst <christoph@winzerhof-wurst.at>
  8. * @author Guillaume COMPAGNON <gcompagnon@outlook.com>
  9. * @author Jan-Christoph Borchardt <hey@jancborchardt.net>
  10. * @author Joas Schilling <coding@schilljs.com>
  11. * @author John Molakvoæ <skjnldsv@protonmail.com>
  12. * @author Julius Haertl <jus@bitgrid.net>
  13. * @author Julius Härtl <jus@bitgrid.net>
  14. * @author Lukas Reschke <lukas@statuscode.ch>
  15. * @author Michael Weimann <mail@michael-weimann.eu>
  16. * @author Morris Jobke <hey@morrisjobke.de>
  17. * @author Roeland Jago Douma <roeland@famdouma.nl>
  18. *
  19. * @license GNU AGPL version 3 or any later version
  20. *
  21. * This program is free software: you can redistribute it and/or modify
  22. * it under the terms of the GNU Affero General Public License as
  23. * published by the Free Software Foundation, either version 3 of the
  24. * License, or (at your option) any later version.
  25. *
  26. * This program is distributed in the hope that it will be useful,
  27. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  28. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  29. * GNU Affero General Public License for more details.
  30. *
  31. * You should have received a copy of the GNU Affero General Public License
  32. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  33. *
  34. */
  35. namespace OCA\Theming\Tests;
  36. use OCA\Theming\ImageManager;
  37. use OCA\Theming\ThemingDefaults;
  38. use OCA\Theming\Util;
  39. use OCP\App\IAppManager;
  40. use OCP\Files\IAppData;
  41. use OCP\Files\NotFoundException;
  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. $this->config
  547. ->expects($this->at(0))
  548. ->method('getAppValue')
  549. ->with('theming', 'logoMime', false)
  550. ->willReturn('image/svg+xml');
  551. $this->config
  552. ->expects($this->at(1))
  553. ->method('getAppValue')
  554. ->with('theming', 'cachebuster', '0')
  555. ->willReturn('0');
  556. $this->urlGenerator->expects($this->once())
  557. ->method('linkToRoute')
  558. ->with('theming.Theming.getImage')
  559. ->willReturn('custom-logo?v=0');
  560. $this->assertEquals('custom-logo' . '?v=0', $this->template->getLogo());
  561. }
  562. public function testGetScssVariablesCached() {
  563. $this->config->expects($this->any())->method('getAppValue')->with('theming', 'cachebuster', '0')->willReturn('1');
  564. $this->cacheFactory->expects($this->once())
  565. ->method('createDistributed')
  566. ->with('theming-1-')
  567. ->willReturn($this->cache);
  568. $this->cache->expects($this->once())->method('get')->with('getScssVariables')->willReturn(['foo' => 'bar']);
  569. $this->assertEquals(['foo' => 'bar'], $this->template->getScssVariables());
  570. }
  571. public function testGetScssVariables() {
  572. $this->config->expects($this->at(0))->method('getAppValue')->with('theming', 'cachebuster', '0')->willReturn('0');
  573. $this->config->expects($this->at(1))->method('getAppValue')->with('theming', 'logoMime', false)->willReturn('jpeg');
  574. $this->config->expects($this->at(2))->method('getAppValue')->with('theming', 'backgroundMime', false)->willReturn('jpeg');
  575. $this->config->expects($this->at(3))->method('getAppValue')->with('theming', 'logoheaderMime', false)->willReturn('jpeg');
  576. $this->config->expects($this->at(4))->method('getAppValue')->with('theming', 'faviconMime', false)->willReturn('jpeg');
  577. $this->config->expects($this->at(5))->method('getAppValue')->with('theming', 'color', null)->willReturn($this->defaults->getColorPrimary());
  578. $this->config->expects($this->at(6))->method('getAppValue')->with('theming', 'color', $this->defaults->getColorPrimary())->willReturn($this->defaults->getColorPrimary());
  579. $this->config->expects($this->at(7))->method('getAppValue')->with('theming', 'color', $this->defaults->getColorPrimary())->willReturn($this->defaults->getColorPrimary());
  580. $this->config->expects($this->at(8))->method('getAppValue')->with('theming', 'color', $this->defaults->getColorPrimary())->willReturn($this->defaults->getColorPrimary());
  581. $this->util->expects($this->any())->method('invertTextColor')->with($this->defaults->getColorPrimary())->willReturn(false);
  582. $this->util->expects($this->any())->method('elementColor')->with($this->defaults->getColorPrimary())->willReturn('#aaaaaa');
  583. $this->cacheFactory->expects($this->once())
  584. ->method('createDistributed')
  585. ->with('theming-0-')
  586. ->willReturn($this->cache);
  587. $this->cache->expects($this->once())->method('get')->with('getScssVariables')->willReturn(null);
  588. $this->imageManager->expects($this->at(0))->method('getImageUrl')->with('logo')->willReturn('custom-logo?v=0');
  589. $this->imageManager->expects($this->at(1))->method('getImageUrl')->with('logoheader')->willReturn('custom-logoheader?v=0');
  590. $this->imageManager->expects($this->at(2))->method('getImageUrl')->with('favicon')->willReturn('custom-favicon?v=0');
  591. $this->imageManager->expects($this->at(3))->method('getImageUrl')->with('background')->willReturn('custom-background?v=0');
  592. $expected = [
  593. 'theming-cachebuster' => '\'0\'',
  594. 'theming-logo-mime' => '\'jpeg\'',
  595. 'theming-background-mime' => '\'jpeg\'',
  596. 'image-logo' => "url('custom-logo?v=0')",
  597. 'image-login-background' => "url('custom-background?v=0')",
  598. 'color-primary' => $this->defaults->getColorPrimary(),
  599. 'color-primary-text' => '#ffffff',
  600. 'image-login-plain' => 'false',
  601. 'color-primary-element' => '#aaaaaa',
  602. 'theming-logoheader-mime' => '\'jpeg\'',
  603. 'theming-favicon-mime' => '\'jpeg\'',
  604. 'image-logoheader' => "url('custom-logoheader?v=0')",
  605. 'image-favicon' => "url('custom-favicon?v=0')",
  606. 'has-legal-links' => 'false'
  607. ];
  608. $this->assertEquals($expected, $this->template->getScssVariables());
  609. }
  610. public function testGetDefaultAndroidURL() {
  611. $this->config
  612. ->expects($this->once())
  613. ->method('getAppValue')
  614. ->with('theming', 'AndroidClientUrl', 'https://play.google.com/store/apps/details?id=com.nextcloud.client')
  615. ->willReturn('https://play.google.com/store/apps/details?id=com.nextcloud.client');
  616. $this->assertEquals('https://play.google.com/store/apps/details?id=com.nextcloud.client', $this->template->getAndroidClientUrl());
  617. }
  618. public function testGetCustomAndroidURL() {
  619. $this->config
  620. ->expects($this->once())
  621. ->method('getAppValue')
  622. ->with('theming', 'AndroidClientUrl', 'https://play.google.com/store/apps/details?id=com.nextcloud.client')
  623. ->willReturn('https://play.google.com/store/apps/details?id=com.mycloud.client');
  624. $this->assertEquals('https://play.google.com/store/apps/details?id=com.mycloud.client', $this->template->getAndroidClientUrl());
  625. }
  626. public function testGetDefaultiOSURL() {
  627. $this->config
  628. ->expects($this->once())
  629. ->method('getAppValue')
  630. ->with('theming', 'iOSClientUrl', 'https://geo.itunes.apple.com/us/app/nextcloud/id1125420102?mt=8')
  631. ->willReturn('https://geo.itunes.apple.com/us/app/nextcloud/id1125420102?mt=8');
  632. $this->assertEquals('https://geo.itunes.apple.com/us/app/nextcloud/id1125420102?mt=8', $this->template->getiOSClientUrl());
  633. }
  634. public function testGetCustomiOSURL() {
  635. $this->config
  636. ->expects($this->once())
  637. ->method('getAppValue')
  638. ->with('theming', 'iOSClientUrl', 'https://geo.itunes.apple.com/us/app/nextcloud/id1125420102?mt=8')
  639. ->willReturn('https://geo.itunes.apple.com/us/app/nextcloud/id1234567890?mt=8');
  640. $this->assertEquals('https://geo.itunes.apple.com/us/app/nextcloud/id1234567890?mt=8', $this->template->getiOSClientUrl());
  641. }
  642. public function testGetDefaultiTunesAppId() {
  643. $this->config
  644. ->expects($this->once())
  645. ->method('getAppValue')
  646. ->with('theming', 'iTunesAppId', '1125420102')
  647. ->willReturn('1125420102');
  648. $this->assertEquals('1125420102', $this->template->getiTunesAppId());
  649. }
  650. public function testGetCustomiTunesAppId() {
  651. $this->config
  652. ->expects($this->once())
  653. ->method('getAppValue')
  654. ->with('theming', 'iTunesAppId', '1125420102')
  655. ->willReturn('1234567890');
  656. $this->assertEquals('1234567890', $this->template->getiTunesAppId());
  657. }
  658. public function dataReplaceImagePath() {
  659. return [
  660. ['core', 'test.png', false],
  661. ['core', 'manifest.json'],
  662. ['core', 'favicon.ico'],
  663. ['core', 'favicon-touch.png']
  664. ];
  665. }
  666. /** @dataProvider dataReplaceImagePath */
  667. public function testReplaceImagePath($app, $image, $result = 'themingRoute?v=0') {
  668. $this->cache->expects($this->any())
  669. ->method('get')
  670. ->with('shouldReplaceIcons')
  671. ->willReturn(true);
  672. $this->config
  673. ->expects($this->any())
  674. ->method('getAppValue')
  675. ->with('theming', 'cachebuster', '0')
  676. ->willReturn('0');
  677. $this->urlGenerator
  678. ->expects($this->any())
  679. ->method('linkToRoute')
  680. ->willReturn('themingRoute');
  681. $this->assertEquals($result, $this->template->replaceImagePath($app, $image));
  682. }
  683. }