diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/controller/ItemControllerTest.php | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/tests/unit/controller/ItemControllerTest.php b/tests/unit/controller/ItemControllerTest.php index 5a1104137..9d104b8f0 100644 --- a/tests/unit/controller/ItemControllerTest.php +++ b/tests/unit/controller/ItemControllerTest.php @@ -84,11 +84,16 @@ class ItemControllerTest extends ControllerTestUtility { $this->assertAnnotations($this->controller, $methodName, $annotations); } + public function testItemsAnnotations(){ $this->assertItemControllerAnnotations('items'); } + public function testNewItemsAnnotations(){ + $this->assertItemControllerAnnotations('newItems'); + } + public function testStarAnnotations(){ $this->assertItemControllerAnnotations('star'); } @@ -446,5 +451,86 @@ class ItemControllerTest extends ControllerTestUtility { } + public function testNewItems(){ + $feeds = array(new Feed()); + $result = array( + 'items' => array(new Item()), + 'feeds' => $feeds, + 'newestItemId' => $this->newestItemId, + 'starred' => 3111 + ); + $post = array( + 'lastModified' => 3, + 'type' => FeedType::FEED, + 'id' => 2 + ); + $this->controller = $this->getPostController($post); + + $this->api->expects($this->once()) + ->method('getUserValue') + ->with($this->equalTo('showAll')) + ->will($this->returnValue('1')); + $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($feeds)); + + $this->itemBusinessLayer->expects($this->once()) + ->method('getNewestItemId') + ->with($this->equalTo($this->user)) + ->will($this->returnValue($this->newestItemId)); + + $this->itemBusinessLayer->expects($this->once()) + ->method('starredCount') + ->with($this->equalTo($this->user)) + ->will($this->returnValue(3111)); + + $this->itemBusinessLayer->expects($this->once()) + ->method('findAllNew') + ->with( + $this->equalTo($post['id']), + $this->equalTo($post['type']), + $this->equalTo($post['lastModified']), + $this->equalTo(true), + $this->equalTo($this->user)) + ->will($this->returnValue($result['items'])); + + $response = $this->controller->newItems(); + $this->assertEquals($result, $response->getParams()); + $this->assertTrue($response instanceof JSONResponse); + } + + + public function testGetNewItemsNoNewestItemsId(){ + $result = array(); + $post = array( + 'lastModified' => 3, + 'type' => FeedType::FEED, + 'id' => 2 + ); + $this->controller = $this->getPostController($post); + + $this->api->expects($this->once()) + ->method('getUserValue') + ->with($this->equalTo('showAll')) + ->will($this->returnValue('1')); + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); + + $this->itemBusinessLayer->expects($this->once()) + ->method('getNewestItemId') + ->with($this->equalTo($this->user)) + ->will($this->throwException(new BusinessLayerException(''))); + + $response = $this->controller->newItems(); + $this->assertEquals($result, $response->getParams()); + $this->assertTrue($response instanceof JSONResponse); + } + }
\ No newline at end of file |