From 29571aff347e7cd8ab9a755d6211fed575d4f129 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Sat, 23 Mar 2013 01:23:47 +0100 Subject: finished itemcontroller --- bl/itembl.php | 7 ++++- controller/itemcontroller.php | 19 ++++++++++- tests/controller/ItemControllerTest.php | 56 ++++++++++++++++++++++++++++++++- 3 files changed, 79 insertions(+), 3 deletions(-) diff --git a/bl/itembl.php b/bl/itembl.php index 629f9317f..f9bd15b9a 100644 --- a/bl/itembl.php +++ b/bl/itembl.php @@ -36,7 +36,12 @@ class ItemBl extends Bl { } - public function findAll(){ + public function findAllNew($id, $type, $updatedSince, $userId){ + + } + + + public function findAll($id, $type, $limit, $offset, $userId){ // TODO all the crazy finding of items } diff --git a/controller/itemcontroller.php b/controller/itemcontroller.php index 1dbf7c43e..7a9fb1aeb 100644 --- a/controller/itemcontroller.php +++ b/controller/itemcontroller.php @@ -48,7 +48,24 @@ class ItemController extends Controller { * @Ajax */ public function items(){ - // TBD + $userId = $this->api->getUserId(); + $limit = $this->params('limit'); + $type = $this->params('type'); + $id = $this->params('id'); + + if($limit !== null){ + $offset = $this->params('offset', 0); + $items = $this->itemBl->findAll($id, $type, $limit, $offset, $userId); + } else { + $updatedSince = $this->params('updatedSince'); + $items = $this->itemBl->findAllNew($id, $type, $updatedSince, $userId); + } + + $params = array( + 'items' => $items + ); + + return $this->renderJSON($params); } diff --git a/tests/controller/ItemControllerTest.php b/tests/controller/ItemControllerTest.php index 4f7fe564a..2b389adad 100644 --- a/tests/controller/ItemControllerTest.php +++ b/tests/controller/ItemControllerTest.php @@ -32,7 +32,7 @@ use \OCA\AppFramework\Db\DoesNotExistException; use \OCA\AppFramework\Db\MultipleObjectsReturnedException; use \OCA\News\Db\Item; - +use \OCA\News\Db\FeedType; require_once(__DIR__ . "/../classloader.php"); @@ -213,4 +213,58 @@ class ItemControllerTest extends ControllerTestUtility { $this->assertTrue($response instanceof JSONResponse); } + + + public function testItems(){ + $result = array( + 'items' => array(new Item()) + ); + $post = array( + 'limit' => 3, + 'type' => FeedType::FEED, + 'id' => 2, + 'offset' => 0 + ); + $this->controller = $this->getPostController($post); + + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); + $this->bl->expects($this->once()) + ->method('findAll') + ->with($post['id'], $post['type'], $post['limit'], + $post['offset'], $this->user) + ->will($this->returnValue($result['items'])); + + $response = $this->controller->items(); + $this->assertEquals($result, $response->getParams()); + $this->assertTrue($response instanceof JSONResponse); + } + + + public function testItemsNew(){ + $result = array( + 'items' => array(new Item()) + ); + $post = array( + 'type' => FeedType::FEED, + 'id' => 2, + 'updatedSince' => 3333 + ); + $this->controller = $this->getPostController($post); + + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); + $this->bl->expects($this->once()) + ->method('findAllNew') + ->with($post['id'], $post['type'], $post['updatedSince'], + $this->user) + ->will($this->returnValue($result['items'])); + + $response = $this->controller->items(); + $this->assertEquals($result, $response->getParams()); + $this->assertTrue($response instanceof JSONResponse); + } + } \ No newline at end of file -- cgit v1.2.3