diff options
-rw-r--r-- | controller/feedcontroller.php | 53 | ||||
-rw-r--r-- | controller/foldercontroller.php | 66 | ||||
-rw-r--r-- | controller/itemcontroller.php | 32 | ||||
-rw-r--r-- | controller/usersettingscontroller.php | 14 | ||||
-rw-r--r-- | js/app/services/persistence.coffee | 2 | ||||
-rw-r--r-- | js/public/app.js | 2 | ||||
-rw-r--r-- | js/tests/services/persistenceSpec.coffee | 3 | ||||
-rw-r--r-- | tests/unit/controller/FeedControllerTest.php | 91 | ||||
-rw-r--r-- | tests/unit/controller/FolderControllerTest.php | 77 | ||||
-rw-r--r-- | tests/unit/controller/ItemControllerTest.php | 21 | ||||
-rw-r--r-- | tests/unit/controller/UserSettingsControllerTest.php | 6 |
11 files changed, 271 insertions, 96 deletions
diff --git a/controller/feedcontroller.php b/controller/feedcontroller.php index e9561cf32..b0b856b79 100644 --- a/controller/feedcontroller.php +++ b/controller/feedcontroller.php @@ -28,11 +28,14 @@ namespace OCA\News\Controller; use \OCA\AppFramework\Controller\Controller; use \OCA\AppFramework\Core\API; use \OCA\AppFramework\Http\Request; +use \OCA\AppFramework\Http\JSONResponse; +use \OCA\AppFramework\Http\Http; use \OCA\News\BusinessLayer\ItemBusinessLayer; use \OCA\News\BusinessLayer\FeedBusinessLayer; use \OCA\News\BusinessLayer\FolderBusinessLayer; use \OCA\News\BusinessLayer\BusinessLayerException; +use \OCA\News\BusinessLayer\BusinessLayerConflictException; use \OCA\News\Db\FeedType; @@ -74,7 +77,7 @@ class FeedController extends Controller { $this->itemBusinessLayer->getNewestItemId($userId); } catch (BusinessLayerException $ex) {} - return $this->renderJSON($params); + return new JSONResponse($params); } @@ -118,7 +121,7 @@ class FeedController extends Controller { ) ); - return $this->renderJSON($params); + return new JSONResponse($params); } @@ -147,9 +150,17 @@ class FeedController extends Controller { $this->itemBusinessLayer->getNewestItemId($userId); } catch (BusinessLayerException $ex) {} - return $this->renderJSON($params); + return new JSONResponse($params); + + } catch(BusinessLayerConflictException $ex) { + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_CONFLICT); + } catch(BusinessLayerException $ex) { - return $this->renderJSON(array(), $ex->getMessage()); + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_UNPROCESSABLE_ENTITY); } } @@ -165,9 +176,11 @@ class FeedController extends Controller { try { $this->feedBusinessLayer->markDeleted($feedId, $userId); - return $this->renderJSON(); + return new JSONResponse(); } catch(BusinessLayerException $ex) { - return $this->renderJSON(array(), $ex->getMessage()); + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_NOT_FOUND); } } @@ -195,10 +208,12 @@ class FeedController extends Controller { ) ); - return $this->renderJSON($params); + return new JSONResponse($params); } catch(BusinessLayerException $ex) { - return $this->renderJSON(array(), $ex->getMessage()); + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_NOT_FOUND); } } @@ -215,9 +230,11 @@ class FeedController extends Controller { try { $this->feedBusinessLayer->move($feedId, $parentFolderId, $userId); - return $this->renderJSON(); + return new JSONResponse(); } catch(BusinessLayerException $ex) { - return $this->renderJSON(array(), $ex->getMessage()); + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_NOT_FOUND); } } @@ -233,9 +250,11 @@ class FeedController extends Controller { try { $this->feedBusinessLayer->rename($feedId, $feedTitle, $userId); - return $this->renderJSON(); + return new JSONResponse(); } catch(BusinessLayerException $ex) { - return $this->renderJSON(array(), $ex->getMessage()); + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_NOT_FOUND); } } @@ -255,7 +274,7 @@ class FeedController extends Controller { $params['feeds'] = array($feed); } - return $this->renderJSON($params); + return new JSONResponse($params); } @@ -279,7 +298,7 @@ class FeedController extends Controller { ) ) ); - return $this->renderJSON($params); + return new JSONResponse($params); } @@ -294,9 +313,11 @@ class FeedController extends Controller { try { $this->feedBusinessLayer->unmarkDeleted($feedId, $userId); - return $this->renderJSON(); + return new JSONResponse(); } catch(BusinessLayerException $ex) { - return $this->renderJSON(array(), $ex->getMessage()); + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_NOT_FOUND); } } diff --git a/controller/foldercontroller.php b/controller/foldercontroller.php index 546ce60b6..09d226920 100644 --- a/controller/foldercontroller.php +++ b/controller/foldercontroller.php @@ -28,12 +28,15 @@ namespace OCA\News\Controller; use \OCA\AppFramework\Controller\Controller; use \OCA\AppFramework\Core\API; use \OCA\AppFramework\Http\Request; +use \OCA\AppFramework\Http\JSONResponse; +use \OCA\AppFramework\Http\Http; use \OCA\News\BusinessLayer\FolderBusinessLayer; use \OCA\News\BusinessLayer\FeedBusinessLayer; use \OCA\News\BusinessLayer\ItemBusinessLayer; use \OCA\News\BusinessLayer\BusinessLayerException; - +use \OCA\News\BusinessLayer\BusinessLayerConflictException; +use \OCA\News\BusinessLayer\BusinessLayerValidationException; class FolderController extends Controller { @@ -62,7 +65,7 @@ class FolderController extends Controller { $result = array( 'folders' => $folders ); - return $this->renderJSON($result); + return new JSONResponse($result); } @@ -82,9 +85,11 @@ class FolderController extends Controller { public function open(){ try { $this->setOpened(true); - return $this->renderJSON(); + return new JSONResponse(); } catch(BusinessLayerException $ex) { - return $this->renderJSON(array(), $ex->getMessage()); + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_NOT_FOUND); } } @@ -97,9 +102,11 @@ class FolderController extends Controller { public function collapse(){ try { $this->setOpened(false); - return $this->renderJSON(); + return new JSONResponse(); } catch(BusinessLayerException $ex) { - return $this->renderJSON(array(), $ex->getMessage()); + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_NOT_FOUND); } } @@ -123,10 +130,19 @@ class FolderController extends Controller { $params = array( 'folders' => array($folder) ); - return $this->renderJSON($params); + return new JSONResponse($params); - } catch (BusinessLayerException $ex){ - return $this->renderJSON(array(), $ex->getMessage()); + + + } catch(BusinessLayerConflictException $ex) { + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_CONFLICT); + + } catch(BusinessLayerValidationException $ex) { + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_UNPROCESSABLE_ENTITY); } } @@ -143,9 +159,11 @@ class FolderController extends Controller { try { $this->folderBusinessLayer->markDeleted($folderId, $userId); - return $this->renderJSON(); + return new JSONResponse(); } catch (BusinessLayerException $ex){ - return $this->renderJSON(array(), $ex->getMessage()); + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_NOT_FOUND); } } @@ -166,10 +184,22 @@ class FolderController extends Controller { $params = array( 'folders' => array($folder) ); - return $this->renderJSON($params); - + return new JSONResponse($params); + + } catch(BusinessLayerConflictException $ex) { + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_CONFLICT); + + } catch(BusinessLayerValidationException $ex) { + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_UNPROCESSABLE_ENTITY); + } catch (BusinessLayerException $ex){ - return $this->renderJSON(array(), $ex->getMessage()); + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_NOT_FOUND); } } @@ -188,7 +218,7 @@ class FolderController extends Controller { $params = array( 'feeds' => $this->feedBusinessLayer->findAll($userId) ); - return $this->renderJSON($params); + return new JSONResponse($params); } @@ -203,9 +233,11 @@ class FolderController extends Controller { try { $this->folderBusinessLayer->unmarkDeleted($folderId, $userId); - return $this->renderJSON(); + return new JSONResponse(); } catch (BusinessLayerException $ex){ - return $this->renderJSON(array(), $ex->getMessage()); + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_NOT_FOUND); } } diff --git a/controller/itemcontroller.php b/controller/itemcontroller.php index a3f632e39..637c5fd49 100644 --- a/controller/itemcontroller.php +++ b/controller/itemcontroller.php @@ -28,6 +28,8 @@ namespace OCA\News\Controller; use \OCA\AppFramework\Controller\Controller; use \OCA\AppFramework\Core\API; use \OCA\AppFramework\Http\Request; +use \OCA\AppFramework\Http\JSONResponse; +use \OCA\AppFramework\Http\Http; use \OCA\News\BusinessLayer\BusinessLayerException; use \OCA\News\BusinessLayer\ItemBusinessLayer; @@ -85,7 +87,7 @@ class ItemController extends Controller { // in that case just return an empty array } catch(BusinessLayerException $ex) {} - return $this->renderJSON($params); + return new JSONResponse($params); } @@ -114,7 +116,7 @@ class ItemController extends Controller { // in that case just return an empty array } catch(BusinessLayerException $ex) {} - return $this->renderJSON($params); + return new JSONResponse($params); } @@ -135,9 +137,11 @@ class ItemController extends Controller { public function star(){ try { $this->setStarred(true); - return $this->renderJSON(); + return new JSONResponse(); } catch(BusinessLayerException $ex) { - return $this->renderJSON(array(), $ex->getMessage()); + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_NOT_FOUND); } } @@ -150,9 +154,11 @@ class ItemController extends Controller { public function unstar(){ try { $this->setStarred(false); - return $this->renderJSON(); + return new JSONResponse(); } catch(BusinessLayerException $ex) { - return $this->renderJSON(array(), $ex->getMessage()); + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_NOT_FOUND); } } @@ -173,9 +179,11 @@ class ItemController extends Controller { public function read(){ try { $this->setRead(true); - return $this->renderJSON(); + return new JSONResponse(); } catch(BusinessLayerException $ex) { - return $this->renderJSON(array(), $ex->getMessage()); + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_NOT_FOUND); } } @@ -188,9 +196,11 @@ class ItemController extends Controller { public function unread(){ try { $this->setRead(false); - return $this->renderJSON(); + return new JSONResponse(); } catch(BusinessLayerException $ex) { - return $this->renderJSON(array(), $ex->getMessage()); + return new JSONResponse(array( + 'msg' => $ex->getMessage() + ), Http::STATUS_NOT_FOUND); } } @@ -209,7 +219,7 @@ class ItemController extends Controller { $params = array( 'feeds' => $this->feedBusinessLayer->findAll($userId) ); - return $this->renderJSON($params); + return new JSONResponse($params); } diff --git a/controller/usersettingscontroller.php b/controller/usersettingscontroller.php index 9dd14fbf2..a34d5397e 100644 --- a/controller/usersettingscontroller.php +++ b/controller/usersettingscontroller.php @@ -28,7 +28,7 @@ namespace OCA\News\Controller; use \OCA\AppFramework\Controller\Controller; use \OCA\AppFramework\Core\API; use \OCA\AppFramework\Http\Request; - +use \OCA\AppFramework\Http\JSONResponse; class UserSettingsController extends Controller { @@ -49,7 +49,7 @@ class UserSettingsController extends Controller { 'showAll' => $showAll === '1' ); - return $this->renderJSON($params); + return new JSONResponse($params); } @@ -61,7 +61,7 @@ class UserSettingsController extends Controller { public function show(){ $this->api->setUserValue('showAll', true); - return $this->renderJSON(); + return new JSONResponse(); } @@ -73,7 +73,7 @@ class UserSettingsController extends Controller { public function hide(){ $this->api->setUserValue('showAll', false); - return $this->renderJSON(); + return new JSONResponse(); } @@ -88,7 +88,7 @@ class UserSettingsController extends Controller { $params = array( 'language' => $language ); - return $this->renderJSON($params); + return new JSONResponse($params); } @@ -102,7 +102,7 @@ class UserSettingsController extends Controller { $params = array( 'compact' => $compact === '1' ); - return $this->renderJSON($params); + return new JSONResponse($params); } @@ -115,7 +115,7 @@ class UserSettingsController extends Controller { $isCompact = $this->params('compact'); $this->api->setUserValue('compact', $isCompact); - return $this->renderJSON(); + return new JSONResponse(); } diff --git a/js/app/services/persistence.coffee b/js/app/services/persistence.coffee index a79dc1224..7aee915a2 100644 --- a/js/app/services/persistence.coffee +++ b/js/app/services/persistence.coffee @@ -82,7 +82,7 @@ $rootScope, $q) -> # back up last change value in closure so we can compare it properly do (lastChange, offset, loading, onSuccess) => successCallbackWrapper = (data) => - if data.data.items.length == 0 && + if data.items.length == 0 && lastChange == @_lastFeedChange && offset != 0 @_preventUselessAutoPageRequest = true diff --git a/js/public/app.js b/js/public/app.js index 5982ab587..1b393b81f 100644 --- a/js/public/app.js +++ b/js/public/app.js @@ -2842,7 +2842,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. lastChange = this._lastFeedChange; (function(lastChange, offset, loading, onSuccess) { return successCallbackWrapper = function(data) { - if (data.data.items.length === 0 && lastChange === _this._lastFeedChange && offset !== 0) { + if (data.items.length === 0 && lastChange === _this._lastFeedChange && offset !== 0) { _this._preventUselessAutoPageRequest = true; } onSuccess(data); diff --git a/js/tests/services/persistenceSpec.coffee b/js/tests/services/persistenceSpec.coffee index fd84a1757..707c1e2fa 100644 --- a/js/tests/services/persistenceSpec.coffee +++ b/js/tests/services/persistenceSpec.coffee @@ -76,8 +76,7 @@ describe 'Persistence', -> it 'should reset the autopage lock when loading a new feed', => data = - data: - items: [] + items: [] called = 0 @req.get.andCallFake (route, params) -> params.onSuccess(data) diff --git a/tests/unit/controller/FeedControllerTest.php b/tests/unit/controller/FeedControllerTest.php index 296f87b22..aa6756e99 100644 --- a/tests/unit/controller/FeedControllerTest.php +++ b/tests/unit/controller/FeedControllerTest.php @@ -27,6 +27,7 @@ namespace OCA\News\Controller; use \OCA\AppFramework\Http\Request; use \OCA\AppFramework\Http\JSONResponse; +use \OCA\AppFramework\Http\Http; use \OCA\AppFramework\Utility\ControllerTestUtility; use \OCA\AppFramework\Db\DoesNotExistException; use \OCA\AppFramework\Db\MultipleObjectsReturnedException; @@ -34,7 +35,7 @@ use \OCA\AppFramework\Db\MultipleObjectsReturnedException; use \OCA\News\Db\Feed; use \OCA\News\Db\FeedType; use \OCA\News\BusinessLayer\BusinessLayerException; - +use \OCA\News\BusinessLayer\BusinessLayerConflictException; require_once(__DIR__ . "/../../classloader.php"); @@ -159,7 +160,7 @@ class FeedControllerTest extends ControllerTestUtility { $response = $this->controller->feeds(); - $this->assertEquals($result, $response->getParams()); + $this->assertEquals($result, $response->getData()); $this->assertTrue($response instanceof JSONResponse); } @@ -190,7 +191,7 @@ class FeedControllerTest extends ControllerTestUtility { $response = $this->controller->feeds(); - $this->assertEquals($result, $response->getParams()); + $this->assertEquals($result, $response->getData()); $this->assertTrue($response instanceof JSONResponse); } @@ -225,7 +226,7 @@ class FeedControllerTest extends ControllerTestUtility { $response = $this->controller->active(); - $this->assertEquals($result, $response->getParams()); + $this->assertEquals($result, $response->getData()); $this->assertTrue($response instanceof JSONResponse); } @@ -249,7 +250,7 @@ class FeedControllerTest extends ControllerTestUtility { $response = $this->controller->active(); - $this->assertEquals($result, $response->getParams()); + $this->assertEquals($result, $response->getData()); $this->assertTrue($response instanceof JSONResponse); } @@ -273,7 +274,7 @@ class FeedControllerTest extends ControllerTestUtility { $response = $this->controller->active(); - $this->assertEquals($result, $response->getParams()); + $this->assertEquals($result, $response->getData()); $this->assertTrue($response instanceof JSONResponse); } @@ -292,7 +293,7 @@ class FeedControllerTest extends ControllerTestUtility { $response = $this->controller->active(); - $this->assertEquals($result, $response->getParams()); + $this->assertEquals($result, $response->getData()); $this->assertTrue($response instanceof JSONResponse); } @@ -328,7 +329,7 @@ class FeedControllerTest extends ControllerTestUtility { $response = $this->controller->create(); - $this->assertEquals($result, $response->getParams()); + $this->assertEquals($result, $response->getData()); $this->assertTrue($response instanceof JSONResponse); } @@ -364,7 +365,7 @@ class FeedControllerTest extends ControllerTestUtility { $response = $this->controller->create(); - $this->assertEquals($result, $response->getParams()); + $this->assertEquals($result, $response->getData()); $this->assertTrue($response instanceof JSONResponse); } @@ -385,9 +386,31 @@ class FeedControllerTest extends ControllerTestUtility { $response = $this->controller->create(); $params = json_decode($response->render(), true); - $this->assertEquals('error', $params['status']); $this->assertEquals($msg, $params['msg']); $this->assertTrue($response instanceof JSONResponse); + $this->assertEquals($response->getStatus(), Http::STATUS_UNPROCESSABLE_ENTITY); + } + + + public function testCreateReturnsErrorForDuplicateCreate(){ + $msg = 'except'; + $ex = new BusinessLayerConflictException($msg); + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); + $this->feedBusinessLayer->expects($this->once()) + ->method('purgeDeleted') + ->with($this->equalTo($this->user), $this->equalTo(false)); + $this->feedBusinessLayer->expects($this->once()) + ->method('create') + ->will($this->throwException($ex)); + + $response = $this->controller->create(); + $params = json_decode($response->render(), true); + + $this->assertEquals($msg, $params['msg']); + $this->assertTrue($response instanceof JSONResponse); + $this->assertEquals($response->getStatus(), Http::STATUS_CONFLICT); } @@ -426,9 +449,9 @@ class FeedControllerTest extends ControllerTestUtility { $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); + $this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND); } @@ -460,7 +483,7 @@ class FeedControllerTest extends ControllerTestUtility { $response = $this->controller->update(); - $this->assertEquals($result, $response->getParams()); + $this->assertEquals($result, $response->getData()); $this->assertTrue($response instanceof JSONResponse); } @@ -488,8 +511,9 @@ class FeedControllerTest extends ControllerTestUtility { $response = $this->controller->update(); $render = $response->render(); - $this->assertEquals('{"data":[],"status":"error","msg":"NO!"}', $render); + $this->assertEquals('{"msg":"NO!"}', $render); $this->assertTrue($response instanceof JSONResponse); + $this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND); } @@ -537,9 +561,9 @@ class FeedControllerTest extends ControllerTestUtility { $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); + $this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND); } @@ -567,6 +591,37 @@ class FeedControllerTest extends ControllerTestUtility { } + public function testRenameDoesNotExist(){ + $post = array( + 'feedTitle' => "New Feed Title" + ); + $url = array( + 'feedId' => 4 + ); + $this->controller = $this->getPostController($post, $url); + + $msg = 'hi'; + + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); + $this->feedBusinessLayer->expects($this->once()) + ->method('rename') + ->with($this->equalTo($url['feedId']), + $this->equalTo($post['feedTitle']), + $this->equalTo($this->user)) + ->will($this->throwException(new BusinessLayerException($msg))); + + $response = $this->controller->rename(); + + $params = $response->getData(); + + $this->assertEquals($msg, $params['msg']); + $this->assertTrue($response instanceof JSONResponse); + $this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND); + } + + public function testImportArticles() { $feed = new Feed(); @@ -589,7 +644,7 @@ class FeedControllerTest extends ControllerTestUtility { $response = $this->controller->importArticles(); - $this->assertEquals($expected, $response->getParams()); + $this->assertEquals($expected, $response->getData()); $this->assertTrue($response instanceof JSONResponse); } @@ -614,7 +669,7 @@ class FeedControllerTest extends ControllerTestUtility { $response = $this->controller->importArticles(); - $this->assertEquals($expected, $response->getParams()); + $this->assertEquals($expected, $response->getData()); $this->assertTrue($response instanceof JSONResponse); } @@ -645,7 +700,7 @@ class FeedControllerTest extends ControllerTestUtility { $response = $this->controller->read(); $this->assertTrue($response instanceof JSONResponse); - $this->assertEquals($expected, $response->getParams()); + $this->assertEquals($expected, $response->getData()); } @@ -684,9 +739,9 @@ class FeedControllerTest extends ControllerTestUtility { $response = $this->controller->restore(); $params = json_decode($response->render(), true); - $this->assertEquals('error', $params['status']); $this->assertEquals($msg, $params['msg']); $this->assertTrue($response instanceof JSONResponse); + $this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND); } } 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); |