1
0

ThemingControllerTest.php 20 KB

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