summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-03-21 21:48:24 +0100
committerBernhard Posselt <nukeawhale@gmail.com>2013-03-21 21:48:24 +0100
commit7ed948b19b3e705dba95bef7d4b2a8630f342e12 (patch)
tree76ee3d02767c6bcac388d7d794d943f265d926f8
parenta10b775b95d6e7a25d3cf3bb5f8c633f7f1a63f5 (diff)
finished open and collapse in foldercontroller
-rw-r--r--bl/folderbl.php2
-rw-r--r--controller/foldercontroller.php11
-rw-r--r--tests/bl/FolderBlTest.php4
-rw-r--r--tests/controller/FolderControllerTest.php88
4 files changed, 69 insertions, 36 deletions
diff --git a/bl/folderbl.php b/bl/folderbl.php
index 9d3a7e98d..74de71be9 100644
--- a/bl/folderbl.php
+++ b/bl/folderbl.php
@@ -49,7 +49,7 @@ class FolderBl extends Bl {
}
- public function setOpened($folderId, $opened, $userId){
+ public function open($folderId, $opened, $userId){
$folder = $this->find($folderId, $userId);
$folder->setOpened($opened);
$this->mapper->update($folder);
diff --git a/controller/foldercontroller.php b/controller/foldercontroller.php
index 80451fb3e..74c872269 100644
--- a/controller/foldercontroller.php
+++ b/controller/foldercontroller.php
@@ -56,12 +56,21 @@ class FolderController extends Controller {
}
+ private function setOpened($isOpened){
+ $userId = $this->api->getUserId();
+ $folderId = $this->params('folderId');
+
+ $this->folderBl->open($folderId, $isOpened, $userId);
+ }
+
/**
* @IsAdminExemption
* @IsSubAdminExemption
* @Ajax
*/
public function open(){
+ $this->setOpened(true);
+ return $this->renderJSON(array());
}
@@ -71,6 +80,8 @@ class FolderController extends Controller {
* @Ajax
*/
public function collapse(){
+ $this->setOpened(false);
+ return $this->renderJSON(array());
}
diff --git a/tests/bl/FolderBlTest.php b/tests/bl/FolderBlTest.php
index de8ba9604..6b771e02b 100644
--- a/tests/bl/FolderBlTest.php
+++ b/tests/bl/FolderBlTest.php
@@ -77,7 +77,7 @@ class FolderBlTest extends \OCA\AppFramework\Utility\TestUtility {
}
- public function testSetOpened(){
+ public function testOpen(){
$folder = new Folder();
$this->folderMapper->expects($this->once())
@@ -89,7 +89,7 @@ class FolderBlTest extends \OCA\AppFramework\Utility\TestUtility {
->method('update')
->with($this->equalTo($folder));
- $this->folderBl->setOpened(3, false, '');
+ $this->folderBl->open(3, false, '');
$this->assertFalse($folder->getOpened());
diff --git a/tests/controller/FolderControllerTest.php b/tests/controller/FolderControllerTest.php
index 60c8590af..b3cdd3947 100644
--- a/tests/controller/FolderControllerTest.php
+++ b/tests/controller/FolderControllerTest.php
@@ -40,7 +40,7 @@ require_once(__DIR__ . "/../classloader.php");
class FolderControllerTest extends ControllerTestUtility {
private $api;
- private $folderBl;
+ private $bl;
private $request;
private $controller;
@@ -50,12 +50,13 @@ class FolderControllerTest extends ControllerTestUtility {
*/
public function setUp(){
$this->api = $this->getAPIMock();
- $this->folderBl = $this->getMockBuilder('\OCA\News\Bl\FolderBl')
+ $this->bl = $this->getMockBuilder('\OCA\News\Bl\FolderBl')
->disableOriginalConstructor()
->getMock();
$this->request = new Request();
$this->controller = new FolderController($this->api, $this->request,
- $this->folderBl);
+ $this->bl);
+ $this->user = 'jack';
}
@@ -65,6 +66,16 @@ class FolderControllerTest extends ControllerTestUtility {
}
+ private function getPostController($postValue, $url=array()){
+ $post = array(
+ 'post' => $postValue,
+ 'urlParams' => $url
+ );
+
+ $request = $this->getRequest($post);
+ return new FolderController($this->api, $request, $this->bl);
+ }
+
public function testFoldersAnnotations(){
$this->assertFolderControllerAnnotations('folders');
}
@@ -95,24 +106,13 @@ class FolderControllerTest extends ControllerTestUtility {
}
- /**
- * folders
- */
- public function testFoldersCalled(){
- $this->folderBl->expects($this->once())
- ->method('findAll')
- ->will($this->returnValue( array() ));
-
- $this->controller->folders();
- }
-
-
- public function testFoldersReturnsFolders(){
+
+ public function testFolders(){
$return = array(
new Folder(),
new Folder(),
);
- $this->folderBl->expects($this->once())
+ $this->bl->expects($this->once())
->method('findAll')
->will($this->returnValue($return));
@@ -121,33 +121,55 @@ class FolderControllerTest extends ControllerTestUtility {
'folders' => $return
);
$this->assertEquals($expected, $response->getParams());
+ $this->assertTrue($response instanceof JSONResponse);
}
-
- public function testFoldersReturnsJSON(){
- $response = $this->controller->folders();
- $this->assertTrue($response instanceof JSONResponse);
+ public function testOpen(){
+ $url = array('folderId' => 5);
+ $this->controller = $this->getPostController(array(), $url);
+
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
+ $this->bl->expects($this->once())
+ ->method('open')
+ ->with($this->equalTo($url['folderId']),
+ $this->equalTo(true), $this->equalTo($this->user));
+
+ $response = $this->controller->open();
+
+ $this->assertTrue($response instanceof JSONResponse);
+ }
+
+
+ public function testCollapse(){
+ $url = array('folderId' => 5);
+ $this->controller = $this->getPostController(array(), $url);
+
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
+ $this->bl->expects($this->once())
+ ->method('open')
+ ->with($this->equalTo($url['folderId']),
+ $this->equalTo(false), $this->equalTo($this->user));
+
+ $response = $this->controller->collapse();
+
+ $this->assertTrue($response instanceof JSONResponse);
}
/**
* collapse
*//*
- public function testCollapseCalled(){
- $urlParams = array('folderId' => 1);
- $this->folderBl->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->folderBl->expects($this->once())
+ $this->bl->expects($this->once())
->method('setCollapsed')
->with($this->equalTo($urlParams['folderId']), $this->equalTo(true));
$this->controller->setURLParams($urlParams);
@@ -167,7 +189,7 @@ class FolderControllerTest extends ControllerTestUtility {
public function testCollapseReturnsJSON(){
$urlParams = array('folderId' => 1);
- $this->folderBl->expects($this->once())
+ $this->bl->expects($this->once())
->method('setCollapsed')
->with($this->equalTo($urlParams['folderId']), $this->equalTo(true));
$this->controller->setURLParams($urlParams);
@@ -180,7 +202,7 @@ class FolderControllerTest extends ControllerTestUtility {
private function collapseException($ex){
$urlParams = array('folderId' => 1);
- $this->folderBl->expects($this->once())
+ $this->bl->expects($this->once())
->method('setCollapsed')
->with($this->equalTo($urlParams['folderId']), $this->equalTo(true))
->will($this->throwException($ex));