diff options
Diffstat (limited to 'tests/unit/controller/FolderControllerTest.php')
-rw-r--r-- | tests/unit/controller/FolderControllerTest.php | 179 |
1 files changed, 43 insertions, 136 deletions
diff --git a/tests/unit/controller/FolderControllerTest.php b/tests/unit/controller/FolderControllerTest.php index 44dc6e14c..332b48bbe 100644 --- a/tests/unit/controller/FolderControllerTest.php +++ b/tests/unit/controller/FolderControllerTest.php @@ -13,10 +13,8 @@ namespace OCA\News\Controller; -use \OCP\IRequest; use \OCP\AppFramework\Http; -use \OCA\News\Utility\ControllerTestUtility; use \OCA\News\Db\Folder; use \OCA\News\Db\Feed; use \OCA\News\BusinessLayer\BusinessLayerException; @@ -26,7 +24,7 @@ use \OCA\News\BusinessLayer\BusinessLayerValidationException; require_once(__DIR__ . "/../../classloader.php"); -class FolderControllerTest extends ControllerTestUtility { +class FolderControllerTest extends \PHPUnit_Framework_TestCase { private $appName; private $folderBusinessLayer; @@ -52,7 +50,10 @@ class FolderControllerTest extends ControllerTestUtility { $this->itemBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\ItemBusinessLayer') ->disableOriginalConstructor() ->getMock(); - $this->request = $this->getRequest(); + $this->request = $this->getMockBuilder( + '\OCP\IRequest') + ->disableOriginalConstructor() + ->getMock(); $this->controller = new FolderController($this->appName, $this->request, $this->folderBusinessLayer, $this->feedBusinessLayer, @@ -62,64 +63,6 @@ class FolderControllerTest extends ControllerTestUtility { } - private function assertFolderControllerAnnotations($methodName){ - $annotations = array('NoAdminRequired'); - $this->assertAnnotations($this->controller, $methodName, $annotations); - } - - - private function getPostController($postValue, $url=array()){ - $post = array( - 'post' => $postValue, - 'urlParams' => $url - ); - - $request = $this->getRequest($post); - return new FolderController($this->appName, $request, - $this->folderBusinessLayer, - $this->feedBusinessLayer, - $this->itemBusinessLayer, - $this->user); - } - - public function testFoldersAnnotations(){ - $this->assertFolderControllerAnnotations('index'); - } - - - public function testOpenAnnotations(){ - $this->assertFolderControllerAnnotations('open'); - } - - - public function testCollapseAnnotations(){ - $this->assertFolderControllerAnnotations('collapse'); - } - - - public function testCreateAnnotations(){ - $this->assertFolderControllerAnnotations('create'); - } - - - public function testDeleteAnnotations(){ - $this->assertFolderControllerAnnotations('delete'); - } - - - public function testRestoreAnnotations(){ - $this->assertFolderControllerAnnotations('restore'); - } - - - public function testRenameAnnotations(){ - $this->assertFolderControllerAnnotations('rename'); - } - - - public function testReadAnnotations(){ - $this->assertFolderControllerAnnotations('read'); - } public function testIndex(){ $return = array( @@ -134,75 +77,61 @@ class FolderControllerTest extends ControllerTestUtility { $expected = array( 'folders' => $return ); - $this->assertEquals($expected, $response->getData()); + $this->assertEquals($expected, $response); } public function testOpen(){ - $url = array('folderId' => 5); - $this->controller = $this->getPostController(array(), $url); - $this->folderBusinessLayer->expects($this->once()) ->method('open') - ->with($this->equalTo($url['folderId']), + ->with($this->equalTo(3), $this->equalTo(true), $this->equalTo($this->user)); - $this->controller->open(); + $this->controller->open(3); } public function testOpenDoesNotExist(){ - $url = array('folderId' => 5); - $this->controller = $this->getPostController(array(), $url); - $this->folderBusinessLayer->expects($this->once()) ->method('open') ->will($this->throwException(new BusinessLayerException($this->msg))); - $response = $this->controller->open(); + $response = $this->controller->open(5); $params = json_decode($response->render(), true); - $this->assertEquals($this->msg, $params['msg']); + $this->assertEquals($this->msg, $params['message']); $this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND); } public function testCollapse(){ - $url = array('folderId' => 5); - $this->controller = $this->getPostController(array(), $url); - $this->folderBusinessLayer->expects($this->once()) ->method('open') - ->with($this->equalTo($url['folderId']), + ->with($this->equalTo(5), $this->equalTo(false), $this->equalTo($this->user)); - $this->controller->collapse(); + $this->controller->collapse(5); } public function testCollapseDoesNotExist(){ - $url = array('folderId' => 5); - $this->controller = $this->getPostController(array(), $url); - $this->folderBusinessLayer->expects($this->once()) ->method('open') ->will($this->throwException(new BusinessLayerException($this->msg))); - $response = $this->controller->collapse(); + $response = $this->controller->collapse(5); $params = json_decode($response->render(), true); - $this->assertEquals($this->msg, $params['msg']); + $this->assertEquals($this->msg, $params['message']); $this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND); } public function testCreate(){ - $post = array('folderName' => 'tech'); - $this->controller = $this->getPostController($post); $result = array( 'folders' => array(new Folder()) ); @@ -212,13 +141,13 @@ class FolderControllerTest extends ControllerTestUtility { ->with($this->equalTo($this->user), $this->equalTo(false)); $this->folderBusinessLayer->expects($this->once()) ->method('create') - ->with($this->equalTo($post['folderName']), + ->with($this->equalTo('tech'), $this->equalTo($this->user)) ->will($this->returnValue($result['folders'][0])); - $response = $this->controller->create(); + $response = $this->controller->create('tech'); - $this->assertEquals($result, $response->getData()); + $this->assertEquals($result, $response); } @@ -232,11 +161,11 @@ class FolderControllerTest extends ControllerTestUtility { ->method('create') ->will($this->throwException($ex)); - $response = $this->controller->create(); + $response = $this->controller->create('tech'); $params = json_decode($response->render(), true); $this->assertEquals($response->getStatus(), Http::STATUS_UNPROCESSABLE_ENTITY); - $this->assertEquals($msg, $params['msg']); + $this->assertEquals($msg, $params['message']); } @@ -250,62 +179,53 @@ class FolderControllerTest extends ControllerTestUtility { ->method('create') ->will($this->throwException($ex)); - $response = $this->controller->create(); + $response = $this->controller->create('tech'); $params = json_decode($response->render(), true); $this->assertEquals($response->getStatus(), Http::STATUS_CONFLICT); - $this->assertEquals($msg, $params['msg']); + $this->assertEquals($msg, $params['message']); } public function testDelete(){ - $url = array('folderId' => 5); - $this->controller = $this->getPostController(array(), $url); - $this->folderBusinessLayer->expects($this->once()) ->method('markDeleted') - ->with($this->equalTo($url['folderId']), + ->with($this->equalTo(5), $this->equalTo($this->user)); - $this->controller->delete(); + $this->controller->delete(5); } public function testDeleteDoesNotExist(){ - $url = array('folderId' => 5); - $this->controller = $this->getPostController(array(), $url); - $this->folderBusinessLayer->expects($this->once()) ->method('markDeleted') ->will($this->throwException(new BusinessLayerException($this->msg))); - $response = $this->controller->delete(); + $response = $this->controller->delete(5); $params = json_decode($response->render(), true); - $this->assertEquals($this->msg, $params['msg']); + $this->assertEquals($this->msg, $params['message']); $this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND); } public function testRename(){ - $post = array('folderName' => 'tech'); - $url = array('folderId' => 4); - $this->controller = $this->getPostController($post, $url); $result = array( 'folders' => array(new Folder()) ); $this->folderBusinessLayer->expects($this->once()) ->method('rename') - ->with($this->equalTo($url['folderId']), - $this->equalTo($post['folderName']), + ->with($this->equalTo(4), + $this->equalTo('tech'), $this->equalTo($this->user)) ->will($this->returnValue($result['folders'][0])); - $response = $this->controller->rename(); + $response = $this->controller->rename('tech', 4); - $this->assertEquals($result, $response->getData()); + $this->assertEquals($result, $response); } @@ -316,11 +236,11 @@ class FolderControllerTest extends ControllerTestUtility { ->method('rename') ->will($this->throwException($ex)); - $response = $this->controller->rename(); + $response = $this->controller->rename('tech', 4); $params = json_decode($response->render(), true); $this->assertEquals($response->getStatus(), Http::STATUS_UNPROCESSABLE_ENTITY); - $this->assertEquals($msg, $params['msg']); + $this->assertEquals($msg, $params['message']); } @@ -331,11 +251,11 @@ class FolderControllerTest extends ControllerTestUtility { ->method('rename') ->will($this->throwException($ex)); - $response = $this->controller->rename(); + $response = $this->controller->rename('tech', 5); $params = json_decode($response->render(), true); $this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND); - $this->assertEquals($msg, $params['msg']); + $this->assertEquals($msg, $params['message']); } @@ -346,70 +266,57 @@ class FolderControllerTest extends ControllerTestUtility { ->method('rename') ->will($this->throwException($ex)); - $response = $this->controller->rename(); + $response = $this->controller->rename('tech', 1); $params = json_decode($response->render(), true); $this->assertEquals($response->getStatus(), Http::STATUS_CONFLICT); - $this->assertEquals($msg, $params['msg']); + $this->assertEquals($msg, $params['message']); } public function testRead(){ $feed = new Feed(); - $url = array( - 'folderId' => 4 - ); - $post = array( - 'highestItemId' => 5 - ); - $this->controller = $this->getPostController($post, $url); $expected = array( 'feeds' => array($feed) ); $this->itemBusinessLayer->expects($this->once()) ->method('readFolder') - ->with($this->equalTo($url['folderId']), - $this->equalTo($post['highestItemId']), + ->with($this->equalTo(4), + $this->equalTo(5), $this->equalTo($this->user)); $this->feedBusinessLayer->expects($this->once()) ->method('findAll') ->with($this->equalTo($this->user)) ->will($this->returnValue(array($feed))); - $response = $this->controller->read(); - $this->assertEquals($expected, $response->getData()); + $response = $this->controller->read(4, 5); + $this->assertEquals($expected, $response); } public function testRestore(){ - $url = array('folderId' => 5); - $this->controller = $this->getPostController(array(), $url); - $this->folderBusinessLayer->expects($this->once()) ->method('unmarkDeleted') - ->with($this->equalTo($url['folderId']), + ->with($this->equalTo(5), $this->equalTo($this->user)); - $this->controller->restore(); + $this->controller->restore(5); } public function testRestoreDoesNotExist(){ - $url = array('folderId' => 5); - $this->controller = $this->getPostController(array(), $url); - $this->folderBusinessLayer->expects($this->once()) ->method('unmarkDeleted') ->will($this->throwException(new BusinessLayerException($this->msg))); - $response = $this->controller->restore(); + $response = $this->controller->restore(5); $params = json_decode($response->render(), true); $this->assertEquals($response->getStatus(), Http::STATUS_NOT_FOUND); - $this->assertEquals($this->msg, $params['msg']); + $this->assertEquals($this->msg, $params['message']); } }
\ No newline at end of file |