Example #1
0
 private function copy_linked_tcversions($id, $new_tplan_id, $user_id = -1, $options = null, $mappings = null, $build_id_mapping)
 {
     $debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;
     $my['options']['tcversion_type'] = null;
     $my['options']['copy_assigned_to'] = 0;
     $my['options'] = array_merge($my['options'], (array) $options);
     $now_ts = $this->db->db_now();
     $sql = "/* {$debugMsg} */ ";
     if ($my['options']['copy_assigned_to']) {
         // BUGID 3846
         $sql .= " SELECT TPTCV.*, COALESCE(UA.user_id,-1) AS tester, " . " COALESCE(UA.build_id,0) as assigned_build " . " FROM {$this->tables['testplan_tcversions']} TPTCV " . " LEFT OUTER JOIN {$this->tables['user_assignments']} UA ON " . " UA.feature_id = TPTCV.id " . " WHERE testplan_id={$id} ";
     } else {
         $sql .= " SELECT TPTCV.* FROM {$this->tables['testplan_tcversions']} TPTCV" . " WHERE testplan_id={$id} ";
     }
     $rs = $this->db->get_recordset($sql);
     if (!is_null($rs)) {
         $tcase_mgr = new testcase($this->db);
         $doMappings = !is_null($mappings);
         // BUGID 3846
         $already_linked_versions = array();
         foreach ($rs as $elem) {
             $tcversion_id = $elem['tcversion_id'];
             // Seems useless - 20100204
             $feature_id = $elem['id'];
             if (!is_null($my['options']['tcversion_type'])) {
                 $sql = "/* {$debugMsg} */ SELECT * FROM {$this->tables['nodes_hierarchy']} WHERE id={$tcversion_id} ";
                 $rs2 = $this->db->get_recordset($sql);
                 $last_version_info = $tcase_mgr->get_last_version_info($rs2[0]['parent_id']);
                 $tcversion_id = $last_version_info ? $last_version_info['id'] : $tcversion_id;
             }
             // mapping need to be done with:
             // platforms
             // test case versions
             $platform_id = $elem['platform_id'];
             if ($doMappings) {
                 if (isset($mappings['platforms'][$platform_id])) {
                     $platform_id = $mappings['platforms'][$platform_id];
                 }
                 if (isset($mappings['test_spec'][$tcversion_id])) {
                     $tcversion_id = $mappings['test_spec'][$tcversion_id];
                 }
             }
             $sql = "/* {$debugMsg} */ " . " INSERT INTO {$this->tables['testplan_tcversions']} " . " (testplan_id,tcversion_id,platform_id,node_order,urgency) " . " VALUES({$new_tplan_id},{$tcversion_id},{$platform_id}," . " {$elem['node_order']},{$elem['urgency']})";
             //echo "<br>debug - <b><i>" . __FUNCTION__ . "</i></b><br><b>" . $sql . "</b><br>";
             // BUGID 3846
             if (!in_array($tcversion_id, $already_linked_versions)) {
                 $this->db->exec_query($sql);
                 $new_feature_id = $this->db->insert_id($this->tables['testplan_tcversions']);
                 $already_linked_versions[] = $tcversion_id;
             }
             if ($my['options']['copy_assigned_to'] && $elem['tester'] > 0) {
                 $features_map = array();
                 $feature_id = $new_feature_id;
                 $features_map[$feature_id]['user_id'] = $elem['tester'];
                 // BUGID 3846
                 $features_map[$feature_id]['build_id'] = $build_id_mapping[$elem['assigned_build']];
                 $features_map[$feature_id]['type'] = $this->assignment_types['testcase_execution']['id'];
                 $features_map[$feature_id]['status'] = $this->assignment_status['open']['id'];
                 $features_map[$feature_id]['creation_ts'] = $now_ts;
                 $features_map[$feature_id]['assigner_id'] = $user_id;
                 if ($features_map[$feature_id]['build_id'] != 0) {
                     $this->assignment_mgr->assign($features_map);
                 }
             }
         }
     }
 }
