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 | |
parent | 3c4044970e38820d67560e219dd94dc9e96b0387 (diff) |
get rid of deprecated getParams and renderJSON method to ease transition to built in appframework
Diffstat (limited to 'tests')
-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 |
4 files changed, 154 insertions, 41 deletions
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); } 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); } diff --git a/tests/unit/controller/ItemControllerTest.php b/tests/unit/controller/ItemControllerTest.php index 9d104b8f0..a7db42d5c 100644 --- a/tests/unit/controller/ItemControllerTest.php +++ b/tests/unit/controller/ItemControllerTest.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\News\Db\Item; @@ -155,7 +156,7 @@ class ItemControllerTest extends ControllerTestUtility { $response = $this->controller->read(); $params = json_decode($response->render(), true); - $this->assertEquals('error', $params['status']); + $this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND); $this->assertEquals($msg, $params['msg']); $this->assertTrue($response instanceof JSONResponse); } @@ -197,7 +198,7 @@ class ItemControllerTest extends ControllerTestUtility { $response = $this->controller->unread(); $params = json_decode($response->render(), true); - $this->assertEquals('error', $params['status']); + $this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND); $this->assertEquals($msg, $params['msg']); $this->assertTrue($response instanceof JSONResponse); } @@ -244,7 +245,7 @@ class ItemControllerTest extends ControllerTestUtility { $response = $this->controller->star(); $params = json_decode($response->render(), true); - $this->assertEquals('error', $params['status']); + $this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND); $this->assertEquals($msg, $params['msg']); $this->assertTrue($response instanceof JSONResponse); } @@ -291,7 +292,7 @@ class ItemControllerTest extends ControllerTestUtility { $response = $this->controller->unstar(); $params = json_decode($response->render(), true); - $this->assertEquals('error', $params['status']); + $this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND); $this->assertEquals($msg, $params['msg']); $this->assertTrue($response instanceof JSONResponse); } @@ -321,7 +322,7 @@ class ItemControllerTest extends ControllerTestUtility { $response = $this->controller->readAll(); $this->assertTrue($response instanceof JSONResponse); - $this->assertEquals($expected, $response->getParams()); + $this->assertEquals($expected, $response->getData()); } @@ -389,7 +390,7 @@ class ItemControllerTest extends ControllerTestUtility { ->will($this->returnValue($result['items'])); $response = $this->controller->items(); - $this->assertEquals($result, $response->getParams()); + $this->assertEquals($result, $response->getData()); $this->assertTrue($response instanceof JSONResponse); } @@ -422,7 +423,7 @@ class ItemControllerTest extends ControllerTestUtility { ->method('findAll'); $response = $this->controller->items(); - $this->assertEquals($result, $response->getParams()); + $this->assertEquals($result, $response->getData()); $this->assertTrue($response instanceof JSONResponse); } @@ -446,7 +447,7 @@ class ItemControllerTest extends ControllerTestUtility { ->will($this->throwException(new BusinessLayerException(''))); $response = $this->controller->items(); - $this->assertEquals($result, $response->getParams()); + $this->assertEquals($result, $response->getData()); $this->assertTrue($response instanceof JSONResponse); } @@ -500,7 +501,7 @@ class ItemControllerTest extends ControllerTestUtility { ->will($this->returnValue($result['items'])); $response = $this->controller->newItems(); - $this->assertEquals($result, $response->getParams()); + $this->assertEquals($result, $response->getData()); $this->assertTrue($response instanceof JSONResponse); } @@ -528,7 +529,7 @@ class ItemControllerTest extends ControllerTestUtility { ->will($this->throwException(new BusinessLayerException(''))); $response = $this->controller->newItems(); - $this->assertEquals($result, $response->getParams()); + $this->assertEquals($result, $response->getData()); $this->assertTrue($response instanceof JSONResponse); } diff --git a/tests/unit/controller/UserSettingsControllerTest.php b/tests/unit/controller/UserSettingsControllerTest.php index cdbebcf1f..0f2be1bc0 100644 --- a/tests/unit/controller/UserSettingsControllerTest.php +++ b/tests/unit/controller/UserSettingsControllerTest.php @@ -117,7 +117,7 @@ class UserSettingsControllerTest extends ControllerTestUtility { ->will($this->returnValue('1')); $response = $this->controller->read(); - $this->assertEquals($result, $response->getParams()); + $this->assertEquals($result, $response->getData()); $this->assertTrue($response instanceof JSONResponse); } @@ -133,7 +133,7 @@ class UserSettingsControllerTest extends ControllerTestUtility { ->will($this->returnValue($lang)); $response = $this->controller->getLanguage(); - $params = $response->getParams(); + $params = $response->getData(); $this->assertEquals($language, $params['language']); $this->assertTrue($response instanceof JSONResponse); @@ -150,7 +150,7 @@ class UserSettingsControllerTest extends ControllerTestUtility { ->will($this->returnValue('1')); $response = $this->controller->isCompactView(); - $this->assertEquals($result, $response->getParams()); + $this->assertEquals($result, $response->getData()); $this->assertTrue($response instanceof JSONResponse); } |