summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-02-02 15:58:40 +0100
committerBernhard Posselt <nukeawhale@gmail.com>2013-02-02 15:58:40 +0100
commit7aaaa14b8328c9d6b29807d5591835413d40625c (patch)
treeecf338393710d2a3848197146b3a80e78a7ca9f6
parentf8311696720f805567bdf1e66c5cf7a8df359900 (diff)
added the collapse method for the foldercontroller + tests
-rw-r--r--controller/foldercontroller.php20
-rw-r--r--tests/controller/FolderControllerTest.php74
2 files changed, 91 insertions, 3 deletions
diff --git a/controller/foldercontroller.php b/controller/foldercontroller.php
index e0ae5f8fb..2e890cb5d 100644
--- a/controller/foldercontroller.php
+++ b/controller/foldercontroller.php
@@ -28,6 +28,7 @@ namespace OCA\News\Controller;
use \OCA\AppFramework\Controller\Controller;
use \OCA\AppFramework\Core\API;
use \OCA\AppFramework\Http\Request;
+use \OCA\AppFramework\Db\DoesNotExistException;
class FolderController extends Controller {
@@ -52,4 +53,23 @@ class FolderController extends Controller {
}
+ /**
+ * @IsAdminExemption
+ * @IsSubAdminExemption
+ * @Ajax
+ *
+ * Collapses a folder
+ */
+ public function collapse(){
+ $folderId = (int) $this->params('folderId');
+
+ try {
+ $this->folderMapper->setCollapsed($folderId, true);
+ return $this->renderJSON(array());
+ } catch (DoesNotExistException $e) {
+ return $this->renderJSON(array(), $e->getMessage());
+ }
+ }
+
+
} \ No newline at end of file
diff --git a/tests/controller/FolderControllerTest.php b/tests/controller/FolderControllerTest.php
index f1a853400..ac7ca30f0 100644
--- a/tests/controller/FolderControllerTest.php
+++ b/tests/controller/FolderControllerTest.php
@@ -28,6 +28,7 @@ namespace OCA\News\Controller;
use \OCA\AppFramework\Http\Request;
use \OCA\AppFramework\Http\JSONResponse;
use OCA\AppFramework\Utility\ControllerTestUtility;
+use \OCA\AppFramework\Db\DoesNotExistException;
require_once(__DIR__ . "/../classloader.php");
@@ -47,14 +48,16 @@ class FolderControllerTest extends ControllerTestUtility {
public function setUp(){
$this->api = $this->getAPIMock();
$this->folderMapper = $this->getMock('FolderMapper',
- array('getAll'));
+ array('getAll', 'setCollapsed'));
$this->request = new Request();
$this->controller = new FolderController($this->api, $this->request,
$this->folderMapper);
}
-
+ /**
+ * getAll
+ */
public function testGetAllCalled(){
$this->folderMapper->expects($this->once())
->method('getAll')
@@ -86,7 +89,7 @@ class FolderControllerTest extends ControllerTestUtility {
}
- public function testReturnsJSON(){
+ public function testGetAllReturnsJSON(){
$this->folderMapper->expects($this->once())
->method('getAll')
->will($this->returnValue( array() ));
@@ -96,4 +99,69 @@ class FolderControllerTest extends ControllerTestUtility {
$this->assertTrue($response instanceof JSONResponse);
}
+
+ /**
+ * collapse
+ */
+ public function testCollapseCalled(){
+ $urlParams = array('folderId' => 1);
+ $this->folderMapper->expects($this->once())
+ ->method('setCollapsed')
+ ->with($this->equalTo($urlParams['folderId']), $this->equalTo(true));
+ $this->controller->setURLParams($urlParams);
+
+ $this->controller->collapse();
+ }
+
+
+ public function testCollapseReturnsNoParams(){
+ $urlParams = array('folderId' => 1);
+ $this->folderMapper->expects($this->once())
+ ->method('setCollapsed')
+ ->with($this->equalTo($urlParams['folderId']), $this->equalTo(true));
+ $this->controller->setURLParams($urlParams);
+
+ $response = $this->controller->collapse();
+ $this->assertEquals(array(), $response->getParams());
+ }
+
+
+ public function testCollapseAnnotations(){
+ $methodName = 'collapse';
+ $annotations = array('IsAdminExemption', 'IsSubAdminExemption', 'Ajax');
+
+ $this->assertAnnotations($this->controller, $methodName, $annotations);
+ }
+
+
+ public function testCollapseReturnsJSON(){
+ $urlParams = array('folderId' => 1);
+ $this->folderMapper->expects($this->once())
+ ->method('setCollapsed')
+ ->with($this->equalTo($urlParams['folderId']), $this->equalTo(true));
+ $this->controller->setURLParams($urlParams);
+
+ $response = $this->controller->collapse();
+
+ $this->assertTrue($response instanceof JSONResponse);
+ }
+
+
+ public function testCollapseExceptionReturnsJSONError(){
+ $errorMsg = 'exception';
+ $ex = new DoesNotExistException($errorMsg);
+ $urlParams = array('folderId' => 1);
+ $this->folderMapper->expects($this->once())
+ ->method('setCollapsed')
+ ->with($this->equalTo($urlParams['folderId']), $this->equalTo(true))
+ ->will($this->throwException($ex));
+ $this->controller->setURLParams($urlParams);
+
+ $response = $this->controller->collapse();
+
+ $expected = '{"status":"error","data":[],"msg":"' . $errorMsg . '"}';
+ $this->assertEquals($expected, $response->render());
+ }
+
+
} \ No newline at end of file