Example #1
0
 /**
  * create a test suite
  * 
  * @param struct $args
  * @param string $args["devKey"]
  * @param int $args["testprojectid"]
  * @param string $args["testsuitename"]
  * @param string $args["details"]
  * @param int $args["parentid"] optional, if do not provided means test suite must be top level.
  * @param int $args["order"] optional. Order inside parent container
  * @param int $args["checkduplicatedname"] optional, default true.
  *                                          will check if there are siblings with same name.
  *
  * @param int $args["actiononduplicatedname"] optional
  *                                            applicable only if $args["checkduplicatedname"]=true
  *                                            what to do if already a sibling exists with same name.
  *   
  * @return mixed $resultInfo
  */
 public function createTestSuite($args)
 {
     $result = array();
     $this->_setArgs($args);
     $operation = __FUNCTION__;
     $msg_prefix = "({$operation}) - ";
     $checkFunctions = array('authenticate', 'checkTestSuiteName', 'checkTestProjectID');
     $status_ok = $this->_runChecks($checkFunctions, $msg_prefix) && $this->userHasRight("mgt_modify_tc", self::CHECK_PUBLIC_PRIVATE_ATTR);
     if ($status_ok) {
         // Optional parameters
         $opt = array(self::$orderParamName => testsuite::DEFAULT_ORDER, self::$checkDuplicatedNameParamName => testsuite::CHECK_DUPLICATE_NAME, self::$actionOnDuplicatedNameParamName => 'block');
         foreach ($opt as $key => $value) {
             if ($this->_isParamPresent($key)) {
                 $opt[$key] = $this->args[$key];
             }
         }
     }
     if ($status_ok) {
         $parent_id = $args[self::$testProjectIDParamName];
         $tprojectInfo = $this->tprojectMgr->get_by_id($args[self::$testProjectIDParamName]);
         $tsuiteMgr = new testsuite($this->dbObj);
         if ($this->_isParamPresent(self::$parentIDParamName)) {
             $parent_id = $args[self::$parentIDParamName];
             // if parentid exists it must:
             // be a test suite id
             $node_info = $tsuiteMgr->get_by_id($args[self::$parentIDParamName]);
             if (!($status_ok = !is_null($node_info))) {
                 $msg = sprintf(INVALID_PARENT_TESTSUITEID_STR, $args[self::$parentIDParamName], $args[self::$testSuiteNameParamName]);
                 $this->errors[] = new IXR_Error(INVALID_PARENT_TESTSUITEID, $msg_prefix . $msg);
             }
             if ($status_ok) {
                 // Must belong to target test project
                 $root_node_id = $tsuiteMgr->getTestProjectFromTestSuite($args[self::$parentIDParamName], null);
                 if (!($status_ok = $root_node_id == $args[self::$testProjectIDParamName])) {
                     $msg = sprintf(TESTSUITE_DONOTBELONGTO_TESTPROJECT_STR, $args[self::$parentIDParamName], $tprojectInfo['name'], $args[self::$testProjectIDParamName]);
                     $this->errors[] = new IXR_Error(TESTSUITE_DONOTBELONGTO_TESTPROJECT, $msg_prefix . $msg);
                 }
             }
         }
     }
     if ($status_ok) {
         $op = $tsuiteMgr->create($parent_id, $args[self::$testSuiteNameParamName], $args[self::$detailsParamName], $opt[self::$orderParamName], $opt[self::$checkDuplicatedNameParamName], $opt[self::$actionOnDuplicatedNameParamName]);
         if ($status_ok = $op['status_ok']) {
             $op['status'] = $op['status_ok'] ? true : false;
             $op['operation'] = $operation;
             $op['additionalInfo'] = '';
             $op['message'] = $op['msg'];
             unset($op['msg']);
             unset($op['status_ok']);
             $result[] = $op;
         } else {
             $op['msg'] = sprintf($op['msg'], $args[self::$testSuiteNameParamName]);
             $this->errors = $op;
         }
     }
     return $status_ok ? $result : $this->errors;
 }