diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-08-31 02:58:56 +0200 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-08-31 02:58:56 +0200 |
commit | 7036a1407c3dce54a6ac5e283ba55720f85ba7de (patch) | |
tree | 7c5fae7ab816a2b0c56b92ca74ebc7cc591d5a3d /tests/unit/external/FolderAPITest.php | |
parent | 6f23208ff68d4a8bf2fc20b1fcad6b5e636fb584 (diff) |
Throw proper error codes when creating invalid folders through the API, fix #297
Diffstat (limited to 'tests/unit/external/FolderAPITest.php')
-rw-r--r-- | tests/unit/external/FolderAPITest.php | 64 |
1 files changed, 61 insertions, 3 deletions
diff --git a/tests/unit/external/FolderAPITest.php b/tests/unit/external/FolderAPITest.php index 3e5bbabb6..145cc6720 100644 --- a/tests/unit/external/FolderAPITest.php +++ b/tests/unit/external/FolderAPITest.php @@ -31,7 +31,8 @@ use \OCA\AppFramework\Utility\ControllerTestUtility; use \OCA\AppFramework\Http\Http; use \OCA\News\BusinessLayer\BusinessLayerException; -use \OCA\News\BusinessLayer\BusinessLayerExistsException; +use \OCA\News\BusinessLayer\BusinessLayerConflictException; +use \OCA\News\BusinessLayer\BusinessLayerValidationException; use \OCA\News\Db\Folder; use \OCA\News\Db\Feed; @@ -177,7 +178,7 @@ class FolderAPITest extends ControllerTestUtility { ->with($this->equalTo($this->user), $this->equalTo(false)); $this->folderBusinessLayer->expects($this->once()) ->method('create') - ->will($this->throwException(new BusinessLayerExistsException($msg))); + ->will($this->throwException(new BusinessLayerConflictException($msg))); $response = $this->folderAPI->create(); @@ -187,6 +188,27 @@ class FolderAPITest extends ControllerTestUtility { } + public function testCreateInvalidFolderName() { + $msg = 'exists'; + + $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(new BusinessLayerValidationException($msg))); + + $response = $this->folderAPI->create(); + + $data = $response->getData(); + $this->assertEquals($msg, $data['message']); + $this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus()); + } + + public function testDelete() { $folderId = 23; @@ -337,7 +359,7 @@ class FolderAPITest extends ControllerTestUtility { ->will($this->returnValue($this->user)); $this->folderBusinessLayer->expects($this->once()) ->method('rename') - ->will($this->throwException(new BusinessLayerExistsException($this->msg))); + ->will($this->throwException(new BusinessLayerConflictException($this->msg))); $response = $this->folderAPI->update(); @@ -347,6 +369,42 @@ class FolderAPITest extends ControllerTestUtility { } + public function testUpdateInvalidFolderName() { + $folderId = 23; + $folderName = ''; + + $this->folderAPI = new FolderAPI( + $this->api, + new Request( + array( + 'urlParams' => array( + 'folderId' => $folderId + ), + + 'params' => array( + 'name' => $folderName + ) + ) + ), + $this->folderBusinessLayer, + $this->itemBusinessLayer + ); + + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); + $this->folderBusinessLayer->expects($this->once()) + ->method('rename') + ->will($this->throwException(new BusinessLayerValidationException($this->msg))); + + $response = $this->folderAPI->update(); + + $data = $response->getData(); + $this->assertEquals($this->msg, $data['message']); + $this->assertEquals(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus()); + } + + public function testRead() { $request = new Request(array( 'urlParams' => array( |