ThemingDefaultsTest.php 25 KB

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