diff options
-rw-r--r-- | appinfo/application.php | 9 | ||||
-rw-r--r-- | appinfo/routes.php | 3 | ||||
-rw-r--r-- | controller/appcontroller.php | 76 | ||||
-rw-r--r-- | img/app-128.png | bin | 0 -> 1797 bytes | |||
-rw-r--r-- | img/app-512.png | bin | 0 -> 7859 bytes | |||
-rw-r--r-- | tests/unit/controller/AppControllerTest.php | 69 |
6 files changed, 157 insertions, 0 deletions
diff --git a/appinfo/application.php b/appinfo/application.php index eaeafc858..d80498a4a 100644 --- a/appinfo/application.php +++ b/appinfo/application.php @@ -29,6 +29,7 @@ use \OCA\News\Controller\UtilityApiController; use \OCA\News\Controller\FolderApiController; use \OCA\News\Controller\FeedApiController; use \OCA\News\Controller\ItemApiController; +use \OCA\News\Controller\AppController; use \OCA\News\Service\FolderService; use \OCA\News\Service\FeedService; @@ -169,6 +170,14 @@ class Application extends App { ); }); + $container->registerService('AppController', function($c) { + return new AppController( + $c->query('AppName'), + $c->query('Request'), + $c->query('ServerContainer')->getURLGenerator(), + $c->query('AppConfig') + ); + }); /** * Business Layer diff --git a/appinfo/routes.php b/appinfo/routes.php index 66f3e97e7..3e2ac189f 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -22,6 +22,9 @@ $application->registerRoutes($this, ['routes' => [ ['name' => 'page#settings', 'url' => '/settings', 'verb' => 'GET'], ['name' => 'page#update_settings', 'url' => '/settings', 'verb' => 'PUT'], + // web app manifest + ['name' => 'app#manifest', 'url' => '/manifest.webapp', 'verb' => 'GET'], + // folders ['name' => 'folder#index', 'url' => '/folders', 'verb' => 'GET'], ['name' => 'folder#create', 'url' => '/folders', 'verb' => 'POST'], diff --git a/controller/appcontroller.php b/controller/appcontroller.php new file mode 100644 index 000000000..15d0d0adb --- /dev/null +++ b/controller/appcontroller.php @@ -0,0 +1,76 @@ +<?php +/** + * ownCloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Alessandro Cosentino <cosenal@gmail.com> + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Alessandro Cosentino 2014 + * @copyright Bernhard Posselt 2014 + */ + +namespace OCA\News\Controller; + +use \OCP\IRequest; +use \OCP\IURLGenerator; +use \OCP\AppFramework\Controller; +use \OCP\AppFramework\Http; +use \OCP\AppFramework\Http\JSONResponse; + +use \OCA\News\Config\AppConfig; + +class AppController extends Controller { + + private $urlGenerator; + private $appConfig; + + public function __construct($appName, + IRequest $request, + IURLGenerator $urlGenerator, + AppConfig $appConfig){ + parent::__construct($appName, $request); + $this->urlGenerator = $urlGenerator; + $this->appConfig = $appConfig; + } + + /** + * @NoAdminRequired + * @NoCSRFRequired + * @PublicPage + * + * Generates a web app manifest, according to specs in: + * https://developer.mozilla.org/en-US/Apps/Build/Manifest + */ + public function manifest() { + $config = $this->appConfig->getConfig(); + + // size of the icons: 128x128 is required by FxOS for all app manifests + $iconSizes = ['128', '512']; + $icons = []; + + foreach ($iconSizes as $size) { + $filename = 'app-' . $size . '.png'; + if (file_exists(__DIR__ . '/../img/' . $filename)) { + $icons[$size] = $this->urlGenerator->imagePath($config['id'], + $filename); + } + } + + $params = [ + "name" => $config['name'], + "description" => $config['description'], + "launch_path" => $this->urlGenerator->linkToRoute( + $config['id'] . '.page.index'), + "icons" => $icons, + "developer" => [ + "name" => "ownCloud community", + "url" => $config['homepage'] + ], + ]; + + return new JSONResponse($params); + } + +}
\ No newline at end of file diff --git a/img/app-128.png b/img/app-128.png Binary files differnew file mode 100644 index 000000000..a8708c096 --- /dev/null +++ b/img/app-128.png diff --git a/img/app-512.png b/img/app-512.png Binary files differnew file mode 100644 index 000000000..72b6e62f3 --- /dev/null +++ b/img/app-512.png diff --git a/tests/unit/controller/AppControllerTest.php b/tests/unit/controller/AppControllerTest.php new file mode 100644 index 000000000..50dcb173a --- /dev/null +++ b/tests/unit/controller/AppControllerTest.php @@ -0,0 +1,69 @@ +<?php +/** + * ownCloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Alessandro Cosentino <cosenal@gmail.com> + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Alessandro Cosentino 2014 + * @copyright Bernhard Posselt 2014 + */ + +namespace OCA\News\Controller; + + +class AppControllerTest extends \PHPUnit_Framework_TestCase { + + private $appName; + private $request; + private $urlGenerator; + private $appConfig; + private $controller; + private $configData; + + /** + * Gets run before each test + */ + public function setUp(){ + $this->appName = 'news'; + $this->request = $this->getMockBuilder( + '\OCP\IRequest') + ->disableOriginalConstructor() + ->getMock(); + $this->urlGenerator = $this->getMockBuilder( + '\OCP\IURLGenerator') + ->disableOriginalConstructor() + ->getMock(); + $this->appConfig = $this->getMockBuilder( + '\OCA\News\Config\AppConfig') + ->disableOriginalConstructor() + ->getMock(); + + $this->configData = [ + "name" => "AppTest", + "id" => "apptest", + "description" => "This is a test app", + "homepage" => "https://github.com/owncloud/test" + ]; + + $this->controller = new AppController($this->appName, $this->request, + $this->urlGenerator, $this->appConfig); + } + + public function testManifest(){ + $this->appConfig->expects($this->once()) + ->method('getConfig') + ->will($this->returnValue($this->configData)); + $result = $this->controller->manifest(); + $jsonResult = json_decode($result->render(), true); + $this->assertEquals($jsonResult['name'], + $this->configData['name']); + $this->assertEquals($jsonResult['description'], + $this->configData['description']); + $this->assertEquals($jsonResult['developer']['url'], + $this->configData['homepage']); + } + +}
\ No newline at end of file |