Example #2
0
 /**
  * get_children_testcases
  * get only test cases with parent=testsuite without doing a deep search
  *
  */
 function get_children_testcases($id, $details = 'simple')
 {
     $testcases = null;
     $only_id = $details == 'only_id' ? true : false;
     $subtree = $this->tree_manager->get_children($id, array('testsuite' => 'exclude_me'));
     $doit = !is_null($subtree);
     if ($doit) {
         $tsuite = $this->get_by_id($id);
         $tsuiteName = $tsuite['name'];
         $testcases = array();
         foreach ($subtree as $the_key => $elem) {
             if ($only_id) {
                 $testcases[] = $elem['id'];
             } else {
                 $testcases[] = $elem;
             }
         }
         $doit = count($testcases) > 0;
     }
     if ($doit && $details == 'full') {
         $rs = array();
         $tcase_mgr = new testcase($this->db);
         foreach ($testcases as $idx => $value) {
             $item = $tcase_mgr->get_last_version_info($value['id']);
             $item['tcversion_id'] = $item['id'];
             $parent['tsuite_name'] = $tsuiteName;
             unset($item['id']);
             $rs[] = $value + $item + $tsuite;
         }
         $testcases = $rs;
     }
     return $testcases;
 }
function saveImportedTCData(&$db, $tcData, $tproject_id, $container_id, $userID, $kwMap, $duplicatedLogic = array('hitCriteria' => 'name', 'actionOnHit' => null))
{
    static $messages;
    static $fieldSizeCfg;
    static $feedbackMsg;
    static $tcase_mgr;
    static $tproject_mgr;
    static $req_spec_mgr;
    static $req_mgr;
    static $safeSizeCfg;
    static $linkedCustomFields;
    static $tprojectHas;
    static $reqSpecSet;
    static $getVersionOpt;
    static $userObj;
    if (!$tcData) {
        return;
    }
    // $tprojectHas = array('customFields' => false, 'reqSpec' => false);
    $hasCustomFieldsInfo = false;
    $hasRequirements = false;
    if (is_null($messages)) {
        $feedbackMsg = array();
        $messages = array();
        $fieldSizeCfg = config_get('field_size');
        $tcase_mgr = new testcase($db);
        $tproject_mgr = new testproject($db);
        $req_spec_mgr = new requirement_spec_mgr($db);
        $req_mgr = new requirement_mgr($db);
        $userObj = new tlUser();
        $k2l = array('already_exists_updated', 'original_name', 'testcase_name_too_long', 'start_warning', 'end_warning', 'testlink_warning', 'hit_with_same_external_ID');
        foreach ($k2l as $k) {
            $messages[$k] = lang_get($k);
        }
        $messages['start_feedback'] = $messages['start_warning'] . "\n" . $messages['testlink_warning'] . "\n";
        $messages['cf_warning'] = lang_get('no_cf_defined_can_not_import');
        $messages['reqspec_warning'] = lang_get('no_reqspec_defined_can_not_import');
        $feedbackMsg['cfield'] = lang_get('cf_value_not_imported_missing_cf_on_testproject');
        $feedbackMsg['tcase'] = lang_get('testcase');
        $feedbackMsg['req'] = lang_get('req_not_in_req_spec_on_tcimport');
        $feedbackMsg['req_spec'] = lang_get('req_spec_ko_on_tcimport');
        // because name can be changed automatically during item creation
        // to avoid name conflict adding a suffix automatically generated,
        // is better to use a max size < max allowed size
        $safeSizeCfg = new stdClass();
        $safeSizeCfg->testcase_name = $fieldSizeCfg->testcase_name * 0.8;
        // Get CF with scope design time and allowed for test cases linked to this test project
        $linkedCustomFields = $tcase_mgr->cfield_mgr->get_linked_cfields_at_design($tproject_id, 1, null, 'testcase', null, 'name');
        $tprojectHas['customFields'] = !is_null($linkedCustomFields);
        $reqSpecSet = $tproject_mgr->getReqSpec($tproject_id, null, array('RSPEC.id', 'NH.name AS title', 'RSPEC.doc_id as rspec_doc_id', 'REQ.req_doc_id'), 'req_doc_id');
        $tprojectHas['reqSpec'] = !is_null($reqSpecSet) && count($reqSpecSet) > 0;
        $getVersionOpt = array('output' => 'minimun');
        $tcasePrefix = $tproject_mgr->getTestCasePrefix($tproject_id);
    }
    $resultMap = array();
    $tc_qty = sizeof($tcData);
    $userIDCache = array();
    for ($idx = 0; $idx < $tc_qty; $idx++) {
        $tc = $tcData[$idx];
        $name = $tc['name'];
        $summary = $tc['summary'];
        $steps = $tc['steps'];
        // I've changed value to use when order has not been provided
        // from testcase:DEFAULT_ORDER to a counter, because with original solution
        // an issue arise with 'save execution and go next'
        // if use has not provided order I think is OK TestLink make any choice.
        $node_order = isset($tc['node_order']) ? intval($tc['node_order']) : $idx + 1;
        $internalid = $tc['internalid'];
        $preconditions = $tc['preconditions'];
        $exec_type = isset($tc['execution_type']) ? $tc['execution_type'] : TESTCASE_EXECUTION_TYPE_MANUAL;
        $importance = isset($tc['importance']) ? $tc['importance'] : MEDIUM;
        $externalid = $tc['externalid'];
        if (intval($externalid) <= 0) {
            $externalid = null;
        }
        $personID = $userID;
        if (!is_null($tc['author_login'])) {
            if (isset($userIDCache[$tc['author_login']])) {
                $personID = $userIDCache[$tc['author_login']];
            } else {
                $userObj->login = $tc['author_login'];
                if ($userObj->readFromDB($db, tlUser::USER_O_SEARCH_BYLOGIN) == tl::OK) {
                    $personID = $userObj->dbID;
                }
                // I will put always a valid userID on this cache,
                // this way if author_login does not exit, and is used multiple times
                // i will do check for existence JUST ONCE.
                $userIDCache[$tc['author_login']] = $personID;
            }
        }
        $name_len = tlStringLen($name);
        if ($name_len > $fieldSizeCfg->testcase_name) {
            // Will put original name inside summary
            $xx = $messages['start_feedback'];
            $xx .= sprintf($messages['testcase_name_too_long'], $name_len, $fieldSizeCfg->testcase_name) . "\n";
            $xx .= $messages['original_name'] . "\n" . $name . "\n" . $messages['end_warning'] . "\n";
            $summary = nl2br($xx) . $summary;
            $name = tlSubStr($name, 0, $safeSizeCfg->testcase_name);
        }
        $kwIDs = null;
        if (isset($tc['keywords']) && $tc['keywords']) {
            $kwIDs = implode(",", buildKeywordList($kwMap, $tc['keywords']));
        }
        $doCreate = true;
        if ($duplicatedLogic['actionOnHit'] == 'update_last_version') {
            switch ($duplicatedLogic['hitCriteria']) {
                case 'name':
                    $info = $tcase_mgr->getDuplicatesByName($name, $container_id);
                    break;
                case 'internalID':
                    $dummy = $tcase_mgr->tree_manager->get_node_hierarchy_info($internalid, $container_id);
                    if (!is_null($dummy)) {
                        $info = null;
                        $info[$internalid] = $dummy;
                    }
                    break;
                case 'externalID':
                    $info = $tcase_mgr->get_by_external($externalid, $container_id);
                    break;
            }
            if (!is_null($info)) {
                $tcase_qty = count($info);
                switch ($tcase_qty) {
                    case 1:
                        $doCreate = false;
                        $tcase_id = key($info);
                        $last_version = $tcase_mgr->get_last_version_info($tcase_id, $getVersionOpt);
                        $tcversion_id = $last_version['id'];
                        $ret = $tcase_mgr->update($tcase_id, $tcversion_id, $name, $summary, $preconditions, $steps, $personID, $kwIDs, $node_order, $exec_type, $importance);
                        $ret['id'] = $tcase_id;
                        $ret['tcversion_id'] = $tcversion_id;
                        $resultMap[] = array($name, $messages['already_exists_updated']);
                        break;
                    case 0:
                        $doCreate = true;
                        break;
                    default:
                        $doCreate = false;
                        break;
                }
            }
        }
        if ($doCreate) {
            // Want to block creation of with existent EXTERNAL ID, if containers ARE DIFFERENT.
            $item_id = intval($tcase_mgr->getInternalID($externalid, array('tproject_id' => $tproject_id)));
            if ($item_id > 0) {
                // who is his parent ?
                $owner = $tcase_mgr->getTestSuite($item_id);
                if ($owner != $container_id) {
                    // Get full path of existent Test Cases
                    $stain = $tcase_mgr->tree_manager->get_path($item_id, null, 'name');
                    $n = count($stain);
                    $stain[$n - 1] = $tcasePrefix . config_get('testcase_cfg')->glue_character . $externalid . ':' . $stain[$n - 1];
                    $stain = implode('/', $stain);
                    $resultMap[] = array($name, $messages['hit_with_same_external_ID'] . $stain);
                    $doCreate = false;
                }
            }
        }
        if ($doCreate) {
            $createOptions = array('check_duplicate_name' => testcase::CHECK_DUPLICATE_NAME, 'action_on_duplicate_name' => $duplicatedLogic['actionOnHit'], 'external_id' => $externalid);
            if ($ret = $tcase_mgr->create($container_id, $name, $summary, $preconditions, $steps, $personID, $kwIDs, $node_order, testcase::AUTOMATIC_ID, $exec_type, $importance, $createOptions)) {
                $resultMap[] = array($name, $ret['msg']);
            }
        }
    }
    return $resultMap;
}
*	20091109 - franciscom - BUGID  0002937: add/remove test case hover over test case 
*                                           tooltip replacement with summary 
*/
require_once '../../config.inc.php';
require_once 'common.php';
testlinkInitPage($db);
// BUGID 4066 - take care of proper escaping when magic_quotes_gpc is enabled
$_REQUEST = strings_stripSlashes($_REQUEST);
$tcase_mgr = new testcase($db);
$tcase_id = isset($_REQUEST['tcase_id']) ? $_REQUEST['tcase_id'] : null;
$tcversion_id = isset($_REQUEST['tcversion_id']) ? $_REQUEST['tcversion_id'] : 0;
$info = '';
if (!is_null($tcase_id)) {
    if ($tcversion_id > 0) {
        $tcase = $tcase_mgr->get_by_id($tcase_id, $tcversion_id);
        if (!is_null($tcase)) {
            $tcase = $tcase[0];
        }
    } else {
        $tcase = $tcase_mgr->get_last_version_info($tcase_id);
    }
    $info = $tcase['summary'];
    // <p> and </p> tag at the beginning and the end of summary cause visualization
    // errors -> remove them and add <br> to get a similar effect
    $info = str_replace("<p>", "", $info);
    $info = str_replace("</p>", "<br>", $info);
    if ($info == "") {
        $info = lang_get("empty_tc_summary");
    }
}
echo $info;
Example #5
0
function saveImportedTCData(&$db, $tcData, $tproject_id, $container_id, $userID, $kwMap, $duplicatedLogic = array('hitCriteria' => 'name', 'actionOnHit' => null))
{
    static $messages;
    static $fieldSizeCfg;
    static $feedbackMsg;
    static $tcase_mgr;
    static $tproject_mgr;
    static $req_spec_mgr;
    static $req_mgr;
    static $safeSizeCfg;
    static $linkedCustomFields;
    static $tprojectHas;
    static $reqSpecSet;
    static $getVersionOpt;
    if (!$tcData) {
        return;
    }
    // $tprojectHas = array('customFields' => false, 'reqSpec' => false);
    $hasCustomFieldsInfo = false;
    $hasRequirements = false;
    if (is_null($messages)) {
        $feedbackMsg = array();
        $messages = array();
        $fieldSizeCfg = config_get('field_size');
        $tcase_mgr = new testcase($db);
        $tproject_mgr = new testproject($db);
        $req_spec_mgr = new requirement_spec_mgr($db);
        $req_mgr = new requirement_mgr($db);
        $messages['cf_warning'] = lang_get('no_cf_defined_can_not_import');
        $messages['reqspec_warning'] = lang_get('no_reqspec_defined_can_not_import');
        $messages['already_exists_updated'] = lang_get('already_exists_updated');
        $messages['original_name'] = lang_get('original_name');
        $messages['testcase_name_too_long'] = lang_get('testcase_name_too_long');
        $messages['start_warning'] = lang_get('start_warning');
        $messages['end_warning'] = lang_get('end_warning');
        $messages['testlink_warning'] = lang_get('testlink_warning');
        $messages['start_feedback'] = $messages['start_warning'] . "\n" . $messages['testlink_warning'] . "\n";
        $feedbackMsg['cfield'] = lang_get('cf_value_not_imported_missing_cf_on_testproject');
        $feedbackMsg['tcase'] = lang_get('testcase');
        $feedbackMsg['req'] = lang_get('req_not_in_req_spec_on_tcimport');
        $feedbackMsg['req_spec'] = lang_get('req_spec_ko_on_tcimport');
        // because name can be changed automatically during item creation
        // to avoid name conflict adding a suffix automatically generated,
        // is better to use a max size < max allowed size
        $safeSizeCfg = new stdClass();
        $safeSizeCfg->testcase_name = $fieldSizeCfg->testcase_name * 0.8;
        // Get CF with scope design time and allowed for test cases linked to this test project
        // $customFields=$tproject_mgr->get_linked_custom_fields($tproject_id,'testcase','name');
        // function get_linked_cfields_at_design($tproject_id,$enabled,$filters=null,
        //                                       $node_type=null,$node_id=null,$access_key='id')
        //
        $linkedCustomFields = $tcase_mgr->cfield_mgr->get_linked_cfields_at_design($tproject_id, 1, null, 'testcase', null, 'name');
        $tprojectHas['customFields'] = !is_null($linkedCustomFields);
        // BUGID - 20090205 - franciscom
        $reqSpecSet = $tproject_mgr->getReqSpec($tproject_id, null, array('RSPEC.id', 'NH.name AS title', 'RSPEC.doc_id as rspec_doc_id', 'REQ.req_doc_id'), 'req_doc_id');
        $tprojectHas['reqSpec'] = !is_null($reqSpecSet) && count($reqSpecSet) > 0;
        $getVersionOpt = array('output' => 'minimun');
    }
    $resultMap = array();
    $tc_qty = sizeof($tcData);
    for ($idx = 0; $idx < $tc_qty; $idx++) {
        $tc = $tcData[$idx];
        $name = $tc['name'];
        $summary = $tc['summary'];
        $steps = $tc['steps'];
        $node_order = isset($tc['node_order']) ? intval($tc['node_order']) : testcase::DEFAULT_ORDER;
        $externalid = $tc['externalid'];
        $internalid = $tc['internalid'];
        $preconditions = $tc['preconditions'];
        $exec_type = isset($tc['execution_type']) ? $tc['execution_type'] : TESTCASE_EXECUTION_TYPE_MANUAL;
        $importance = isset($tc['importance']) ? $tc['importance'] : MEDIUM;
        $name_len = tlStringLen($name);
        if ($name_len > $fieldSizeCfg->testcase_name) {
            // Will put original name inside summary
            $xx = $messages['start_feedback'];
            $xx .= sprintf($messages['testcase_name_too_long'], $name_len, $fieldSizeCfg->testcase_name) . "\n";
            $xx .= $messages['original_name'] . "\n" . $name . "\n" . $messages['end_warning'] . "\n";
            $summary = nl2br($xx) . $summary;
            $name = tlSubStr($name, 0, $safeSizeCfg->testcase_name);
        }
        $kwIDs = null;
        if (isset($tc['keywords']) && $tc['keywords']) {
            $kwIDs = implode(",", buildKeywordList($kwMap, $tc['keywords']));
        }
        $doCreate = true;
        if ($duplicatedLogic['actionOnHit'] == 'update_last_version') {
            switch ($duplicatedLogic['hitCriteria']) {
                case 'name':
                    $info = $tcase_mgr->getDuplicatesByName($name, $container_id);
                    break;
                case 'internalID':
                    $dummy = $tcase_mgr->tree_manager->get_node_hierarchy_info($internalid, $container_id);
                    if (!is_null($dummy)) {
                        $info[$internalid] = $dummy;
                    }
                    break;
                case 'externalID':
                    $info = $tcase_mgr->get_by_external($externalid, $container_id);
                    break;
            }
            if (!is_null($info)) {
                $tcase_qty = count($info);
                switch ($tcase_qty) {
                    case 1:
                        $doCreate = false;
                        $tcase_id = key($info);
                        $last_version = $tcase_mgr->get_last_version_info($tcase_id, $getVersionOpt);
                        $tcversion_id = $last_version['id'];
                        $ret = $tcase_mgr->update($tcase_id, $tcversion_id, $name, $summary, $preconditions, $steps, $userID, $kwIDs, $node_order, $exec_type, $importance);
                        // BUGID 3801
                        $ret['id'] = $tcase_id;
                        $ret['tcversion_id'] = $tcversion_id;
                        $resultMap[] = array($name, $messages['already_exists_updated']);
                        break;
                    case 0:
                        $doCreate = true;
                        break;
                    default:
                        $doCreate = false;
                        break;
                }
            }
        }
        if ($doCreate) {
            $createOptions = array('check_duplicate_name' => testcase::CHECK_DUPLICATE_NAME, 'action_on_duplicate_name' => $duplicatedLogic['actionOnHit']);
            if ($ret = $tcase_mgr->create($container_id, $name, $summary, $preconditions, $steps, $userID, $kwIDs, $node_order, testcase::AUTOMATIC_ID, $exec_type, $importance, $createOptions)) {
                $resultMap[] = array($name, $ret['msg']);
            }
        }
        // 20090106 - franciscom
        // Custom Fields Management
        // Check if CF with this name and that can be used on Test Cases is defined in current Test Project.
        // If Check fails => give message to user.
        // Else Import CF data
        //
        $hasCustomFieldsInfo = isset($tc['customfields']) && !is_null($tc['customfields']);
        if ($hasCustomFieldsInfo) {
            new dBug($ret);
            if ($tprojectHas['customFields']) {
                // BUGID 3431 - Custom Field values at Test Case VERSION Level
                $msg = processCustomFields($tcase_mgr, $name, $ret['id'], $ret['tcversion_id'], $tc['customfields'], $linkedCustomFields, $feedbackMsg);
                if (!is_null($msg)) {
                    $resultMap = array_merge($resultMap, $msg);
                }
            } else {
                // Can not import Custom Fields Values, give feedback
                $msg[] = array($name, $messages['cf_warning']);
                $resultMap = array_merge($resultMap, $msg);
            }
        }
        // BUGID - 20090205 - franciscom
        // Requirements Management
        // Check if Requirement ...
        // If Check fails => give message to user.
        // Else Import
        //
        $hasRequirements = isset($tc['requirements']) && !is_null($tc['requirements']);
        if ($hasRequirements) {
            if ($tprojectHas['reqSpec']) {
                $msg = processRequirements($db, $req_mgr, $name, $ret['id'], $tc['requirements'], $reqSpecSet, $feedbackMsg);
                if (!is_null($msg)) {
                    $resultMap = array_merge($resultMap, $msg);
                }
            } else {
                $msg[] = array($name, $messages['reqspec_warning']);
                $resultMap = array_merge($resultMap, $msg);
            }
        }
    }
    return $resultMap;
}