diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-04-06 15:26:45 +0200 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-04-06 15:26:58 +0200 |
commit | dbd18a20993221baf9e851fbd8eba1a48c411b3d (patch) | |
tree | d6bb96ddde1d70e960e1e8fc7b3d2d8a1ce3ca79 /tests/unit/controller/FolderControllerTest.php | |
parent | 3c4044970e38820d67560e219dd94dc9e96b0387 (diff) |
get rid of deprecated getParams and renderJSON method to ease transition to built in appframework
Diffstat (limited to 'tests/unit/controller/FolderControllerTest.php')
-rw-r--r-- | tests/unit/controller/FolderControllerTest.php | 77 |
1 files changed, 67 insertions, 10 deletions
diff --git a/tests/unit/controller/FolderControllerTest.php b/tests/unit/controller/FolderControllerTest.php index e4295583b..bcfa61c67 100644 --- a/tests/unit/controller/FolderControllerTest.php +++ b/tests/unit/controller/FolderControllerTest.php @@ -30,11 +30,13 @@ use \OCA\AppFramework\Http\JSONResponse; use \OCA\AppFramework\Utility\ControllerTestUtility; use \OCA\AppFramework\Db\DoesNotExistException; use \OCA\AppFramework\Db\MultipleObjectsReturnedException; +use \OCA\AppFramework\Http\Http; use \OCA\News\Db\Folder; use \OCA\News\Db\Feed; use \OCA\News\BusinessLayer\BusinessLayerException; use \OCA\News\BusinessLayer\BusinessLayerConflictException; +use \OCA\News\BusinessLayer\BusinessLayerValidationException; require_once(__DIR__ . "/../../classloader.php"); @@ -145,7 +147,7 @@ class FolderControllerTest extends ControllerTestUtility { $expected = array( 'folders' => $return ); - $this->assertEquals($expected, $response->getParams()); + $this->assertEquals($expected, $response->getData()); $this->assertTrue($response instanceof JSONResponse); } @@ -183,9 +185,9 @@ class FolderControllerTest extends ControllerTestUtility { $params = json_decode($response->render(), true); - $this->assertEquals('error', $params['status']); $this->assertEquals($this->msg, $params['msg']); $this->assertTrue($response instanceof JSONResponse); + $this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND); } @@ -222,9 +224,9 @@ class FolderControllerTest extends ControllerTestUtility { $params = json_decode($response->render(), true); - $this->assertEquals('error', $params['status']); $this->assertEquals($this->msg, $params['msg']); $this->assertTrue($response instanceof JSONResponse); + $this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND); } @@ -249,13 +251,35 @@ class FolderControllerTest extends ControllerTestUtility { $response = $this->controller->create(); - $this->assertEquals($result, $response->getParams()); + $this->assertEquals($result, $response->getData()); $this->assertTrue($response instanceof JSONResponse); } public function testCreateReturnsErrorForInvalidCreate(){ $msg = 'except'; + $ex = new BusinessLayerValidationException($msg); + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); + $this->folderBusinessLayer->expects($this->once()) + ->method('purgeDeleted') + ->with($this->equalTo($this->user), $this->equalTo(false)); + $this->folderBusinessLayer->expects($this->once()) + ->method('create') + ->will($this->throwException($ex)); + + $response = $this->controller->create(); + $params = json_decode($response->render(), true); + + $this->assertEquals($response->getStatus(), Http::STATUS_UNPROCESSABLE_ENTITY); + $this->assertEquals($msg, $params['msg']); + $this->assertTrue($response instanceof JSONResponse); + } + + + public function testCreateReturnsErrorForDuplicateCreate(){ + $msg = 'except'; $ex = new BusinessLayerConflictException($msg); $this->api->expects($this->once()) ->method('getUserId') @@ -270,7 +294,7 @@ class FolderControllerTest extends ControllerTestUtility { $response = $this->controller->create(); $params = json_decode($response->render(), true); - $this->assertEquals('error', $params['status']); + $this->assertEquals($response->getStatus(), Http::STATUS_CONFLICT); $this->assertEquals($msg, $params['msg']); $this->assertTrue($response instanceof JSONResponse); } @@ -309,9 +333,9 @@ class FolderControllerTest extends ControllerTestUtility { $params = json_decode($response->render(), true); - $this->assertEquals('error', $params['status']); $this->assertEquals($this->msg, $params['msg']); $this->assertTrue($response instanceof JSONResponse); + $this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND); } @@ -335,13 +359,45 @@ class FolderControllerTest extends ControllerTestUtility { $response = $this->controller->rename(); - $this->assertEquals($result, $response->getParams()); + $this->assertEquals($result, $response->getData()); $this->assertTrue($response instanceof JSONResponse); } public function testRenameReturnsErrorForInvalidCreate(){ $msg = 'except'; + $ex = new BusinessLayerValidationException($msg); + $this->folderBusinessLayer->expects($this->once()) + ->method('rename') + ->will($this->throwException($ex)); + + $response = $this->controller->rename(); + $params = json_decode($response->render(), true); + + $this->assertEquals($response->getStatus(), Http::STATUS_UNPROCESSABLE_ENTITY); + $this->assertEquals($msg, $params['msg']); + $this->assertTrue($response instanceof JSONResponse); + } + + + public function testRenameDoesNotExist(){ + $msg = 'except'; + $ex = new BusinessLayerException($msg); + $this->folderBusinessLayer->expects($this->once()) + ->method('rename') + ->will($this->throwException($ex)); + + $response = $this->controller->rename(); + $params = json_decode($response->render(), true); + + $this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND); + $this->assertEquals($msg, $params['msg']); + $this->assertTrue($response instanceof JSONResponse); + } + + + public function testRenameReturnsErrorForDuplicateCreate(){ + $msg = 'except'; $ex = new BusinessLayerConflictException($msg); $this->folderBusinessLayer->expects($this->once()) ->method('rename') @@ -350,11 +406,12 @@ class FolderControllerTest extends ControllerTestUtility { $response = $this->controller->rename(); $params = json_decode($response->render(), true); - $this->assertEquals('error', $params['status']); + $this->assertEquals($response->getStatus(), Http::STATUS_CONFLICT); $this->assertEquals($msg, $params['msg']); $this->assertTrue($response instanceof JSONResponse); } + public function testRead(){ $feed = new Feed(); @@ -384,7 +441,7 @@ class FolderControllerTest extends ControllerTestUtility { $response = $this->controller->read(); $this->assertTrue($response instanceof JSONResponse); - $this->assertEquals($expected, $response->getParams()); + $this->assertEquals($expected, $response->getData()); } @@ -421,7 +478,7 @@ class FolderControllerTest extends ControllerTestUtility { $params = json_decode($response->render(), true); - $this->assertEquals('error', $params['status']); + $this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND); $this->assertEquals($this->msg, $params['msg']); $this->assertTrue($response instanceof JSONResponse); } |