Exemple #1
0
/**
 * write execution result to DB
 * 
 * @param resource &$db reference to database handler
 * @param obj &$exec_signature object with tproject_id,tplan_id,build_id,platform_id,user_id
 * 
 * @internal Revisions:
 * 
 *
 * 20100522 - BUGID 3479 - Bulk Execution - Custom Fields Bulk Assignment
 */
function write_execution(&$db, &$exec_signature, &$exec_data, $map_last_exec)
{
    $executions_table = DB_TABLE_PREFIX . 'executions';
    $resultsCfg = config_get('results');
    // $bugInterfaceOn = config_get('bugInterfaceOn');
    $db_now = $db->db_now();
    $cfield_mgr = new cfield_mgr($db);
    $cf_prefix = $cfield_mgr->get_name_prefix();
    $len_cfp = tlStringLen($cf_prefix);
    $cf_nodeid_pos = 4;
    $bulk_notes = '';
    $ENABLED = 1;
    $cf_map = $cfield_mgr->get_linked_cfields_at_execution($exec_signature->tproject_id, $ENABLED, 'testcase');
    $has_custom_fields = is_null($cf_map) ? 0 : 1;
    // extract custom fields id.
    $map_nodeid_array_cfnames = null;
    foreach ($exec_data as $input_name => $value) {
        if (strncmp($input_name, $cf_prefix, $len_cfp) == 0) {
            $dummy = explode('_', $input_name);
            $map_nodeid_array_cfnames[$dummy[$cf_nodeid_pos]][] = $input_name;
        }
    }
    if (isset($exec_data['do_bulk_save'])) {
        // create structure to use common algoritm
        $item2loop = $exec_data['status'];
        $is_bulk_save = 1;
        $bulk_notes = $db->prepare_string(trim($exec_data['bulk_exec_notes']));
    } else {
        $item2loop = $exec_data['save_results'];
        $is_bulk_save = 0;
    }
    foreach ($item2loop as $tcversion_id => $val) {
        $tcase_id = $exec_data['tc_version'][$tcversion_id];
        $current_status = $exec_data['status'][$tcversion_id];
        $version_number = $exec_data['version_number'][$tcversion_id];
        $has_been_executed = $current_status != $resultsCfg['status_code']['not_run'] ? TRUE : FALSE;
        if ($has_been_executed) {
            $my_notes = $is_bulk_save ? $bulk_notes : $db->prepare_string(trim($exec_data['notes'][$tcversion_id]));
            $sql = "INSERT INTO {$executions_table} " . "(build_id,tester_id,status,testplan_id,tcversion_id," . " execution_ts,notes,tcversion_number,platform_id)" . " VALUES ( {$exec_signature->build_id}, {$exec_signature->user_id}, '{$exec_data['status'][$tcversion_id]}'," . "{$exec_signature->tplan_id}, {$tcversion_id},{$db_now},'{$my_notes}'," . "{$version_number},{$exec_signature->platform_id}" . ")";
            $db->exec_query($sql);
            // at least for Postgres DBMS table name is needed.
            $execution_id = $db->insert_id($executions_table);
            if ($has_custom_fields) {
                // test useful when doing bulk update, because some type of custom fields
                // like checkbox can not exist on exec_data. => why ??
                //
                $hash_cf = null;
                $access_key = $is_bulk_save ? 0 : $tcase_id;
                if (isset($map_nodeid_array_cfnames[$access_key])) {
                    foreach ($map_nodeid_array_cfnames[$access_key] as $cf_v) {
                        $hash_cf[$cf_v] = $exec_data[$cf_v];
                    }
                }
                $cfield_mgr->execution_values_to_db($hash_cf, $tcversion_id, $execution_id, $exec_signature->tplan_id, $cf_map);
            }
        }
    }
}
 function testplan_design_values_to_db($hash, $node_id, $link_id, $cf_map = null, $hash_type = null)
 {
     if (is_null($hash) && is_null($cf_map)) {
         return;
     }
     $debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;
     $cfield = is_null($hash_type) ? $this->_build_cfield($hash, $cf_map) : $hash;
     if (!is_null($cfield)) {
         foreach ($cfield as $field_id => $type_and_value) {
             // echo "DEBUG: \$field_id:$field_id - \$link_id:$link_id<br>";
             $value = $type_and_value['cf_value'];
             // do I need to update or insert this value?
             $sql = "SELECT value FROM {$this->tables['cfield_testplan_design_values']} " . " WHERE field_id={$field_id} AND\tlink_id={$link_id}";
             $result = $this->db->exec_query($sql);
             // max_length_value = 0 => no limit
             if ($this->max_length_value > 0 && tlStringLen($value) > $this->max_length_value) {
                 $value = substr($value, 0, $this->max_length_value);
             }
             $safe_value = $this->db->prepare_string($value);
             // BUGID 3989
             if ($this->db->num_rows($result) > 0 && $value != "") {
                 $sql = "UPDATE {$this->tables['cfield_testplan_design_values']} " . " SET value='{$safe_value}' " . " WHERE field_id={$field_id} AND\tlink_id={$link_id}";
                 $this->db->exec_query($sql);
             } else {
                 if ($this->db->num_rows($result) == 0 && $value != "") {
                     # Remark got from Mantis code:
                     # Always store the value, even if it's the dafault value
                     # This is important, as the definitions might change but the
                     #  values stored with a bug must not change
                     $sql = "INSERT INTO {$this->tables['cfield_testplan_design_values']} " . " ( field_id, link_id, value ) " . " VALUES\t( {$field_id}, {$link_id}, '{$safe_value}' )";
                     $this->db->exec_query($sql);
                     // BUGID 3989
                 } else {
                     if ($this->db->num_rows($result) > 0 && $value == "") {
                         $sql = "/* {$debugMsg} */ DELETE FROM {$this->tables['cfield_testplan_design_values']} " . " WHERE field_id={$field_id} AND\tlink_id={$link_id}";
                         $this->db->exec_query($sql);
                     }
                 }
             }
         }
         //foreach($cfield
     }
     //if( !is_null($cfield) )
 }
 /** @TODO add description */
 function formatTcPrefix($str)
 {
     $fstr = trim($str);
     if (tlStringLen($fstr) == 0) {
         throw new Exception('Empty prefix is not allowed');
     }
     // limit tcasePrefix len.
     if (tlStringLen($fstr) > self::TESTCASE_PREFIX_MAXLEN) {
         $fstr = substr($fstr, self::TESTCASE_PREFIX_MAXLEN);
     }
     return $fstr;
 }
Exemple #4
0
 public function checkLogin($login)
 {
     $result = tl::OK;
     $login = trim($login);
     if ($login == "" || tlStringLen($login) > $this->maxLoginLength) {
         $result = self::E_LOGINLENGTH;
     } else {
         if (!preg_match($this->loginRegExp, $login)) {
             //Only allow a basic set of characters
             $result = self::E_NOTALLOWED;
         }
     }
     return $result;
 }
