summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--external/apiresult.php55
-rw-r--r--external/external.php2
-rw-r--r--external/feedapi.php2
-rw-r--r--external/folderapi.php8
-rw-r--r--tests/unit/external/APIResultTest.php45
-rw-r--r--tests/unit/external/FeedAPITest.php4
-rw-r--r--tests/unit/external/FolderAPITest.php89
7 files changed, 201 insertions, 4 deletions
diff --git a/external/apiresult.php b/external/apiresult.php
new file mode 100644
index 000000000..64702b125
--- /dev/null
+++ b/external/apiresult.php
@@ -0,0 +1,55 @@
+<?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;
+
+class APIResult {
+
+ const OK = 100;
+ const SERVER_ERROR = 996;
+ const UNAUTHORISED = 997;
+ const NOT_FOUND = 998;
+ const UNKNOWN_ERROR = 999;
+
+ private $data;
+ private $statusCode;
+
+ public function __construct($data, $statusCode=APIResult::OK) {
+ $this->data = $data;
+ $this->statusCode = $statusCode;
+ }
+
+
+ public function getData() {
+ return $this->data;
+ }
+
+
+ public function getStatusCode() {
+ return $this->statusCode;
+ }
+
+
+}
diff --git a/external/external.php b/external/external.php
index b134eee72..ea9657c90 100644
--- a/external/external.php
+++ b/external/external.php
@@ -35,7 +35,7 @@ class External {
\Pimple $container) {
$container['urlParams'] = $urlParams;
$response = $container[$controllerName]->$methodName();
- return new \OC_OCS_Result($response);
+ return new \OC_OCS_Result($response->getData(), $response->getStatusCode());
}
diff --git a/external/feedapi.php b/external/feedapi.php
index 7dfceccc8..6b888b52d 100644
--- a/external/feedapi.php
+++ b/external/feedapi.php
@@ -72,7 +72,7 @@ class FeedAPI extends Controller {
$this->itemBusinessLayer->getNewestItemId($userId);
} catch(BusinessLayerException $ex) {}
- return $result;
+ return new APIResult($result);
}
diff --git a/external/folderapi.php b/external/folderapi.php
index 7d490ded4..629b1cff5 100644
--- a/external/folderapi.php
+++ b/external/folderapi.php
@@ -46,8 +46,16 @@ class FolderAPI extends Controller {
public function getAll() {
+ $userId = $this->api->getUserId();
+ $result = array(
+ 'folders' => array()
+ );
+ foreach ($this->folderBusinessLayer->findAll($userId) as $folder) {
+ array_push($result['folders'], $folder->toAPI());
+ }
+ return new APIResult($result);
}
diff --git a/tests/unit/external/APIResultTest.php b/tests/unit/external/APIResultTest.php
new file mode 100644
index 000000000..2287e683a
--- /dev/null
+++ b/tests/unit/external/APIResultTest.php
@@ -0,0 +1,45 @@
+<?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 APIResultTest extends \PHPUnit_Framework_TestCase {
+
+
+ public function testGetStatusCode() {
+ $result = new APIResult(null, APIResult::SERVER_ERROR);
+ $this->assertEquals(996, $result->getStatusCode());
+ }
+
+ public function testGetData() {
+ $result = new APIResult('hi');
+ $this->assertEquals('hi', $result->getData());
+ $this->assertEquals(100, $result->getStatusCode());
+ }
+
+} \ No newline at end of file
diff --git a/tests/unit/external/FeedAPITest.php b/tests/unit/external/FeedAPITest.php
index b3c945115..7b66733bd 100644
--- a/tests/unit/external/FeedAPITest.php
+++ b/tests/unit/external/FeedAPITest.php
@@ -105,7 +105,7 @@ class FeedAPITest extends \PHPUnit_Framework_TestCase {
'feeds' => array($feeds[0]->toAPI()),
'starredCount' => $starredCount,
'newestItemId' => $newestItemId
- ), $response);
+ ), $response->getData());
}
@@ -136,7 +136,7 @@ class FeedAPITest extends \PHPUnit_Framework_TestCase {
$this->assertEquals(array(
'feeds' => array($feeds[0]->toAPI()),
'starredCount' => $starredCount,
- ), $response);
+ ), $response->getData());
}
diff --git a/tests/unit/external/FolderAPITest.php b/tests/unit/external/FolderAPITest.php
new file mode 100644
index 000000000..61339c7ab
--- /dev/null
+++ b/tests/unit/external/FolderAPITest.php
@@ -0,0 +1,89 @@
+<?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\News\BusinessLayer\BusinessLayerException;
+
+use \OCA\News\Db\Folder;
+use \OCA\News\Db\Feed;
+use \OCA\News\Db\Item;
+
+require_once(__DIR__ . "/../../classloader.php");
+
+
+class FolderAPITest extends \PHPUnit_Framework_TestCase {
+
+ private $folderBusinessLayer;
+ private $folderAPI;
+ private $api;
+ private $user;
+ private $request;
+
+ protected function setUp() {
+ $this->api = $this->folderBusinessLayer = $this->getMockBuilder(
+ '\OCA\AppFramework\Core\API')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->request = $this->folderBusinessLayer = $this->getMockBuilder(
+ '\OCA\AppFramework\Http\Request')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->folderBusinessLayer = $this->getMockBuilder(
+ '\OCA\News\BusinessLayer\FolderBusinessLayer')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->feedAPI = new FolderAPI(
+ $this->api,
+ $this->request,
+ $this->folderBusinessLayer
+ );
+ $this->user = 'tom';
+ }
+
+
+ public function testGetAll() {
+ $folders = array(
+ new Folder()
+ );
+
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
+ $this->folderBusinessLayer->expects($this->once())
+ ->method('findAll')
+ ->with($this->equalTo($this->user))
+ ->will($this->returnValue($folders));
+
+ $response = $this->feedAPI->getAll();
+
+ $this->assertEquals(array(
+ 'folders' => array($folders[0]->toAPI())
+ ), $response->getData());
+ }
+
+
+
+} \ No newline at end of file