/** * * */ function getBareBonesReq($dbHandler, $reqID) { $debugMsg = ' Function: ' . __FUNCTION__; $tables = tlObjectWithDB::getDBTables(array('requirements', 'nodes_hierarchy')); $sql = " /* {$debugMsg} */ SELECT REQ.req_doc_id, NH_REQ.name " . " FROM {$tables['requirements']} REQ " . " JOIN {$tables['nodes_hierarchy']} NH_REQ\tON NH_REQ.id = REQ.id " . " WHERE REQ.id = " . intval($reqID); $bones = $dbHandler->get_recordset($sql); return $bones[0]; }
function doExport(&$dbHandler, $filename) { $tables = tlObjectWithDB::getDBTables(array('custom_fields', 'cfield_node_types')); $adodbXML = new ADODB_XML("1.0", "ISO-8859-1"); $sql = " SELECT name,label,type,possible_values,default_value,valid_regexp, " . " length_min,length_max,show_on_design,enable_on_design,show_on_execution," . " enable_on_execution,show_on_testplan_design,enable_on_testplan_design, " . " node_type_id,required " . " FROM {$tables['custom_fields']} CF,{$tables['cfield_node_types']} " . " WHERE CF.id=field_id "; $adodbXML->setRootTagName('custom_fields'); $adodbXML->setRowTagName('custom_field'); $content = $adodbXML->ConvertToXMLString($dbHandler->db, $sql); downloadContentsToFile($content, $filename); exit; }
function doExport(&$dbHandler, $filename) { $adodbXML = new ADODB_XML("1.0", "ISO-8859-1"); $adodbXML->setRootTagName('users'); $adodbXML->setRowTagName('user'); $tables = tlObjectWithDB::getDBTables(array('users')); $fieldSet = 'id,login,role_id,email,first,last,locale,default_testproject_id,active'; $sql = " SELECT {$fieldSet} FROM {$tables['users']} "; $content = $adodbXML->ConvertToXMLString($dbHandler->db, $sql); downloadContentsToFile($content, $filename); exit; }
function doExport(&$db, $filename, $testproject_id) { $debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__; $tables = tlObjectWithDB::getDBTables(array('platforms')); $adodbXML = new ADODB_XML("1.0", "UTF-8"); $sql = "/* {$debugMsg} */ SELECT name,notes " . " FROM {$tables['platforms']} PLAT " . " WHERE PLAT.testproject_id=" . intval($testproject_id); $adodbXML->setRootTagName('platforms'); $adodbXML->setRowTagName('platform'); $content = $adodbXML->ConvertToXMLString($db->db, $sql); downloadContentsToFile($content, $filename); exit; }
public function __construct(&$dbHandler) { $this->db = $dbHandler; $this->tprojectMgr = new testproject($dbHandler); $this->tables = tlObjectWithDB::getDBTables(array('tcversions', 'nodes_hierarchy', 'testplan_tcversions', 'cfield_design_values')); $this->cfg = new stdClass(); $this->cfg->showTestCaseID = config_get('treemenu_show_testcase_id'); $this->cfg->glueChar = config_get('testcase_cfg')->glue_character; $this->cfg->nodeTypeCode = $this->tprojectMgr->tree_manager->get_available_node_types(); $this->cfg->nodeCodeType = array_flip($this->cfg->nodeTypeCode); $this->cfg->results = config_get('results'); $this->cfg->renderTestSpecNode = new stdClass(); $this->cfg->renderTestSpecNode->key2del = array_merge(array_keys($this->cfg->results['status_code']), array('node_type_id', 'parent_id', 'node_order', 'node_table', 'tcversion_id', 'external_id', 'version', 'testcase_count')); }
/** * process_req * */ function process_req(&$dbHandler, $docID, $tprojectID, $tprojectPrefix) { $tables = tlObjectWithDB::getDBTables(array('requirements', 'nodes_hierarchy', 'req_specs', 'tcversions')); $ret = array(); $ret['url'] = null; $ret['msg'] = sprintf(lang_get('req_not_found'), $docID, $tprojectPrefix); $req_mgr = new requirement_mgr($dbHandler); $req = $req_mgr->getByDocID($docID, $tprojectID); if (!is_null($req)) { // link to open in requirement frame $req = current($req); $ret['url'] = "lib/requirements/reqView.php?item=requirement&requirement_id={$req['id']}"; $cookie = buildCookie($dbHandler, $req['id'], $tprojectID, 'ys-requirement_spec'); setcookie($cookie['value'], $cookie['path'], TL_COOKIE_KEEPTIME, '/'); } return $ret; }
function drop_tables(&$dbHandler, $dbTablePrefix, $dbType) { // From 1.9 and up we have detail of tables. $schema = tlObjectWithDB::getDBTables(); // tables present on target db $my_ado = $dbHandler->get_dbmgr_object(); $tablesOnDB = $my_ado->MetaTables('TABLES'); if (count($tablesOnDB) > 0 && isset($tablesOnDB[0])) { echo "<br />Dropping all TL existent tables:<br />"; foreach ($schema as $tablePlainName => $tableFullName) { // echo 'DEBUG - $tablePlainName:' . $tablePlainName . '<br>'; // echo 'DEBUG - $tableFullName:' . $tableFullName . '<br>'; // BUGID 3654 $targetTable = $dbTablePrefix . $tablePlainName; if (in_array($targetTable, $tablesOnDB)) { // Need to add option (CASCADE ?) to delete dependent object echo "Droping {$targetTable}" . "<br />"; $sql = "DROP TABLE {$targetTable}"; $sql .= $dbType != 'mssql' ? " CASCADE " : ' '; $dbHandler->exec_query($sql); } } echo "<span class='ok'>Done!</span>"; } }
/** * Generate a filtered map with all fitting requirements in it. * * @author Andreas Simon * @param Database $db reference to database handler object * @param int $testproject_id ID of the project for which the tree shall be generated * @param testproject $testproject_mgr reference to testproject manager object * @param array $filters Filter settings which shall be applied to the tree * @param array $options Further options which shall be applied on generating the tree * @return array $filtered_map map with all fitting requirements */ function get_filtered_req_map(&$db, $testproject_id, &$testproject_mgr, $filters, $options) { $filtered_map = null; $tables = tlObjectWithDB::getDBTables(array('nodes_hierarchy', 'requirements', 'req_specs', 'req_relations', 'req_versions', 'req_coverage', 'tcversions', 'cfield_design_values')); $sql = " SELECT R.id, R.req_doc_id, NH_R.name AS title, R.srs_id, " . " RS.doc_id AS req_spec_doc_id, NH_RS.name AS req_spec_title, " . " RV.version, RV.id AS version_id, NH_R.node_order, " . " RV.expected_coverage, RV.status, RV.type, RV.active, RV.is_open " . " FROM {$tables['requirements']} R " . " JOIN {$tables['nodes_hierarchy']} NH_R ON NH_R.id = R.id " . " JOIN {$tables['nodes_hierarchy']} NH_RV ON NH_RV.parent_id = NH_R.id " . " JOIN {$tables['req_versions']} RV ON RV.id = NH_RV.id " . " JOIN {$tables['req_specs']} RS ON RS.id = R.srs_id " . " JOIN {$tables['nodes_hierarchy']} NH_RS ON NH_RS.id = RS.id "; if (isset($filters['filter_relation'])) { $sql .= " JOIN {$tables['req_relations']} RR " . " ON (RR.destination_id = R.id OR RR.source_id = R.id) "; } if (isset($filters['filter_tc_id'])) { $tc_cfg = config_get('testcase_cfg'); $tc_prefix = $testproject_mgr->getTestCasePrefix($testproject_id); $tc_prefix .= $tc_cfg->glue_character; $tc_ext_id = $db->prepare_int(str_replace($tc_prefix, '', $filters['filter_tc_id'])); $sql .= " JOIN {$tables['req_coverage']} RC ON RC.req_id = R.id " . " JOIN {$tables['nodes_hierarchy']} NH_T ON NH_T.id = RC.testcase_id " . " JOIN {$tables['nodes_hierarchy']} NH_TV on NH_TV.parent_id = NH_T.id " . " JOIN {$tables['tcversions']} TV ON TV.id = NH_TV.id " . " AND TV.tc_external_id = {$tc_ext_id} "; } if (isset($filters['filter_custom_fields'])) { $suffix = 1; foreach ($filters['filter_custom_fields'] as $cf_id => $cf_value) { $sql .= " JOIN {$tables['cfield_design_values']} CF{$suffix} " . " ON CF{$suffix}.node_id = RV.id " . " AND CF{$suffix}.field_id = {$cf_id} "; // single value or array? if (is_array($cf_value)) { $sql .= " AND ( "; $count = 1; foreach ($cf_value as $value) { if ($count > 1) { $sql .= " OR "; } $sql .= " CF{$suffix}.value LIKE '%{$value}%' "; $count++; } $sql .= " ) "; } else { $sql .= " AND CF{$suffix}.value LIKE '%{$cf_value}%' "; } $suffix++; } } $sql .= " WHERE RS.testproject_id = {$testproject_id} "; if (isset($filters['filter_doc_id'])) { $doc_id = $db->prepare_string($filters['filter_doc_id']); $sql .= " AND R.req_doc_id LIKE '%{$doc_id}%' OR RS.doc_id LIKE '%{$doc_id}%' "; } if (isset($filters['filter_title'])) { $title = $db->prepare_string($filters['filter_title']); $sql .= " AND NH_R.name LIKE '%{$title}%' "; } if (isset($filters['filter_coverage'])) { $coverage = $db->prepare_int($filters['filter_coverage']); $sql .= " AND expected_coverage = {$coverage} "; } if (isset($filters['filter_status'])) { $statuses = (array) $filters['filter_status']; foreach ($statuses as $key => $status) { $statuses[$key] = "'" . $db->prepare_string($status) . "'"; } $statuses = implode(",", $statuses); $sql .= " AND RV.status IN ({$statuses}) "; } if (isset($filters['filter_type'])) { $types = (array) $filters['filter_type']; // BUGID 3671 foreach ($types as $key => $type) { $types[$key] = $db->prepare_string($type); } $types = implode("','", $types); $sql .= " AND RV.type IN ('{$types}') "; } if (isset($filters['filter_spec_type'])) { $spec_types = (array) $filters['filter_spec_type']; // BUGID 3671 foreach ($spec_types as $key => $type) { $spec_types[$key] = $db->prepare_string($type); } $spec_types = implode("','", $spec_types); $sql .= " AND RS.type IN ('{$spec_types}') "; } if (isset($filters['filter_relation'])) { $sql .= " AND ( "; $count = 1; foreach ($filters['filter_relation'] as $key => $rel_filter) { $relation_info = explode('_', $rel_filter); $relation_type = $db->prepare_int($relation_info[0]); $relation_side = isset($relation_info[1]) ? $relation_info[1] : null; $sql .= $count == 1 ? " ( " : " OR ( "; if ($relation_side == "destination") { $sql .= " RR.destination_id = R.id "; } else { if ($relation_side == "source") { $sql .= " RR.source_id = R.id "; } else { $sql .= " (RR.destination_id = R.id OR RR.source_id = R.id) "; } } $sql .= " AND RR.relation_type = {$relation_type} ) "; $count++; } $sql .= " ) "; } $sql .= " ORDER BY RV.version DESC "; $filtered_map = $db->fetchRowsIntoMap($sql, 'id'); return $filtered_map; }
/** * * */ function initEnv(&$dbHandler) { $uaWhiteList = array(); $uaWhiteList['elements'] = array('link', 'create', 'doCreate', 'add_note'); $uaWhiteList['lenght'] = array(); foreach ($uaWhiteList['elements'] as $xmen) { $uaWhiteList['lenght'][] = strlen($xmen); } $user_action['maxLengh'] = max($uaWhiteList['lenght']); $user_action['minLengh'] = min($uaWhiteList['lenght']); $iParams = array("exec_id" => array("GET", tlInputParameter::INT_N), "bug_id" => array("REQUEST", tlInputParameter::STRING_N), "tproject_id" => array("REQUEST", tlInputParameter::INT_N), "tplan_id" => array("REQUEST", tlInputParameter::INT_N), "tcversion_id" => array("REQUEST", tlInputParameter::INT_N), "bug_notes" => array("POST", tlInputParameter::STRING_N), "issueType" => array("POST", tlInputParameter::INT_N), "issuePriority" => array("POST", tlInputParameter::INT_N), "artifactComponent" => array("POST", tlInputParameter::ARRAY_INT), "artifactVersion" => array("POST", tlInputParameter::ARRAY_INT), "user_action" => array("REQUEST", tlInputParameter::STRING_N, $user_action['minLengh'], $user_action['maxLengh'])); $args = new stdClass(); I_PARAMS($iParams, $args); if ($args->exec_id) { $_SESSION['bugAdd_execID'] = intval($args->exec_id); } else { $args->exec_id = intval(isset($_SESSION['bugAdd_execID']) ? $_SESSION['bugAdd_execID'] : 0); } $args->user = $_SESSION['currentUser']; $gui = new stdClass(); switch ($args->user_action) { case 'create': case 'doCreate': $gui->pageTitle = lang_get('create_issue'); break; case 'add_note': $gui->pageTitle = lang_get('add_issue_note'); break; case 'link': default: $gui->pageTitle = lang_get('title_bug_add'); break; } $gui->msg = ''; $gui->bug_summary = ''; $gui->tproject_id = $args->tproject_id; $gui->tplan_id = $args->tplan_id; $gui->tcversion_id = $args->tcversion_id; $gui->user_action = $args->user_action; $gui->bug_id = $args->bug_id; $gui->issueType = $args->issueType; $gui->issuePriority = $args->issuePriority; $gui->artifactVersion = $args->artifactVersion; $gui->artifactComponent = $args->artifactComponent; // ----------------------------------------------------------------------- // Special processing list($itObj, $itCfg) = getIssueTracker($dbHandler, $args, $gui); // Second access to user input $bug_summary['minLengh'] = 1; $bug_summary['maxLengh'] = $itObj->getBugSummaryMaxLength(); $inputCfg = array("bug_summary" => array("POST", tlInputParameter::STRING_N, $bug_summary['minLengh'], $bug_summary['maxLengh'])); I_PARAMS($inputCfg, $args); $args->bug_id = trim($args->bug_id); switch ($args->user_action) { case 'create': if ($args->bug_id == '' && $args->exec_id > 0) { $map = get_execution($dbHandler, $args->exec_id); $args->bug_notes = $map[0]['notes']; } break; case 'doCreate': case 'add_note': case 'link': default: break; } $gui->bug_notes = $args->bug_notes = trim($args->bug_notes); $args->basehref = $_SESSION['basehref']; $tables = tlObjectWithDB::getDBTables(array('testplans')); $sql = ' SELECT api_key FROM ' . $tables['testplans'] . ' WHERE id=' . intval($args->tplan_id); $rs = $dbHandler->get_recordset($sql); $args->tplan_apikey = $rs[0]['api_key']; return array($args, $gui, $itObj, $itCfg); }
/** * @internal revisions * 20121010 - asimon - TICKET 4353: added active/inactive filter */ function prepareTestSpecNode(&$db, &$tprojectMgr, $tprojectID, &$node, &$map_node_tccount, $filters = null, $options = null) { static $status_descr_list; static $debugMsg; static $tables; static $my; static $filtersApplied; static $decoding_info; static $tcFilterByKeywords; static $doFilterOn; if (!$tables) { $debugMsg = 'Class: ' . __CLASS__ . ' - ' . 'Method: ' . __FUNCTION__ . ' - '; $tables = tlObjectWithDB::getDBTables(array('tcversions', 'nodes_hierarchy', 'testplan_tcversions')); $decoding_info = array('node_id_descr' => array_flip($tprojectMgr->tree_manager->get_available_node_types())); $my = array(); $my['options'] = array('hideTestCases' => 0); $my['filters'] = array('keywords' => null); $my['options'] = array_merge($my['options'], (array) $options); $my['filters'] = array_merge($my['filters'], (array) $filters); if ($doFilterOn['keywords'] = !is_null($my['filters']['keywords'])) { $tcFilterByKeywords = $tprojectMgr->getTCasesFilteredByKeywords($tprojectID, $my['filters']['keywords'], $my['filters']['keywords_filter_type']); if (is_null($tcFilterByKeywords)) { // tree will be empty $node = null; $tcase_counters['testcase_count'] = 0; return $tcase_counters; } } // Critic for logic that prune empty branches // TICKET 4353: added active/inactive filter $filtersApplied = $doFilterOn['keywords'] || $my['options']['ignoreInactiveTestCases'] || $my['options']['ignoreActiveTestCases']; } $tcase_counters['testcase_count'] = 0; $node_type = isset($node['node_type_id']) ? $decoding_info['node_id_descr'][$node['node_type_id']] : null; if ($node_type == 'testcase') { $remove_node = false; if ($my['options']['ignoreInactiveTestCases']) { $sql = " SELECT COUNT(TCV.id) AS count_active_versions " . " FROM {$tables['tcversions']} TCV, {$tables['nodes_hierarchy']} NH " . " WHERE NH.parent_id=" . $node['id'] . " AND NH.id = TCV.id AND TCV.active=1"; $result = $db->exec_query($sql); $row = $db->fetch_array($result); if ($row['count_active_versions'] == 0) { $remove_node = true; } } else { if ($my['options']['ignoreActiveTestCases']) { $sql = " SELECT COUNT(TCV.id) AS count_active_versions " . " FROM {$tables['tcversions']} TCV, {$tables['nodes_hierarchy']} NH " . " WHERE NH.parent_id=" . $node['id'] . " AND NH.id = TCV.id AND TCV.active=1"; $result = $db->exec_query($sql); $row = $db->fetch_array($result); if ($row['count_active_versions'] != 0) { $remove_node = true; } } } if ($my['options']['hideTestCases'] || $remove_node || $doFilterOn['keywords'] && !isset($tcFilterByKeywords[$node['id']])) { $node = null; } else { // needed to avoid problems when using json_encode with EXTJS unset($node['childNodes']); $node['leaf'] = true; $tcase_counters['testcase_count'] = 1; } } // if($node_type == 'testcase') // ================================================================================ if (!is_null($node) && isset($node['childNodes']) && is_array($node['childNodes'])) { // node has to be a Test Suite ? $childNodes =& $node['childNodes']; $childNodesQty = count($childNodes); //$pos2unset = array(); for ($idx = 0; $idx < $childNodesQty; $idx++) { $current =& $childNodes[$idx]; // I use set an element to null to filter out leaf menu items if (is_null($current)) { continue; } $counters_map = prepareTestSpecNode($db, $tprojectMgr, $tprojectID, $current, $map_node_tccount); // 20120831 - to be analized carefully, because this can be solution // to null issue with json and ext-js // if( is_null($current) ) // { // echo 'TO NULX'; // unset($childNodes[$idx]); // } $tcase_counters['testcase_count'] += $counters_map['testcase_count']; } //new dBug($pos2unset); $node['testcase_count'] = $tcase_counters['testcase_count']; if (isset($node['id'])) { $map_node_tccount[$node['id']] = array('testcount' => $node['testcase_count'], 'name' => $node['name']); } // node must be destroyed if empty had we have using filtering conditions if ($filtersApplied && !$tcase_counters['testcase_count'] && $node_type != 'testproject') { $node = null; } } else { if ($node_type == 'testsuite') { // does this means is an empty test suite ??? - franciscom 20080328 $map_node_tccount[$node['id']] = array('testcount' => 0, 'name' => $node['name']); // If is an EMPTY Test suite and we have added filtering conditions, // We will destroy it. if ($filtersApplied) { $node = null; } } } return $tcase_counters; }
/** * * */ function display_children($dbHandler, $root_node, $parent, $filter_node, $tcprefix, $show_tcases = 1, $operation = 'manage', $helpText = array()) { static $showTestCaseID; $tables = tlObjectWithDB::getDBTables(array('tcversions', 'nodes_hierarchy', 'node_types')); $forbidden_parent = array('testproject' => 'none', 'testcase' => 'testproject', 'testsuite' => 'none'); $external = ''; $nodes = null; $filter_node_type = $show_tcases ? '' : ",'testcase'"; switch ($operation) { case 'print': $js_function = array('testproject' => 'TPROJECT_PTP', 'testsuite' => 'TPROJECT_PTS', 'testcase' => 'TPROJECT_PTS'); break; case 'manage': default: $js_function = array('testproject' => 'EP', 'testsuite' => 'ETS', 'testcase' => 'ET'); break; } $sql = " SELECT NHA.*, NT.description AS node_type " . " FROM {$tables['nodes_hierarchy']} NHA, {$tables['node_types']} NT " . " WHERE NHA.node_type_id = NT.id " . " AND parent_id = " . intval($parent) . " AND NT.description NOT IN " . " ('testcase_version','testplan','requirement_spec','requirement'{$filter_node_type}) "; if (!is_null($filter_node) && $filter_node > 0 && $parent == $root_node) { $sql .= " AND NHA.id = " . intval($filter_node); } $sql .= " ORDER BY NHA.node_order "; // for debug //file_put_contents('/tmp/sql_display_node.txt', $sql); $nodeSet = $dbHandler->get_recordset($sql); if ($show_tcases) { // Get external id, used on test case nodes $sql = " SELECT DISTINCT tc_external_id,NHA.parent_id " . " FROM {$tables['tcversions']} TCV " . " JOIN {$tables['nodes_hierarchy']} NHA ON NHA.id = TCV.id " . " JOIN {$tables['nodes_hierarchy']} NHB ON NHA.parent_id = NHB.id " . " WHERE NHB.parent_id = " . intval($parent) . " AND NHA.node_type_id = 4"; $external = $dbHandler->fetchRowsIntoMap($sql, 'parent_id'); } // print_r(array_values($nodeSet)); //file_put_contents('/tmpsql_display_node.txt', serialize(array_values($nodeSet))); if (!is_null($nodeSet)) { $tproject_mgr = new testproject($dbHandler); foreach ($nodeSet as $key => $row) { $path['text'] = htmlspecialchars($row['name']); $path['id'] = $row['id']; // this attribute/property is used on custom code on drag and drop $path['position'] = $row['node_order']; $path['leaf'] = false; $path['cls'] = 'folder'; // customs key will be accessed using node.attributes.[key name] $path['testlink_node_type'] = $row['node_type']; $path['testlink_node_name'] = $path['text']; // already htmlspecialchars() done $path['forbidden_parent'] = 'none'; $tcase_qty = null; switch ($row['node_type']) { case 'testproject': // at least on Test Specification seems that we do not execute this piece of code. $path['href'] = "javascript:EP({$path['id']})"; $path['forbidden_parent'] = $forbidden_parent[$row['node_type']]; break; case 'testsuite': $tcase_qty = $tproject_mgr->count_testcases($row['id']); $path['href'] = "javascript:" . $js_function[$row['node_type']] . "({$path['id']})"; $path['forbidden_parent'] = $forbidden_parent[$row['node_type']]; break; case 'testcase': $path['href'] = "javascript:" . $js_function[$row['node_type']] . "({$path['id']})"; $path['forbidden_parent'] = $forbidden_parent[$row['node_type']]; if (is_null($showTestCaseID)) { $showTestCaseID = config_get('treemenu_show_testcase_id'); } if ($showTestCaseID) { $path['text'] = htmlspecialchars($tcprefix . $external[$row['id']]['tc_external_id'] . ":") . $path['text']; } $path['leaf'] = true; break; } if (!is_null($tcase_qty)) { $path['text'] .= " ({$tcase_qty})"; } switch ($row['node_type']) { case 'testproject': case 'testsuite': if (isset($helpText[$row['node_type']])) { $path['text'] = '<span title="' . $helpText[$row['node_type']] . '">' . $path['text'] . '</span>'; } break; } $nodes[] = $path; } } return $nodes; }
function check_exec_values(&$db, &$tcase_mgr, &$user_mgr, $tcaseCfg, $execValues, &$columnDef) { $tables = tlObjectWithDB::getDBTables(array('users', 'execution_bugs')); $checks = array('status_ok' => false, 'tcase_id' => 0, 'tester_id' => 0, 'msg' => array()); $tcase_id = $execValues['tcase_id']; $tcase_external_id = trim($execValues['tcase_external_id']); // external_id has precedence over internal id $using_external_id = $tcase_external_id != ""; if ($using_external_id) { // need to get internal id $checks['tcase_id'] = $tcase_mgr->getInternalID($tcase_external_id, $tcaseCfg->glue_character); $checks['status_ok'] = intval($checks['tcase_id']) > 0 ? true : false; if (!$checks['status_ok']) { $checks['msg'][] = sprintf(lang_get('tcase_external_id_do_not_exists'), $tcase_external_id); } } else { // before using internal id, I want to check it's a number $checks['tcase_id'] = $tcase_id; $checks['status_ok'] = intval($checks['tcase_id']) > 0 ? true : false; if (!$checks['status_ok']) { $checks['msg'][] = sprintf(lang_get('tcase_id_is_not_number'), $tcase_id); } } if ($checks['status_ok']) { // useful for user feedback $identity = $using_external_id ? $tcase_external_id : $checks['tcase_id']; } if ($checks['status_ok'] && $execValues['timestamp'] != '') { $checks['status_ok'] = isValidISODateTime($execValues['timestamp']); if (!$checks['status_ok']) { $checks['msg'][] = sprintf(lang_get('invalid_execution_timestamp'), $identity, $execValues['timestamp']); } } if ($checks['status_ok'] && $execValues['tester'] != '') { $sql = "SELECT id,login FROM {$tables['users']} WHERE login ='******'tester']) . "'"; $userInfo = $db->get_recordset($sql); if (!is_null($userInfo) && isset($userInfo[0]['id'])) { $checks['tester_id'] = $userInfo[0]['id']; } else { $checks['status_ok'] = false; $checks['msg'][] = sprintf(lang_get('invalid_tester'), $identity, $execValues['tester']); } } // BUGID 3331 $execValues['bug_id'] = isset($execValues['bug_id']) ? trim((string) $execValues['bug_id']) : ''; if ($checks['status_ok'] && $execValues['bug_id'] != '') { if (($field_len = strlen($execValues['bug_id'])) > $columnDef['bug_id']->max_length) { $checks['status_ok'] = false; $checks['msg'][] = sprintf(lang_get('bug_id_invalid_len'), $field_len, $columnDef['bug_id']->max_length); } } // BUGID 3543 if ($checks['status_ok'] && isset($execValues['execution_type'])) { $execDomain = $tcase_mgr->get_execution_types(); $checks['status_ok'] = isset($execDomain[$execValues['execution_type']]); if (!$checks['status_ok']) { $checks['msg'][] = sprintf(lang_get('invalid_exec_type'), $execValues['execution_type']); } } return $checks; }
$tproject_mgr = new testproject($db); $req_cfg = config_get('req_cfg'); $charset = config_get('charset'); $args = init_args(); $commandMgr = new reqSpecCommands($db, $args->tprojectID); $gui = $commandMgr->initGuiBean(); $edit_label = lang_get('requirement_spec'); $edit_icon = TL_THEME_IMG_DIR . "edit_icon.png"; $gui->main_descr = lang_get('caption_search_form_req_spec'); $gui->warning_msg = ''; $gui->path_info = null; $gui->resultSet = null; $gui->tableSet = null; $itemSet = null; if ($args->tprojectID) { $tables = tlObjectWithDB::getDBTables(array('cfield_design_values', 'nodes_hierarchy', 'req_specs', 'req_specs_revisions')); $filter = null; $join = null; // we use same approach used on requirements search => search on revisions if ($args->requirement_document_id) { $id = $db->prepare_string($args->requirement_document_id); $filter['by_id'] = " AND RSPECREV.doc_id like '%{$id}%' "; } if ($args->name) { $title = $db->prepare_string($args->name); $filter['by_name'] = " AND NHRSPEC.name like '%{$title}%' "; } if ($args->reqSpecType != "notype") { $type = $db->prepare_string($args->reqSpecType); $filter['by_type'] = " AND RSPECREV.type='{$type}' "; }
// - test plan api key: // is needed to get attacments for: // test case executions // test specifications ( access to parent data - OK!) // // What kind of attachments I've got ? $doIt = false; $attContext = $attachmentInfo['fk_table']; switch ($attContext) { case 'executions': // check apikey // 1. has to be a test plan key // 2. execution must belong to the test plan. $item = getEntityByAPIKey($db, $args->apikey, 'testplan'); if (!is_null($item)) { $tables = tlObjectWithDB::getDBTables(array('executions')); $sql = "SELECT testplan_id FROM {$tables['executions']} " . "WHERE id = " . intval($attachmentInfo['fk_id']); $rs = $db->get_recordset($sql); if (!is_null($rs)) { if ($rs['0']['testplan_id'] == $item['id']) { // GOOD ! $doIt = true; } } } break; } break; case 'GUI': default: $doIt = true;
function doUpdate(&$dbHandler, &$argsObj) { $tables = tlObjectWithDB::getDBTables('executions'); $sql = "UPDATE {$tables['executions']} " . " SET notes='" . $dbHandler->prepare_string($argsObj->notes) . "' " . " WHERE id={$argsObj->exec_id} "; $dbHandler->exec_query($sql); }
* @filesource $RCSfile: uncoveredTestCases.php,v $ * @version $Revision: 1.8 $ * @modified $Date: 2009/09/28 08:44:20 $ by $Author: franciscom $ * @author Francisco Mancardi - francisco.mancardi@gmail.com * * For a test project, list test cases that has no requirement assigned * * rev: 20081109 - franciscom - BUGID 512 * */ require_once "../../config.inc.php"; require_once "common.php"; require_once "specview.php"; testlinkInitPage($db, false, false, "checkRights"); $templateCfg = templateConfiguration(); $tables = tlObjectWithDB::getDBTables(array('req_coverage', 'nodes_hierarchy', 'tcversions', 'node_types')); $args = init_args(); $tproject_mgr = new testproject($db); // get list of available Req Specification // $reqSpec = $tproject_mgr->getOptionReqSpec($args->tproject_id); $reqSpec = $tproject_mgr->genComboReqSpec($args->tproject_id); $uncovered = null; $gui = new stdClass(); $gui->items = null; $gui->tproject_name = $args->tproject_name; $gui->has_reqspec = count($reqSpec) > 0; $gui->has_requirements = false; $gui->has_tc = false; if ($gui->has_reqspec) { // Check if at least one of these requirement spec are not empty. $reqSpecMgr = new requirement_spec_mgr($db);
/** * replace BBCode-link tagged links in req/reqspec scope with actual links * * @internal revisions: * 20100301 - asimon - added anchor and tproj parameters to tags * * @param resource $dbHandler database handle * @param string $scope text in which to replace tags with links * @param integer $tprojectID ID of testproject to which req/reqspec belongs * @return string $scope text with generated links */ function req_link_replace($dbHandler, $scope, $tprojectID) { $tree_mgr = new tree($dbHandler); $tproject_mgr = new testproject($dbHandler); $prefix = $tproject_mgr->getTestCasePrefix($tprojectID); $tables = tlObjectWithDB::getDBTables(array('requirements', 'req_specs')); $cfg = config_get('internal_links'); $string2replace = array(); $title = array(); // configure target in which link shall open // use a reasonable default value if nothing is set in config $cfg->target = isset($cfg->target) ? $cfg->target : 'popup'; switch ($cfg->target) { case 'popup': // use javascript to open popup window $string2replace['req'] = '<a href="javascript:openLinkedReqWindow(%s,\'%s\')">%s%s</a>'; $string2replace['req_spec'] = '<a href="javascript:openLinkedReqSpecWindow(%s,\'%s\')">%s%s</a>'; break; case 'window': case 'frame': // open in same frame $target = $cfg->target == 'window' ? 'target="_blank"' : 'target="_self"'; $string2replace['req'] = '<a ' . $target . ' href="lib/requirements/reqView.php?' . 'item=requirement&requirement_id=%s#%s">%s%s</a>'; $string2replace['req_spec'] = '<a ' . $target . ' href="lib/requirements/reqSpecView.php?' . 'item=req_spec&req_spec_id=%s#%s">%s%s</a>'; break; } // configure link title (first part of the generated link) // default: use item type as name (localized name for req) $title['req'] = lang_get('requirement') . ": "; // default: use short item type as name (localized name for req spec) $title['req_spec'] = lang_get('req_spec_short') . ": "; if ($cfg->req_link_title->type == 'string' && $cfg->req_link_title->value != '') { $title['req'] = lang_get($cfg->req_link_title->value); } else { if ($cfg->req_link_title->type == 'none') { $title['req'] = ''; } } // now for the req specs if ($cfg->req_spec_link_title->type == 'string' && $cfg->req_spec_link_title->value != '') { // use user-configured string as link title $title['req_spec'] = lang_get($cfg->req_spec_link_title->value); } else { if ($cfg->req_spec_link_title->type == 'none') { $title['req_spec'] = ''; } } // now the actual replacing $patterns2search = array(); $patterns2search['req'] = "#\\[req[\\s]*(tproj=([\\w]+))*[\\s]*(anchor=([\\w]+))*[\\s]*(tproj=([\\w]+))*\\](.*)\\[/req\\]#iU"; $patterns2search['req_spec'] = "#\\[req_spec[\\s]*(tproj=([\\w]+))*[\\s]*(anchor=([\\w]+))*[\\s]*(tproj=([\\w]+))*\\](.*)\\[/req_spec\\]#iU"; $sql2exec = array(); $sql2exec['req'] = " SELECT id, req_doc_id AS doc_id " . " FROM {$tables['requirements']} WHERE req_doc_id="; $sql2exec['req_spec'] = " SELECT id, doc_id FROM {$tables['req_specs']} " . " WHERE doc_id="; foreach ($patterns2search as $accessKey => $pattern) { $matches = array(); preg_match_all($pattern, $scope, $matches); if (count($matches[7]) == 0) { continue; } foreach ($matches[0] as $key => $matched_string) { // get testproject prefix, if that was found with regex // if not, get prefix of current project if ($matches[2][$key] != '') { $matched_prefix = $matches[2][$key]; } else { if ($matches[6][$key] != '') { $matched_prefix = $matches[6][$key]; } else { $matched_prefix = $prefix; } } $matched_anchor = $matches[4][$key]; $matched_doc_id = $matches[7][$key]; $sql = $sql2exec[$accessKey] . "'{$matched_doc_id}'"; $rs = $dbHandler->get_recordset($sql); if (count($rs)) { //20100818 - Julian - fixed error if same doc_id exists in multiple projects foreach ($rs as $key => $value) { // get root of linked node and check $real_root = $tree_mgr->getTreeRoot($value['id']); $matched_root_info = $tproject_mgr->get_by_prefix($matched_prefix); if ($real_root == $matched_root_info['id']) { $urlString = sprintf($string2replace[$accessKey], $value['id'], $matched_anchor, $title[$accessKey], $value['doc_id']); $scope = str_replace($matched_string, $urlString, $scope); } } } } } return $scope; }
$charset = config_get('charset'); $commandMgr = new reqCommands($db); $gui = $commandMgr->initGuiBean(); $gui->main_descr = lang_get('caption_search_form_req'); $gui->warning_msg = ''; $gui->path_info = null; $gui->resultSet = null; $gui->tableSet = null; $edit_label = lang_get('requirement'); $edit_icon = TL_THEME_IMG_DIR . "edit_icon.png"; $map = null; $args = init_args(); $gui->tcasePrefix = $tproject_mgr->getTestCasePrefix($args->tprojectID); $gui->tcasePrefix .= $tcase_cfg->glue_character; if ($args->tprojectID) { $tables = tlObjectWithDB::getDBTables(array('cfield_design_values', 'nodes_hierarchy', 'req_specs', 'req_relations', 'req_versions', 'requirements', 'req_coverage', 'tcversions')); $filter = null; $from = array('by_custom_field' => null, 'by_relation_type' => null, 'by_tcid' => null); if ($args->requirement_document_id) { //search by id $id = $db->prepare_string($args->requirement_document_id); $filter['by_id'] = " AND REQ.req_doc_id like '%{$id}%'"; } if ($args->name) { //search by name/title $title = $db->prepare_string($args->name); $filter['by_name'] = " AND NHP.name like '%{$title}%' "; } if ($args->version) { //search by version $version = $db->prepare_int($args->version);
function display_children($dbHandler, $root_node, $parent, $filter_node, $show_children = ON, $operation = 'manage', $mode = 'reqspec') { $tables = tlObjectWithDB::getDBTables(array('requirements', 'nodes_hierarchy', 'node_types', 'req_specs')); $cfg = config_get('req_cfg'); $forbidden_parent['testproject'] = 'none'; $forbidden_parent['requirement'] = 'testproject'; $forbidden_parent['requirement_spec'] = 'requirement_spec'; if ($cfg->child_requirements_mgmt) { $forbidden_parent['requirement_spec'] = 'none'; } $fn = array(); $fn['print']['reqspec'] = array('testproject' => 'TPROJECT_PTP_RS', 'requirement_spec' => 'TPROJECT_PRS', 'requirement' => 'openLinkedReqWindow'); $fn['manage']['reqspec'] = array('testproject' => 'TPROJECT_REQ_SPEC_MGMT', 'requirement_spec' => 'REQ_SPEC_MGMT', 'requirement' => 'REQ_MGMT'); $fn['print']['addtc'] = array('testproject' => 'TPROJECT_PTP', 'requirement_spec' => 'TPROJECT_PRS', 'requirement' => 'TPROJECT_PRS'); $fn['manage']['addtc'] = array('testproject' => 'EP', 'requirement_spec' => 'ERS', 'requirement' => 'ER'); switch ($operation) { case 'print': case 'manage': $js_function = $fn[$operation][$mode]; break; default: $js_function = $fn['manage'][$mode]; break; } $nodes = null; $filter_node_type = $show_children ? '' : ",'requirement'"; $sql = " SELECT NHA.*, NT.description AS node_type, RSPEC.doc_id " . " FROM {$tables['nodes_hierarchy']} NHA JOIN {$tables['node_types']} NT " . " ON NHA.node_type_id=NT.id " . " AND NT.description NOT IN " . " ('testcase','testsuite','testcase_version','testplan','requirement_spec_revision' {$filter_node_type}) " . " LEFT OUTER JOIN {$tables['req_specs']} RSPEC " . " ON RSPEC.id = NHA.id " . " WHERE NHA.parent_id = " . intval($parent); if (!is_null($filter_node) && $filter_node > 0 && $parent == $root_node) { $sql .= " AND NHA.id = " . intval($filter_node); } $sql .= " ORDER BY NHA.node_order "; $nodeSet = $dbHandler->get_recordset($sql); if (!is_null($nodeSet)) { $sql = " SELECT DISTINCT req_doc_id AS doc_id,NHA.id" . " FROM {$tables['requirements']} REQ JOIN {$tables['nodes_hierarchy']} NHA ON NHA.id = REQ.id " . " JOIN {$tables['nodes_hierarchy']} NHB ON NHA.parent_id = NHB.id " . " JOIN {$tables['node_types']} NT ON NT.id = NHA.node_type_id " . " WHERE NHB.id = " . intval($parent) . " AND NT.description = 'requirement'"; $requirements = $dbHandler->fetchRowsIntoMap($sql, 'id'); $treeMgr = new tree($dbHandler); $ntypes = $treeMgr->get_available_node_types(); $peerTypes = array('target' => $ntypes['requirement'], 'container' => $ntypes['requirement_spec']); foreach ($nodeSet as $key => $row) { $path['text'] = htmlspecialchars($row['name']); $path['id'] = $row['id']; // this attribute/property is used on custom code on drag and drop $path['position'] = $row['node_order']; $path['leaf'] = false; $path['cls'] = 'folder'; // Important: // We can add custom keys, and will be able to access it using // public property 'attributes' of object of Class Ext.tree.TreeNode // $path['testlink_node_type'] = $row['node_type']; $path['testlink_node_name'] = $path['text']; // already htmlspecialchars() done $path['forbidden_parent'] = 'none'; switch ($row['node_type']) { case 'testproject': $path['href'] = "javascript:EP({$path['id']})"; $path['forbidden_parent'] = $forbidden_parent[$row['node_type']]; break; case 'requirement_spec': $req_list = array(); $treeMgr->getAllItemsID($row['id'], $req_list, $peerTypes); $path['href'] = "javascript:" . $js_function[$row['node_type']] . "({$path['id']})"; $path['text'] = htmlspecialchars($row['doc_id'] . ":") . $path['text']; $path['forbidden_parent'] = $forbidden_parent[$row['node_type']]; if (!is_null($req_list)) { $item_qty = count($req_list); $path['text'] .= " ({$item_qty})"; } break; case 'requirement': $path['href'] = "javascript:" . $js_function[$row['node_type']] . "({$path['id']})"; $path['text'] = htmlspecialchars($requirements[$row['id']]['doc_id'] . ":") . $path['text']; $path['leaf'] = true; $path['forbidden_parent'] = $forbidden_parent[$row['node_type']]; break; } $nodes[] = $path; } // foreach } return $nodes; }
* * @version $Id: getreqlog.php,v 1.1.2.5 2010/12/15 21:48:13 mx-julian Exp $ * @author Francisco Mancardi * * Used on Add/Remove test case to test plan feature, to display summary via ExtJS tooltip * * @internal Revisions: */ require_once '../../config.inc.php'; require_once 'common.php'; testlinkInitPage($db); $reqMgr = new requirement_mgr($db); $item_id = isset($_REQUEST['item_id']) ? intval($_REQUEST['item_id']) : null; $info = ''; if (!is_null($item_id)) { $tables = tlObjectWithDB::getDBTables(array('req_versions', 'req_revisions')); // get item type $node_types = $reqMgr->tree_mgr->get_available_node_types(); $dummy = $reqMgr->tree_mgr->get_node_hierarchy_info($item_id); $target_table = 'req_revisions'; if ($dummy['node_type_id'] == $node_types['requirement_version']) { $target_table = 'req_versions'; } $sql = "SELECT log_message FROM {$tables[$target_table]} WHERE id=" . intval($item_id); $info = $db->get_recordset($sql); $info = nl2br($info[0]['log_message']); // <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 log message is empty show this information
/** * @param $db resource the database connecton * @param $execID integer the execution id whose notes should be set * @param $notes string the execution notes to set * @return unknown_type */ function updateExecutionNotes(&$db, $execID, $notes) { $table = tlObjectWithDB::getDBTables('executions'); $sql = "UPDATE {$table['executions']} " . "SET notes = '" . $db->prepare_string($notes) . "' " . "WHERE id = {$execID}"; return $db->exec_query($sql) ? tl::OK : tl::ERROR; }
$map_status_label = $results_config['status_label']; $map_statuscode_css = array(); foreach ($map_code_status as $code => $status) { if (isset($map_status_label[$status])) { $label = $map_status_label[$status]; $map_statuscode_css[$code] = array(); $map_statuscode_css[$code]['translation'] = lang_get($label); $map_statuscode_css[$code]['css_class'] = $map_code_status[$code] . '_text'; } } // Get all test cases created by user in the current project $options = new stdClass(); $options->mode = 'full_path'; $gui->resultSet = $tcase_mgr->get_created_per_user($args->tproject_id, $args->tplan_id, $options); if ($doIt = !is_null($gui->resultSet)) { $tables = tlObjectWithDB::getDBTables(array('nodes_hierarchy')); $tplanSet = array_keys($gui->resultSet); $sql = "SELECT name,id FROM {$tables['nodes_hierarchy']} " . "WHERE id IN (" . implode(',', $tplanSet) . ")"; $gui->tplanNames = $db->fetchRowsIntoMap($sql, 'id'); $optColumns = array('priority' => $args->priority_enabled); foreach ($gui->resultSet as $tplan_id => $tcase_set) { list($columns, $sortByColumn) = getColumnsDefinition($optColumns); $rows = array(); foreach ($tcase_set as $tcase_platform) { foreach ($tcase_platform as $tcase) { $current_row = array(); $tcase_id = $tcase['testcase_id']; $tcversion_id = $tcase['tcversion_id']; $current_row[] = htmlspecialchars($tcase['login']); $current_row[] = htmlspecialchars($tcase['tcase_full_path']); // create linked icons
$templateCfg = templateConfiguration(); $smarty = new TLSmarty(); $tpl = 'tcSearchResults.tpl'; $tproject_mgr = new testproject($db); $tcase_mgr = new testcase($db); $tcase_cfg = config_get('testcase_cfg'); $charset = config_get('charset'); $filter = null; list($args, $filter) = init_args($tproject_mgr); $ga = initializeGui($args, $tproject_mgr); $gx = $tcase_mgr->getTcSearchSkeleton($args); $gui = (object) array_merge((array) $ga, (array) $gx); initSearch($gui, $args, $tproject_mgr); $map = null; if ($args->tprojectID && $args->doAction == 'doSearch') { $tables = tlObjectWithDB::getDBTables(array('cfield_design_values', 'nodes_hierarchy', 'requirements', 'req_coverage', 'tcsteps', 'testcase_keywords', 'tcversions', 'users')); $gui->tcasePrefix = $tproject_mgr->getTestCasePrefix($args->tprojectID); $gui->tcasePrefix .= $tcase_cfg->glue_character; $from = array('by_keyword_id' => ' ', 'by_custom_field' => ' ', 'by_requirement_doc_id' => '', 'users' => ''); $tcaseID = null; $emptyTestProject = false; if ($args->targetTestCase != "" && strcmp($args->targetTestCase, $gui->tcasePrefix) != 0) { if (strpos($args->targetTestCase, $tcase_cfg->glue_character) === false) { $args->targetTestCase = $gui->tcasePrefix . $args->targetTestCase; } $tcaseID = $tcase_mgr->getInternalID($args->targetTestCase); $filter['by_tc_id'] = " AND NH_TCV.parent_id = " . intval($tcaseID); } else { $tproject_mgr->get_all_testcases_id($args->tprojectID, $a_tcid); if (!is_null($a_tcid)) { $filter['by_tc_id'] = " AND NH_TCV.parent_id IN (" . implode(",", $a_tcid) . ") ";
/** * initialize Gui */ function initializeGui(&$db, &$args, $dateFormat) { $gui = new stdClass(); $gui->glueChar = config_get('testcase_cfg')->glue_character; $gui->tproject_id = $args->tproject_id; $gui->tproject_name = $args->tproject_name; $gui->warning_msg = ''; $gui->tableSet = null; $history_img = TL_THEME_IMG_DIR . "history_small.png"; $exec_img = TL_THEME_IMG_DIR . "exec_icon.png"; $edit_img = TL_THEME_IMG_DIR . "edit_icon.png"; $l18n = init_labels(array('tcversion_indicator' => null, 'goto_testspec' => null, 'version' => null, 'testplan' => null, 'assigned_tc_overview' => null, 'testcases_created_per_user' => null, 'design' => null, 'execution' => null, 'execution_history' => null, 'low_priority' => null, 'medium_priority' => null, 'high_priority' => null)); $gui->pageTitle = sprintf($l18n['testcases_created_per_user'], $gui->tproject_name); $results_config = config_get('results'); $map_status_code = $results_config['status_code']; $map_code_status = $results_config['code_status']; $map_status_label = $results_config['status_label']; $map_statuscode_css = array(); foreach ($map_code_status as $code => $status) { if (isset($map_status_label[$status])) { $label = $map_status_label[$status]; $map_statuscode_css[$code] = array(); $map_statuscode_css[$code]['translation'] = lang_get($label); $map_statuscode_css[$code]['css_class'] = $map_code_status[$code] . '_text'; } } $options = new stdClass(); // convert starttime to iso format for database usage if (isset($args->selected_start_date) && sizeof($args->selected_start_date) > 0) { $date_array = split_localized_date($args->selected_start_date[0], $dateFormat); if ($date_array != null) { // set date in iso format $options->startTime = $date_array['year'] . "-" . $date_array['month'] . "-" . $date_array['day']; } } // convert starttime to iso format for database usage if (isset($args->selected_end_date) && sizeof($args->selected_end_date) > 0) { $date_array = split_localized_date($args->selected_end_date[0], $dateFormat); if ($date_array != null) { // set date in iso format $options->endTime = $date_array['year'] . "-" . $date_array['month'] . "-" . $date_array['day']; } } $start_hour = isset($args->start_Hour) ? $args->start_Hour : "00"; $options->startTime = $options->startTime . " " . $start_hour . ":00:00"; $end_hour = isset($args->end_Hour) ? $args->end_Hour : "00"; $options->endTime = $options->endTime . " " . $end_hour . ":59:59"; $options->mode = 'full_path'; // TBD: remove it $options->tplan_id = $args->tplan_id; // used to retrieve test cases from $tcase_mgr = new testcase($db); $gui->resultSet = $tcase_mgr->get_created_per_user($args->user_id, $args->tproject_id, $options); if (!is_null($gui->resultSet)) { $tables = tlObjectWithDB::getDBTables(array('nodes_hierarchy')); $tplanSet = array_keys($gui->resultSet); $sql = "SELECT name,id FROM {$tables['nodes_hierarchy']} " . "WHERE id IN (" . implode(',', $tplanSet) . ")"; $gui->tplanNames = $db->fetchRowsIntoMap($sql, 'id'); $optColumns = array('priority' => $args->priority_enabled); // For each test case set under a test plan ID, create the rows and columns foreach ($gui->resultSet as $tplan_id => $tcase_set) { list($columns, $sortByColumn) = getColumnsDefinition($optColumns); $rows = array(); foreach ($tcase_set as $tcase_platform) { foreach ($tcase_platform as $tcase) { $current_row = array(); $tcase_id = $tcase['testcase_id']; $tcversion_id = $tcase['tcversion_id']; $current_row[] = htmlspecialchars($tcase['login']); $current_row[] = htmlspecialchars($tcase['tcase_full_path']); // Create linked icons $exec_history_link = "<a href=\"javascript:openExecHistoryWindow({$tcase_id});\">" . "<img title=\"{$l18n['execution_history']}\" src=\"{$history_img}\" /></a> "; $edit_link = "<a href=\"javascript:openTCEditWindow({$tcase_id});\">" . "<img title=\"{$l18n['design']}\" src=\"{$edit_img}\" /></a> "; $current_row[] = "<!-- " . sprintf("%010d", $tcase['tc_external_id']) . " -->" . $exec_history_link . $edit_link . htmlspecialchars($tcase['prefix']) . $gui->glueChar . $tcase['tc_external_id'] . " : " . htmlspecialchars($tcase['name']) . sprintf($l18n['tcversion_indicator'], $tcase['version']); $last_execution = $tcase_mgr->get_last_execution($tcase_id, $tcversion_id, $tplan_id, $tcase['build_id'], $tcase['platform_id']); $status = $last_execution[$tcversion_id]['status']; if (!$status) { $status = $map_status_code['not_run']; } $current_row[] = array("value" => $status, "text" => $map_statuscode_css[$status]['translation'], "cssClass" => $map_statuscode_css[$status]['css_class']); $current_row[] = $tcase['creation_ts']; $current_row[] = $tcase['modification_ts']; // add this row to the others $rows[] = $current_row; } } // Different table ID for different reports: $table_id = "tl_table_tc_created_per_user_"; // Add test plan ID to table ID $table_id .= $tplan_id; $matrix = new tlExtTable($columns, $rows, $table_id); $matrix->title = $l18n['testplan'] . ": " . htmlspecialchars($gui->tplanNames[$tplan_id]['name']); // Default grouping by first column, which is user for overview, build otherwise $matrix->setGroupByColumnName(lang_get($columns[0]['title_key'])); // Make table collapsible if more than 1 table is shown and surround by frame if (count($tplanSet) > 1) { $matrix->collapsible = true; $matrix->frame = true; } // Define toolbar $matrix->showToolbar = true; $matrix->toolbarExpandCollapseGroupsButton = true; $matrix->toolbarShowAllColumnsButton = true; $matrix->setSortByColumnName($sortByColumn); $matrix->sortDirection = 'DESC'; $gui->tableSet[$tplan_id] = $matrix; } } return $gui; }
/** * replace BBCode-link tagged links in req/reqspec scope with actual links * * @internal revisions: * 20110525 - Julian - BUGID 4487 - allow to specify requirement version for internal links * 20100301 - asimon - added anchor and tproj parameters to tags * * @param resource $dbHandler database handle * @param string $scope text in which to replace tags with links * @param integer $tprojectID ID of testproject to which req/reqspec belongs * @return string $scope text with generated links */ function req_link_replace($dbHandler, $scope, $tprojectID) { // Use this to improve performance when is called in loops static $tree_mgr; static $tproject_mgr; static $req_mgr; static $cfg; static $l18n; static $title; static $tables; if (!$tproject_mgr) { $tproject_mgr = new testproject($dbHandler); $tree_mgr = new tree($dbHandler); $req_mgr = new requirement_mgr($dbHandler); $tables = tlObjectWithDB::getDBTables(array('requirements', 'req_specs')); $cfg = config_get('internal_links'); $l18n['version'] = lang_get('tcversion_indicator'); $prop2loop = array('req' => array('prop' => 'req_link_title', 'default_lbl' => 'requirement'), 'req_spec' => array('prop' => 'req_spec_link_title', 'default_lbl' => 'req_spec_short')); // configure link title (first part of the generated link) $title = array(); foreach ($prop2loop as $key => $elem) { $prop = $elem['prop']; if ($cfg->{$prop}->type == 'string' && $cfg->{$prop}->value != '') { $title[$key] = lang_get($cfg->{$prop}->value); } else { if ($cfg->{$prop}->type == 'none') { $title[$key] = ''; } else { $title[$key] = lang_get($elem['default_lbl']) . ": "; } } } } $prefix = $tproject_mgr->getTestCasePrefix($tprojectID); $string2replace = array(); // configure target in which link shall open // use a reasonable default value if nothing is set in config $cfg->target = isset($cfg->target) ? $cfg->target : 'popup'; switch ($cfg->target) { case 'popup': // use javascript to open popup window $string2replace['req'] = '<a href="javascript:openLinkedReqVersionWindow(%s,%s,\'%s\')">%s%s%s</a>'; $string2replace['req_spec'] = '<a href="javascript:openLinkedReqSpecWindow(%s,\'%s\')">%s%s</a>'; break; case 'window': case 'frame': // open in same frame $target = $cfg->target == 'window' ? 'target="_blank"' : 'target="_self"'; $string2replace['req'] = '<a ' . $target . ' href="lib/requirements/reqView.php?' . 'item=requirement&requirement_id=%s&req_version_id=%s#%s">%s%s%s</a>'; $string2replace['req_spec'] = '<a ' . $target . ' href="lib/requirements/reqSpecView.php?' . 'item=req_spec&req_spec_id=%s#%s">%s%s</a>'; break; } // now the actual replacing $patterns2search = array(); $patterns2search['req'] = "#\\[req(.*)\\](.*)\\[/req\\]#iU"; $patterns2search['req_spec'] = "#\\[req_spec(.*)\\](.*)\\[/req_spec\\]#iU"; $patternPositions = array('complete_string' => 0, 'attributes' => 1, 'doc_id' => 2); $items2search['req'] = array('tproj', 'anchor', 'version'); $items2search['req_spec'] = array('tproj', 'anchor'); $itemPositions = array('item' => 0, 'item_value' => 1); $sql2exec = array(); $sql2exec['req'] = " SELECT id, req_doc_id AS doc_id " . " FROM {$tables['requirements']} WHERE req_doc_id="; $sql2exec['req_spec'] = " SELECT id, doc_id FROM {$tables['req_specs']} " . " WHERE doc_id="; foreach ($patterns2search as $accessKey => $pattern) { $matches = array(); preg_match_all($pattern, $scope, $matches); // if no req_doc_id is set skip loop if (count($matches[$patternPositions['doc_id']]) == 0) { continue; } foreach ($matches[$patternPositions['complete_string']] as $key => $matched_string) { $matched = array(); $matched['tproj'] = ''; $matched['anchor'] = ''; $matched['version'] = ''; // only look for attributes if any found if ($matches[$patternPositions['attributes']][$key] != '') { foreach ($items2search[$accessKey] as $item) { $matched_item = array(); preg_match('/' . $item . '=([\\w]+)/', $matched_string, $matched_item); $matched[$item] = isset($matched_item[$itemPositions['item_value']]) ? $matched_item[$itemPositions['item_value']] : ''; } } // set tproj to current project if tproj is not specified in attributes if (!isset($matched['tproj']) || $matched['tproj'] == '') { $matched['tproj'] = $prefix; } // get all reqs / req specs with the specified doc_id $sql = $sql2exec[$accessKey] . "'{$matches[$patternPositions['doc_id']][$key]}'"; $rs = $dbHandler->get_recordset($sql); if (count($rs) > 0) { foreach ($rs as $key => $value) { // get root of linked node and check $real_root = $tree_mgr->getTreeRoot($value['id']); $matched_root_info = $tproject_mgr->get_by_prefix($matched['tproj']); // do only continue if project with the specified project exists and // if the requirement really belongs to the specified project (requirements // with the same doc_id may exist within different projects) if ($real_root == $matched_root_info['id']) { if ($accessKey == 'req') { // add version to link title if set $version = ''; $req_version_id = 'null'; if ($matched['version'] != '') { // get requirement version_id of the specified version $req_version = $req_mgr->get_by_id($value['id'], null, $matched['version']); // if version is not set or wrong version was set // -> show latest version by setting version_id to null $req_version_id = isset($req_version[0]['version_id']) ? $req_version[0]['version_id'] : 'null'; // if req_version_id exists set the version to show on hyperlink text if ($req_version_id != 'null') { $version = sprintf($l18n['version'], $matched['version']); } } $urlString = sprintf($string2replace[$accessKey], $value['id'], $req_version_id, $matched['anchor'], $title[$accessKey], $value['doc_id'], $version); } else { // build urlString for req specs which do not have a version $urlString = sprintf($string2replace[$accessKey], $value['id'], $matched['anchor'], $title[$accessKey], $value['doc_id']); } $scope = str_replace($matched_string, $urlString, $scope); } } } } } return $scope; }
function check_exec_values(&$db, &$tcase_mgr, &$user_mgr, $tcaseCfg, &$execValues, &$columnDef) { $tables = tlObjectWithDB::getDBTables(array('users', 'execution_bugs')); $checks = array('status_ok' => false, 'tcase_id' => 0, 'tester_id' => 0, 'msg' => array()); $tcase_id = $execValues['tcase_id']; $tcase_external_id = trim($execValues['tcase_external_id']); $using_external_id = $tcase_external_id != ""; // external_id has precedence over internal id if ($using_external_id) { // need to get internal id $checks['tcase_id'] = $tcase_mgr->getInternalID($tcase_external_id); $checks['status_ok'] = intval($checks['tcase_id']) > 0 ? true : false; if (!$checks['status_ok']) { $checks['msg'][] = sprintf(lang_get('tcase_external_id_do_not_exists'), $tcase_external_id); } } else { // before using internal id, I want to check it's a number $checks['tcase_id'] = $tcase_id; $checks['status_ok'] = intval($checks['tcase_id']) > 0 ? true : false; if (!$checks['status_ok']) { $checks['msg'][] = sprintf(lang_get('tcase_id_is_not_number'), $tcase_id); } } if ($checks['status_ok']) { // useful for user feedback $identity = $using_external_id ? $tcase_external_id : $checks['tcase_id']; } if ($checks['status_ok'] && $execValues['timestamp'] != '') { $checks['status_ok'] = isValidISODateTime($execValues['timestamp']); if (!$checks['status_ok']) { $checks['msg'][] = sprintf(lang_get('invalid_execution_timestamp'), $identity, $execValues['timestamp']); } } if ($checks['status_ok'] && $execValues['tester'] != '') { $sql = "SELECT id,login FROM {$tables['users']} WHERE login ='******'tester']) . "'"; $userInfo = $db->get_recordset($sql); if (!is_null($userInfo) && isset($userInfo[0]['id'])) { $checks['tester_id'] = $userInfo[0]['id']; } else { $checks['status_ok'] = false; $checks['msg'][] = sprintf(lang_get('invalid_tester'), $identity, $execValues['tester']); } } $execValues['bug_id'] = isset($execValues['bug_id']) ? $execValues['bug_id'] : null; if ($checks['status_ok'] && !is_null($execValues['bug_id']) && is_array($execValues['bug_id'])) { foreach ($execValues['bug_id'] as $bug_id) { if (($field_len = strlen(trim($bug_id))) > $columnDef['bug_id']->max_length) { $checks['msg'][] = sprintf(lang_get('bug_id_invalid_len'), $field_len, $columnDef['bug_id']->max_length); $checks['status_ok'] = false; break; } } } if ($checks['status_ok'] && isset($execValues['execution_type'])) { $execValues['execution_type'] = intval($execValues['execution_type']); $execDomain = $tcase_mgr->get_execution_types(); if ($execValues['execution_type'] == 0) { $execValues['execution_type'] = TESTCASE_EXECUTION_TYPE_MANUAL; // right now this is useless, but may be in future can be used, then I choose to leave it. $checks['msg'][] = sprintf(lang_get('missing_exec_type'), $execValues['execution_type'], $execDomain[$execValues['execution_type']]); } else { $checks['status_ok'] = isset($execDomain[$execValues['execution_type']]); if (!$checks['status_ok']) { $checks['msg'][] = sprintf(lang_get('invalid_exec_type'), $execValues['execution_type']); } } } return $checks; }
/** * */ function getEntityByAPIKey(&$dbHandler, $apiKey, $type) { $debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__; $tables = tlObjectWithDB::getDBTables(array('testprojects', 'testplans')); switch ($type) { case 'testproject': $target = $tables['testprojects']; break; case 'testplan': $target = $tables['testplans']; break; } $sql = "/* {$debugMsg} */ " . " SELECT id FROM {$target} " . " WHERE api_key = '" . $dbHandler->prepare_string($apiKey) . "'"; $rs = $dbHandler->get_recordset($sql); return $rs ? $rs[0] : null; }
/** * @internal revisions */ function importTestPlanLinksFromXML(&$dbHandler, &$tplanMgr, $targetFile, $contextObj) { // <testplan> // <name></name> // <platforms> // <platform> // <name> </name> // <internal_id></internal_id> // </platform> // <platform> // ... // </platform> // </platforms> // <executables> // <link> // <platform> // <name> </name> // </platform> // <testcase> // <name> </name> // <externalid> </externalid> // <version> </version> // <execution_order> </execution_order> // </testcase> // </link> // <link> // ... // </link> // </executables> // </testplan> // </xml> $msg = array(); $labels = init_labels(array('link_without_required_platform' => null, 'ok' => null, 'link_without_platform_element' => null, 'no_platforms_on_tproject' => null, 'tcase_link_updated' => null, 'link_with_platform_not_needed' => null, 'tproject_has_zero_testcases' => null, 'platform_not_on_tproject' => null, 'platform_linked' => null, 'platform_not_linked' => null, 'tcase_doesnot_exist' => null, 'tcversion_doesnot_exist' => null, 'not_imported' => null, 'link_to_tplan_feedback' => null, 'link_to_platform' => null)); // Double Check // Check if Test Plan Parent (Test Project) has testcases, if not abort $tprojectMgr = new testproject($dbHandler); $tprojectInfo = $tprojectMgr->get_by_id($contextObj->tproject_id); $tcasePrefix = $tprojectInfo['prefix'] . config_get('testcase_cfg')->glue_character; $tprojectHasTC = $tprojectMgr->count_testcases($contextObj->tproject_id) > 0; if (!$tprojectHasTC) { $msg[] = array(sprintf($labels['tproject_has_zero_testcases'], $tprojectInfo['name']), $labels['not_imported']); return $msg; // >>>-----> Bye } $xml = @simplexml_load_file_wrapper($targetFile); if ($xml !== FALSE) { $tcaseMgr = new testcase($dbHandler); $tcaseSet = array(); $tprojectMgr->get_all_testcases_id($contextObj->tproject_id, $tcaseSet, array('output' => 'external_id')); $tcaseSet = array_flip($tcaseSet); // Test Plan name will not be used // <testplan> <name></name> // // Platform definition info will not be used // // I will try to link the platforms if are defined $status_ok = true; if (property_exists($xml, 'platforms')) { $platformMgr = new tlPlatform($dbHandler, $contextObj->tproject_id); $platformUniverse = $platformMgr->getAllAsMap(); if (is_null($platformUniverse)) { $status_ok = false; $msg[] = array($labels['no_platforms_on_tproject'], $labels['not_imported']); } else { $platformUniverse = array_flip($platformUniverse); $op = processPlatforms($platformMgr, $tplanMgr, $platformUniverse, $xml->platforms, $labels, $contextObj->tplan_id); $status_ok = $op['status_ok']; $msg = $op['msg']; } } if ($status_ok && $xml->xpath('//executables')) { $tables = tlObjectWithDB::getDBTables(array('testplan_tcversions')); $platformSet = $tplanMgr->getPlatforms($contextObj->tplan_id, array('outputFormat' => 'mapAccessByName')); $targetHasPlatforms = count($platformSet) > 0; $xmlLinks = $xml->executables->children(); $loops2do = count($xmlLinks); // new dBug($platformSet); for ($idx = 0; $idx < $loops2do; $idx++) { // if Target Test Plan has platforms and importing file NO => Fatal Error $targetName = null; $platformID = -1; $linkWithPlatform = false; $status_ok = false; $dummy_msg = null; $import_status = $labels['ok']; if ($platformElementExists = property_exists($xmlLinks[$idx], 'platform')) { $targetName = trim((string) $xmlLinks[$idx]->platform->name); $linkWithPlatform = $targetName != ''; } // echo "\$targetHasPlatforms:$targetHasPlatforms<br>"; // echo "\$linkWithPlatform:$linkWithPlatform<br>"; if ($targetHasPlatforms) { // each link need to have platform or will not be imported if ($linkWithPlatform && isset($platformSet[$targetName])) { $platformID = $platformSet[$targetName]['id']; $status_ok = true; $dummy_msg = null; } else { $import_status = $labels['not_imported']; if (!$platformElementExists) { $dummy_msg = sprintf($labels['link_without_platform_element'], $idx + 1); } else { if (!$linkWithPlatform) { $dummy_msg = sprintf($labels['link_without_required_platform'], $idx + 1); } else { $dummy_msg = sprintf($labels['platform_not_linked'], $idx + 1, $targetName, $contextObj->tplan_name); } } } } else { if ($linkWithPlatform) { $import_status = $labels['not_imported']; $dummy_msg = sprintf($labels['link_with_platform_not_needed'], $idx + 1); } else { $platformID = 0; $status_ok = true; } } if (!is_null($dummy_msg)) { $msg[] = array($dummy_msg, $import_status); } // echo '$status_ok' . $status_ok . ' ' . __LINE__ . '<br>' ; if ($status_ok) { $createLink = false; $updateLink = false; // Link passed ok check on platform // Now we need to understand if requested Test case is present on Test Project $externalID = (int) $xmlLinks[$idx]->testcase->externalid; $tcaseName = (string) $xmlLinks[$idx]->testcase->name; $execOrder = (int) $xmlLinks[$idx]->testcase->execution_order; $version = (int) $xmlLinks[$idx]->testcase->version; if (isset($tcaseSet[$externalID])) { // now need to check if requested version exists $dummy = $tcaseMgr->get_basic_info($tcaseSet[$externalID], array('number' => $version)); if (count($dummy) > 0) { // Check : // for same test plan there is a different version already linked ? // if YES => error. // $lvFilters = array('tplan_id' => $contextObj->tplan_id); $linkedVersions = $tcaseMgr->get_linked_versions($dummy[0]['id'], $lvFilters); $updateLink = false; $doUpdateFeedBack = true; // TICKET 5189: Import a test plan does not import test cases execution order // new dBug($linkedVersions); if (!($createLink = is_null($linkedVersions))) { // Now need to understand if is already linked with this signature. if (!isset($linkedVersions[$dummy[0]['tcversion_id']])) { //echo 'CREATE'; $createLink = true; } else { // linked platforms $createLink = false; $updateLink = false; $plat_keys = array_keys($linkedVersions[$dummy[0]['tcversion_id']][$contextObj->tplan_id]); $plat_keys = array_flip($plat_keys); if (isset($plat_keys[$platformID])) { $updateLink = true; } else { if ($platformID == 0) { // User request to add without platform, but platforms exist => SKIP $msg[] = array('platform 0 missing messages', $labels['not_imported']); } else { $createLink = true; } } } } if ($createLink) { // Create link // function link_tcversions($id,&$items_to_link,$userId) $item2link['items'] = array($dummy[0]['id'] => array($platformID => $dummy[0]['tcversion_id'])); $item2link['tcversion'] = array($dummy[0]['id'] => $dummy[0]['tcversion_id']); $tplanMgr->link_tcversions($contextObj->tplan_id, $item2link, $contextObj->userID); $dummy_msg = sprintf($labels['link_to_tplan_feedback'], $externalID, $version); if ($platformID > 0) { $dummy_msg .= sprintf($labels['link_to_platform'], $targetName); } $msg[] = array($dummy_msg, $labels['ok']); // TICKET 5189: Import a test plan does not import test cases execution order $updateLink = true; $doUpdateFeedBack = false; } if ($updateLink) { $newOrder = array($dummy[0]['tcversion_id'] => $execOrder); $tplanMgr->setExecutionOrder($contextObj->tplan_id, $newOrder); if ($doUpdateFeedBack) { $dummy_msg = sprintf($labels['tcase_link_updated'], $tcasePrefix . $externalID . ' ' . $tcaseName, $version); $msg[] = array($dummy_msg, $labels['ok']); } } } else { $msg[] = array(sprintf($labels['tcversion_doesnot_exist'], $externalID, $version, $tprojectInfo['name'])); } } else { $msg[] = array(sprintf($labels['tcase_doesnot_exist'], $externalID, $tprojectInfo['name'])); } //$tcaseMgr->get_by_external // echo '<pre><xmp>'; // var_dump($xmlLinks[$idx]->testcase); // echo 'TCBAME' . (string)$xmlLinks[$idx]->testcase->name; // echo '</xmp></pre>'; } } } } return $msg; }
*/ require_once "../../config.inc.php"; require_once "common.php"; testlinkInitPage($db); $templateCfg = templateConfiguration(); $tproject_mgr = new testproject($db); $req_cfg = config_get('req_cfg'); $gui = new stdClass(); $gui->main_descr = lang_get('caption_search_form_req_spec'); $gui->warning_msg = ''; $gui->path_info = null; $gui->resultSet = null; $map = null; $args = init_args(); if ($args->tprojectID) { $tables = tlObjectWithDB::getDBTables(array("cfield_design_values", 'nodes_hierarchy', 'req_specs')); $filter = null; $from = null; if ($args->requirement_document_id) { //search by id $id = $db->prepare_string($args->requirement_document_id); $filter['by_id'] = " AND RS.doc_id like '%{$id}%' "; } if ($args->name) { //search by name/title $title = $db->prepare_string($args->name); $filter['by_name'] = " AND NH.name like '%{$title}%' "; } if ($args->reqSpecType != "notype") { //search by type $type = $db->prepare_string($args->reqSpecType);
/** * checks if a keyword for a certain testproject already exists in the database * * @param resource $db [ref] the database connection * @param string $name the name of the keyword * @param integer $tprojectID the testprojectID * @param integer $kwID an additional keyword id which is excluded in the search * @return integer return tl::OK if the keyword is found, else tlKeyword::E_NAMEALREADYEXISTS */ public static function doesKeywordExist(&$db, $name, $tprojectID, $kwID = null) { $result = tl::OK; $tables = tlObjectWithDB::getDBTables("keywords"); $name = $db->prepare_string(strtoupper($name)); $query = " SELECT id FROM {$tables['keywords']} " . " WHERE UPPER(keyword) ='" . $name . "' AND testproject_id = " . $tprojectID; if ($kwID) { $query .= " AND id <> " . $kwID; } if ($db->fetchFirstRow($query)) { $result = self::E_NAMEALREADYEXISTS; } return $result; }