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 | |
parent | e9878cb5b583bc993a9f3a482d0b371bbeea5bd2 (diff) |
added proper exception handling for all controllers and businesslayer
Diffstat (limited to 'tests/unit/controller')
-rw-r--r-- | tests/unit/controller/FeedControllerTest.php | 49 | ||||
-rw-r--r-- | tests/unit/controller/FolderControllerTest.php | 70 | ||||
-rw-r--r-- | tests/unit/controller/ItemControllerTest.php | 102 |
3 files changed, 217 insertions, 4 deletions
diff --git a/tests/unit/controller/FeedControllerTest.php b/tests/unit/controller/FeedControllerTest.php index 14c31b545..403d9c3c8 100644 --- a/tests/unit/controller/FeedControllerTest.php +++ b/tests/unit/controller/FeedControllerTest.php @@ -348,6 +348,29 @@ class FeedControllerTest extends ControllerTestUtility { } + public function testDeleteDoesNotExist(){ + $url = array( + 'feedId' => 4 + ); + $msg = 'hehe'; + $this->controller = $this->getPostController(array(), $url); + + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); + $this->feedBusinessLayer->expects($this->once()) + ->method('delete') + ->will($this->throwException(new BusinessLayerException($msg))); + + $response = $this->controller->delete(); + $params = json_decode($response->render(), true); + + $this->assertEquals('error', $params['status']); + $this->assertEquals($msg, $params['msg']); + $this->assertTrue($response instanceof JSONResponse); + } + + public function testUpdate(){ $feed = new Feed(); $feed->setId(3); @@ -433,6 +456,32 @@ class FeedControllerTest extends ControllerTestUtility { } + public function testMoveDoesNotExist(){ + $post = array( + 'parentFolderId' => 3 + ); + $url = array( + 'feedId' => 4 + ); + $msg = 'john'; + $this->controller = $this->getPostController($post, $url); + + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); + $this->feedBusinessLayer->expects($this->once()) + ->method('move') + ->will($this->throwException(new BusinessLayerException($msg))); + + $response = $this->controller->move(); + $params = json_decode($response->render(), true); + + $this->assertEquals('error', $params['status']); + $this->assertEquals($msg, $params['msg']); + $this->assertTrue($response instanceof JSONResponse); + } + + public function testImportGoogleReader() { $feed = new Feed(); diff --git a/tests/unit/controller/FolderControllerTest.php b/tests/unit/controller/FolderControllerTest.php index b71c522e0..4b070a0bb 100644 --- a/tests/unit/controller/FolderControllerTest.php +++ b/tests/unit/controller/FolderControllerTest.php @@ -33,6 +33,7 @@ use \OCA\AppFramework\Db\MultipleObjectsReturnedException; use \OCA\News\Db\Folder; use \OCA\News\BusinessLayer\BusinessLayerException; +use \OCA\News\BusinessLayer\BusinessLayerExistsException; require_once(__DIR__ . "/../../classloader.php"); @@ -43,6 +44,7 @@ class FolderControllerTest extends ControllerTestUtility { private $folderBusinessLayer; private $request; private $controller; + private $msg; /** @@ -57,6 +59,7 @@ class FolderControllerTest extends ControllerTestUtility { $this->controller = new FolderController($this->api, $this->request, $this->folderBusinessLayer); $this->user = 'jack'; + $this->msg = 'ron'; } @@ -143,6 +146,27 @@ class FolderControllerTest extends ControllerTestUtility { } + public function testOpenDoesNotExist(){ + $url = array('folderId' => 5); + $this->controller = $this->getPostController(array(), $url); + + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); + $this->folderBusinessLayer->expects($this->once()) + ->method('open') + ->will($this->throwException(new BusinessLayerException($this->msg))); + + $response = $this->controller->open(); + + $params = json_decode($response->render(), true); + + $this->assertEquals('error', $params['status']); + $this->assertEquals($this->msg, $params['msg']); + $this->assertTrue($response instanceof JSONResponse); + } + + public function testCollapse(){ $url = array('folderId' => 5); $this->controller = $this->getPostController(array(), $url); @@ -161,6 +185,27 @@ class FolderControllerTest extends ControllerTestUtility { } + public function testCollapseDoesNotExist(){ + $url = array('folderId' => 5); + $this->controller = $this->getPostController(array(), $url); + + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); + $this->folderBusinessLayer->expects($this->once()) + ->method('open') + ->will($this->throwException(new BusinessLayerException($this->msg))); + + $response = $this->controller->collapse(); + + $params = json_decode($response->render(), true); + + $this->assertEquals('error', $params['status']); + $this->assertEquals($this->msg, $params['msg']); + $this->assertTrue($response instanceof JSONResponse); + } + + public function testCreate(){ $post = array('folderName' => 'tech'); $this->controller = $this->getPostController($post); @@ -186,7 +231,7 @@ class FolderControllerTest extends ControllerTestUtility { public function testCreateReturnsErrorForInvalidCreate(){ $msg = 'except'; - $ex = new BusinessLayerException($msg); + $ex = new BusinessLayerExistsException($msg); $this->folderBusinessLayer->expects($this->once()) ->method('create') ->will($this->throwException($ex)); @@ -218,6 +263,27 @@ class FolderControllerTest extends ControllerTestUtility { } + public function testDeleteDoesNotExist(){ + $url = array('folderId' => 5); + $this->controller = $this->getPostController(array(), $url); + + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); + $this->folderBusinessLayer->expects($this->once()) + ->method('delete') + ->will($this->throwException(new BusinessLayerException($this->msg))); + + $response = $this->controller->delete(); + + $params = json_decode($response->render(), true); + + $this->assertEquals('error', $params['status']); + $this->assertEquals($this->msg, $params['msg']); + $this->assertTrue($response instanceof JSONResponse); + } + + public function testRename(){ $post = array('folderName' => 'tech'); $url = array('folderId' => 4); @@ -245,7 +311,7 @@ class FolderControllerTest extends ControllerTestUtility { public function testRenameReturnsErrorForInvalidCreate(){ $msg = 'except'; - $ex = new BusinessLayerException($msg); + $ex = new BusinessLayerExistsException($msg); $this->folderBusinessLayer->expects($this->once()) ->method('rename') ->will($this->throwException($ex)); 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 |