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

ThemingDefaultsTest.php 27KB

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