summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-03-21 23:07:03 +0100
committerBernhard Posselt <nukeawhale@gmail.com>2013-03-21 23:07:03 +0100
commitb6adabf245fb2e32763dda43a54270eef11d3411 (patch)
tree1169c16521c05278789e22e70f88141f99d1e44d /tests
parent7ed948b19b3e705dba95bef7d4b2a8630f342e12 (diff)
finished foldercontroller
Diffstat (limited to 'tests')
-rw-r--r--tests/controller/FolderControllerTest.php120
1 files changed, 75 insertions, 45 deletions
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