From b6adabf245fb2e32763dda43a54270eef11d3411 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Thu, 21 Mar 2013 23:07:03 +0100 Subject: finished foldercontroller --- tests/controller/FolderControllerTest.php | 120 +++++++++++++++++++----------- 1 file changed, 75 insertions(+), 45 deletions(-) (limited to 'tests') diff --git a/tests/controller/FolderControllerTest.php b/tests/controller/FolderControllerTest.php index b3cdd3947..f06d985f7 100644 --- a/tests/controller/FolderControllerTest.php +++ b/tests/controller/FolderControllerTest.php @@ -32,7 +32,7 @@ use \OCA\AppFramework\Db\DoesNotExistException; use \OCA\AppFramework\Db\MultipleObjectsReturnedException; use \OCA\News\Db\Folder; - +use \OCA\News\Bl\BLException; require_once(__DIR__ . "/../classloader.php"); @@ -161,70 +161,100 @@ class FolderControllerTest extends ControllerTestUtility { } - /** - * collapse - *//* - - + public function testCreate(){ + $post = array('folderName' => 'tech'); + $this->controller = $this->getPostController($post); + $result = array( + 'folders' => array(new Folder()) + ); - public function testCollapseReturnsNoParams(){ - $urlParams = array('folderId' => 1); + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); $this->bl->expects($this->once()) - ->method('setCollapsed') - ->with($this->equalTo($urlParams['folderId']), $this->equalTo(true)); - $this->controller->setURLParams($urlParams); + ->method('create') + ->with($this->equalTo($post['folderName']), + $this->equalTo($this->user)) + ->will($this->returnValue($result['folders'][0])); + + $response = $this->controller->create(); - $response = $this->controller->collapse(); - $this->assertEquals(array(), $response->getParams()); + $this->assertEquals($result, $response->getParams()); + $this->assertTrue($response instanceof JSONResponse); } - public function testCollapseAnnotations(){ - $methodName = 'collapse'; - $annotations = array('IsAdminExemption', 'IsSubAdminExemption', 'Ajax'); + public function testCreateReturnsErrorForInvalidCreate(){ + $msg = 'except'; + $ex = new BLException($msg); + $this->bl->expects($this->once()) + ->method('create') + ->will($this->throwException($ex)); - $this->assertAnnotations($this->controller, $methodName, $annotations); + $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); } - public function testCollapseReturnsJSON(){ - $urlParams = array('folderId' => 1); - $this->bl->expects($this->once()) - ->method('setCollapsed') - ->with($this->equalTo($urlParams['folderId']), $this->equalTo(true)); - $this->controller->setURLParams($urlParams); + public function testDelete(){ + $url = array('folderId' => 5); + $this->controller = $this->getPostController(array(), $url); - $response = $this->controller->collapse(); + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); + $this->bl->expects($this->once()) + ->method('delete') + ->with($this->equalTo($url['folderId']), + $this->equalTo($this->user)); + + $response = $this->controller->delete(); - $this->assertTrue($response instanceof JSONResponse); + $this->assertTrue($response instanceof JSONResponse); } - private function collapseException($ex){ - $urlParams = array('folderId' => 1); - $this->bl->expects($this->once()) - ->method('setCollapsed') - ->with($this->equalTo($urlParams['folderId']), $this->equalTo(true)) - ->will($this->throwException($ex)); - $this->controller->setURLParams($urlParams); + public function testRename(){ + $post = array('folderName' => 'tech'); + $url = array('folderId' => 4); + $this->controller = $this->getPostController($post, $url); + $result = array( + 'folders' => array(new Folder()) + ); - $response = $this->controller->collapse(); + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); + $this->bl->expects($this->once()) + ->method('rename') + ->with($this->equalTo($url['folderId']), + $this->equalTo($post['folderName']), + $this->equalTo($this->user)) + ->will($this->returnValue($result['folders'][0])); + + $response = $this->controller->rename(); - $expected = '{"status":"error","data":[],"msg":"' . $ex->getMessage() . '"}'; - $this->assertEquals($expected, $response->render()); + $this->assertEquals($result, $response->getParams()); + $this->assertTrue($response instanceof JSONResponse); } - - public function testCollapseDoesNotExistExceptionReturnsJSONError(){ - $ex = new DoesNotExistException('exception'); - $this->collapseException($ex); - } + public function testRenameReturnsErrorForInvalidCreate(){ + $msg = 'except'; + $ex = new BLException($msg); + $this->bl->expects($this->once()) + ->method('rename') + ->will($this->throwException($ex)); - public function testCollapseMultipleObjectsReturnedReturnsJSONError(){ - $ex = new MultipleObjectsReturnedException('exception'); - $this->collapseException($ex); - } -urlParams has been removed, please refactor*/ + $response = $this->controller->rename(); + $params = json_decode($response->render(), true); + $this->assertEquals('error', $params['status']); + $this->assertEquals($msg, $params['msg']); + $this->assertTrue($response instanceof JSONResponse); + } } \ No newline at end of file -- cgit v1.2.3