diff options
-rw-r--r-- | appinfo/api.php | 11 | ||||
-rw-r--r-- | dependencyinjection/dicontainer.php | 5 | ||||
-rw-r--r-- | external/newsapi.php | 47 | ||||
-rw-r--r-- | tests/unit/external/NewsAPITest.php | 65 |
4 files changed, 128 insertions, 0 deletions
diff --git a/appinfo/api.php b/appinfo/api.php index b2b657cf5..2c9c7b24b 100644 --- a/appinfo/api.php +++ b/appinfo/api.php @@ -30,6 +30,17 @@ use \OCA\AppFramework\External\External; /** + * Generic API + */ +\OCP\API::register('get', '/apps/news/version', + function($params) { + return External::main('NewsAPI', 'version', $params, new DIContainer()); + }, + 'news', + \OC_API::USER_AUTH +); + +/** * Folder API */ \OCP\API::register('get', '/apps/news/folders', diff --git a/dependencyinjection/dicontainer.php b/dependencyinjection/dicontainer.php index 761b95f64..e6a137853 100644 --- a/dependencyinjection/dicontainer.php +++ b/dependencyinjection/dicontainer.php @@ -43,6 +43,7 @@ use \OCA\News\Db\FeedMapper; use \OCA\News\Db\ItemMapper; use \OCA\News\Db\StatusFlag; +use \OCA\News\External\NewsAPI; use \OCA\News\External\FolderAPI; use \OCA\News\External\FeedAPI; use \OCA\News\External\ItemAPI; @@ -156,6 +157,10 @@ class DIContainer extends BaseContainer { /** * External API */ + $this['NewsAPI'] = $this->share(function($c){ + return new NewsAPI($c['API'], $c['Request']); + }); + $this['FolderAPI'] = $this->share(function($c){ return new FolderAPI($c['API'], $c['Request'], $c['FolderBusinessLayer']); diff --git a/external/newsapi.php b/external/newsapi.php new file mode 100644 index 000000000..747f818ec --- /dev/null +++ b/external/newsapi.php @@ -0,0 +1,47 @@ +<?php + +/** +* ownCloud - News +* +* @author Alessandro Cosentino +* @author Bernhard Posselt +* @copyright 2012 Alessandro Cosentino cosenal@gmail.com +* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +* License as published by the Free Software Foundation; either +* version 3 of the License, or any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU AFFERO GENERAL PUBLIC LICENSE for more details. +* +* You should have received a copy of the GNU Affero General Public +* License along with this library. If not, see <http://www.gnu.org/licenses/>. +* +*/ + +namespace OCA\News\External; + +use \OCA\AppFramework\Core\API; +use \OCA\AppFramework\Controller\Controller; +use \OCA\AppFramework\Http\Request; + + +class NewsAPI extends Controller { + + + public function __construct(API $api, Request $request){ + parent::__construct($api, $request); + } + + + public function version() { + $version = $this->api->getAppValue('installed_version'); + return new NewsAPIResult(array('version' => $version)); + } + + +} diff --git a/tests/unit/external/NewsAPITest.php b/tests/unit/external/NewsAPITest.php new file mode 100644 index 000000000..84522d75d --- /dev/null +++ b/tests/unit/external/NewsAPITest.php @@ -0,0 +1,65 @@ +<?php + +/** +* ownCloud - News +* +* @author Alessandro Cosentino +* @author Bernhard Posselt +* @copyright 2012 Alessandro Cosentino cosenal@gmail.com +* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +* License as published by the Free Software Foundation; either +* version 3 of the License, or any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU AFFERO GENERAL PUBLIC LICENSE for more details. +* +* You should have received a copy of the GNU Affero General Public +* License along with this library. If not, see <http://www.gnu.org/licenses/>. +* +*/ + +namespace OCA\News\External; + + +require_once(__DIR__ . "/../../classloader.php"); + + +class NewsAPITest extends \PHPUnit_Framework_TestCase { + + private $api; + private $request; + private $newsAPI; + + protected function setUp() { + $this->api = $this->getMockBuilder( + '\OCA\AppFramework\Core\API') + ->disableOriginalConstructor() + ->getMock(); + $this->request = $this->getMockBuilder( + '\OCA\AppFramework\Http\Request') + ->disableOriginalConstructor() + ->getMock(); + $this->newsAPI = new NewsAPI($this->api, $this->request); + } + + + public function testGetVersion(){ + $this->api->expects($this->once()) + ->method('getAppValue') + ->with($this->equalTo('installed_version')) + ->will($this->returnValue('1.0')); + + $response = $this->newsAPI->version(); + $data = $response->getData(); + $version = $data['version']; + + $this->assertEquals('1.0', $version); + } + + +}
\ No newline at end of file |