diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-05-02 21:03:33 +0200 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-05-02 21:03:33 +0200 |
commit | ec8394eda1b1769b3cf1032fc03a107092b222a4 (patch) | |
tree | bcf13ab35f8b0accc4e30a466b9a5c0233648c3e | |
parent | 2b42d8bd9e54afa35d0e8b6cfd67183e3d3d00a8 (diff) |
add read button
-rw-r--r-- | external/itemapi.php | 30 | ||||
-rw-r--r-- | tests/unit/external/ItemAPITest.php | 66 |
2 files changed, 89 insertions, 7 deletions
diff --git a/external/itemapi.php b/external/itemapi.php index e4d8ab904..b1b75ca35 100644 --- a/external/itemapi.php +++ b/external/itemapi.php @@ -75,17 +75,41 @@ class ItemAPI extends Controller { public function getUpdated() { + $result = array( + 'items' => array() + ); - } + $userId = $this->api->getUserId(); + $lastModified = (int) $this->params('lastModified', 0); + $type = (int) $this->params('type'); + $id = (int) $this->params('id'); + + $items = $this->itemBusinessLayer->findAllNew( + $id, + $type, + $lastModified, + true, + $userId + ); + + foreach ($items as $item) { + array_push($result['items'], $item->toAPI()); + } + return new NewsAPIResult($result); + } - public function get() { + private function setRead($isRead) { + $userId = $this->api->getUserId(); + $itemId = $this->params('itemId'); + $this->itemBusinessLayer->read($itemId, $isRead, $userId); } public function read() { - + $this->setRead(true); + return new NewsAPIResult(); } diff --git a/tests/unit/external/ItemAPITest.php b/tests/unit/external/ItemAPITest.php index e8fe747d5..c91b06db7 100644 --- a/tests/unit/external/ItemAPITest.php +++ b/tests/unit/external/ItemAPITest.php @@ -54,12 +54,15 @@ class ItemAPITest extends \PHPUnit_Framework_TestCase { '\OCA\News\BusinessLayer\ItemBusinessLayer') ->disableOriginalConstructor() ->getMock(); + $this->user = 'tom'; + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); $this->itemAPI = new ItemAPI( $this->api, $this->request, $this->itemBusinessLayer ); - $this->user = 'tom'; } @@ -80,9 +83,6 @@ class ItemAPITest extends \PHPUnit_Framework_TestCase { $this->itemBusinessLayer ); - $this->api->expects($this->once()) - ->method('getUserId') - ->will($this->returnValue($this->user)); $this->itemBusinessLayer->expects($this->once()) ->method('findAll') ->with( @@ -103,5 +103,63 @@ class ItemAPITest extends \PHPUnit_Framework_TestCase { } + public function testGetUpdated() { + $items = array( + new Item() + ); + $request = new Request(array('params' => array( + 'lastModified' => 30, + 'type' => 1, + 'id' => 2, + ))); + $this->itemAPI = new ItemAPI( + $this->api, + $request, + $this->itemBusinessLayer + ); + + $this->itemBusinessLayer->expects($this->once()) + ->method('findAllNew') + ->with( + $this->equalTo(2), + $this->equalTo(1), + $this->equalTo(30), + $this->equalTo(true), + $this->equalTo($this->user) + ) + ->will($this->returnValue($items)); + + $response = $this->itemAPI->getUpdated(); + + $this->assertEquals(array( + 'items' => array($items[0]->toAPI()) + ), $response->getData()); + } + + + public function testRead() { + $request = new Request(array('urlParams' => array( + 'itemId' => 2 + ))); + $this->itemAPI = new ItemAPI( + $this->api, + $request, + $this->itemBusinessLayer + ); + + $this->itemBusinessLayer->expects($this->once()) + ->method('read') + ->with( + $this->equalTo(2), + $this->equalTo(true), + $this->equalTo($this->user) + ); + + $response = $this->itemAPI->read(); + + $this->assertNull($response->getData()); + $this->assertNull($response->getMessage()); + $this->assertEquals(NewsAPIResult::OK, $response->getStatusCode()); + } }
\ No newline at end of file |