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.

ThemingControllerTest.php 20KB

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