Example #1
0
 /**
  * @param struct $args
  * @param string $args["devKey"]
  * @param string $args["action"]: assignOne, unassignOne, unassignAll
  * 
  * @param int $args["testplanid"]
  * @param string $args["testcaseexternalid"] format PREFIX-NUMBER
  * @param int $args["buildid"] Mandatory => you can provide buildname as alternative
  * @param int $args["buildname"] Mandatory => you can provide buildid (DB ID) as alternative
  * @param int $args["platformid"] optional - BECOMES MANDATORY if Test plan has platforms
  *                                           you can provide platformname as alternative  
  *  
  * @param int $args["platformname"] optional - BECOMES MANDATORY if Test plan has platforms
  *                                           you can provide platformid as alternative  
  * @param string $args["user'] - login name => tester
  *
  */
 private function manageTestCaseExecutionTask($args, $msg_prefix)
 {
     $status_ok = true;
     $this->_setArgs($args);
     $resultInfo = array();
     // Checks are done in order
     $checkFunctions = array('authenticate', 'checkTestPlanID', 'checkTestCaseIdentity', 'checkBuildID');
     $status_ok = $this->_runChecks($checkFunctions, $msg_prefix);
     if ($status_ok) {
         switch ($args['action']) {
             case 'assignOne':
             case 'unassignOne':
                 if ($status_ok = $this->_isParamPresent(self::$userParamName, $msg_prefix, self::SET_ERROR)) {
                     $tester_id = tlUser::doesUserExist($this->dbObj, $this->args[self::$userParamName]);
                     if (!($status_ok = !is_null($tester_id))) {
                         $msg = $msg_prefix . sprintf(NO_USER_BY_THIS_LOGIN_STR, $this->args[self::$userParamName]);
                         $this->errors[] = new IXR_Error(NO_USER_BY_THIS_LOGIN, $msg);
                     }
                 }
                 break;
             case 'unassignAll':
                 break;
         }
     }
     // Check if requested test case is linked to test plan
     // if answer is yes, get link info, in order to be able to check if
     // we need also platform info
     if ($status_ok) {
         $execContext = array('tplan_id' => $this->args[self::$testPlanIDParamName], 'platform_id' => null, 'build_id' => $this->args[self::$buildIDParamName]);
         $tplan_id = $this->args[self::$testPlanIDParamName];
         $tcase_id = $this->args[self::$testCaseIDParamName];
         $filters = array('exec_status' => "ALL", 'active_status' => "ALL", 'tplan_id' => $tplan_id, 'platform_id' => null);
         $info = $this->tcaseMgr->get_linked_versions($tcase_id, $filters, array('output' => "feature_id"));
         // more than 1 item => we have platforms
         // access key => tcversion_id, tplan_id, platform_id
         $link = current($info);
         $link = $link[$tplan_id];
         // Inside test plan, is indexed by platform
         $hits = count($link);
         $platform_id = 0;
         $check_platform = count($hits) > 1 || !isset($link[0]);
     }
     if ($status_ok && $check_platform) {
         // this means that platform is MANDATORY
         if (!$this->_isParamPresent(self::$platformIDParamName, $msg_prefix) && !$this->_isParamPresent(self::$platformNameParamName, $msg_prefix)) {
             $status_ok = false;
             $pname = self::$platformNameParamName . ' OR ' . self::$platformIDParamName;
             $msg = $messagePrefix . sprintf(MISSING_REQUIRED_PARAMETER_STR, $pname);
             $this->errors[] = new IXR_Error(MISSING_REQUIRED_PARAMETER, $msg);
         } else {
             // get platform_id and check it
             if ($status_ok = $this->checkPlatformIdentity($tplan_id)) {
                 $platform_set = $this->tplanMgr->getPlatforms($tplan_id, array('outputFormat' => 'mapAccessByID', 'outputDetails' => 'name'));
                 // Now check if link has all 3 components
                 // test plan, test case, platform
                 $platform_id = $this->args[self::$platformIDParamName];
                 $platform_info = array($platform_id => $platform_set[$platform_id]);
                 if ($status_ok = $this->_checkTCIDAndTPIDValid($platform_info, $msg_prefix)) {
                     $execContext['platform_id'] = $platform_id;
                 }
             }
         }
     }
     if ($status_ok) {
         $assignment_mgr = new assignment_mgr($this->dbObj);
         $types = $assignment_mgr->get_available_types();
         // Remove old execution task assignment
         // `id` int(10) unsigned NOT NULL auto_increment,
         // `type` int(10) unsigned NOT NULL default '1',
         // `feature_id` int(10) unsigned NOT NULL default '0',
         // `user_id` int(10) unsigned default '0',
         // `build_id` int(10) unsigned default '0',
         // `deadline_ts` datetime NULL,
         // `assigner_id`  int(10) unsigned default '0',
         // `creation_ts` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
         // `status` int(10) unsigned default '1',
         // ATTENTION WITH PLATFORMS
         $link = is_null($execContext['platform_id']) ? $link[0] : $link[$execContext['platform_id']];
         $feature = array($link['feature_id'] => array('build_id' => $execContext['build_id']));
         switch ($args['action']) {
             case 'unassignOne':
                 $signature[] = array('type' => $types['testcase_execution']['id'], 'user_id' => $tester_id, 'feature_id' => $link['feature_id'], 'build_id' => $execContext['build_id']);
                 $assignment_mgr->deleteBySignature($signature);
                 break;
             case 'assignOne':
                 // Step 1 - remove if exists
                 $signature[] = array('type' => $types['testcase_execution']['id'], 'user_id' => $tester_id, 'feature_id' => $link['feature_id'], 'build_id' => $execContext['build_id']);
                 $assignment_mgr->deleteBySignature($signature);
                 // Step 2 - Now assign
                 $assign_status = $assignment_mgr->get_available_status();
                 $oo[$link['feature_id']]['type'] = $types['testcase_execution']['id'];
                 $oo[$link['feature_id']]['status'] = $assign_status['open']['id'];
                 $oo[$link['feature_id']]['user_id'] = $tester_id;
                 $oo[$link['feature_id']]['assigner_id'] = $this->userID;
                 $oo[$link['feature_id']]['build_id'] = $execContext['build_id'];
                 $assignment_mgr->assign($oo);
                 break;
             case 'unassignAll':
                 $oo[$link['feature_id']]['type'] = $types['testcase_execution']['id'];
                 $oo[$link['feature_id']]['build_id'] = $execContext['build_id'];
                 $assignment_mgr->delete_by_feature_id_and_build_id($oo);
                 break;
         }
         $resultInfo = array("status" => true, "args" => $this->args);
         unset($resultInfo['args']['devKey']);
     }
     return $status_ok ? $resultInfo : $this->errors;
 }
             foreach ($platform_tcversion as $platform_id => $tcversion_id) {
                 $feature_id = $args->feature_id[$key_tc][$platform_id];
                 $op = 'ins';
                 $features2[$op][$feature_id]['user_id'] = $args->tester_for_tcid[$key_tc][$platform_id];
                 $features2[$op][$feature_id]['type'] = $task_test_execution;
                 $features2[$op][$feature_id]['status'] = $open;
                 $features2[$op][$feature_id]['creation_ts'] = $db_now;
                 $features2[$op][$feature_id]['assigner_id'] = $args->user_id;
                 $features2[$op][$feature_id]['tcase_id'] = $key_tc;
                 $features2[$op][$feature_id]['tcversion_id'] = $tcversion_id;
                 $features2[$op][$feature_id]['build_id'] = $args->build_id;
             }
         }
         foreach ($features2 as $key => $values) {
             if (count($features2[$key]) > 0) {
                 $assignment_mgr->assign($values);
                 $called[$key] = true;
             }
         }
         if ($args->send_mail) {
             foreach ($called as $ope => $ope_status) {
                 if ($ope_status) {
                     send_mail_to_testers($db, $tcase_mgr, $gui, $args, $features2[$ope], $ope);
                 }
             }
         }
         // if($args->send_mail)
     }
     break;
 case 'doBulkRemove':
     if (!is_null($args->achecked_tc)) {
     $lexid = 0;
     if ($args->copyIssues && $args->level == 'testcase') {
         $lexid = $tcase_mgr->getSystemWideLastestExecutionID($args->version_id);
     }
     $_REQUEST['save_results'] = $args->save_results;
     list($execSet, $gui->addIssueOp) = write_execution($db, $args, $_REQUEST, $its);
     if ($args->assignTask) {
         $fid = $tplan_mgr->getFeatureID($args->tplan_id, $args->platform_id, $args->version_id);
         $taskMgr = new assignment_mgr($db);
         $taskDomain = $taskMgr->get_available_types();
         $taskStatusDomain = $taskMgr->get_available_status();
         $fmap[$fid]['user_id'] = $fmap[$fid]['assigner_id'] = $args->user_id;
         $fmap[$fid]['build_id'] = $args->build_id;
         $fmap[$fid]['type'] = $taskDomain['testcase_execution']['id'];
         $fmap[$fid]['status'] = $taskStatusDomain['open']['id'];
         $taskMgr->assign($fmap);
     }
     if ($lexid > 0 && $args->copyIssues && $args->level == 'testcase') {
         copyIssues($db, $lexid, $execSet[$args->version_id]);
     }
 }
 // Need to re-read to update test case status
 if ($args->save_and_next || $args->doMoveNext || $args->doMovePrevious) {
     $nextInChain = -1;
     if ($cfg->exec_cfg->exec_mode->save_and_move == 'unlimited') {
         if ($args->caller == 'tcAssignedToMe') {
             $optz = array('order_by' => 'ORDER BY TPTCV.node_order');
             $filters['build_id'] = $args->build_id;
             $xx = $tcase_mgr->get_assigned_to_user($args->user_id, $args->tproject_id, array($args->tplan_id), $optz, $filters);
             $xx = current($xx);
             // key test case id