summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--external/feedapi.php41
-rw-r--r--external/folderapi.php4
-rw-r--r--external/itemapi.php4
-rw-r--r--tests/unit/external/FeedAPITest.php206
4 files changed, 243 insertions, 12 deletions
diff --git a/external/feedapi.php b/external/feedapi.php
index d88eda35f..b6ec82d0e 100644
--- a/external/feedapi.php
+++ b/external/feedapi.php
@@ -33,6 +33,7 @@ use \OCA\News\BusinessLayer\FeedBusinessLayer;
use \OCA\News\BusinessLayer\FolderBusinessLayer;
use \OCA\News\BusinessLayer\ItemBusinessLayer;
use \OCA\News\BusinessLayer\BusinessLayerException;
+use \OCA\News\BusinessLayer\BusinessLayerExistsException;
class FeedAPI extends Controller {
@@ -54,7 +55,6 @@ class FeedAPI extends Controller {
public function getAll() {
-
$userId = $this->api->getUserId();
$result = array(
@@ -77,22 +77,61 @@ class FeedAPI extends Controller {
public function create() {
+ $userId = $this->api->getUserId();
+ $feedUrl = $this->params('url');
+ $folderId = (int) $this->params('folderId', 0);
+ try {
+ $feed = $this->feedBusinessLayer->create($feedUrl, $folderId, $userId);
+ return new NewsAPIResult(array(
+ 'feeds' => array($feed->toAPI())
+ ));
+ } catch(BusinessLayerExistsException $ex) {
+ return new NewsAPIResult(null, NewsAPIResult::EXISTS_ERROR,
+ $ex->getMessage());
+ } catch(BusinessLayerException $ex) {
+ return new NewsAPIResult(null, NewsAPIResult::NOT_FOUND_ERROR,
+ $ex->getMessage());
+ }
}
public function delete() {
+ $userId = $this->api->getUserId();
+ $feedId = (int) $this->params('feedId');
+ try {
+ $this->feedBusinessLayer->delete($feedId, $userId);
+ return new NewsAPIResult();
+ } catch(BusinessLayerException $ex) {
+ return new NewsAPIResult(null, NewsAPIResult::NOT_FOUND_ERROR,
+ $ex->getMessage());
+ }
}
public function read() {
+ $userId = $this->api->getUserId();
+ $feedId = (int) $this->params('feedId');
+ $newestItemId = (int) $this->params('newestItemId');
+ $this->itemBusinessLayer->readFeed($feedId, $newestItemId, $userId);
+ return new NewsAPIResult();
}
public function move() {
+ $userId = $this->api->getUserId();
+ $feedId = (int) $this->params('feedId');
+ $folderId = (int) $this->params('folderId');
+ try {
+ $this->feedBusinessLayer->move($feedId, $folderId, $userId);
+ return new NewsAPIResult();
+ } catch(BusinessLayerException $ex) {
+ return new NewsAPIResult(null, NewsAPIResult::NOT_FOUND_ERROR,
+ $ex->getMessage());
+ }
}
diff --git a/external/folderapi.php b/external/folderapi.php
index 36ef9c35f..642ca1968 100644
--- a/external/folderapi.php
+++ b/external/folderapi.php
@@ -81,7 +81,7 @@ class FolderAPI extends Controller {
public function delete() {
$userId = $this->api->getUserId();
- $folderId = $this->params('folderId');
+ $folderId = (int) $this->params('folderId');
try {
$this->folderBusinessLayer->delete($folderId, $userId);
@@ -95,7 +95,7 @@ class FolderAPI extends Controller {
public function update() {
$userId = $this->api->getUserId();
- $folderId = $this->params('folderId');
+ $folderId = (int) $this->params('folderId');
$folderName = $this->params('name');
try {
diff --git a/external/itemapi.php b/external/itemapi.php
index 99dc8ddef..9699b4371 100644
--- a/external/itemapi.php
+++ b/external/itemapi.php
@@ -102,7 +102,7 @@ class ItemAPI extends Controller {
private function setRead($isRead) {
$userId = $this->api->getUserId();
- $itemId = $this->params('itemId');
+ $itemId = (int) $this->params('itemId');
try {
$this->itemBusinessLayer->read($itemId, $isRead, $userId);
return new NewsAPIResult();
@@ -115,7 +115,7 @@ class ItemAPI extends Controller {
private function setStarred($isStarred) {
$userId = $this->api->getUserId();
- $feedId = $this->params('feedId');
+ $feedId = (int) $this->params('feedId');
$guidHash = $this->params('guidHash');
try {
$this->itemBusinessLayer->star($feedId, $guidHash, $isStarred, $userId);
diff --git a/tests/unit/external/FeedAPITest.php b/tests/unit/external/FeedAPITest.php
index 2b0706d04..b83940832 100644
--- a/tests/unit/external/FeedAPITest.php
+++ b/tests/unit/external/FeedAPITest.php
@@ -25,8 +25,10 @@
namespace OCA\News\External;
-use \OCA\News\BusinessLayer\BusinessLayerException;
+use \OCA\AppFramework\Http\Request;
+use \OCA\News\BusinessLayer\BusinessLayerException;
+use \OCA\News\BusinessLayer\BusinessLayerExistsException;
use \OCA\News\Db\Folder;
use \OCA\News\Db\Feed;
use \OCA\News\Db\Item;
@@ -43,6 +45,7 @@ class FeedAPITest extends \PHPUnit_Framework_TestCase {
private $api;
private $user;
private $request;
+ private $msg;
protected function setUp() {
$this->api = $this->getMockBuilder(
@@ -73,6 +76,10 @@ class FeedAPITest extends \PHPUnit_Framework_TestCase {
$this->itemBusinessLayer
);
$this->user = 'tom';
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
+ $this->msg = 'hohoho';
}
@@ -83,9 +90,6 @@ class FeedAPITest extends \PHPUnit_Framework_TestCase {
$starredCount = 3;
$newestItemId = 2;
- $this->api->expects($this->once())
- ->method('getUserId')
- ->will($this->returnValue($this->user));
$this->itemBusinessLayer->expects($this->once())
->method('starredCount')
->with($this->equalTo($this->user))
@@ -115,9 +119,6 @@ class FeedAPITest extends \PHPUnit_Framework_TestCase {
);
$starredCount = 3;
- $this->api->expects($this->once())
- ->method('getUserId')
- ->will($this->returnValue($this->user));
$this->itemBusinessLayer->expects($this->once())
->method('starredCount')
->with($this->equalTo($this->user))
@@ -140,4 +141,195 @@ class FeedAPITest extends \PHPUnit_Framework_TestCase {
}
+ public function testDelete() {
+ $request = new Request(array('urlParams' => array(
+ 'feedId' => 2
+ )));
+ $this->feedAPI = new FeedAPI(
+ $this->api,
+ $request,
+ $this->folderBusinessLayer,
+ $this->feedBusinessLayer,
+ $this->itemBusinessLayer
+ );
+
+
+ $this->feedBusinessLayer->expects($this->once())
+ ->method('delete')
+ ->with(
+ $this->equalTo(2),
+ $this->equalTo($this->user));
+
+ $response = $this->feedAPI->delete();
+
+ $this->assertNull($response->getData());
+ $this->assertNull($response->getMessage());
+ $this->assertEquals(NewsAPIResult::OK, $response->getStatusCode());
+ }
+
+
+ public function testDeleteDoesNotExist() {
+ $request = new Request(array('urlParams' => array(
+ 'feedId' => 2
+ )));
+ $this->feedAPI = new FeedAPI(
+ $this->api,
+ $request,
+ $this->folderBusinessLayer,
+ $this->feedBusinessLayer,
+ $this->itemBusinessLayer
+ );
+
+
+ $this->feedBusinessLayer->expects($this->once())
+ ->method('delete')
+ ->will($this->throwException(new BusinessLayerException($this->msg)));
+
+ $response = $this->feedAPI->delete();
+
+ $this->assertNull($response->getData());
+ $this->assertEquals($this->msg, $response->getMessage());
+ $this->assertEquals(NewsAPIResult::NOT_FOUND_ERROR, $response->getStatusCode());
+ }
+
+
+ public function testCreate() {
+ $feeds = array(
+ new Feed()
+ );
+ $request = new Request(array('params' => array(
+ 'url' => 'ho',
+ 'folderId' => 3
+ )));
+ $this->feedAPI = new FeedAPI(
+ $this->api,
+ $request,
+ $this->folderBusinessLayer,
+ $this->feedBusinessLayer,
+ $this->itemBusinessLayer
+ );
+
+
+ $this->feedBusinessLayer->expects($this->once())
+ ->method('create')
+ ->with(
+ $this->equalTo('ho'),
+ $this->equalTo(3),
+ $this->equalTo($this->user))
+ ->will($this->returnValue($feeds[0]));
+
+ $response = $this->feedAPI->create();
+
+ $this->assertEquals(array(
+ 'feeds' => array($feeds[0]->toAPI())
+ ), $response->getData());
+
+ $this->assertNull($response->getMessage());
+ $this->assertEquals(NewsAPIResult::OK, $response->getStatusCode());
+ }
+
+
+ public function testCreateExists() {
+ $this->feedBusinessLayer->expects($this->once())
+ ->method('create')
+ ->will($this->throwException(new BusinessLayerExistsException($this->msg)));
+
+ $response = $this->feedAPI->create();
+
+ $this->assertNull($response->getData());
+ $this->assertEquals($this->msg, $response->getMessage());
+ $this->assertEquals(NewsAPIResult::EXISTS_ERROR, $response->getStatusCode());
+ }
+
+
+ public function testCreateError() {
+ $this->feedBusinessLayer->expects($this->once())
+ ->method('create')
+ ->will($this->throwException(new BusinessLayerException($this->msg)));
+
+ $response = $this->feedAPI->create();
+
+ $this->assertNull($response->getData());
+ $this->assertEquals($this->msg, $response->getMessage());
+ $this->assertEquals(NewsAPIResult::NOT_FOUND_ERROR, $response->getStatusCode());
+ }
+
+
+ public function testRead() {
+ $request = new Request(array(
+ 'urlParams' => array(
+ 'feedId' => 3
+ ),
+ 'params' => array(
+ 'newestItemId' => 30,
+ )
+ ));
+ $this->feedAPI = new FeedAPI(
+ $this->api,
+ $request,
+ $this->folderBusinessLayer,
+ $this->feedBusinessLayer,
+ $this->itemBusinessLayer
+ );
+
+
+ $this->itemBusinessLayer->expects($this->once())
+ ->method('readFeed')
+ ->with(
+ $this->equalTo(3),
+ $this->equalTo(30),
+ $this->equalTo($this->user));
+
+ $response = $this->feedAPI->read();
+
+ $this->assertNull($response->getData());
+ $this->assertNull($response->getMessage());
+ $this->assertEquals(NewsAPIResult::OK, $response->getStatusCode());
+ }
+
+
+ public function testMove() {
+ $request = new Request(array(
+ 'urlParams' => array(
+ 'feedId' => 3
+ ),
+ 'params' => array(
+ 'folderId' => 30,
+ )
+ ));
+ $this->feedAPI = new FeedAPI(
+ $this->api,
+ $request,
+ $this->folderBusinessLayer,
+ $this->feedBusinessLayer,
+ $this->itemBusinessLayer
+ );
+
+
+ $this->feedBusinessLayer->expects($this->once())
+ ->method('move')
+ ->with(
+ $this->equalTo(3),
+ $this->equalTo(30),
+ $this->equalTo($this->user));
+
+ $response = $this->feedAPI->move();
+
+ $this->assertNull($response->getData());
+ $this->assertNull($response->getMessage());
+ $this->assertEquals(NewsAPIResult::OK, $response->getStatusCode());
+ }
+
+
+ public function testMoveDoesNotExist() {
+ $this->feedBusinessLayer->expects($this->once())
+ ->method('move')
+ ->will($this->throwException(new BusinessLayerException($this->msg)));
+
+ $response = $this->feedAPI->move();
+
+ $this->assertNull($response->getData());
+ $this->assertEquals($this->msg, $response->getMessage());
+ $this->assertEquals(NewsAPIResult::NOT_FOUND_ERROR, $response->getStatusCode());
+ }
} \ No newline at end of file