ThemingDefaultsTest.php 26 KB

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