ThemingControllerTest.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\Theming\Tests\Controller;
  7. use OC\L10N\L10N;
  8. use OCA\Theming\Controller\ThemingController;
  9. use OCA\Theming\ImageManager;
  10. use OCA\Theming\Service\ThemesService;
  11. use OCA\Theming\ThemingDefaults;
  12. use OCP\App\IAppManager;
  13. use OCP\AppFramework\Http;
  14. use OCP\AppFramework\Http\DataResponse;
  15. use OCP\AppFramework\Services\IAppConfig;
  16. use OCP\AppFramework\Utility\ITimeFactory;
  17. use OCP\Files\NotFoundException;
  18. use OCP\Files\SimpleFS\ISimpleFile;
  19. use OCP\IConfig;
  20. use OCP\IL10N;
  21. use OCP\IRequest;
  22. use OCP\IURLGenerator;
  23. use PHPUnit\Framework\MockObject\MockObject;
  24. use Test\TestCase;
  25. class ThemingControllerTest extends TestCase {
  26. private IRequest&MockObject $request;
  27. private IConfig&MockObject $config;
  28. private IAppConfig&MockObject $appConfig;
  29. private ThemingDefaults&MockObject $themingDefaults;
  30. private IL10N&MockObject $l10n;
  31. private IAppManager&MockObject $appManager;
  32. private ImageManager&MockObject $imageManager;
  33. private IURLGenerator&MockObject $urlGenerator;
  34. private ThemesService&MockObject $themesService;
  35. private ThemingController $themingController;
  36. protected function setUp(): void {
  37. $this->request = $this->createMock(IRequest::class);
  38. $this->config = $this->createMock(IConfig::class);
  39. $this->appConfig = $this->createMock(IAppConfig::class);
  40. $this->themingDefaults = $this->createMock(ThemingDefaults::class);
  41. $this->l10n = $this->createMock(L10N::class);
  42. $this->appManager = $this->createMock(IAppManager::class);
  43. $this->urlGenerator = $this->createMock(IURLGenerator::class);
  44. $this->imageManager = $this->createMock(ImageManager::class);
  45. $this->themesService = $this->createMock(ThemesService::class);
  46. $timeFactory = $this->createMock(ITimeFactory::class);
  47. $timeFactory->expects($this->any())
  48. ->method('getTime')
  49. ->willReturn(123);
  50. $this->overwriteService(ITimeFactory::class, $timeFactory);
  51. $this->themingController = new ThemingController(
  52. 'theming',
  53. $this->request,
  54. $this->config,
  55. $this->appConfig,
  56. $this->themingDefaults,
  57. $this->l10n,
  58. $this->urlGenerator,
  59. $this->appManager,
  60. $this->imageManager,
  61. $this->themesService,
  62. );
  63. parent::setUp();
  64. }
  65. public function dataUpdateStylesheetSuccess() {
  66. return [
  67. ['name', str_repeat('a', 250), 'Saved'],
  68. ['url', 'https://nextcloud.com/' . str_repeat('a', 478), 'Saved'],
  69. ['slogan', str_repeat('a', 500), 'Saved'],
  70. ['color', '#0082c9', 'Saved'],
  71. ['color', '#0082C9', 'Saved'],
  72. ['color', '#0082C9', 'Saved'],
  73. ['imprintUrl', 'https://nextcloud.com/' . str_repeat('a', 478), 'Saved'],
  74. ['privacyUrl', 'https://nextcloud.com/' . str_repeat('a', 478), 'Saved'],
  75. ];
  76. }
  77. /**
  78. * @dataProvider dataUpdateStylesheetSuccess
  79. *
  80. * @param string $setting
  81. * @param string $value
  82. * @param string $message
  83. */
  84. public function testUpdateStylesheetSuccess($setting, $value, $message) {
  85. $this->themingDefaults
  86. ->expects($this->once())
  87. ->method('set')
  88. ->with($setting, $value);
  89. $this->l10n
  90. ->expects($this->once())
  91. ->method('t')
  92. ->willReturnCallback(function ($str) {
  93. return $str;
  94. });
  95. $expected = new DataResponse(
  96. [
  97. 'data' =>
  98. [
  99. 'message' => $message,
  100. ],
  101. 'status' => 'success',
  102. ]
  103. );
  104. $this->assertEquals($expected, $this->themingController->updateStylesheet($setting, $value));
  105. }
  106. public function dataUpdateStylesheetError() {
  107. return [
  108. ['name', str_repeat('a', 251), 'The given name is too long'],
  109. ['url', 'http://example.com/' . str_repeat('a', 501), 'The given web address is too long'],
  110. ['url', str_repeat('a', 501), 'The given web address is not a valid URL'],
  111. ['url', 'javascript:alert(1)', 'The given web address is not a valid URL'],
  112. ['slogan', str_repeat('a', 501), 'The given slogan is too long'],
  113. ['primary_color', '0082C9', 'The given color is invalid'],
  114. ['primary_color', '#0082Z9', 'The given color is invalid'],
  115. ['primary_color', 'Nextcloud', 'The given color is invalid'],
  116. ['background_color', '0082C9', 'The given color is invalid'],
  117. ['background_color', '#0082Z9', 'The given color is invalid'],
  118. ['background_color', 'Nextcloud', 'The given color is invalid'],
  119. ['imprintUrl', '0082C9', 'The given legal notice address is not a valid URL'],
  120. ['imprintUrl', '0082C9', 'The given legal notice address is not a valid URL'],
  121. ['imprintUrl', 'javascript:foo', 'The given legal notice address is not a valid URL'],
  122. ['privacyUrl', '#0082Z9', 'The given privacy policy address is not a valid URL'],
  123. ];
  124. }
  125. /**
  126. * @dataProvider dataUpdateStylesheetError
  127. *
  128. * @param string $setting
  129. * @param string $value
  130. * @param string $message
  131. */
  132. public function testUpdateStylesheetError($setting, $value, $message) {
  133. $this->themingDefaults
  134. ->expects($this->never())
  135. ->method('set')
  136. ->with($setting, $value);
  137. $this->l10n
  138. ->expects($this->any())
  139. ->method('t')
  140. ->willReturnCallback(function ($str) {
  141. return $str;
  142. });
  143. $expected = new DataResponse(
  144. [
  145. 'data' =>
  146. [
  147. 'message' => $message,
  148. ],
  149. 'status' => 'error',
  150. ],
  151. Http::STATUS_BAD_REQUEST
  152. );
  153. $this->assertEquals($expected, $this->themingController->updateStylesheet($setting, $value));
  154. }
  155. public function testUpdateLogoNoData() {
  156. $this->request
  157. ->expects($this->once())
  158. ->method('getParam')
  159. ->with('key')
  160. ->willReturn('logo');
  161. $this->request
  162. ->expects($this->once())
  163. ->method('getUploadedFile')
  164. ->with('image')
  165. ->willReturn(null);
  166. $this->l10n
  167. ->expects($this->any())
  168. ->method('t')
  169. ->willReturnCallback(function ($str) {
  170. return $str;
  171. });
  172. $expected = new DataResponse(
  173. [
  174. 'data' =>
  175. [
  176. 'message' => 'No file uploaded',
  177. ],
  178. 'status' => 'failure',
  179. ],
  180. Http::STATUS_UNPROCESSABLE_ENTITY
  181. );
  182. $this->assertEquals($expected, $this->themingController->uploadImage());
  183. }
  184. public function testUploadInvalidUploadKey() {
  185. $this->request
  186. ->expects($this->once())
  187. ->method('getParam')
  188. ->with('key')
  189. ->willReturn('invalid');
  190. $this->request
  191. ->expects($this->never())
  192. ->method('getUploadedFile');
  193. $this->l10n
  194. ->expects($this->any())
  195. ->method('t')
  196. ->willReturnCallback(function ($str) {
  197. return $str;
  198. });
  199. $expected = new DataResponse(
  200. [
  201. 'data' =>
  202. [
  203. 'message' => 'Invalid key',
  204. ],
  205. 'status' => 'failure',
  206. ],
  207. Http::STATUS_BAD_REQUEST
  208. );
  209. $this->assertEquals($expected, $this->themingController->uploadImage());
  210. }
  211. /**
  212. * Checks that trying to upload an SVG favicon without imagemagick
  213. * results in an unsupported media type response.
  214. *
  215. * @test
  216. * @return void
  217. */
  218. public function testUploadSVGFaviconWithoutImagemagick() {
  219. $this->imageManager
  220. ->method('shouldReplaceIcons')
  221. ->willReturn(false);
  222. $this->request
  223. ->expects($this->once())
  224. ->method('getParam')
  225. ->with('key')
  226. ->willReturn('favicon');
  227. $this->request
  228. ->expects($this->once())
  229. ->method('getUploadedFile')
  230. ->with('image')
  231. ->willReturn([
  232. 'tmp_name' => __DIR__ . '/../../../../tests/data/testimagelarge.svg',
  233. 'type' => 'image/svg',
  234. 'name' => 'testimagelarge.svg',
  235. 'error' => 0,
  236. ]);
  237. $this->l10n
  238. ->expects($this->any())
  239. ->method('t')
  240. ->willReturnCallback(function ($str) {
  241. return $str;
  242. });
  243. $this->imageManager->expects($this->once())
  244. ->method('updateImage')
  245. ->willThrowException(new \Exception('Unsupported image type'));
  246. $expected = new DataResponse(
  247. [
  248. 'data' =>
  249. [
  250. 'message' => 'Unsupported image type',
  251. ],
  252. 'status' => 'failure'
  253. ],
  254. Http::STATUS_UNPROCESSABLE_ENTITY
  255. );
  256. $this->assertEquals($expected, $this->themingController->uploadImage());
  257. }
  258. public function testUpdateLogoInvalidMimeType() {
  259. $this->request
  260. ->expects($this->once())
  261. ->method('getParam')
  262. ->with('key')
  263. ->willReturn('logo');
  264. $this->request
  265. ->expects($this->once())
  266. ->method('getUploadedFile')
  267. ->with('image')
  268. ->willReturn([
  269. 'tmp_name' => __DIR__ . '/../../../../tests/data/lorem.txt',
  270. 'type' => 'application/pdf',
  271. 'name' => 'logo.pdf',
  272. 'error' => 0,
  273. ]);
  274. $this->l10n
  275. ->expects($this->any())
  276. ->method('t')
  277. ->willReturnCallback(function ($str) {
  278. return $str;
  279. });
  280. $this->imageManager->expects($this->once())
  281. ->method('updateImage')
  282. ->willThrowException(new \Exception('Unsupported image type'));
  283. $expected = new DataResponse(
  284. [
  285. 'data' =>
  286. [
  287. 'message' => 'Unsupported image type',
  288. ],
  289. 'status' => 'failure'
  290. ],
  291. Http::STATUS_UNPROCESSABLE_ENTITY
  292. );
  293. $this->assertEquals($expected, $this->themingController->uploadImage());
  294. }
  295. public function dataUpdateImages() {
  296. return [
  297. ['image/jpeg', false],
  298. ['image/jpeg', true],
  299. ['image/gif'],
  300. ['image/png'],
  301. ['image/svg+xml'],
  302. ['image/svg']
  303. ];
  304. }
  305. /** @dataProvider dataUpdateImages */
  306. public function testUpdateLogoNormalLogoUpload($mimeType, $folderExists = true) {
  307. $tmpLogo = \OC::$server->getTempManager()->getTemporaryFolder() . '/logo.svg';
  308. $destination = \OC::$server->getTempManager()->getTemporaryFolder();
  309. touch($tmpLogo);
  310. copy(__DIR__ . '/../../../../tests/data/testimage.png', $tmpLogo);
  311. $this->request
  312. ->expects($this->once())
  313. ->method('getParam')
  314. ->with('key')
  315. ->willReturn('logo');
  316. $this->request
  317. ->expects($this->once())
  318. ->method('getUploadedFile')
  319. ->with('image')
  320. ->willReturn([
  321. 'tmp_name' => $tmpLogo,
  322. 'type' => $mimeType,
  323. 'name' => 'logo.svg',
  324. 'error' => 0,
  325. ]);
  326. $this->l10n
  327. ->expects($this->any())
  328. ->method('t')
  329. ->willReturnCallback(function ($str) {
  330. return $str;
  331. });
  332. $this->imageManager->expects($this->once())
  333. ->method('getImageUrl')
  334. ->with('logo')
  335. ->willReturn('imageUrl');
  336. $this->imageManager->expects($this->once())
  337. ->method('updateImage');
  338. $expected = new DataResponse(
  339. [
  340. 'data' =>
  341. [
  342. 'name' => 'logo.svg',
  343. 'message' => 'Saved',
  344. 'url' => 'imageUrl',
  345. ],
  346. 'status' => 'success'
  347. ]
  348. );
  349. $this->assertEquals($expected, $this->themingController->uploadImage());
  350. }
  351. /** @dataProvider dataUpdateImages */
  352. public function testUpdateLogoLoginScreenUpload($folderExists) {
  353. $tmpLogo = \OC::$server->getTempManager()->getTemporaryFolder() . 'logo.png';
  354. touch($tmpLogo);
  355. copy(__DIR__ . '/../../../../tests/data/desktopapp.png', $tmpLogo);
  356. $this->request
  357. ->expects($this->once())
  358. ->method('getParam')
  359. ->with('key')
  360. ->willReturn('background');
  361. $this->request
  362. ->expects($this->once())
  363. ->method('getUploadedFile')
  364. ->with('image')
  365. ->willReturn([
  366. 'tmp_name' => $tmpLogo,
  367. 'type' => 'image/svg+xml',
  368. 'name' => 'logo.svg',
  369. 'error' => 0,
  370. ]);
  371. $this->l10n
  372. ->expects($this->any())
  373. ->method('t')
  374. ->willReturnCallback(function ($str) {
  375. return $str;
  376. });
  377. $this->imageManager->expects($this->once())
  378. ->method('updateImage');
  379. $this->imageManager->expects($this->once())
  380. ->method('getImageUrl')
  381. ->with('background')
  382. ->willReturn('imageUrl');
  383. $expected = new DataResponse(
  384. [
  385. 'data' =>
  386. [
  387. 'name' => 'logo.svg',
  388. 'message' => 'Saved',
  389. 'url' => 'imageUrl',
  390. ],
  391. 'status' => 'success'
  392. ]
  393. );
  394. $this->assertEquals($expected, $this->themingController->uploadImage());
  395. }
  396. public function testUpdateLogoLoginScreenUploadWithInvalidImage() {
  397. $tmpLogo = \OC::$server->getTempManager()->getTemporaryFolder() . '/logo.svg';
  398. touch($tmpLogo);
  399. file_put_contents($tmpLogo, file_get_contents(__DIR__ . '/../../../../tests/data/data.zip'));
  400. $this->request
  401. ->expects($this->once())
  402. ->method('getParam')
  403. ->with('key')
  404. ->willReturn('logo');
  405. $this->request
  406. ->expects($this->once())
  407. ->method('getUploadedFile')
  408. ->with('image')
  409. ->willReturn([
  410. 'tmp_name' => $tmpLogo,
  411. 'type' => 'foobar',
  412. 'name' => 'logo.svg',
  413. 'error' => 0,
  414. ]);
  415. $this->l10n
  416. ->expects($this->any())
  417. ->method('t')
  418. ->willReturnCallback(function ($str) {
  419. return $str;
  420. });
  421. $this->imageManager->expects($this->once())
  422. ->method('updateImage')
  423. ->willThrowException(new \Exception('Unsupported image type'));
  424. $expected = new DataResponse(
  425. [
  426. 'data' =>
  427. [
  428. 'message' => 'Unsupported image type',
  429. ],
  430. 'status' => 'failure'
  431. ],
  432. Http::STATUS_UNPROCESSABLE_ENTITY
  433. );
  434. $this->assertEquals($expected, $this->themingController->uploadImage());
  435. }
  436. public function dataPhpUploadErrors() {
  437. return [
  438. [UPLOAD_ERR_INI_SIZE, 'The uploaded file exceeds the upload_max_filesize directive in php.ini'],
  439. [UPLOAD_ERR_FORM_SIZE, 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'],
  440. [UPLOAD_ERR_PARTIAL, 'The file was only partially uploaded'],
  441. [UPLOAD_ERR_NO_FILE, 'No file was uploaded'],
  442. [UPLOAD_ERR_NO_TMP_DIR, 'Missing a temporary folder'],
  443. [UPLOAD_ERR_CANT_WRITE, 'Could not write file to disk'],
  444. [UPLOAD_ERR_EXTENSION, 'A PHP extension stopped the file upload'],
  445. ];
  446. }
  447. /**
  448. * @dataProvider dataPhpUploadErrors
  449. */
  450. public function testUpdateLogoLoginScreenUploadWithInvalidImageUpload($error, $expectedErrorMessage) {
  451. $this->request
  452. ->expects($this->once())
  453. ->method('getParam')
  454. ->with('key')
  455. ->willReturn('background');
  456. $this->request
  457. ->expects($this->once())
  458. ->method('getUploadedFile')
  459. ->with('image')
  460. ->willReturn([
  461. 'tmp_name' => '',
  462. 'type' => 'image/svg+xml',
  463. 'name' => 'logo.svg',
  464. 'error' => $error,
  465. ]);
  466. $this->l10n
  467. ->expects($this->any())
  468. ->method('t')
  469. ->willReturnCallback(function ($str) {
  470. return $str;
  471. });
  472. $expected = new DataResponse(
  473. [
  474. 'data' =>
  475. [
  476. 'message' => $expectedErrorMessage,
  477. ],
  478. 'status' => 'failure'
  479. ],
  480. Http::STATUS_UNPROCESSABLE_ENTITY
  481. );
  482. $this->assertEquals($expected, $this->themingController->uploadImage());
  483. }
  484. /**
  485. * @dataProvider dataPhpUploadErrors
  486. */
  487. public function testUpdateLogoUploadWithInvalidImageUpload($error, $expectedErrorMessage) {
  488. $this->request
  489. ->expects($this->once())
  490. ->method('getParam')
  491. ->with('key')
  492. ->willReturn('background');
  493. $this->request
  494. ->expects($this->once())
  495. ->method('getUploadedFile')
  496. ->with('image')
  497. ->willReturn([
  498. 'tmp_name' => '',
  499. 'type' => 'text/svg',
  500. 'name' => 'logo.svg',
  501. 'error' => $error,
  502. ]);
  503. $this->l10n
  504. ->expects($this->any())
  505. ->method('t')
  506. ->willReturnCallback(function ($str) {
  507. return $str;
  508. });
  509. $expected = new DataResponse(
  510. [
  511. 'data' =>
  512. [
  513. 'message' => $expectedErrorMessage
  514. ],
  515. 'status' => 'failure'
  516. ],
  517. Http::STATUS_UNPROCESSABLE_ENTITY
  518. );
  519. $this->assertEquals($expected, $this->themingController->uploadImage());
  520. }
  521. public function testUndo() {
  522. $this->l10n
  523. ->expects($this->once())
  524. ->method('t')
  525. ->with('Saved')
  526. ->willReturn('Saved');
  527. $this->themingDefaults
  528. ->expects($this->once())
  529. ->method('undo')
  530. ->with('MySetting')
  531. ->willReturn('MyValue');
  532. $expected = new DataResponse(
  533. [
  534. 'data' =>
  535. [
  536. 'value' => 'MyValue',
  537. 'message' => 'Saved'
  538. ],
  539. 'status' => 'success'
  540. ]
  541. );
  542. $this->assertEquals($expected, $this->themingController->undo('MySetting'));
  543. }
  544. public function dataUndoDelete() {
  545. return [
  546. [ 'backgroundMime', 'background' ],
  547. [ 'logoMime', 'logo' ]
  548. ];
  549. }
  550. /** @dataProvider dataUndoDelete */
  551. public function testUndoDelete($value, $filename) {
  552. $this->l10n
  553. ->expects($this->once())
  554. ->method('t')
  555. ->with('Saved')
  556. ->willReturn('Saved');
  557. $this->themingDefaults
  558. ->expects($this->once())
  559. ->method('undo')
  560. ->with($value)
  561. ->willReturn($value);
  562. $expected = new DataResponse(
  563. [
  564. 'data' =>
  565. [
  566. 'value' => $value,
  567. 'message' => 'Saved',
  568. ],
  569. 'status' => 'success'
  570. ]
  571. );
  572. $this->assertEquals($expected, $this->themingController->undo($value));
  573. }
  574. public function testGetLogoNotExistent() {
  575. $this->imageManager->method('getImage')
  576. ->with($this->equalTo('logo'))
  577. ->willThrowException(new NotFoundException());
  578. $expected = new Http\NotFoundResponse();
  579. $this->assertEquals($expected, $this->themingController->getImage('logo'));
  580. }
  581. public function testGetLogo() {
  582. $file = $this->createMock(ISimpleFile::class);
  583. $file->method('getName')->willReturn('logo.svg');
  584. $file->method('getMTime')->willReturn(42);
  585. $this->imageManager->expects($this->once())
  586. ->method('getImage')
  587. ->willReturn($file);
  588. $this->config
  589. ->expects($this->any())
  590. ->method('getAppValue')
  591. ->with('theming', 'logoMime', '')
  592. ->willReturn('text/svg');
  593. @$expected = new Http\FileDisplayResponse($file);
  594. $expected->cacheFor(3600);
  595. $expected->addHeader('Content-Type', 'text/svg');
  596. $expected->addHeader('Content-Disposition', 'attachment; filename="logo"');
  597. $csp = new Http\ContentSecurityPolicy();
  598. $csp->allowInlineStyle();
  599. $expected->setContentSecurityPolicy($csp);
  600. @$this->assertEquals($expected, $this->themingController->getImage('logo'));
  601. }
  602. public function testGetLoginBackgroundNotExistent() {
  603. $this->imageManager->method('getImage')
  604. ->with($this->equalTo('background'))
  605. ->willThrowException(new NotFoundException());
  606. $expected = new Http\NotFoundResponse();
  607. $this->assertEquals($expected, $this->themingController->getImage('background'));
  608. }
  609. public function testGetLoginBackground() {
  610. $file = $this->createMock(ISimpleFile::class);
  611. $file->method('getName')->willReturn('background.png');
  612. $file->method('getMTime')->willReturn(42);
  613. $this->imageManager->expects($this->once())
  614. ->method('getImage')
  615. ->willReturn($file);
  616. $this->config
  617. ->expects($this->any())
  618. ->method('getAppValue')
  619. ->with('theming', 'backgroundMime', '')
  620. ->willReturn('image/png');
  621. @$expected = new Http\FileDisplayResponse($file);
  622. $expected->cacheFor(3600);
  623. $expected->addHeader('Content-Type', 'image/png');
  624. $expected->addHeader('Content-Disposition', 'attachment; filename="background"');
  625. $csp = new Http\ContentSecurityPolicy();
  626. $csp->allowInlineStyle();
  627. $expected->setContentSecurityPolicy($csp);
  628. @$this->assertEquals($expected, $this->themingController->getImage('background'));
  629. }
  630. public function testGetManifest() {
  631. $this->config
  632. ->expects($this->once())
  633. ->method('getAppValue')
  634. ->with('theming', 'cachebuster', '0')
  635. ->willReturn('0');
  636. $this->themingDefaults
  637. ->expects($this->any())
  638. ->method('getName')
  639. ->willReturn('Nextcloud');
  640. $this->urlGenerator
  641. ->expects($this->once())
  642. ->method('getBaseUrl')
  643. ->willReturn('localhost');
  644. $this->urlGenerator
  645. ->expects($this->exactly(2))
  646. ->method('linkToRoute')
  647. ->withConsecutive(
  648. ['theming.Icon.getTouchIcon', ['app' => 'core']],
  649. ['theming.Icon.getFavicon', ['app' => 'core']],
  650. )->willReturnOnConsecutiveCalls(
  651. 'touchicon',
  652. 'favicon',
  653. );
  654. $response = new Http\JSONResponse([
  655. 'name' => 'Nextcloud',
  656. 'start_url' => 'localhost',
  657. 'icons' =>
  658. [
  659. [
  660. 'src' => 'touchicon?v=0',
  661. 'type' => 'image/png',
  662. 'sizes' => '512x512'
  663. ],
  664. [
  665. 'src' => 'favicon?v=0',
  666. 'type' => 'image/svg+xml',
  667. 'sizes' => '16x16'
  668. ]
  669. ],
  670. 'display' => 'standalone',
  671. 'short_name' => 'Nextcloud',
  672. 'theme_color' => null,
  673. 'background_color' => null,
  674. 'description' => null
  675. ]);
  676. $response->cacheFor(3600);
  677. $this->assertEquals($response, $this->themingController->getManifest('core'));
  678. }
  679. }