Exemple #5
0
 /**
  * Returns the bug summary in a human readable format, cut down to 45 chars
  *
  * @return string returns the summary (in readable form) of the given bug
  *
  * @version 1.2
  * @author Raphael Bosshard
  * @author Arjen van Summeren
  * @author John Wanke
  *         updated $query value to be GForge-specific.
  *         updated to use associative index ['summary'] instead of [0].
  * @since 23.10.2008, 16:29:00
  **/
 function getBugSummaryString($id)
 {
     if (!$this->isConnected()) {
         return null;
     }
     $status = null;
     $summary = null;
     $query = "SELECT summary FROM tracker_item WHERE tracker_item_id='" . $id . "'";
     $result = $this->dbConnection->exec_query($query);
     if ($result) {
         $summary = $this->dbConnection->fetch_array($result);
         if ($summary) {
             $summary = $summary['summary'];
             if (tlStringLen($summary) > 45) {
                 $summary = tlSubStr($summary, 0, 42) . "...";
             }
         } else {
             $summary = null;
         }
     }
     return $summary;
 }
function request2cf($hash)
{
    // design and execution has sense for node types regarding testing
    // testplan,testsuite,testcase, but no sense for requirements.
    //
    // Missing keys are combos that will be disabled and not show at UI.
    // For req spec and req, no combo is showed.
    // To avoid problems (need to be checked), my choice is set to 1
    // *_on_design keys, that right now will not present only for
    // req spec and requirements.
    //
    $missing_keys = array('show_on_design' => 0, 'enable_on_design' => 0, 'show_on_execution' => 0, 'enable_on_execution' => 0, 'show_on_testplan_design' => 0, 'enable_on_testplan_design' => 0, 'possible_values' => ' ');
    $cf_prefix = 'cf_';
    $len_cfp = tlStringLen($cf_prefix);
    $start_pos = $len_cfp;
    $cf = array();
    foreach ($hash as $key => $value) {
        if (strncmp($key, $cf_prefix, $len_cfp) == 0) {
            $dummy = substr($key, $start_pos);
            $cf[$dummy] = $value;
        }
    }
    foreach ($missing_keys as $key => $value) {
        if (!isset($cf[$key])) {
            $cf[$key] = $value;
        }
    }
    // After logic refactoring
    // if ENABLE_ON_[area] == 1
    //    DISPLAY_ON_[area] = 1
    //
    //
    // IMPORTANT/CRITIC:
    // this KEY MUST BE ALIGNED WITH name on User Inteface
    // then if is changed on UI must be changed HERE
    $setter = array('design' => 0, 'execution' => 0, 'testplan_design' => 0);
    switch ($cf['enable_on']) {
        case 'design':
        case 'execution':
        case 'testplan_design':
            $setter[$cf['enable_on']] = 1;
            break;
        default:
            $setter['design'] = 1;
            break;
    }
    foreach ($setter as $key => $value) {
        $cf['enable_on_' . $key] = $value;
        if ($cf['enable_on_' . $key]) {
            $cf['show_on_' . $key] = 1;
        }
    }
    return $cf;
}
 /**
  * @return 
  *	       
  */
 public function throwIfEmptyName($name)
 {
     $safeName = trim($name);
     if (tlStringLen($safeName) == 0) {
         $msg = "Class: " . __CLASS__ . " - " . "Method: " . __FUNCTION__;
         $msg .= " Empty name ";
         throw new Exception($msg);
     }
     return $safeName;
 }
Exemple #8
0
/**
 * Trim string and limit to N chars
 * 
 * @param string
 * @param int [len]: how many chars return
 *
 * @return string trimmed string
 *
 * @author Francisco Mancardi - 20050905 - refactoring
 */
function trim_and_limit($s, $len = 100)
{
    $s = trim($s);
    if (tlStringLen($s) > $len) {
        $s = tlSubStr($s, 0, $len);
    }
    return $s;
}
Exemple #9
0
/**
 * write execution result to DB
 * 
 * @param resource &$db reference to database handler
 * @param obj &$exec_signature object with tproject_id,tplan_id,build_id,platform_id,user_id
 * 
 * @internal revisions
 * 
 */
function write_execution(&$db, &$exec_signature, &$exec_data)
{
    $executions_table = DB_TABLE_PREFIX . 'executions';
    $resultsCfg = config_get('results');
    $execCfg = config_get('exec_cfg');
    $db_now = $db->db_now();
    $cfield_mgr = new cfield_mgr($db);
    $cf_prefix = $cfield_mgr->get_name_prefix();
    $len_cfp = tlStringLen($cf_prefix);
    $cf_nodeid_pos = 4;
    $bulk_notes = '';
    $ENABLED = 1;
    $cf_map = $cfield_mgr->get_linked_cfields_at_execution($exec_signature->tproject_id, $ENABLED, 'testcase');
    $has_custom_fields = is_null($cf_map) ? 0 : 1;
    // extract custom fields id.
    $map_nodeid_array_cfnames = null;
    foreach ($exec_data as $input_name => $value) {
        if (strncmp($input_name, $cf_prefix, $len_cfp) == 0) {
            $dummy = explode('_', $input_name);
            $map_nodeid_array_cfnames[$dummy[$cf_nodeid_pos]][] = $input_name;
        }
    }
    if (isset($exec_data['do_bulk_save'])) {
        // create structure to use common algoritm
        $item2loop = $exec_data['status'];
        $is_bulk_save = 1;
        $bulk_notes = $db->prepare_string(trim($exec_data['bulk_exec_notes']));
    } else {
        $item2loop = $exec_data['save_results'];
        $is_bulk_save = 0;
    }
    foreach ($item2loop as $tcversion_id => $val) {
        $tcase_id = $exec_data['tc_version'][$tcversion_id];
        $current_status = $exec_data['status'][$tcversion_id];
        $version_number = $exec_data['version_number'][$tcversion_id];
        $has_been_executed = $current_status != $resultsCfg['status_code']['not_run'] ? TRUE : FALSE;
        if ($has_been_executed) {
            $my_notes = $is_bulk_save ? $bulk_notes : $db->prepare_string(trim($exec_data['notes'][$tcversion_id]));
            $sql = "INSERT INTO {$executions_table} " . "(build_id,tester_id,status,testplan_id,tcversion_id," . " execution_ts,notes,tcversion_number,platform_id,execution_duration)" . " VALUES ( {$exec_signature->build_id}, {$exec_signature->user_id}, '{$exec_data['status'][$tcversion_id]}'," . "{$exec_signature->tplan_id}, {$tcversion_id},{$db_now},'{$my_notes}'," . "{$version_number},{$exec_signature->platform_id}";
            if (trim($exec_data['execution_duration']) == '') {
                $dura = 'NULL ';
            } else {
                $dura = floatval($exec_data['execution_duration']);
            }
            $sql .= ',' . $dura . ")";
            $db->exec_query($sql);
            // at least for Postgres DBMS table name is needed.
            $execution_id = $db->insert_id($executions_table);
            if ($has_custom_fields) {
                // test useful when doing bulk update, because some type of custom fields
                // like checkbox can not exist on exec_data. => why ??
                //
                $hash_cf = null;
                $access_key = $is_bulk_save ? 0 : $tcase_id;
                if (isset($map_nodeid_array_cfnames[$access_key])) {
                    foreach ($map_nodeid_array_cfnames[$access_key] as $cf_v) {
                        $hash_cf[$cf_v] = $exec_data[$cf_v];
                    }
                }
                $cfield_mgr->execution_values_to_db($hash_cf, $tcversion_id, $execution_id, $exec_signature->tplan_id, $cf_map);
            }
            // 20140412
            $hasMoreData = new stdClass();
            $hasMoreData->step_notes = isset($exec_data['step_notes']);
            $hasMoreData->step_status = isset($exec_data['step_status']);
            $hasMoreData->nike = $execCfg->steps_exec && ($hasMoreData->step_notes || $hasMoreData->step_status);
            if ($hasMoreData->nike) {
                $target = DB_TABLE_PREFIX . 'execution_tcsteps';
                $key2loop = array_keys($exec_data['step_notes']);
                foreach ($key2loop as $step_id) {
                    $doIt = !is_null($exec_data['step_notes'][$step_id]) && trim($exec_data['step_notes'][$step_id]) != '' || $exec_data['step_status'][$step_id] != $resultsCfg['status_code']['not_run'];
                    if ($doIt) {
                        $sql = " INSERT INTO {$target} (execution_id,tcstep_id,notes";
                        $values = " VALUES ( {$execution_id}, {$step_id}," . "'" . $db->prepare_string($exec_data['step_notes'][$step_id]) . "'";
                        $status = strtolower(trim($exec_data['step_status'][$step_id]));
                        $status = $status[0];
                        if ($status != $resultsCfg['status_code']['not_run']) {
                            $sql .= ",status";
                            $values .= ",'" . $db->prepare_string($status) . "'";
                        }
                        $sql .= ") " . $values . ")";
                        $db->exec_query($sql);
                    }
                }
            }
        }
    }
}
/**
 * 
 *
 * 
 **/
