From 59069e85a26dd72bb1798e0ee517d607f6021443 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Thu, 9 May 2013 13:44:16 +0200 Subject: also send newest item id when creating a feed from the api --- external/feedapi.php | 12 ++++++++-- tests/unit/external/FeedAPITest.php | 44 +++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/external/feedapi.php b/external/feedapi.php index b6ec82d0e..7273a5413 100644 --- a/external/feedapi.php +++ b/external/feedapi.php @@ -83,9 +83,17 @@ class FeedAPI extends Controller { try { $feed = $this->feedBusinessLayer->create($feedUrl, $folderId, $userId); - return new NewsAPIResult(array( + $result = array( 'feeds' => array($feed->toAPI()) - )); + ); + + try { + $result['newestItemId'] = + $this->itemBusinessLayer->getNewestItemId($userId); + } catch(BusinessLayerException $ex) {} + + return new NewsAPIResult($result); + } catch(BusinessLayerExistsException $ex) { return new NewsAPIResult(null, NewsAPIResult::EXISTS_ERROR, $ex->getMessage()); diff --git a/tests/unit/external/FeedAPITest.php b/tests/unit/external/FeedAPITest.php index b83940832..8e0d78731 100644 --- a/tests/unit/external/FeedAPITest.php +++ b/tests/unit/external/FeedAPITest.php @@ -217,6 +217,49 @@ class FeedAPITest extends \PHPUnit_Framework_TestCase { $this->equalTo(3), $this->equalTo($this->user)) ->will($this->returnValue($feeds[0])); + $this->itemBusinessLayer->expects($this->once()) + ->method('getNewestItemId') + ->will($this->returnValue(3)); + + $response = $this->feedAPI->create(); + + $this->assertEquals(array( + 'feeds' => array($feeds[0]->toAPI()), + 'newestItemId' => 3 + ), $response->getData()); + + $this->assertNull($response->getMessage()); + $this->assertEquals(NewsAPIResult::OK, $response->getStatusCode()); + } + + + public function testCreateNoItems() { + $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])); + $this->itemBusinessLayer->expects($this->once()) + ->method('getNewestItemId') + ->will($this->throwException(new BusinessLayerException(''))); $response = $this->feedAPI->create(); @@ -229,6 +272,7 @@ class FeedAPITest extends \PHPUnit_Framework_TestCase { } + public function testCreateExists() { $this->feedBusinessLayer->expects($this->once()) ->method('create') -- cgit v1.2.3