function get_by_name($name, $tsuite_name = '', $tproject_name = '') { $debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__; $recordset = null; $filters_on = array('tsuite_name' => false, 'tproject_name' => false); // BUGID 3729 - limit all names $field_size = config_get('field_size'); $tsuite_name = tlSubStr(trim($tsuite_name), 0, $field_size->testsuite_name); $tproject_name = tlSubStr(trim($tproject_name), 0, $field_size->testproject_name); $name = tlSubStr(trim($name), 0, $field_size->testcase_name); $sql = "/* {$debugMsg} */ " . " SELECT DISTINCT NH_TCASE.id,NH_TCASE.name,NH_TCASE_PARENT.id AS parent_id," . " NH_TCASE_PARENT.name AS tsuite_name, TCV.tc_external_id " . " FROM {$this->tables['nodes_hierarchy']} NH_TCASE, " . " {$this->tables['nodes_hierarchy']} NH_TCASE_PARENT, " . " {$this->tables['nodes_hierarchy']} NH_TCVERSIONS," . " {$this->tables['tcversions']} TCV " . " WHERE NH_TCASE.node_type_id = {$this->my_node_type} " . " AND NH_TCASE.name = '{$this->db->prepare_string($name)}' " . " AND TCV.id=NH_TCVERSIONS.id " . " AND NH_TCVERSIONS.parent_id=NH_TCASE.id " . " AND NH_TCASE_PARENT.id=NH_TCASE.parent_id "; if ($tsuite_name != "") { $sql .= " AND NH_TCASE_PARENT.name = '{$this->db->prepare_string($tsuite_name)}' " . " AND NH_TCASE_PARENT.node_type_id = {$this->node_types_descr_id['testsuite']} "; } $recordset = $this->db->get_recordset($sql); if (count($recordset) && $tproject_name != "") { list($tproject_info) = $this->tproject_mgr->get_by_name($tproject_name); foreach ($recordset as $idx => $tcase_info) { if ($this->get_testproject($tcase_info['id']) != $tproject_info['id']) { unset($recordset[$idx]); } } } return $recordset; }
/** * @param string $value the string which should be trimmed * @return string the trimmed value */ public function trim($value) { switch ($this->trim) { case tlStringValidationInfo::TRIM_LEFT: $value = ltrim($value); break; case tlStringValidationInfo::TRIM_RIGHT: $value = rtrim($value); break; case tlStringValidationInfo::TRIM_BOTH: $value = trim($value); break; } if ($this->maxLen) { $value = tlSubStr($value, 0, $this->maxLen); } return $value; }
/** * 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; }
function saveImportedTCData(&$db, $tcData, $tproject_id, $container_id, $userID, $kwMap, $duplicatedLogic = array('hitCriteria' => 'name', 'actionOnHit' => null)) { static $messages; static $fieldSizeCfg; static $feedbackMsg; static $tcase_mgr; static $tproject_mgr; static $req_spec_mgr; static $req_mgr; static $safeSizeCfg; static $linkedCustomFields; static $tprojectHas; static $reqSpecSet; static $getVersionOpt; static $userObj; if (!$tcData) { return; } // $tprojectHas = array('customFields' => false, 'reqSpec' => false); $hasCustomFieldsInfo = false; $hasRequirements = false; if (is_null($messages)) { $feedbackMsg = array(); $messages = array(); $fieldSizeCfg = config_get('field_size'); $tcase_mgr = new testcase($db); $tproject_mgr = new testproject($db); $req_spec_mgr = new requirement_spec_mgr($db); $req_mgr = new requirement_mgr($db); $userObj = new tlUser(); $k2l = array('already_exists_updated', 'original_name', 'testcase_name_too_long', 'start_warning', 'end_warning', 'testlink_warning', 'hit_with_same_external_ID'); foreach ($k2l as $k) { $messages[$k] = lang_get($k); } $messages['start_feedback'] = $messages['start_warning'] . "\n" . $messages['testlink_warning'] . "\n"; $messages['cf_warning'] = lang_get('no_cf_defined_can_not_import'); $messages['reqspec_warning'] = lang_get('no_reqspec_defined_can_not_import'); $feedbackMsg['cfield'] = lang_get('cf_value_not_imported_missing_cf_on_testproject'); $feedbackMsg['tcase'] = lang_get('testcase'); $feedbackMsg['req'] = lang_get('req_not_in_req_spec_on_tcimport'); $feedbackMsg['req_spec'] = lang_get('req_spec_ko_on_tcimport'); // because name can be changed automatically during item creation // to avoid name conflict adding a suffix automatically generated, // is better to use a max size < max allowed size $safeSizeCfg = new stdClass(); $safeSizeCfg->testcase_name = $fieldSizeCfg->testcase_name * 0.8; // Get CF with scope design time and allowed for test cases linked to this test project $linkedCustomFields = $tcase_mgr->cfield_mgr->get_linked_cfields_at_design($tproject_id, 1, null, 'testcase', null, 'name'); $tprojectHas['customFields'] = !is_null($linkedCustomFields); $reqSpecSet = $tproject_mgr->getReqSpec($tproject_id, null, array('RSPEC.id', 'NH.name AS title', 'RSPEC.doc_id as rspec_doc_id', 'REQ.req_doc_id'), 'req_doc_id'); $tprojectHas['reqSpec'] = !is_null($reqSpecSet) && count($reqSpecSet) > 0; $getVersionOpt = array('output' => 'minimun'); $tcasePrefix = $tproject_mgr->getTestCasePrefix($tproject_id); } $resultMap = array(); $tc_qty = sizeof($tcData); $userIDCache = array(); for ($idx = 0; $idx < $tc_qty; $idx++) { $tc = $tcData[$idx]; $name = $tc['name']; $summary = $tc['summary']; $steps = $tc['steps']; // I've changed value to use when order has not been provided // from testcase:DEFAULT_ORDER to a counter, because with original solution // an issue arise with 'save execution and go next' // if use has not provided order I think is OK TestLink make any choice. $node_order = isset($tc['node_order']) ? intval($tc['node_order']) : $idx + 1; $internalid = $tc['internalid']; $preconditions = $tc['preconditions']; $exec_type = isset($tc['execution_type']) ? $tc['execution_type'] : TESTCASE_EXECUTION_TYPE_MANUAL; $importance = isset($tc['importance']) ? $tc['importance'] : MEDIUM; $externalid = $tc['externalid']; if (intval($externalid) <= 0) { $externalid = null; } $personID = $userID; if (!is_null($tc['author_login'])) { if (isset($userIDCache[$tc['author_login']])) { $personID = $userIDCache[$tc['author_login']]; } else { $userObj->login = $tc['author_login']; if ($userObj->readFromDB($db, tlUser::USER_O_SEARCH_BYLOGIN) == tl::OK) { $personID = $userObj->dbID; } // I will put always a valid userID on this cache, // this way if author_login does not exit, and is used multiple times // i will do check for existence JUST ONCE. $userIDCache[$tc['author_login']] = $personID; } } $name_len = tlStringLen($name); if ($name_len > $fieldSizeCfg->testcase_name) { // Will put original name inside summary $xx = $messages['start_feedback']; $xx .= sprintf($messages['testcase_name_too_long'], $name_len, $fieldSizeCfg->testcase_name) . "\n"; $xx .= $messages['original_name'] . "\n" . $name . "\n" . $messages['end_warning'] . "\n"; $summary = nl2br($xx) . $summary; $name = tlSubStr($name, 0, $safeSizeCfg->testcase_name); } $kwIDs = null; if (isset($tc['keywords']) && $tc['keywords']) { $kwIDs = implode(",", buildKeywordList($kwMap, $tc['keywords'])); } $doCreate = true; if ($duplicatedLogic['actionOnHit'] == 'update_last_version') { switch ($duplicatedLogic['hitCriteria']) { case 'name': $info = $tcase_mgr->getDuplicatesByName($name, $container_id); break; case 'internalID': $dummy = $tcase_mgr->tree_manager->get_node_hierarchy_info($internalid, $container_id); if (!is_null($dummy)) { $info = null; $info[$internalid] = $dummy; } break; case 'externalID': $info = $tcase_mgr->get_by_external($externalid, $container_id); break; } if (!is_null($info)) { $tcase_qty = count($info); switch ($tcase_qty) { case 1: $doCreate = false; $tcase_id = key($info); $last_version = $tcase_mgr->get_last_version_info($tcase_id, $getVersionOpt); $tcversion_id = $last_version['id']; $ret = $tcase_mgr->update($tcase_id, $tcversion_id, $name, $summary, $preconditions, $steps, $personID, $kwIDs, $node_order, $exec_type, $importance); $ret['id'] = $tcase_id; $ret['tcversion_id'] = $tcversion_id; $resultMap[] = array($name, $messages['already_exists_updated']); break; case 0: $doCreate = true; break; default: $doCreate = false; break; } } } if ($doCreate) { // Want to block creation of with existent EXTERNAL ID, if containers ARE DIFFERENT. $item_id = intval($tcase_mgr->getInternalID($externalid, array('tproject_id' => $tproject_id))); if ($item_id > 0) { // who is his parent ? $owner = $tcase_mgr->getTestSuite($item_id); if ($owner != $container_id) { // Get full path of existent Test Cases $stain = $tcase_mgr->tree_manager->get_path($item_id, null, 'name'); $n = count($stain); $stain[$n - 1] = $tcasePrefix . config_get('testcase_cfg')->glue_character . $externalid . ':' . $stain[$n - 1]; $stain = implode('/', $stain); $resultMap[] = array($name, $messages['hit_with_same_external_ID'] . $stain); $doCreate = false; } } } if ($doCreate) { $createOptions = array('check_duplicate_name' => testcase::CHECK_DUPLICATE_NAME, 'action_on_duplicate_name' => $duplicatedLogic['actionOnHit'], 'external_id' => $externalid); if ($ret = $tcase_mgr->create($container_id, $name, $summary, $preconditions, $steps, $personID, $kwIDs, $node_order, testcase::AUTOMATIC_ID, $exec_type, $importance, $createOptions)) { $resultMap[] = array($name, $ret['msg']); } } } return $resultMap; }
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; }
/** * 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; }
/** * 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; }
/** * 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; }