Skip to content
This repository has been archived by the owner on Jul 6, 2020. It is now read-only.

Commit

Permalink
add default locale and developer names and move the method to the pag…
Browse files Browse the repository at this point in the history
…econtroller, @cosenal
  • Loading branch information
Bernhard Posselt committed Sep 29, 2014
1 parent 45d7c47 commit 26d9504
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 164 deletions.
18 changes: 7 additions & 11 deletions appinfo/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
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;
Expand Down Expand Up @@ -79,6 +78,8 @@ public function __construct(array $urlParams=array()){
$c->query('AppName'),
$c->query('Request'),
$c->query('CoreConfig'),
$c->query('URLGenerator'),
$c->query('AppConfig'),
$c->query('L10N'),
$c->query('UserId')
);
Expand Down Expand Up @@ -170,15 +171,6 @@ public function __construct(array $urlParams=array()){
);
});

$container->registerService('AppController', function($c) {
return new AppController(
$c->query('AppName'),
$c->query('Request'),
$c->query('ServerContainer')->getURLGenerator(),
$c->query('AppConfig')
);
});

/**
* Business Layer
*/
Expand Down Expand Up @@ -271,7 +263,7 @@ public function __construct(array $urlParams=array()){
$config = new AppConfig(
$c->query('ServerContainer')->getNavigationManager(),
$c->query('L10N'),
$c->query('ServerContainer')->getURLGenerator(),
$c->query('URLGenerator'),
phpversion(),
implode('.', Util::getVersion()),
$extensions,
Expand All @@ -290,6 +282,10 @@ public function __construct(array $urlParams=array()){
return $c->query('ServerContainer')->getL10N($c->query('AppName'));
});

$container->registerService('URLGenerator', function($c) {
return $c->query('ServerContainer')->getURLGenerator();
});

$container->registerService('UserId', function() {
return User::getUser();
});
Expand Down
4 changes: 1 addition & 3 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
['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'],
['name' => 'page#manifest', 'url' => '/manifest.webapp', 'verb' => 'GET'],

// folders
['name' => 'folder#index', 'url' => '/folders', 'verb' => 'GET'],
Expand Down
78 changes: 0 additions & 78 deletions controller/appcontroller.php

This file was deleted.

54 changes: 53 additions & 1 deletion controller/pagecontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,34 @@

namespace OCA\News\Controller;

use OCP\AppFramework\Http\TemplateResponse;
use \OCP\AppFramework\Http\TemplateResponse;
use \OCP\IRequest;
use \OCP\IConfig;
use \OCP\IL10N;
use \OCP\IURLGenerator;
use \OCP\AppFramework\Controller;

use \OCA\News\Config\AppConfig;

class PageController extends Controller {

private $settings;
private $l10n;
private $userId;
private $appConfig;
private $urlGenerator;

public function __construct($appName,
IRequest $request,
IConfig $settings,
IURLGenerator $urlGenerator,
AppConfig $appConfig,
IL10N $l10n,
$userId){
parent::__construct($appName, $request);
$this->settings = $settings;
$this->urlGenerator = $urlGenerator;
$this->appConfig = $appConfig;
$this->l10n = $l10n;
$this->userId = $userId;
}
Expand Down Expand Up @@ -82,4 +90,48 @@ public function updateSettings($showAll, $compact, $preventReadOnScroll, $oldest
}


/**
* @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 = [];

$locale = str_replace('_', '-', $this->l10n->getLanguageCode());

foreach ($iconSizes as $size) {
$filename = 'app-' . $size . '.png';
if (file_exists(__DIR__ . '/../img/' . $filename)) {
$icons[$size] = $this->urlGenerator->imagePath($config['id'],
$filename);
}
}

$authors = [];
foreach ($config['authors'] as $author) {
$authors[] = $author['name'];
}

return [
"name" => $config['name'],
"type" => 'web',
"default_locale" => $locale,
"description" => $config['description'],
"launch_path" => $this->urlGenerator->linkToRoute(
$config['id'] . '.page.index'),
"icons" => $icons,
"developer" => [
"name" => implode(', ', $authors),
"url" => $config['homepage']
]
];
}

}
70 changes: 0 additions & 70 deletions tests/unit/controller/AppControllerTest.php

This file was deleted.

43 changes: 42 additions & 1 deletion tests/unit/controller/PageControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,26 @@ class PageControllerTest extends \PHPUnit_Framework_TestCase {
private $controller;
private $user;
private $l10n;
private $urlGenerator;
private $appConfig;
private $configData;

/**
* Gets run before each test
*/
public function setUp(){
$this->appName = 'news';
$this->user = 'becka';
$this->configData = [
'name' => 'AppTest',
'id' => 'apptest',
'authors' => [
['name' => 'john'],
['name' => 'test']
],
'description' => 'This is a test app',
'homepage' => 'https://github.com/owncloud/test'
];
$this->l10n = $this->request = $this->getMockBuilder(
'\OCP\IL10n')
->disableOriginalConstructor()
Expand All @@ -41,8 +54,17 @@ public function setUp(){
'\OCP\IRequest')
->disableOriginalConstructor()
->getMock();
$this->urlGenerator = $this->getMockBuilder(
'\OCP\IURLGenerator')
->disableOriginalConstructor()
->getMock();
$this->appConfig = $this->getMockBuilder(
'\OCA\News\Config\AppConfig')
->disableOriginalConstructor()
->getMock();
$this->controller = new PageController($this->appName, $this->request,
$this->settings, $this->l10n, $this->user);
$this->settings, $this->urlGenerator, $this->appConfig, $this->l10n,
$this->user);
}


Expand Down Expand Up @@ -125,4 +147,23 @@ public function testUpdateSettings() {

}


public function testManifest(){
$this->appConfig->expects($this->once())
->method('getConfig')
->will($this->returnValue($this->configData));
$this->l10n->expects($this->once())
->method('getLanguageCode')
->will($this->returnValue('de_DE'));

$result = $this->controller->manifest();
$this->assertEquals($this->configData['name'], $result['name']);
$this->assertEquals('web', $result['type']);
$this->assertEquals($this->configData['description'], $result['description']);
$this->assertEquals('de-DE', $result['default_locale']);
$this->assertEquals($this->configData['homepage'], $result['developer']['url']);
$this->assertEquals('john, test', $result['developer']['name']);
}


}

1 comment on commit 26d9504

@cosenal
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.