diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-04-29 13:25:04 +0200 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-04-29 13:30:01 +0200 |
commit | 3fc18156ae0b586e8de0c82949acfa6291317536 (patch) | |
tree | 201e97511bea44c58b5e9d78d8cf36ae2e2b54f9 /tests/unit/controller/FeedControllerTest.php | |
parent | a03b54c6a59837d0045c140ea7aef3fae95daa95 (diff) |
go back to order by id, fix #138, use a newest item id to prevent marking items as read that the user didnt see yet fix #141, also update the starred count periodically
Diffstat (limited to 'tests/unit/controller/FeedControllerTest.php')
-rw-r--r-- | tests/unit/controller/FeedControllerTest.php | 55 |
1 files changed, 51 insertions, 4 deletions
diff --git a/tests/unit/controller/FeedControllerTest.php b/tests/unit/controller/FeedControllerTest.php index b41977962..14c31b545 100644 --- a/tests/unit/controller/FeedControllerTest.php +++ b/tests/unit/controller/FeedControllerTest.php @@ -46,6 +46,7 @@ class FeedControllerTest extends ControllerTestUtility { private $request; private $controller; private $folderBusinessLayer; + private $itemBusinessLayer; /** @@ -53,6 +54,9 @@ class FeedControllerTest extends ControllerTestUtility { */ public function setUp(){ $this->api = $this->getAPIMock(); + $this->itemBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\ItemBusinessLayer') + ->disableOriginalConstructor() + ->getMock(); $this->feedBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\FeedBusinessLayer') ->disableOriginalConstructor() ->getMock(); @@ -61,7 +65,8 @@ class FeedControllerTest extends ControllerTestUtility { ->getMock(); $this->request = new Request(); $this->controller = new FeedController($this->api, $this->request, - $this->feedBusinessLayer, $this->folderBusinessLayer); + $this->feedBusinessLayer, $this->folderBusinessLayer, + $this->itemBusinessLayer); $this->user = 'jack'; } @@ -78,7 +83,8 @@ class FeedControllerTest extends ControllerTestUtility { ); $request = $this->getRequest($post); - return new FeedController($this->api, $request, $this->feedBusinessLayer, $this->folderBusinessLayer); + return new FeedController($this->api, $request, $this->feedBusinessLayer, + $this->folderBusinessLayer, $this->itemBusinessLayer); } @@ -119,8 +125,40 @@ class FeedControllerTest extends ControllerTestUtility { public function testFeeds(){ $result = array( 'feeds' => array( - array('a feed') - ) + array('a feed'), + ), + 'starred' => 13 + ); + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); + $this->feedBusinessLayer->expects($this->once()) + ->method('findAll') + ->with($this->equalTo($this->user)) + ->will($this->returnValue($result['feeds'])); + $this->itemBusinessLayer->expects($this->once()) + ->method('getNewestItemId') + ->with($this->equalTo($this->user)) + ->will($this->throwException(new BusinessLayerException(''))); + $this->itemBusinessLayer->expects($this->once()) + ->method('starredCount') + ->with($this->equalTo($this->user)) + ->will($this->returnValue($result['starred'])); + + $response = $this->controller->feeds(); + + $this->assertEquals($result, $response->getParams()); + $this->assertTrue($response instanceof JSONResponse); + } + + + public function testFeedsHighestItemIdExists(){ + $result = array( + 'feeds' => array( + array('a feed'), + ), + 'starred' => 13, + 'newestItemId' => 5 ); $this->api->expects($this->once()) ->method('getUserId') @@ -129,6 +167,14 @@ class FeedControllerTest extends ControllerTestUtility { ->method('findAll') ->with($this->equalTo($this->user)) ->will($this->returnValue($result['feeds'])); + $this->itemBusinessLayer->expects($this->once()) + ->method('getNewestItemId') + ->with($this->equalTo($this->user)) + ->will($this->returnValue($result['newestItemId'])); + $this->itemBusinessLayer->expects($this->once()) + ->method('starredCount') + ->with($this->equalTo($this->user)) + ->will($this->returnValue($result['starred'])); $response = $this->controller->feeds(); @@ -137,6 +183,7 @@ class FeedControllerTest extends ControllerTestUtility { } + private function activeInitMocks($id, $type){ $this->api->expects($this->at(0)) ->method('getUserId') |