summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bl/folderbl.php2
-rw-r--r--controller/feedcontroller.php4
-rw-r--r--controller/foldercontroller.php43
-rw-r--r--tests/controller/FolderControllerTest.php120
4 files changed, 120 insertions, 49 deletions
diff --git a/bl/folderbl.php b/bl/folderbl.php
index 74de71be9..8a75d5de7 100644
--- a/bl/folderbl.php
+++ b/bl/folderbl.php
@@ -42,6 +42,7 @@ class FolderBl extends Bl {
public function create($name, $parentId) {
+ // TODO: throw error when already existing
$folder = new Folder();
$folder->setName($name);
$folder->setParentId($parentId);
@@ -57,6 +58,7 @@ class FolderBl extends Bl {
public function rename($folderId, $folderName, $userId){
+ // TODO: throw error when already existing
$folder = $this->find($folderId, $userId);
$folder->setName($folderName);
$this->mapper->update($folder);
diff --git a/controller/feedcontroller.php b/controller/feedcontroller.php
index 4f7233b9f..62af79197 100644
--- a/controller/feedcontroller.php
+++ b/controller/feedcontroller.php
@@ -117,7 +117,7 @@ class FeedController extends Controller {
$this->feedBl->delete($feedId, $userId);
- return $this->renderJSON(array());
+ return $this->renderJSON();
}
@@ -152,7 +152,7 @@ class FeedController extends Controller {
$this->feedBl->move($feedId, $parentFolderId, $userId);
- return $this->renderJSON(array());
+ return $this->renderJSON();
}
diff --git a/controller/foldercontroller.php b/controller/foldercontroller.php
index 74c872269..ec188a276 100644
--- a/controller/foldercontroller.php
+++ b/controller/foldercontroller.php
@@ -30,6 +30,7 @@ use \OCA\AppFramework\Core\API;
use \OCA\AppFramework\Http\Request;
use \OCA\News\Bl\FolderBl;
+use \OCA\News\Bl\BLException;
class FolderController extends Controller {
@@ -70,7 +71,7 @@ class FolderController extends Controller {
*/
public function open(){
$this->setOpened(true);
- return $this->renderJSON(array());
+ return $this->renderJSON();
}
@@ -81,7 +82,7 @@ class FolderController extends Controller {
*/
public function collapse(){
$this->setOpened(false);
- return $this->renderJSON(array());
+ return $this->renderJSON();
}
@@ -91,6 +92,22 @@ class FolderController extends Controller {
* @Ajax
*/
public function create(){
+ $userId = $this->api->getUserId();
+ $folderName = $this->params('folderName');
+
+ try {
+ $folder = $this->folderBl->create($folderName, $userId);
+
+ $params = array(
+ 'folders' => array($folder)
+ );
+ return $this->renderJSON($params);
+
+ } catch (BLException $ex){
+
+ return $this->renderJSON(array(), $ex->getMessage());
+ }
+
}
@@ -100,6 +117,12 @@ class FolderController extends Controller {
* @Ajax
*/
public function delete(){
+ $userId = $this->api->getUserId();
+ $folderId = $this->params('folderId');
+
+ $this->folderBl->delete($folderId, $userId);
+
+ return $this->renderJSON();
}
@@ -109,6 +132,22 @@ class FolderController extends Controller {
* @Ajax
*/
public function rename(){
+ $userId = $this->api->getUserId();
+ $folderName = $this->params('folderName');
+ $folderId = $this->params('folderId');
+
+ try {
+ $folder = $this->folderBl->rename($folderId, $folderName, $userId);
+
+ $params = array(
+ 'folders' => array($folder)
+ );
+ return $this->renderJSON($params);
+
+ } catch (BLException $ex){
+
+ return $this->renderJSON(array(), $ex->getMessage());
+ }
}
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