diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-05-02 19:40:10 +0200 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-05-02 19:40:10 +0200 |
commit | 5ae697ac9dbaf999d51fa7805078249f33c301dc (patch) | |
tree | a4f408c9462ff4353820e266efad4864043d08f2 /tests/unit/controller/ItemControllerTest.php | |
parent | e9878cb5b583bc993a9f3a482d0b371bbeea5bd2 (diff) |
added proper exception handling for all controllers and businesslayer
Diffstat (limited to 'tests/unit/controller/ItemControllerTest.php')
-rw-r--r-- | tests/unit/controller/ItemControllerTest.php | 102 |
1 files changed, 100 insertions, 2 deletions
diff --git a/tests/unit/controller/ItemControllerTest.php b/tests/unit/controller/ItemControllerTest.php index b0d2a52bc..16df210e0 100644 --- a/tests/unit/controller/ItemControllerTest.php +++ b/tests/unit/controller/ItemControllerTest.php @@ -128,7 +128,32 @@ class ItemControllerTest extends ControllerTestUtility { ->with($url['itemId'], true, $this->user); - $this->controller->read(); + $result = $this->controller->read(); + $this->assertTrue($result instanceof JSONResponse); + } + + + public function testReadDoesNotExist(){ + $url = array( + 'itemId' => 4 + ); + $msg = 'hi'; + $this->controller = $this->getPostController(array(), $url); + + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); + $this->itemBusinessLayer->expects($this->once()) + ->method('read') + ->will($this->throwException(new BusinessLayerException($msg))); + + + $response = $this->controller->read(); + $params = json_decode($response->render(), true); + + $this->assertEquals('error', $params['status']); + $this->assertEquals($msg, $params['msg']); + $this->assertTrue($response instanceof JSONResponse); } @@ -149,7 +174,32 @@ class ItemControllerTest extends ControllerTestUtility { } - public function testStar(){ + + public function testUnreadDoesNotExist(){ + $url = array( + 'itemId' => 4 + ); + $msg = 'hi'; + $this->controller = $this->getPostController(array(), $url); + + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); + $this->itemBusinessLayer->expects($this->once()) + ->method('read') + ->will($this->throwException(new BusinessLayerException($msg))); + + + $response = $this->controller->unread(); + $params = json_decode($response->render(), true); + + $this->assertEquals('error', $params['status']); + $this->assertEquals($msg, $params['msg']); + $this->assertTrue($response instanceof JSONResponse); + } + + + public function testStar(){ $url = array( 'feedId' => 4, 'guidHash' => md5('test') @@ -172,6 +222,30 @@ class ItemControllerTest extends ControllerTestUtility { } + public function testStarDoesNotExist(){ + $url = array( + 'feedId' => 4, + 'guidHash' => md5('test') + ); + $msg = 'ho'; + $this->controller = $this->getPostController(array(), $url); + + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); + $this->itemBusinessLayer->expects($this->once()) + ->method('star') + ->will($this->throwException(new BusinessLayerException($msg)));; + + $response = $this->controller->star(); + $params = json_decode($response->render(), true); + + $this->assertEquals('error', $params['status']); + $this->assertEquals($msg, $params['msg']); + $this->assertTrue($response instanceof JSONResponse); + } + + public function testUnstar(){ $url = array( 'feedId' => 4, @@ -195,6 +269,30 @@ class ItemControllerTest extends ControllerTestUtility { } + public function testUnstarDoesNotExist(){ + $url = array( + 'feedId' => 4, + 'guidHash' => md5('test') + ); + $msg = 'ho'; + $this->controller = $this->getPostController(array(), $url); + + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); + $this->itemBusinessLayer->expects($this->once()) + ->method('star') + ->will($this->throwException(new BusinessLayerException($msg)));; + + $response = $this->controller->unstar(); + $params = json_decode($response->render(), true); + + $this->assertEquals('error', $params['status']); + $this->assertEquals($msg, $params['msg']); + $this->assertTrue($response instanceof JSONResponse); + } + + public function testReadFeed(){ $url = array( 'feedId' => 4 |