function initializeGui(&$dbHandler, &$argsObj)
{
    $guiObj = new stdClass();
    $guiObj->importLimitBytes = config_get('import_file_max_size_bytes');
    $guiObj->importLimitKB = $guiObj->importLimitBytes / 1024;
    $guiObj->importTypes = array('XML' => 'Mantis XML');
    $guiObj->req_spec_id = $argsObj->req_spec_id;
    $guiObj->refreshTree = $guiObj->doImport = tlStringLen($argsObj->importType);
    $guiObj->resultMap = null;
    $guiObj->req_spec_name = '';
    $guiObj->file_check = array('status_ok' => 1, 'msg' => 'ok');
    $guiObj->import_title = lang_get('title_req_import');
    $guiObj->fileName = TL_TEMP_PATH . session_id() . "-import_req_from_issue";
    if ($argsObj->req_spec_id) {
        $tree_mgr = new tree($dbHandler);
        $node_info = $tree_mgr->get_node_hierarchy_info($argsObj->req_spec_id);
        unset($tree_mgr);
        $guiObj->req_spec_name = $node_info['name'];
    }
    return $guiObj;
}
Exemple #11
0
 *       20070505 - franciscom - use of role_separator configuration
 *
**/
require_once '../../config.inc.php';
require_once "common.php";
testlinkInitPage($db, true);
$tproject_mgr = new testproject($db);
$args = init_args();
$gui = new stdClass();
$gui->tprojectID = isset($_SESSION['testprojectID']) ? $_SESSION['testprojectID'] : 0;
$gui->tcasePrefix = '';
$gui->searchSize = 8;
// magic default
if ($gui->tprojectID > 0) {
    $gui->tcasePrefix = $tproject_mgr->getTestCasePrefix($gui->tprojectID) . config_get('testcase_cfg')->glue_character;
    $gui->searchSize = tlStringLen($gui->tcasePrefix) + 7;
    // magic again
}
$user = $_SESSION['currentUser'];
$userID = $user->dbID;
$gui->TestProjects = $tproject_mgr->get_accessible_for_user($userID, 'map', $tlCfg->gui->tprojects_combo_order_by);
$gui->TestProjectCount = sizeof($gui->TestProjects);
$gui->TestPlanCount = 0;
if ($gui->tprojectID) {
    $testPlanSet = $user->getAccessibleTestPlans($db, $gui->tprojectID);
    $gui->TestPlanCount = sizeof($testPlanSet);
    $tplanID = isset($_SESSION['testplanID']) ? $_SESSION['testplanID'] : null;
    if (!is_null($tplanID)) {
        // Need to set this info on session with first Test Plan from $testPlanSet
        // if this test plan is present on $testPlanSet
        //	  OK we will set it on $testPlanSet as selected one.
Exemple #12
0
/**
 */
function initEnvironment(&$dbHandler, &$userObj)
{
    $argsObj = new stdClass();
    $guiObj = new stdClass();
    $cfg = config_get("gui");
    $tprojectMgr = new testproject($dbHandler);
    $_REQUEST = strings_stripSlashes($_REQUEST);
    $iParams = array("tprojectIDNavBar" => array(tlInputParameter::INT_N), "tproject_id" => array(tlInputParameter::INT_N), "tplan_id" => array(tlInputParameter::INT_N));
    R_PARAMS($iParams, $argsObj);
    $guiObj->tcasePrefix = '';
    $guiObj->tplanCount = 0;
    $guiObj->tprojectSet = $tprojectMgr->get_accessible_for_user($userObj->dbID);
    $guiObj->tprojectCount = sizeof($guiObj->tprojectSet);
    // -----------------------------------------------------------------------------------------------------
    // Important Logic
    // -----------------------------------------------------------------------------------------------------
    $argsObj->tprojectIDNavBar = intval($argsObj->tprojectIDNavBar);
    $argsObj->tproject_id = intval($argsObj->tproject_id);
    $argsObj->tproject_id = $argsObj->tproject_id > 0 ? $argsObj->tproject_id : $argsObj->tprojectIDNavBar;
    if ($argsObj->tproject_id == 0) {
        $argsObj->tproject_id = key($guiObj->tprojectSet);
    }
    $guiObj->tprojectID = $argsObj->tproject_id;
    $guiObj->tprojectOptions = null;
    $guiObj->tprojectTopMenu = null;
    if ($guiObj->tprojectID > 0) {
        $dummy = $tprojectMgr->get_by_id($guiObj->tprojectID);
        $guiObj->tprojectOptions = $dummy['opt'];
    }
    // -----------------------------------------------------------------------------------------------------
    $argsObj->tplan_id = intval($argsObj->tplan_id);
    $guiObj->tplanID = $argsObj->tplan_id;
    // Julian: left magic here - do think this value will never be used as a project with a prefix
    //         has to be created after first login -> searchSize should be set dynamically.
    //         If any reviewer agrees on that feel free to change it.
    $guiObj->searchSize = 8;
    if ($guiObj->tprojectID > 0) {
        $guiObj->tcasePrefix = $tprojectMgr->getTestCasePrefix($guiObj->tprojectID) . config_get('testcase_cfg')->glue_character;
        $guiObj->searchSize = tlStringLen($guiObj->tcasePrefix) + $cfg->dynamic_quick_tcase_search_input_size;
        $guiObj->tplanSet = $userObj->getAccessibleTestPlans($dbHandler, $guiObj->tprojectID);
        $guiObj->tplanCount = sizeof($guiObj->tplanSet);
        if ($guiObj->tplanID == 0) {
            $guiObj->tplanID = $guiObj->tplanSet[0]['id'];
            $guiObj->tplanSet[0]['selected'] = 1;
        }
    }
    return array($argsObj, $guiObj);
}
Exemple #13
0
/**
 * write execution result to DB
 * 
 * @param resource &$db reference to database handler
 * @param obj &$exec_signature object with tproject_id,tplan_id,build_id,platform_id,user_id
 * 
 * @internal revisions
 * 
 */
function write_execution(&$db, &$exec_signature, &$exec_data, &$issueTracker)
{
    static $docRepo;
    if (is_null($docRepo)) {
        $docRepo = tlAttachmentRepository::create($db);
    }
    $executions_table = DB_TABLE_PREFIX . 'executions';
    $resultsCfg = config_get('results');
    $execCfg = config_get('exec_cfg');
    $db_now = $db->db_now();
    $cfield_mgr = new cfield_mgr($db);
    $cf_prefix = $cfield_mgr->get_name_prefix();
    $len_cfp = tlStringLen($cf_prefix);
    $cf_nodeid_pos = 4;
    $bulk_notes = '';
    $ENABLED = 1;
    $cf_map = $cfield_mgr->get_linked_cfields_at_execution($exec_signature->tproject_id, $ENABLED, 'testcase');
    $has_custom_fields = is_null($cf_map) ? 0 : 1;
    // extract custom fields id.
    $map_nodeid_array_cfnames = null;
    foreach ($exec_data as $input_name => $value) {
        if (strncmp($input_name, $cf_prefix, $len_cfp) == 0) {
            $dummy = explode('_', $input_name);
            $map_nodeid_array_cfnames[$dummy[$cf_nodeid_pos]][] = $input_name;
        }
    }
    if (isset($exec_data['do_bulk_save'])) {
        // create structure to use common algoritm
        $item2loop = $exec_data['status'];
        $is_bulk_save = 1;
        $bulk_notes = $db->prepare_string(trim($exec_data['bulk_exec_notes']));
        $execStatusKey = 'status';
    } else {
        $item2loop = $exec_data['save_results'];
        $is_bulk_save = 0;
        $execStatusKey = 'statusSingle';
    }
    $addIssueOp = array('createIssue' => null, 'issueForStep' => null);
    foreach ($item2loop as $tcversion_id => $val) {
        $tcase_id = $exec_data['tc_version'][$tcversion_id];
        $current_status = $exec_data[$execStatusKey][$tcversion_id];
        $version_number = $exec_data['version_number'][$tcversion_id];
        $has_been_executed = $current_status != $resultsCfg['status_code']['not_run'] ? TRUE : FALSE;
        if ($has_been_executed) {
            $my_notes = $is_bulk_save ? $bulk_notes : $db->prepare_string(trim($exec_data['notes'][$tcversion_id]));
            $sql = "INSERT INTO {$executions_table} " . "(build_id,tester_id,status,testplan_id,tcversion_id," . " execution_ts,notes,tcversion_number,platform_id,execution_duration)" . " VALUES ( {$exec_signature->build_id}, {$exec_signature->user_id}, '{$exec_data[$execStatusKey][$tcversion_id]}'," . "{$exec_signature->tplan_id}, {$tcversion_id},{$db_now},'{$my_notes}'," . "{$version_number},{$exec_signature->platform_id}";
            $dura = 'NULL ';
            if (isset($exec_data['execution_duration'])) {
                if (trim($exec_data['execution_duration']) == '') {
                    $dura = 'NULL ';
                } else {
                    $dura = floatval($exec_data['execution_duration']);
                }
            }
            $sql .= ',' . $dura . ")";
            $db->exec_query($sql);
            // at least for Postgres DBMS table name is needed.
            $execution_id = $db->insert_id($executions_table);
            $execSet[$tcversion_id] = $execution_id;
            if ($has_custom_fields) {
                // test useful when doing bulk update, because some type of custom fields
                // like checkbox can not exist on exec_data. => why ??
                //
                $hash_cf = null;
                $access_key = $is_bulk_save ? 0 : $tcase_id;
                if (isset($map_nodeid_array_cfnames[$access_key])) {
                    foreach ($map_nodeid_array_cfnames[$access_key] as $cf_v) {
                        $hash_cf[$cf_v] = $exec_data[$cf_v];
                    }
                }
                $cfield_mgr->execution_values_to_db($hash_cf, $tcversion_id, $execution_id, $exec_signature->tplan_id, $cf_map);
            }
            $hasMoreData = new stdClass();
            $hasMoreData->step_notes = isset($exec_data['step_notes']);
            $hasMoreData->step_status = isset($exec_data['step_status']);
            $hasMoreData->nike = $execCfg->steps_exec && ($hasMoreData->step_notes || $hasMoreData->step_status);
            if ($hasMoreData->nike) {
                $target = DB_TABLE_PREFIX . 'execution_tcsteps';
                $key2loop = array_keys($exec_data['step_notes']);
                foreach ($key2loop as $step_id) {
                    $doIt = !is_null($exec_data['step_notes'][$step_id]) && trim($exec_data['step_notes'][$step_id]) != '' || $exec_data['step_status'][$step_id] != $resultsCfg['status_code']['not_run'];
                    if ($doIt) {
                        $sql = " INSERT INTO {$target} (execution_id,tcstep_id,notes";
                        $values = " VALUES ( {$execution_id}, {$step_id}," . "'" . $db->prepare_string($exec_data['step_notes'][$step_id]) . "'";
                        $status = strtolower(trim($exec_data['step_status'][$step_id]));
                        $status = $status[0];
                        if ($status != $resultsCfg['status_code']['not_run']) {
                            $sql .= ",status";
                            $values .= ",'" . $db->prepare_string($status) . "'";
                        }
                        $sql .= ") " . $values . ")";
                        $db->exec_query($sql);
                        $execution_tcsteps_id = $db->insert_id($target);
                        // NOW MANAGE attachments
                        if (isset($_FILES['uploadedFile']['name'][$step_id]) && !is_null($_FILES['uploadedFile']['name'][$step_id])) {
                            $repOpt = array('allow_empty_title' => TRUE);
                            // May be we have enabled MULTIPLE on file upload
                            if (is_array($_FILES['uploadedFile']['name'][$step_id])) {
                                $curly = count($_FILES['uploadedFile']['name'][$step_id]);
                                for ($moe = 0; $moe < $curly; $moe++) {
                                    $fSize = isset($_FILES['uploadedFile']['size'][$step_id][$moe]) ? $_FILES['uploadedFile']['size'][$step_id][$moe] : 0;
                                    $fTmpName = isset($_FILES['uploadedFile']['tmp_name'][$step_id][$moe]) ? $_FILES['uploadedFile']['tmp_name'][$step_id][$moe] : '';
                                    if ($fSize && $fTmpName != "") {
                                        $fk2loop = array_keys($_FILES['uploadedFile']);
                                        foreach ($fk2loop as $tk) {
                                            $fInfo[$tk] = $_FILES['uploadedFile'][$tk][$step_id][$moe];
                                        }
                                        $uploaded = $docRepo->insertAttachment($execution_tcsteps_id, $target, '', $fInfo, $repOpt);
                                    }
                                }
                            } else {
                                $fSize = isset($_FILES['uploadedFile']['size'][$step_id]) ? $_FILES['uploadedFile']['size'][$step_id] : 0;
                                $fTmpName = isset($_FILES['uploadedFile']['tmp_name'][$step_id]) ? $_FILES['uploadedFile']['tmp_name'][$step_id] : '';
                                if ($fSize && $fTmpName != "") {
                                    $fk2loop = array_keys($_FILES['uploadedFile']);
                                    foreach ($fk2loop as $tk) {
                                        $fInfo[$tk] = $_FILES['uploadedFile'][$tk][$step_id];
                                    }
                                    $uploaded = $docRepo->insertAttachment($execution_tcsteps_id, $target, '', $fInfo);
                                }
                            }
                        }
                    }
                }
            }
            $itCheckOK = !is_null($issueTracker) && method_exists($issueTracker, 'addIssue');
            // re-init
            $addIssueOp = array('createIssue' => null, 'issueForStep' => null);
            if ($itCheckOK) {
                $execContext = new stdClass();
                $execContext->exec_id = $execution_id;
                $execContext->tcversion_id = $tcversion_id;
                $execContext->user = $exec_signature->user;
                $execContext->basehref = $exec_signature->basehref;
                $execContext->tplan_apikey = $exec_signature->tplan_apikey;
                // Issue on Test Case
                if (isset($exec_data['createIssue'])) {
                    completeCreateIssue($execContext, $exec_signature);
                    $addIssueOp['createIssue'] = addIssue($db, $execContext, $issueTracker);
                }
                // Issues at step level
                if (isset($exec_data['issueForStep'])) {
                    foreach ($exec_data['issueForStep'] as $stepID => $val) {
                        completeIssueForStep($execContext, $exec_signature, $exec_data, $stepID);
                        $addIssueOp['issueForStep'][$stepID] = addIssue($db, $execContext, $issueTracker, $stepID);
                    }
                }
            }
            // $itCheckOK
        }
    }
    return array($execSet, $addIssueOp);
}
Exemple #14
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;
}
Exemple #15
0
 /**
  * Returns the bug summary in a human redable format, cutted down to 45 chars
  *
  * @return string returns the summary (in readable form) of the given bug
  *
  * @version 1.0
  * @author Raphael Bosshard
  * @author Arjen van Summeren
  * @since 28.09.2005, 16:06:25
  **/
 function getBugSummaryString($id)
 {
     if (!$this->isConnected()) {
         return null;
     }
     $status = null;
     $query = "SELECT short_desc FROM {$this->dbSchema}.bugs WHERE bug_id='" . $id . "'";
     $result = $this->dbConnection->exec_query($query);
     $summary = null;
     if ($result) {
         $summary = $this->dbConnection->fetch_array($result);
         if ($summary) {
             $summary = array_pop($summary);
             if (tlStringLen($summary) > 45) {
                 $summary = tlSubStr($summary, 0, 42) . "...";
             }
         } else {
             $summary = null;
         }
     }
     return $summary;
 }
 /** @TODO add description */
 function formatTcPrefix($str)
 {
     // limit tcasePrefix len.
     $fstr = trim($str);
     if (tlStringLen($fstr) > self::TESTCASE_PREFIX_MAXLEN) {
         $tcprefix = substr($fstr, self::TESTCASE_PREFIX_MAXLEN);
     }
     return $fstr;
 }
 /**
  * @param string $value the string which should be validated
  * @return bool returns true if the value was successfully validated, else throws an Exception
  */
 public function validate($value)
 {
     $minLen = $this->minLen;
     if ($minLen && tlStringLen($value) < $minLen) {
         $msg = "Input parameter validation failed [minLen: " . tlStringLen($value) . " {$minLen}]";
         tLog($msg, 'ERROR');
         throw new Exception($msg);
     }
     $regExp = $this->regExp;
     if ($regExp) {
         $dummy = null;
         if (!preg_match($regExp, $value, $dummy)) {
             $msg = "Input parameter validation failed [regExp: " . htmlspecialchars($value) . " " . htmlspecialchars($regExp) . "]";
             tLog($msg, 'ERROR');
             throw new Exception($msg);
         }
     }
     $pfnValidation = $this->pfnValidation;
     if ($pfnValidation) {
         if (!$pfnValidation($value)) {
             $msg = "Input parameter validation failed [external function" . " - {$pfnValidation}]";
             tLog($msg, 'ERROR');
             throw new Exception($msg);
         }
     }
     return true;
 }
Exemple #18
0
 function create_tcase_only($parent_id, $name, $order = self::DEFAULT_ORDER, $id = self::AUTOMATIC_ID, $options = null)
 {
     $dummy = config_get('field_size');
     $name_max_len = $dummy->testcase_name;
     $name = trim($name);
     $originalNameLen = tlStringLen($name);
     $getOptions = array();
     $ret = array('id' => -1, 'external_id' => 0, 'status_ok' => 1, 'msg' => 'ok', 'new_name' => '', 'version_number' => 1, 'has_duplicate' => false);
     $my['options'] = array('check_duplicate_name' => self::DONT_CHECK_DUPLICATE_NAME, 'action_on_duplicate_name' => 'generate_new');
     $my['options'] = array_merge($my['options'], (array) $options);
     $doCreate = true;
     if ($my['options']['check_duplicate_name']) {
         $algo_cfg = config_get('testcase_cfg')->duplicated_name_algorithm;
         $getOptions['check_criteria'] = $algo_cfg->type == 'counterSuffix' ? 'like' : '=';
         $getOptions['access_key'] = $algo_cfg->type == 'counterSuffix' ? 'name' : 'id';
         $itemSet = $this->getDuplicatesByName($name, $parent_id, $getOptions);
         if (!is_null($itemSet) && ($siblingQty = count($itemSet)) > 0) {
             $ret['has_duplicate'] = true;
             switch ($my['options']['action_on_duplicate_name']) {
                 case 'block':
                     $doCreate = false;
                     $ret['status_ok'] = 0;
                     $ret['msg'] = sprintf(lang_get('testcase_name_already_exists'), $name);
                     break;
                 case 'generate_new':
                     $doCreate = true;
                     switch ($algo_cfg->type) {
                         case 'stringPrefix':
                             $name = $algo_cfg->text . " " . $name;
                             $final_len = strlen($name);
                             if ($final_len > $name_max_len) {
                                 $name = substr($name, 0, $name_max_len);
                             }
                             break;
                         case 'counterSuffix':
                             $mask = !is_null($algo_cfg->text) ? $algo_cfg->text : '#%s';
                             $nameSet = array_flip(array_keys($itemSet));
                             $target = $name . ($suffix = sprintf($mask, ++$siblingQty));
                             // BUGID 3367
                             $final_len = strlen($target);
                             if ($final_len > $name_max_len) {
                                 $target = substr($target, strlen($suffix), $name_max_len);
                             }
                             // Need to recheck if new generated name does not crash with existent name
                             // why? Suppose you have created:
                             // TC [1]
                             // TC [2]
                             // TC [3]
                             // Then you delete TC [2].
                             // When I got siblings  il will got 2 siblings, if I create new progressive using next,
                             // it will be 3 => I will get duplicated name.
                             while (isset($nameSet[$target])) {
                                 $target = $name . ($suffix = sprintf($mask, ++$siblingQty));
                                 // BUGID 3367
                                 $final_len = strlen($target);
                                 if ($final_len > $name_max_len) {
                                     $target = substr($target, strlen($suffix), $name_max_len);
                                 }
                             }
                             $name = $target;
                             break;
                     }
                     $ret['status_ok'] = 1;
                     $ret['new_name'] = $name;
                     $ret['msg'] = sprintf(lang_get('created_with_title'), $name);
                     break;
                 case 'create_new_version':
                     $doCreate = false;
                     // If we found more that one with same name and same parent,
                     // will take the first one.
                     // BUGID 3374
                     $xx = current($itemSet);
                     $ret['id'] = $xx['id'];
                     $ret['external_id'] = $xx['tc_external_id'];
                     $ret['status_ok'] = 1;
                     $ret['new_name'] = $name;
                     $ret['version_number'] = -1;
                     $ret['msg'] = lang_get('create_new_version');
                     break;
                 default:
                     break;
             }
         }
     }
     if ($ret['status_ok'] && $doCreate) {
         $safeLenName = tlSubStr($name, 0, $name_max_len);
         // Get tproject id
         $path2root = $this->tree_manager->get_path($parent_id);
         $tproject_id = $path2root[0]['parent_id'];
         $tcaseNumber = $this->tproject_mgr->generateTestCaseNumber($tproject_id);
         $tcase_id = $this->tree_manager->new_node($parent_id, $this->my_node_type, $safeLenName, $order, $id);
         $ret['id'] = $tcase_id;
         $ret['external_id'] = $tcaseNumber;
         if (!$ret['has_duplicate'] && $originalNameLen > $name_max_len) {
             $ret['new_name'] = $safeLenName;
             $ret['msg'] = sprintf(lang_get('testcase_name_length_exceeded'), $originalNameLen, $name_max_len);
         }
     }
     return $ret;
 }
Exemple #19
0
/**
 */
function initEnvironment(&$dbHandler, &$userObj)
{
    $argsObj = new stdClass();
    $guiObj = new stdClass();
    $cfg = config_get("gui");
    $tprojectMgr = new testproject($dbHandler);
    $_REQUEST = strings_stripSlashes($_REQUEST);
    $iParams = array("tprojectIDNavBar" => array(tlInputParameter::INT_N), "tproject_id" => array(tlInputParameter::INT_N), "tplan_id" => array(tlInputParameter::INT_N), "testplan" => array(tlInputParameter::INT_N), "updateMainPage" => array(tlInputParameter::INT_N), "runUpdateLogic" => array(tlInputParameter::INT_N));
    R_PARAMS($iParams, $argsObj);
    // @TODO in future refactor tlInput logic to allow pass default value
    $argsObj->updateMainPage = is_null($argsObj->updateMainPage) ? 0 : $argsObj->updateMainPage;
    $argsObj->runUpdateLogic = is_null($argsObj->runUpdateLogic) ? 1 : $argsObj->runUpdateLogic;
    $argsObj->updateMainPage = intval($argsObj->updateMainPage);
    $guiObj->tcasePrefix = '';
    $guiObj->tplanCount = 0;
    $guiObj->tprojectSet = $tprojectMgr->get_accessible_for_user($userObj->dbID);
    $guiObj->tprojectCount = sizeof($guiObj->tprojectSet);
    // -----------------------------------------------------------------------------------------------------
    // Important Logic
    // -----------------------------------------------------------------------------------------------------
    // only when the user has changed test project using the combo in NavBar.tpl this key is present
    // Use this clue to launch a refresh of other frames present on the screen
    // using the onload HTML body attribute
    $argsObj->tprojectIDNavBar = intval($argsObj->tprojectIDNavBar);
    $argsObj->tproject_id = intval($argsObj->tproject_id);
    $guiObj->updateMainPage = $argsObj->updateMainPage;
    if ($guiObj->updateMainPage == 0 && $argsObj->runUpdateLogic) {
        $guiObj->updateMainPage = $argsObj->tprojectIDNavBar > 0 ? 1 : 0;
        if ($argsObj->tprojectIDNavBar == 0 && $argsObj->tproject_id == 0) {
            // we have this situation when doing refresh on browser with something similar
            // http://localhost:8080/development/gitrepo/tlcode/index.php
            // on browser URL
            $guiObj->updateMainPage = 1;
        }
    }
    $argsObj->tproject_id = $argsObj->tproject_id > 0 ? $argsObj->tproject_id : $argsObj->tprojectIDNavBar;
    if ($argsObj->tproject_id == 0) {
        $argsObj->tproject_id = key($guiObj->tprojectSet);
    }
    $guiObj->tprojectID = $argsObj->tproject_id;
    $guiObj->tprojectOptions = null;
    $guiObj->tprojectTopMenu = null;
    if ($guiObj->tprojectID > 0) {
        $dummy = $tprojectMgr->get_by_id($guiObj->tprojectID);
        $guiObj->tprojectOptions = $dummy['opt'];
        if ($guiObj->updateMainPage) {
            setcookie('TL_lastTestProjectForUserID_' . $userObj->dbID, $guiObj->tprojectID, TL_COOKIE_KEEPTIME, '/');
        }
    }
    // -----------------------------------------------------------------------------------------------------
    $argsObj->tplan_id = intval($argsObj->tplan_id);
    $argsObj->tplan_id = $argsObj->tplan_id > 0 ? $argsObj->tplan_id : intval($argsObj->testplan);
    $guiObj->tplanID = $argsObj->tplan_id;
    // Julian: left magic here - do think this value will never be used as a project with a prefix
    //         has to be created after first login -> searchSize should be set dynamically.
    //         If any reviewer agrees on that feel free to change it.
    $guiObj->searchSize = 8;
    $reqMgmtEnabled = 0;
    if ($guiObj->tprojectID > 0) {
        $dummy = $tprojectMgr->get_by_id($guiObj->tprojectID);
        $reqMgmtEnabled = $dummy['opt']->requirementsEnabled;
        $guiObj->tcasePrefix = $dummy['prefix'] . config_get('testcase_cfg')->glue_character;
        $guiObj->searchSize = tlStringLen($guiObj->tcasePrefix) + $cfg->dynamic_quick_tcase_search_input_size;
        $guiObj->tplanSet = $userObj->getAccessibleTestPlans($dbHandler, $guiObj->tprojectID);
        $guiObj->tplanCount = sizeof($guiObj->tplanSet);
        if ($guiObj->tplanID == 0) {
            $guiObj->tplanID = $guiObj->tplanSet[0]['id'];
            $guiObj->tplanSet[0]['selected'] = 1;
        }
    }
    $guiObj->topMenu = initTopMenu($dbHandler, $userObj, $guiObj->tprojectID, $guiObj->tplanID, $reqMgmtEnabled);
    return array($argsObj, $guiObj);
}
/**
 * 
 *
 * 
 **/
function initializeGui(&$dbHandler, &$argsObj)
{
    $guiObj = new stdClass();
    $guiObj->importLimitBytes = config_get('import_file_max_size_bytes');
    $guiObj->importLimitKB = $guiObj->importLimitBytes / 1024;
    $guiObj->containerID = $argsObj->container_id;
    $guiObj->refreshTree = $guiObj->doImport = tlStringLen($argsObj->importType);
    $guiObj->resultMap = null;
    $guiObj->container_name = '';
    $guiObj->file_check = array('status_ok' => 1, 'msg' => 'ok');
    $guiObj->import_title = lang_get('title_tc_import_to');
    $guiObj->container_description = lang_get('test_case');
    $dest_common = TL_TEMP_PATH . session_id() . "-importtcs";
    $dest_files = array('XML' => $dest_common . ".xml");
    $guiObj->dest = $dest_files['XML'];
    if (!is_null($argsObj->importType)) {
        $guiObj->dest = $dest_files[$argsObj->importType];
    }
    if ($argsObj->container_id) {
        $tree_mgr = new tree($dbHandler);
        $node_info = $tree_mgr->get_node_hierarchy_info($argsObj->container_id);
        unset($tree_mgr);
        $guiObj->container_name = $node_info['name'];
        if ($argsObj->container_id == $argsObj->tproject_id) {
            $guiObj->container_description = lang_get('testproject');
        }
    }
    return $guiObj;
}
Exemple #21
0
 * internal revisions
 *
**/
require_once '../../config.inc.php';
require_once "common.php";
testlinkInitPage($db, 'initProject' == 'initProject');
$tproject_mgr = new testproject($db);
$args = init_args();
$gui = new stdClass();
$gui_cfg = config_get("gui");
$gui->tprojectID = isset($_SESSION['testprojectID']) ? $_SESSION['testprojectID'] : 0;
$gui->tcasePrefix = '';
$gui->searchSize = 8;
if ($gui->tprojectID > 0) {
    $gui->tcasePrefix = $tproject_mgr->getTestCasePrefix($gui->tprojectID) . config_get('testcase_cfg')->glue_character;
    $gui->searchSize = tlStringLen($gui->tcasePrefix) + $gui_cfg->dynamic_quick_tcase_search_input_size;
}
$gui->TestProjects = $tproject_mgr->get_accessible_for_user($args->user->dbID, array('output' => 'map_name_with_inactive_mark', 'order_by' => $tlCfg->gui->tprojects_combo_order_by));
$gui->TestProjectCount = sizeof($gui->TestProjects);
$gui->TestPlanCount = 0;
$tprojectQty = $tproject_mgr->getItemCount();
if ($gui->TestProjectCount == 0 && $tprojectQty > 0) {
    // User rights configurations does not allow access to ANY test project
    $_SESSION['testprojectTopMenu'] = '';
    $gui->tprojectID = 0;
}
if ($gui->tprojectID) {
    $testPlanSet = $args->user->getAccessibleTestPlans($db, $gui->tprojectID);
    $gui->TestPlanCount = sizeof($testPlanSet);
    $tplanID = isset($_SESSION['testplanID']) ? $_SESSION['testplanID'] : null;
    if (!is_null($tplanID)) {
Exemple #22
0
function doSaveCustomFields(&$argsObj, &$userInput, &$tplanMgr, &$tcaseMgr)
{
    // N.B.: I've use this piece of code also on write_execution(), think is time to create
    //       a method on cfield_mgr class.
    //       One issue: find a good method name
    $cf_prefix = $tcaseMgr->cfield_mgr->get_name_prefix();
    $len_cfp = tlStringLen($cf_prefix);
    $cf_nodeid_pos = 4;
    $nodeid_array_cfnames = null;
    // Example: two test cases (21 and 19 are testplan_tcversions.id => FEATURE_ID)
    //          with 3 custom fields
    //
    // custom_field_[TYPE]_[CFIELD_ID]_[FEATURE_ID]
    //
    // (
    // [21] => Array
    //     (
    //         [0] => custom_field_0_3_21
    //         [1] => custom_field_0_7_21
    //         [5] => custom_field_6_9_21
    //     )
    //
    // [19] => Array
    //     (
    //         [0] => custom_field_0_3_19
    //         [1] => custom_field_0_7_19
    //         [5] => custom_field_6_9_19
    //     )
    // )
    //
    foreach ($userInput as $input_name => $value) {
        if (strncmp($input_name, $cf_prefix, $len_cfp) == 0) {
            $dummy = explode('_', $input_name);
            $nodeid_array_cfnames[$dummy[$cf_nodeid_pos]][] = $input_name;
        }
    }
    // foreach($argsObj->linkedWithCF as $key => $link_id)
    foreach ($nodeid_array_cfnames as $link_id => $customFieldsNames) {
        // Create a SubSet of userInput just with inputs regarding CF for a link_id
        // Example for link_id=21:
        //
        // $cfvalues=( 'custom_field_0_3_21' => A
        //             'custom_field_0_7_21' =>
        //             'custom_field_8_8_21_day' => 0
        //             'custom_field_8_8_21_month' => 0
        //             'custom_field_8_8_21_year' => 0
        //             'custom_field_6_9_21_' => Every day)
        //
        $cfvalues = null;
        foreach ($customFieldsNames as $cf) {
            $cfvalues[$cf] = $userInput[$cf];
        }
        $tcaseMgr->cfield_mgr->testplan_design_values_to_db($cfvalues, null, $link_id);
    }
}
Exemple #23
0
 function create_tcase_only($parent_id, $name, $order = self::DEFAULT_ORDER, $id = self::AUTOMATIC_ID, $options = null)
 {
     $dummy = config_get('field_size');
     $name_max_len = $dummy->testcase_name;
     $name = trim($name);
     $originalNameLen = tlStringLen($name);
     $getOptions = array();
     $ret = array('id' => -1, 'external_id' => 0, 'status_ok' => 1, 'msg' => 'ok', 'new_name' => '', 'version_number' => 1, 'has_duplicate' => false, 'external_id_already_exists' => false, 'update_name' => false);
     $my['options'] = array('check_duplicate_name' => self::DONT_CHECK_DUPLICATE_NAME, 'action_on_duplicate_name' => 'generate_new', 'external_id' => null, 'importLogic' => null);
     $my['options'] = array_merge($my['options'], (array) $options);
     $doCreate = true;
     $forceGenerateExternalID = false;
     $algo_cfg = config_get('testcase_cfg')->duplicated_name_algorithm;
     $getDupOptions['check_criteria'] = $algo_cfg->type == 'counterSuffix' ? 'like' : '=';
     $getDupOptions['access_key'] = $algo_cfg->type == 'counterSuffix' ? 'name' : 'id';
     // If external ID has been provided, check if exists.
     // If answer is yes, then
     // 1. collect current info
     // 2. if $my['options']['check_duplicate_name'] is create new version
     //    change to BLOCK
     //
     if (!is_null($my['options']['importLogic'])) {
         $doQuickReturn = false;
         switch ($my['options']['importLogic']['hitCriteria']) {
             case 'externalID':
                 if (($sf = intval($my['options']['external_id'])) > 0) {
                     // check if already exists a test case with this external id
                     $info = $this->get_by_external($sf, $parent_id);
                     if (!is_null($info)) {
                         if (count($info) > 1) {
                             // abort
                             throw new Exception("More than one test case with same external ID");
                         }
                         $doQuickReturn = true;
                         $ret['id'] = key($info);
                         $ret['external_id'] = $sf;
                         $ret['version_number'] = -1;
                         $ret['external_id_already_exists'] = true;
                     }
                 }
                 switch ($my['options']['importLogic']['actionOnHit']) {
                     case 'create_new_version':
                         if ($doQuickReturn) {
                             // I this situation we will need to also update test case name, if user
                             // has provided one on import file.
                             // Then we need to check that new name will not conflict with an existing one
                             $doCreate = false;
                             if (strcmp($info['name'], $name) != 0) {
                                 $itemSet = $this->getDuplicatesByName($name, $parent_id, $getDupOptions);
                                 if (is_null($itemSet)) {
                                     $ret['name'] = $name;
                                     $ret['update_name'] = true;
                                 }
                             }
                             return $ret;
                         }
                         break;
                     case 'generate_new':
                         // on GUI => create a new test case with a different title
                         // IMPORTANT:
                         // if name provided on import file does not hit an existent one
                         // then I'm going to use it, instead of generating a NEW NAME
                         $forceGenerateExternalID = true;
                         /*
                         $itemSet = $this->getDuplicatesByName($name,$parent_id,$getDupOptions); 
                         if( is_null($itemSet) )
                         {
                           $ret['name'] = $name;
                           $ret['update_name'] = true;
                         } 
                         */
                         break;
                 }
                 /*
                 if( $my['options']['importLogic']['actionOnHit'] == 'create_new_version')
                 {
                   if( ($sf = intval($my['options']['external_id'])) > 0 )
                   {
                     $info = $this->get_by_external($sf, $parent_id);
                     if( !is_null($info))
                     {
                       if( count($info) > 1)
                       {
                         // abort
                         throw new Exception("More than one test case with same external ID");
                       }  
                 
                       $doCreate = false;
                       $ret['id'] = key($info);
                       $ret['external_id'] = $sf;
                       $ret['version_number'] = -1;
                       $ret['external_id_already_exists'] = true;
                 
                       // I this situation we will need to also update test case name.
                       // Then we need to check that new name will not conflict with an existing one
                       if( strcmp($info['name'],$name) != 0)
                       {
                         $itemSet = $this->getDuplicatesByName($name,$parent_id,$getDupOptions);  
                         if( is_null($itemSet) )
                         {
                           $ret['name'] = $name;
                           $ret['update_name'] = true;
                         }  
                       }  
                       return $ret;
                     }  
                   }  
                 }
                 */
                 break;
         }
     }
     if ($my['options']['check_duplicate_name']) {
         $itemSet = $this->getDuplicatesByName($name, $parent_id, $getDupOptions);
         if (!is_null($itemSet) && ($siblingQty = count($itemSet)) > 0) {
             $ret['has_duplicate'] = true;
             switch ($my['options']['action_on_duplicate_name']) {
                 case 'block':
                     $doCreate = false;
                     $ret['status_ok'] = 0;
                     $ret['msg'] = sprintf(lang_get('testcase_name_already_exists'), $name);
                     break;
                 case 'generate_new':
                     $doCreate = true;
                     // TICKET 5159: importing duplicate test suites
                     // Need to force use of generated External ID
                     // (this seems the best alternative)
                     $my['options']['external_id'] = null;
                     switch ($algo_cfg->type) {
                         case 'stringPrefix':
                             $name = $algo_cfg->text . " " . $name;
                             $final_len = strlen($name);
                             if ($final_len > $name_max_len) {
                                 $name = substr($name, 0, $name_max_len);
                             }
                             break;
                         case 'counterSuffix':
                             $mask = !is_null($algo_cfg->text) ? $algo_cfg->text : '#%s';
                             $nameSet = array_flip(array_keys($itemSet));
                             // 20110109 - franciscom
                             // does not understand why I've choosen time ago
                             // to increment $siblingQty before using it
                             // This way if TC X exists on target parent
                             // I will create TC X [2] insteand of TC X [1]
                             // Anyway right now I will not change.
                             $target = $name . ($suffix = sprintf($mask, ++$siblingQty));
                             $final_len = strlen($target);
                             if ($final_len > $name_max_len) {
                                 $target = substr($target, strlen($suffix), $name_max_len);
                             }
                             // Need to recheck if new generated name does not crash with existent name
                             // why? Suppose you have created:
                             // TC [1]
                             // TC [2]
                             // TC [3]
                             // Then you delete TC [2].
                             // When I got siblings  il will got 2 siblings, if I create new progressive using next,
                             // it will be 3 => I will get duplicated name.
                             while (isset($nameSet[$target])) {
                                 $target = $name . ($suffix = sprintf($mask, ++$siblingQty));
                                 $final_len = strlen($target);
                                 if ($final_len > $name_max_len) {
                                     $target = substr($target, strlen($suffix), $name_max_len);
                                 }
                             }
                             $name = $target;
                             break;
                     }
                     $ret['status_ok'] = 1;
                     $ret['new_name'] = $name;
                     $ret['msg'] = sprintf(lang_get('created_with_title'), $name);
                     break;
                 case 'create_new_version':
                     $doCreate = false;
                     // If we found more that one with same name and same parent,
                     // will take the first one.
                     $xx = current($itemSet);
                     $ret['id'] = $xx['id'];
                     $ret['external_id'] = $xx['tc_external_id'];
                     $ret['status_ok'] = 1;
                     $ret['new_name'] = $name;
                     $ret['version_number'] = -1;
                     $ret['msg'] = lang_get('create_new_version');
                     break;
                 default:
                     break;
             }
         }
     }
     // 20120822 - think we have potencial issue, because we never check if
     // duplicated EXTERNAL ID exists.
     // Right now there is no time to try a fix
     if ($ret['status_ok'] && $doCreate) {
         $safeLenName = tlSubStr($name, 0, $name_max_len);
         // Get tproject id
         $path2root = $this->tree_manager->get_path($parent_id);
         $tproject_id = $path2root[0]['parent_id'];
         $tcase_id = $this->tree_manager->new_node($parent_id, $this->my_node_type, $safeLenName, $order, $id);
         $ret['id'] = $tcase_id;
         $generateExtID = false;
         if ($forceGenerateExternalID || is_null($my['options']['external_id'])) {
             $generateExtID = true;
         } else {
             // this need more work and checks (20140209)
             $sf = intval($my['options']['external_id']);
             if (is_null($this->get_by_external($sf, $parent_id))) {
                 $ret['external_id'] = $sf;
                 // CRITIC: setTestCaseCounter() will update only if new provided value > current value
                 $this->tproject_mgr->setTestCaseCounter($tproject_id, $ret['external_id']);
             } else {
                 $generateExtID = true;
             }
         }
         if ($generateExtID) {
             $ret['external_id'] = $this->tproject_mgr->generateTestCaseNumber($tproject_id);
         }
         if (!$ret['has_duplicate'] && $originalNameLen > $name_max_len) {
             $ret['new_name'] = $safeLenName;
             $ret['msg'] = sprintf(lang_get('testcase_name_length_exceeded'), $originalNameLen, $name_max_len);
         }
     }
     return $ret;
 }
Exemple #24
0
 /**
  * Returns the bug summary in a human redable format, cutted down to 45 chars
  *
  * @return string returns the summary (in readable form) of the given bug
  *
  * @version 1.0
  * @author Raphael Bosshard
  * @author Arjen van Summeren
  * @since 28.09.2005, 16:06:25
  **/
 function getBugSummaryString($id)
 {
     if (!$this->isConnected()) {
         return null;
     }
     $status = null;
     $query = "SELECT Summary as shrt_desc FROM {$this->m_dbName}.defects WHERE DefectNum='" . $id . "' \r\n\t\tAND defects.projectid ='{$this->m_dbProjectID}'";
     $result = $this->m_dbConnection->exec_query($query);
     $summary = null;
     if ($result) {
         $summary = $this->m_dbConnection->fetch_array($result);
         if ($summary) {
             $summary = $summary[0];
             if (tlStringLen($summary) > 45) {
                 $summary = tlSubStr($summary, 0, 42) . "...";
             }
         } else {
             $summary = null;
         }
     }
     return $summary;
 }