From 770aae42f6c57e3a273c7b09a91d43a366175234 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Mon, 11 Sep 2017 15:04:26 +0200 Subject: [PATCH] Add themed manifest.json to theming app Signed-off-by: Julius Haertl --- apps/theming/appinfo/routes.php | 6 +++ .../lib/Controller/ThemingController.php | 35 +++++++++++++ .../Controller/ThemingControllerTest.php | 49 +++++++++++++++++++ 3 files changed, 90 insertions(+) diff --git a/apps/theming/appinfo/routes.php b/apps/theming/appinfo/routes.php index f4aa2f9316..530e13f53d 100644 --- a/apps/theming/appinfo/routes.php +++ b/apps/theming/appinfo/routes.php @@ -60,6 +60,12 @@ return ['routes' => [ 'url' => '/js/theming', 'verb' => 'GET', ], + [ + 'name' => 'Theming#getManifest', + 'url' => '/manifest/{app}', + 'verb' => 'GET', + 'defaults' => array('app' => 'core') + ], [ 'name' => 'Icon#getFavicon', 'url' => '/favicon/{app}', diff --git a/apps/theming/lib/Controller/ThemingController.php b/apps/theming/lib/Controller/ThemingController.php index b409d309f4..06c2c430b7 100644 --- a/apps/theming/lib/Controller/ThemingController.php +++ b/apps/theming/lib/Controller/ThemingController.php @@ -423,4 +423,39 @@ class ThemingController extends Controller { $response->cacheFor(3600); return $response; } + + /** + * @NoCSRFRequired + * @PublicPage + * + * @return Http\JSONResponse + */ + public function getManifest($app) { + $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); + $responseJS = [ + 'name' => $this->themingDefaults->getName(), + 'start_url' => $this->urlGenerator->getBaseUrl(), + 'icons' => + [ + [ + 'src' => $this->urlGenerator->linkToRoute('theming.Icon.getTouchIcon', + ['app' => $app]) . '?v=' . $cacheBusterValue, + 'type'=> 'image/png', + 'sizes'=> '128x128' + ], + [ + 'src' => $this->urlGenerator->linkToRoute('theming.Icon.getFavicon', + ['app' => $app]) . '?v=' . $cacheBusterValue, + 'type' => 'image/svg+xml', + 'sizes' => '16x16' + ] + ], + 'display' => 'standalone' + ]; + $response = new Http\JSONResponse($responseJS); + $response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime())); + $response->addHeader('Pragma', 'cache'); + $response->cacheFor(3600); + return $response; + } } diff --git a/apps/theming/tests/Controller/ThemingControllerTest.php b/apps/theming/tests/Controller/ThemingControllerTest.php index 5e6e43ca3c..c03eccb6ee 100644 --- a/apps/theming/tests/Controller/ThemingControllerTest.php +++ b/apps/theming/tests/Controller/ThemingControllerTest.php @@ -729,4 +729,53 @@ class ThemingControllerTest extends TestCase { $expected->cacheFor(3600); @$this->assertEquals($expected, $this->themingController->getJavascript()); } + + public function testGetManifest() { + $this->config + ->expects($this->once()) + ->method('getAppValue') + ->with('theming', 'cachebuster', '0') + ->willReturn('0'); + $this->themingDefaults + ->expects($this->any()) + ->method('getName') + ->willReturn('Nextcloud'); + $this->urlGenerator + ->expects($this->at(0)) + ->method('getBaseUrl') + ->willReturn('localhost'); + $this->urlGenerator + ->expects($this->at(1)) + ->method('linkToRoute') + ->with('theming.Icon.getTouchIcon', ['app' => 'core']) + ->willReturn('touchicon'); + $this->urlGenerator + ->expects($this->at(2)) + ->method('linkToRoute') + ->with('theming.Icon.getFavicon', ['app' => 'core']) + ->willReturn('favicon'); + $response = new Http\JSONResponse([ + 'name' => 'Nextcloud', + 'start_url' => 'localhost', + 'icons' => + [ + [ + 'src' => 'touchicon?v=0', + 'type'=> 'image/png', + 'sizes'=> '128x128' + ], + [ + 'src' => 'favicon?v=0', + 'type' => 'image/svg+xml', + 'sizes' => '16x16' + ] + ], + 'display' => 'standalone' + ]); + $response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime())); + $response->addHeader('Pragma', 'cache'); + $response->cacheFor(3600); + $this->assertEquals($response, $this->themingController->getManifest('core')); + } + }