summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-08-31 02:58:56 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2013-08-31 02:58:56 +0200
commit7036a1407c3dce54a6ac5e283ba55720f85ba7de (patch)
tree7c5fae7ab816a2b0c56b92ca74ebc7cc591d5a3d /tests
parent6f23208ff68d4a8bf2fc20b1fcad6b5e636fb584 (diff)
Throw proper error codes when creating invalid folders through the API, fix #297
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/businesslayer/FolderBusinessLayerTest.php32
-rw-r--r--tests/unit/controller/FolderControllerTest.php6
-rw-r--r--tests/unit/external/FeedAPITest.php4
-rw-r--r--tests/unit/external/FolderAPITest.php64
4 files changed, 98 insertions, 8 deletions
diff --git a/tests/unit/businesslayer/FolderBusinessLayerTest.php b/tests/unit/businesslayer/FolderBusinessLayerTest.php
index d28c078a5..7f512920e 100644
--- a/tests/unit/businesslayer/FolderBusinessLayerTest.php
+++ b/tests/unit/businesslayer/FolderBusinessLayerTest.php
@@ -115,6 +115,22 @@ class FolderBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
}
+ public function testCreateThrowsExWhenFolderNameEmpty(){
+ $folderName = '';
+ $rows = array(
+ array('id' => 1)
+ );
+
+ $this->folderMapper->expects($this->once())
+ ->method('findByName')
+ ->with($this->equalTo($folderName))
+ ->will($this->returnValue(array()));
+
+ $this->setExpectedException('\OCA\News\BusinessLayer\BusinessLayerValidationException');
+ $result = $this->folderBusinessLayer->create($folderName, 'john', 3);
+ }
+
+
public function testOpen(){
$folder = new Folder();
@@ -175,6 +191,22 @@ class FolderBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
}
+ public function testRenameThrowsExWhenFolderNameEmpty(){
+ $folderName = '';
+ $rows = array(
+ array('id' => 1)
+ );
+
+ $this->folderMapper->expects($this->once())
+ ->method('findByName')
+ ->with($this->equalTo($folderName))
+ ->will($this->returnValue(array()));
+
+ $this->setExpectedException('\OCA\News\BusinessLayer\BusinessLayerException');
+ $result = $this->folderBusinessLayer->rename(3, $folderName, 'john');
+ }
+
+
public function testMarkDeleted() {
$id = 3;
$folder = new Folder();
diff --git a/tests/unit/controller/FolderControllerTest.php b/tests/unit/controller/FolderControllerTest.php
index f273c9ec7..e4295583b 100644
--- a/tests/unit/controller/FolderControllerTest.php
+++ b/tests/unit/controller/FolderControllerTest.php
@@ -34,7 +34,7 @@ use \OCA\AppFramework\Db\MultipleObjectsReturnedException;
use \OCA\News\Db\Folder;
use \OCA\News\Db\Feed;
use \OCA\News\BusinessLayer\BusinessLayerException;
-use \OCA\News\BusinessLayer\BusinessLayerExistsException;
+use \OCA\News\BusinessLayer\BusinessLayerConflictException;
require_once(__DIR__ . "/../../classloader.php");
@@ -256,7 +256,7 @@ class FolderControllerTest extends ControllerTestUtility {
public function testCreateReturnsErrorForInvalidCreate(){
$msg = 'except';
- $ex = new BusinessLayerExistsException($msg);
+ $ex = new BusinessLayerConflictException($msg);
$this->api->expects($this->once())
->method('getUserId')
->will($this->returnValue($this->user));
@@ -342,7 +342,7 @@ class FolderControllerTest extends ControllerTestUtility {
public function testRenameReturnsErrorForInvalidCreate(){
$msg = 'except';
- $ex = new BusinessLayerExistsException($msg);
+ $ex = new BusinessLayerConflictException($msg);
$this->folderBusinessLayer->expects($this->once())
->method('rename')
->will($this->throwException($ex));
diff --git a/tests/unit/external/FeedAPITest.php b/tests/unit/external/FeedAPITest.php
index fbc608cac..ec6aedf19 100644
--- a/tests/unit/external/FeedAPITest.php
+++ b/tests/unit/external/FeedAPITest.php
@@ -31,7 +31,7 @@ use \OCA\AppFramework\Http\Http;
use \OCA\AppFramework\Utility\ControllerTestUtility;
use \OCA\News\BusinessLayer\BusinessLayerException;
-use \OCA\News\BusinessLayer\BusinessLayerExistsException;
+use \OCA\News\BusinessLayer\BusinessLayerConflictException;
use \OCA\News\Db\Folder;
use \OCA\News\Db\Feed;
use \OCA\News\Db\Item;
@@ -343,7 +343,7 @@ class FeedAPITest extends ControllerTestUtility {
->with($this->equalTo($this->user), $this->equalTo(false));
$this->feedBusinessLayer->expects($this->once())
->method('create')
- ->will($this->throwException(new BusinessLayerExistsException($this->msg)));
+ ->will($this->throwException(new BusinessLayerConflictException($this->msg)));
$response = $this->feedAPI->create();
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(