diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-04-15 16:02:32 +0200 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-04-15 16:02:32 +0200 |
commit | 464ff6c4c1bda3edbd0f132c4d3d866539d3a117 (patch) | |
tree | 96b8fd57e24ebaab762a190a933cd98e1c7a4881 /tests/unit/controller | |
parent | 89c31ab5fcb2f931fecc5ce82608ff7c8129510a (diff) |
renamed bl to businesslayer, handle exception in update routine, fix #69
Diffstat (limited to 'tests/unit/controller')
-rw-r--r-- | tests/unit/controller/ExportControllerTest.php | 14 | ||||
-rw-r--r-- | tests/unit/controller/FeedControllerTest.php | 64 | ||||
-rw-r--r-- | tests/unit/controller/FolderControllerTest.php | 30 | ||||
-rw-r--r-- | tests/unit/controller/ItemControllerTest.php | 24 |
4 files changed, 80 insertions, 52 deletions
diff --git a/tests/unit/controller/ExportControllerTest.php b/tests/unit/controller/ExportControllerTest.php index b835e585a..74cce1d71 100644 --- a/tests/unit/controller/ExportControllerTest.php +++ b/tests/unit/controller/ExportControllerTest.php @@ -42,8 +42,8 @@ class ExportControllerTest extends ControllerTestUtility { private $request; private $controller; private $user; - private $feedBl; - private $folderBl; + private $feedBusinessLayer; + private $folderBusinessLayer; private $opmlExporter; /** @@ -51,16 +51,16 @@ class ExportControllerTest extends ControllerTestUtility { */ public function setUp(){ $this->api = $this->getAPIMock(); - $this->feedBl = $this->getMockBuilder('\OCA\News\Bl\FeedBl') + $this->feedBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\FeedBusinessLayer') ->disableOriginalConstructor() ->getMock(); - $this->folderBl = $this->getMockBuilder('\OCA\News\Bl\FolderBl') + $this->folderBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\FolderBusinessLayer') ->disableOriginalConstructor() ->getMock(); $this->request = new Request(); $this->opmlExporter = new OPMLExporter(); $this->controller = new ExportController($this->api, $this->request, - $this->feedBl, $this->folderBl, $this->opmlExporter); + $this->feedBusinessLayer, $this->folderBusinessLayer, $this->opmlExporter); $this->user = 'john'; } @@ -76,11 +76,11 @@ class ExportControllerTest extends ControllerTestUtility { $this->api->expects($this->once()) ->method('getUserId') ->will($this->returnValue($this->user)); - $this->feedBl->expects($this->once()) + $this->feedBusinessLayer->expects($this->once()) ->method('findAll') ->with($this->equalTo($this->user)) ->will($this->returnValue(array())); - $this->folderBl->expects($this->once()) + $this->folderBusinessLayer->expects($this->once()) ->method('findAll') ->with($this->equalTo($this->user)) ->will($this->returnValue(array())); diff --git a/tests/unit/controller/FeedControllerTest.php b/tests/unit/controller/FeedControllerTest.php index e7c7c29e3..c7c69fb03 100644 --- a/tests/unit/controller/FeedControllerTest.php +++ b/tests/unit/controller/FeedControllerTest.php @@ -33,7 +33,7 @@ use \OCA\AppFramework\Db\MultipleObjectsReturnedException; use \OCA\News\Db\Feed; use \OCA\News\Db\FeedType; -use \OCA\News\Bl\BLException; +use \OCA\News\BusinessLayer\BusinessLayerException; require_once(__DIR__ . "/../../classloader.php"); @@ -42,10 +42,10 @@ require_once(__DIR__ . "/../../classloader.php"); class FeedControllerTest extends ControllerTestUtility { private $api; - private $bl; + private $feedBusinessLayer; private $request; private $controller; - private $folderBl; + private $folderBusinessLayer; /** @@ -53,15 +53,15 @@ class FeedControllerTest extends ControllerTestUtility { */ public function setUp(){ $this->api = $this->getAPIMock(); - $this->bl = $this->getMockBuilder('\OCA\News\Bl\FeedBl') + $this->feedBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\FeedBusinessLayer') ->disableOriginalConstructor() ->getMock(); - $this->folderBl = $this->getMockBuilder('\OCA\News\Bl\FolderBl') + $this->folderBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\FolderBusinessLayer') ->disableOriginalConstructor() ->getMock(); $this->request = new Request(); $this->controller = new FeedController($this->api, $this->request, - $this->bl, $this->folderBl); + $this->feedBusinessLayer, $this->folderBusinessLayer); $this->user = 'jack'; } @@ -78,7 +78,7 @@ class FeedControllerTest extends ControllerTestUtility { ); $request = $this->getRequest($post); - return new FeedController($this->api, $request, $this->bl, $this->folderBl); + return new FeedController($this->api, $request, $this->feedBusinessLayer, $this->folderBusinessLayer); } @@ -121,7 +121,7 @@ class FeedControllerTest extends ControllerTestUtility { $this->api->expects($this->once()) ->method('getUserId') ->will($this->returnValue($this->user)); - $this->bl->expects($this->once()) + $this->feedBusinessLayer->expects($this->once()) ->method('findAll') ->with($this->equalTo($this->user)) ->will($this->returnValue($result['feeds'])); @@ -170,14 +170,14 @@ class FeedControllerTest extends ControllerTestUtility { public function testActiveFeedDoesNotExist(){ $id = 3; $type = FeedType::FEED; - $ex = new BLException('hiu'); + $ex = new BusinessLayerException('hiu'); $result = array( 'activeFeed' => array( 'id' => 0, 'type' => FeedType::SUBSCRIPTIONS ) ); - $this->bl->expects($this->once()) + $this->feedBusinessLayer->expects($this->once()) ->method('find') ->with($this->equalTo($id), $this->equalTo($this->user)) ->will($this->throwException($ex)); @@ -194,14 +194,14 @@ class FeedControllerTest extends ControllerTestUtility { public function testActiveFolderDoesNotExist(){ $id = 3; $type = FeedType::FOLDER; - $ex = new BLException('hiu'); + $ex = new BusinessLayerException('hiu'); $result = array( 'activeFeed' => array( 'id' => 0, 'type' => FeedType::SUBSCRIPTIONS ) ); - $this->folderBl->expects($this->once()) + $this->folderBusinessLayer->expects($this->once()) ->method('find') ->with($this->equalTo($id), $this->equalTo($this->user)) ->will($this->throwException($ex)); @@ -249,7 +249,7 @@ class FeedControllerTest extends ControllerTestUtility { ->method('getUserId') ->will($this->returnValue($this->user)); - $this->bl->expects($this->once()) + $this->feedBusinessLayer->expects($this->once()) ->method('create') ->with($this->equalTo($post['url']), $this->equalTo($post['parentFolderId']), @@ -265,8 +265,8 @@ class FeedControllerTest extends ControllerTestUtility { public function testCreateReturnsErrorForInvalidCreate(){ $msg = 'except'; - $ex = new BLException($msg); - $this->bl->expects($this->once()) + $ex = new BusinessLayerException($msg); + $this->feedBusinessLayer->expects($this->once()) ->method('create') ->will($this->throwException($ex)); @@ -288,7 +288,7 @@ class FeedControllerTest extends ControllerTestUtility { $this->api->expects($this->once()) ->method('getUserId') ->will($this->returnValue($this->user)); - $this->bl->expects($this->once()) + $this->feedBusinessLayer->expects($this->once()) ->method('delete') ->with($this->equalTo($url['feedId'])); @@ -312,7 +312,7 @@ class FeedControllerTest extends ControllerTestUtility { $this->api->expects($this->once()) ->method('getUserId') ->will($this->returnValue($this->user)); - $this->bl->expects($this->once()) + $this->feedBusinessLayer->expects($this->once()) ->method('update') ->with($this->equalTo($url['feedId']), $this->equalTo($this->user)) ->will($this->returnValue($result['feeds'][0])); @@ -324,6 +324,34 @@ class FeedControllerTest extends ControllerTestUtility { } + public function testUpdateReturnsJSONError(){ + $result = array( + 'feeds' => array( + new Feed() + ) + ); + + $url = array( + 'feedId' => 4 + ); + $this->controller = $this->getPostController(array(), $url); + + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); + $this->feedBusinessLayer->expects($this->once()) + ->method('update') + ->with($this->equalTo($url['feedId']), $this->equalTo($this->user)) + ->will($this->throwException(new BusinessLayerException('NO!'))); + + $response = $this->controller->update(); + $render = $response->render(); + + $this->assertEquals('{"status":"error","data":[],"msg":"NO!"}', $render); + $this->assertTrue($response instanceof JSONResponse); + } + + public function testMove(){ $post = array( 'parentFolderId' => 3 @@ -336,7 +364,7 @@ class FeedControllerTest extends ControllerTestUtility { $this->api->expects($this->once()) ->method('getUserId') ->will($this->returnValue($this->user)); - $this->bl->expects($this->once()) + $this->feedBusinessLayer->expects($this->once()) ->method('move') ->with($this->equalTo($url['feedId']), $this->equalTo($post['parentFolderId']), diff --git a/tests/unit/controller/FolderControllerTest.php b/tests/unit/controller/FolderControllerTest.php index 231cc9187..b71c522e0 100644 --- a/tests/unit/controller/FolderControllerTest.php +++ b/tests/unit/controller/FolderControllerTest.php @@ -32,7 +32,7 @@ use \OCA\AppFramework\Db\DoesNotExistException; use \OCA\AppFramework\Db\MultipleObjectsReturnedException; use \OCA\News\Db\Folder; -use \OCA\News\Bl\BLException; +use \OCA\News\BusinessLayer\BusinessLayerException; require_once(__DIR__ . "/../../classloader.php"); @@ -40,7 +40,7 @@ require_once(__DIR__ . "/../../classloader.php"); class FolderControllerTest extends ControllerTestUtility { private $api; - private $bl; + private $folderBusinessLayer; private $request; private $controller; @@ -50,12 +50,12 @@ class FolderControllerTest extends ControllerTestUtility { */ public function setUp(){ $this->api = $this->getAPIMock(); - $this->bl = $this->getMockBuilder('\OCA\News\Bl\FolderBl') + $this->folderBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\FolderBusinessLayer') ->disableOriginalConstructor() ->getMock(); $this->request = new Request(); $this->controller = new FolderController($this->api, $this->request, - $this->bl); + $this->folderBusinessLayer); $this->user = 'jack'; } @@ -73,7 +73,7 @@ class FolderControllerTest extends ControllerTestUtility { ); $request = $this->getRequest($post); - return new FolderController($this->api, $request, $this->bl); + return new FolderController($this->api, $request, $this->folderBusinessLayer); } public function testFoldersAnnotations(){ @@ -112,7 +112,7 @@ class FolderControllerTest extends ControllerTestUtility { new Folder(), new Folder(), ); - $this->bl->expects($this->once()) + $this->folderBusinessLayer->expects($this->once()) ->method('findAll') ->will($this->returnValue($return)); @@ -132,7 +132,7 @@ class FolderControllerTest extends ControllerTestUtility { $this->api->expects($this->once()) ->method('getUserId') ->will($this->returnValue($this->user)); - $this->bl->expects($this->once()) + $this->folderBusinessLayer->expects($this->once()) ->method('open') ->with($this->equalTo($url['folderId']), $this->equalTo(true), $this->equalTo($this->user)); @@ -150,7 +150,7 @@ class FolderControllerTest extends ControllerTestUtility { $this->api->expects($this->once()) ->method('getUserId') ->will($this->returnValue($this->user)); - $this->bl->expects($this->once()) + $this->folderBusinessLayer->expects($this->once()) ->method('open') ->with($this->equalTo($url['folderId']), $this->equalTo(false), $this->equalTo($this->user)); @@ -171,7 +171,7 @@ class FolderControllerTest extends ControllerTestUtility { $this->api->expects($this->once()) ->method('getUserId') ->will($this->returnValue($this->user)); - $this->bl->expects($this->once()) + $this->folderBusinessLayer->expects($this->once()) ->method('create') ->with($this->equalTo($post['folderName']), $this->equalTo($this->user)) @@ -186,8 +186,8 @@ class FolderControllerTest extends ControllerTestUtility { public function testCreateReturnsErrorForInvalidCreate(){ $msg = 'except'; - $ex = new BLException($msg); - $this->bl->expects($this->once()) + $ex = new BusinessLayerException($msg); + $this->folderBusinessLayer->expects($this->once()) ->method('create') ->will($this->throwException($ex)); @@ -207,7 +207,7 @@ class FolderControllerTest extends ControllerTestUtility { $this->api->expects($this->once()) ->method('getUserId') ->will($this->returnValue($this->user)); - $this->bl->expects($this->once()) + $this->folderBusinessLayer->expects($this->once()) ->method('delete') ->with($this->equalTo($url['folderId']), $this->equalTo($this->user)); @@ -229,7 +229,7 @@ class FolderControllerTest extends ControllerTestUtility { $this->api->expects($this->once()) ->method('getUserId') ->will($this->returnValue($this->user)); - $this->bl->expects($this->once()) + $this->folderBusinessLayer->expects($this->once()) ->method('rename') ->with($this->equalTo($url['folderId']), $this->equalTo($post['folderName']), @@ -245,8 +245,8 @@ class FolderControllerTest extends ControllerTestUtility { public function testRenameReturnsErrorForInvalidCreate(){ $msg = 'except'; - $ex = new BLException($msg); - $this->bl->expects($this->once()) + $ex = new BusinessLayerException($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 cb055b8f3..ca72ee330 100644 --- a/tests/unit/controller/ItemControllerTest.php +++ b/tests/unit/controller/ItemControllerTest.php @@ -38,7 +38,7 @@ require_once(__DIR__ . "/../../classloader.php"); class ItemControllerTest extends ControllerTestUtility { private $api; - private $bl; + private $itemBusinessLayer; private $request; private $controller; @@ -48,12 +48,12 @@ class ItemControllerTest extends ControllerTestUtility { */ public function setUp(){ $this->api = $this->getAPIMock(); - $this->bl = $this->getMockBuilder('\OCA\News\Bl\ItemBl') + $this->itemBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\ItemBusinessLayer') ->disableOriginalConstructor() ->getMock(); $this->request = new Request(); $this->controller = new ItemController($this->api, $this->request, - $this->bl); + $this->itemBusinessLayer); $this->user = 'jackob'; } @@ -64,7 +64,7 @@ class ItemControllerTest extends ControllerTestUtility { ); $request = $this->getRequest($post); - return new ItemController($this->api, $request, $this->bl); + return new ItemController($this->api, $request, $this->itemBusinessLayer); } @@ -117,7 +117,7 @@ class ItemControllerTest extends ControllerTestUtility { $this->api->expects($this->once()) ->method('getUserId') ->will($this->returnValue($this->user)); - $this->bl->expects($this->once()) + $this->itemBusinessLayer->expects($this->once()) ->method('read') ->with($url['itemId'], true, $this->user); @@ -135,7 +135,7 @@ class ItemControllerTest extends ControllerTestUtility { $this->api->expects($this->once()) ->method('getUserId') ->will($this->returnValue($this->user)); - $this->bl->expects($this->once()) + $this->itemBusinessLayer->expects($this->once()) ->method('read') ->with($url['itemId'], false, $this->user); @@ -153,7 +153,7 @@ class ItemControllerTest extends ControllerTestUtility { $this->api->expects($this->once()) ->method('getUserId') ->will($this->returnValue($this->user)); - $this->bl->expects($this->once()) + $this->itemBusinessLayer->expects($this->once()) ->method('star') ->with( $this->equalTo($url['feedId']), @@ -176,7 +176,7 @@ class ItemControllerTest extends ControllerTestUtility { $this->api->expects($this->once()) ->method('getUserId') ->will($this->returnValue($this->user)); - $this->bl->expects($this->once()) + $this->itemBusinessLayer->expects($this->once()) ->method('star') ->with( $this->equalTo($url['feedId']), @@ -201,7 +201,7 @@ class ItemControllerTest extends ControllerTestUtility { $this->api->expects($this->once()) ->method('getUserId') ->will($this->returnValue($this->user)); - $this->bl->expects($this->once()) + $this->itemBusinessLayer->expects($this->once()) ->method('readFeed') ->with($url['feedId'], $post['highestItemId'], $this->user); @@ -217,7 +217,7 @@ class ItemControllerTest extends ControllerTestUtility { $this->api->expects($this->once()) ->method('getUserId') ->will($this->returnValue($this->user)); - $this->bl->expects($this->once()) + $this->itemBusinessLayer->expects($this->once()) ->method('starredCount') ->with($this->user) ->will($this->returnValue($result['starred'])); @@ -263,7 +263,7 @@ class ItemControllerTest extends ControllerTestUtility { $this->itemsApiExpects($post['id'], $post['type']); - $this->bl->expects($this->once()) + $this->itemBusinessLayer->expects($this->once()) ->method('findAll') ->with($post['id'], $post['type'], $post['limit'], $post['offset'], true, $this->user) @@ -288,7 +288,7 @@ class ItemControllerTest extends ControllerTestUtility { $this->itemsApiExpects($post['id'], $post['type']); - $this->bl->expects($this->once()) + $this->itemBusinessLayer->expects($this->once()) ->method('findAllNew') ->with($post['id'], $post['type'], $post['updatedSince'], true, $this->user) |