From f0a78013980a10614c2d4623348154414d28121f Mon Sep 17 00:00:00 2001 From: Zach Mullen Date: Thu, 17 Nov 2011 12:08:59 -0500 Subject: [PATCH] BUG: refs #0358. Fix folder.create api method and add a test for it --- .../controllers/components/ApiComponent.php | 4 ++-- .../tests/controllers/ApiCallMethodsTest.php | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/modules/api/controllers/components/ApiComponent.php b/modules/api/controllers/components/ApiComponent.php index b927047b5..4aeefb2b0 100644 --- a/modules/api/controllers/components/ApiComponent.php +++ b/modules/api/controllers/components/ApiComponent.php @@ -673,7 +673,7 @@ function folderCreate($args) $modelLoader = new MIDAS_ModelLoader(); $folderModel = $modelLoader->loadModel('Folder'); $name = $args['name']; - $description = $args['description']; + $description = isset($args['description']) ? $args['description'] : ''; $uuid = isset($args['uuid']) ? $args['uuid'] : ''; $record = false; @@ -720,7 +720,7 @@ function folderCreate($args) $policyGroup = $folder->getFolderpolicygroup(); $policyUser = $folder->getFolderpolicyuser(); $folderpolicygroupModel = $modelLoader->loadModel('Folderpolicygroup'); - $folderpolicyuserModel = $modelLoader->loadModel('Folderpolicygroup'); + $folderpolicyuserModel = $modelLoader->loadModel('Folderpolicyuser'); foreach($policyGroup as $policy) { $folderpolicygroupModel->createPolicy($policy->getGroup(), $new_folder, $policy->getPolicy()); diff --git a/modules/api/tests/controllers/ApiCallMethodsTest.php b/modules/api/tests/controllers/ApiCallMethodsTest.php index 40f413c2c..f39979462 100644 --- a/modules/api/tests/controllers/ApiCallMethodsTest.php +++ b/modules/api/tests/controllers/ApiCallMethodsTest.php @@ -174,6 +174,27 @@ public function testCommunityList() //TODO test that a private community is not returned (requires another community in the data set) } + /** Test creating a folder */ + public function testFolderCreate() + { + $usersFile = $this->loadData('User', 'default'); + $userDao = $this->User->load($usersFile[0]->getKey()); + + $this->resetAll(); + $this->params['token'] = $this->_loginAsAdministrator(); + $this->params['method'] = 'midas.folder.create'; + $this->params['name'] = 'testFolderCreate'; + $this->params['parentid'] = $userDao->getPublicfolderId(); + $resp = $this->_callJsonApi(); + $this->_assertStatusOk($resp); + + // Make sure folder was created correctly + $this->assertNotEmpty($resp->data->uuid); + $this->assertEquals($userDao->getPublicfolderId(), $resp->data->parent_id); + $this->assertEquals('testFolderCreate', $resp->data->name); + $this->assertEquals('', $resp->data->description); + } + /** Test listing of child folders */ public function testFolderChildren() {