$tproject_id = 1;
echo "<pre>               get_keywords_map({$tproject_id})";
echo "</pre>";
$keywords_map = $tproject_mgr->get_keywords_map($tproject_id);
new dBug($keywords_map);
echo "<pre> testproject - get_keywords_tcases(\$testproject_id, \$keyword_id=0)";
echo "</pre>";
echo "<pre>               get_keywords_tcases({$tproject_id})";
echo "</pre>";
$keywords_tcases = $tproject_mgr->get_keywords_tcases($tproject_id);
new dBug($keywords_tcases);
echo "<pre> testproject - get_linked_custom_fields(\$id,\$node_type=null)";
echo "</pre>";
echo "<pre>               get_linked_custom_fields({$tproject_id})";
echo "</pre>";
$linked_custom_fields = $tproject_mgr->get_linked_custom_fields($tproject_id);
new dBug($linked_custom_fields);
echo "<pre> testproject - gen_combo_test_suites(\$id,\$exclude_branches=null,\$mode='dotted')";
echo "</pre>";
echo "<pre>               gen_combo_test_suites({$tproject_id},null,'dotted')";
echo "</pre>";
$combo_test_suites = $tproject_mgr->gen_combo_test_suites($tproject_id, null, 'dotted');
new dBug($combo_test_suites);
echo "<pre>               gen_combo_test_suites({$tproject_id},null,'dotted')";
echo "</pre>";
$combo_test_suites = $tproject_mgr->gen_combo_test_suites($tproject_id, null, 'array');
new dBug($combo_test_suites);
echo "<pre> testproject - getReqSpec(\$testproject_id, \$id = null)";
echo "</pre>";
echo "<pre>               getReqSpec({$tproject_id})";
echo "</pre>";
예제 #2
0
function saveImportedResultData(&$db, $resultData, $context)
{
    if (!$resultData) {
        return;
    }
    $debugMsg = ' FUNCTION: ' . __FUNCTION__;
    $tables = tlObjectWithDB::getDBTables(array('executions', 'execution_bugs'));
    $l18n = array('import_results_tc_not_found' => '', 'import_results_invalid_result' => '', 'tproject_id_not_found' => '', 'import_results_ok' => '', 'internal_id' => '', 'external_id' => '');
    foreach ($l18n as $key => $value) {
        $l18n[$key] = lang_get($key);
    }
    // Get Column definitions to get size dinamically instead of create constants
    $columnDef = array();
    $adodbObj = $db->get_dbmgr_object();
    $columnDef['execution_bugs'] = $adodbObj->MetaColumns($tables['execution_bugs']);
    $keySet = array_keys($columnDef['execution_bugs']);
    foreach ($keySet as $keyName) {
        if (($keylow = strtolower($keyName)) != $keyName) {
            $columnDef['execution_bugs'][$keylow] = $columnDef['execution_bugs'][$keyName];
            unset($columnDef['execution_bugs'][$keyName]);
        }
    }
    $user = new tlUser($context->userID);
    $user->readFromDB($db);
    $tcase_mgr = new testcase($db);
    $resulstCfg = config_get('results');
    $tcaseCfg = config_get('testcase_cfg');
    $resultMap = array();
    $tplan_mgr = null;
    $tc_qty = sizeof($resultData);
    $cfields = null;
    if ($tc_qty) {
        $tplan_mgr = new testplan($db);
        $tproject_mgr = new testproject($db);
        // BUGID 3843
        $cfields = $tproject_mgr->get_linked_custom_fields($context->tprojectID, 'testcase', 'name');
    }
    // Need to do checks on common settings
    //
    // test project exists
    //
    // test plan id:
    //              belongs to target test project
    //              is active
    // build id:
    //          belongs to target test plan
    //          is open
    //
    // platform id:
    //          is linked  to target test plan
    //
    // execution type if not present -> set to MANUAL
    //				  if presente is valid i.e. inside the TL domain
    //
    $checks['status_ok'] = true;
    $checks['msg'] = null;
    $dummy = $tproject_mgr->get_by_id($context->tprojectID);
    $checks['status_ok'] = !is_null($dummy);
    if (!$checks['status_ok']) {
        $checks['msg'][] = sprintf($l18n['tproject_id_not_found'], $context->tprojectID);
    }
    if (!$checks['status_ok']) {
        foreach ($checks['msg'] as $warning) {
            $resultMap[] = array($warning);
        }
    }
    $doIt = $checks['status_ok'];
    // --------------------------------------------------------------------
    for ($idx = 0; $doIt && $idx < $tc_qty; $idx++) {
        $tester_id = 0;
        $tester_name = '';
        $using_external_id = false;
        $message = null;
        $status_ok = true;
        $tcase_exec = $resultData[$idx];
        // BUGID 3751: New attribute "execution type" makes old XML import files incompatible
        // Important NOTICE:
        // tcase_exec is passed BY REFERENCE to allow check_exec_values()change execution type if needed
        //
        $checks = check_exec_values($db, $context->tprojectID, $cfields, $tcase_mgr, $user_mgr, $tcaseCfg, $tcase_exec, $columnDef['execution_bugs']);
        $status_ok = $checks['status_ok'];
        if ($status_ok) {
            $tcase_id = $checks['tcase_id'];
            $tcase_external_id = trim($tcase_exec['tcase_external_id']);
            $tester_id = $checks['tester_id'];
            // external_id has precedence over internal id
            $using_external_id = $tcase_external_id != "";
        } else {
            foreach ($checks['msg'] as $warning) {
                $resultMap[] = array($warning);
            }
        }
        if ($status_ok) {
            $tcase_identity = $using_external_id ? $tcase_external_id : $tcase_id;
            $verbose_identity = $using_external_id ? $l18n['external_id'] : $l18n['internal_id'];
            $verbose_identity = sprintf($verbose_identity, $tcase_identity);
            $result_code = strtolower($tcase_exec['result']);
            $result_is_acceptable = isset($resulstCfg['code_status'][$result_code]) ? true : false;
            $notes = $tcase_exec['notes'];
            $message = null;
            $filters = array('tcase_id' => $tcase_id, 'build_id' => $context->buildID, 'platform_id' => $context->platformID);
            $linked_cases = $tplan_mgr->get_linked_tcversions($context->tplanID, $filters);
            $info_on_case = $linked_cases[$tcase_id];
            if (!$linked_cases) {
                $message = sprintf($l18n['import_results_tc_not_found'], $verbose_identity);
            } else {
                if (!$result_is_acceptable) {
                    $message = sprintf($l18n['import_results_invalid_result'], $verbose_identity, $tcase_exec['result']);
                } else {
                    $tcversion_id = $info_on_case['tcversion_id'];
                    $version = $info_on_case['version'];
                    $notes = $db->prepare_string(trim($notes));
                    // N.B.: db_now() returns an string ready to be used in an SQL insert
                    //       example '2008-09-04', while $tcase_exec["timestamp"] => 2008-09-04
                    //
                    $execution_ts = $tcase_exec['timestamp'] != '' ? "'" . $tcase_exec["timestamp"] . "'" : $db->db_now();
                    if ($tester_id != 0) {
                        $tester_name = $tcase_exec['tester'];
                    } else {
                        $tester_name = $user->login;
                        $tester_id = $context->userID;
                    }
                    // BUGID 3543 - added execution_type
                    $sql = " /* {$debugMsg} */ " . " INSERT INTO {$tables['executions']} (build_id,tester_id,status,testplan_id," . " tcversion_id,execution_ts,notes,tcversion_number,platform_id,execution_type)" . " VALUES ({$context->buildID}, {$tester_id},'{$result_code}',{$context->tplanID}, " . " {$tcversion_id},{$execution_ts},'{$notes}', {$version}, " . " {$context->platformID}, {$tcase_exec['execution_type']})";
                    $db->exec_query($sql);
                    // BUGID 3331
                    if (isset($tcase_exec['bug_id']) && !is_null($tcase_exec['bug_id']) && is_array($tcase_exec['bug_id'])) {
                        $execution_id = $db->insert_id($tables['executions']);
                        foreach ($tcase_exec['bug_id'] as $bug_id) {
                            $bug_id = trim($bug_id);
                            $sql = " /* {$debugMsg} */ " . " SELECT execution_id AS check_qty FROM  {$tables['execution_bugs']} " . " WHERE bug_id = '{$bug_id}' AND execution_id={$execution_id} ";
                            $rs = $db->get_recordset($sql);
                            if (is_null($rs)) {
                                $sql = " /* {$debugMsg} */ " . " INSERT INTO {$tables['execution_bugs']} (bug_id,execution_id)" . " VALUES ('" . $db->prepare_string($bug_id) . "', {$execution_id} )";
                                $db->exec_query($sql);
                            }
                        }
                    }
                    // Improvements on feedback
                    $message = sprintf($l18n['import_results_ok'], $info_on_case['name'] . " - " . $verbose_identity, $version, $tester_name, $resulstCfg['code_status'][$result_code], $execution_ts);
                }
            }
        }
        if (!is_null($message)) {
            $resultMap[] = array($message);
        }
    }
    return $resultMap;
}