function migrate_cc_specs(&$source_db, &$target_db, &$items, &$old_new) { $mgtcom_keys = array('intro' => 'introduction', 'scope' => 'scope', 'ref' => 'references', 'method' => 'methodology', 'lim' => 'limitations'); $mgtcat_keys = array('objective' => 'objective', 'config' => 'configuration', 'data' => 'data', 'tools' => 'tools'); $tproject_mgr = new testproject($target_db); $ts_mgr = new testsuite($target_db); $tree_mgr = new tree($target_db); foreach ($items as $prod_id => $pd) { $old_new['product'][$prod_id] = @$tproject_mgr->create($pd['name'], $pd['color'], $pd['option_reqs'], EMPTY_NOTES, $pd['active']); echo "<pre><font color='blue'>Product {$pd['name']} has became a test project!</font></pre>"; flush(); $tproject_id = $old_new['product'][$prod_id]; $sql = "SELECT * FROM mgtcomponent WHERE prodid={$prod_id}"; $comp = $source_db->fetchRowsIntoMap($sql, 'id'); // for change_order_bulk($hash_node_id, $hash_node_order) // $hash_node_id=array(10=>10, 23=>23, 30=>30); // $hash_node_order=array(10=>3, 23=>1, 30=>2); // $hash_node_id=array(); // $hash_node_order=array(); // 20071021 - francisco.mancardi@gruppotesi.com // // $hash_order_node_order=array(3=>10, 1=>23, 2=>30); // means: node_id: 10 order:3 // node_id: 23 order:1 // node_id: 30 order:2 $hash_order_node_id = array(); if (count($comp) > 0) { foreach ($comp as $coid => $cod) { $details = ''; foreach ($mgtcom_keys as $key => $val) { $details .= $val . ": <br>" . $cod[$key] . "<p>"; } $ret = $ts_mgr->create($tproject_id, $cod['name'], $details); if ($ret['status_ok']) { echo "<pre>Component " . htmlentities($cod['name']) . " Migrated<br></pre>"; flush(); $mgtcomp_id = $ret['id']; $old_new['mgtcomp'][$coid] = $mgtcomp_id; } // ---------------------------------------------------------------------------------- $sql = "SELECT * FROM mgtcategory WHERE compid={$coid}"; $cat = $source_db->fetchRowsIntoMap($sql, 'id'); if (count($cat) > 0) { foreach ($cat as $caid => $cad) { // ---------------------------------------------------------------------------------- $details = ''; foreach ($mgtcat_keys as $key => $val) { $details .= $val . ": <br>" . $cad[$key] . "<p>"; } // ---------------------------------------------------------------------------------- $ret = $ts_mgr->create($mgtcomp_id, $cad['name'], $details); if ($ret['status_ok']) { echo "<pre> Category " . htmlentities($cad['name']) . " Migrated<br></pre>"; flush(); $mgtcat_id = $ret['id']; $old_new['mgtcat'][$caid] = $mgtcat_id; if ($cad['CATorder'] != 0) { // 20071021 - franciscom // $hash_node_id[$mgtcat_id]=$mgtcat_id; // $hash_node_order[$mgtcat_id]=$cad['CATorder']; $node_id = $mgtcat_id; $node_order = $cad['CATorder']; $hash_order_node_id[$node_order] = $node_id; } } // ---------------------------------------------------------------------------------- } } } // 20060725 - franciscom // $tree_mgr->change_order_bulk($hash_node_id, $hash_node_order) ; $tree_mgr->change_order_bulk($hash_order_node_id); } } }
function create_tc_from_requirement($mixIdReq, $srs_id, $user_id, $tproject_id = null, $tc_count = null) { $debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__; $tcase_mgr = new testcase($this->db); $tsuite_mgr = new testsuite($this->db); $req_cfg = config_get('req_cfg'); $field_size = config_get('field_size'); $auto_testsuite_name = $req_cfg->default_testsuite_name; $node_descr_type = $this->tree_mgr->get_available_node_types(); $empty_steps = null; $empty_preconditions = ''; // fix for BUGID 2995 $labels['tc_created'] = lang_get('tc_created'); $output = null; $reqSet = is_array($mixIdReq) ? $mixIdReq : array($mixIdReq); /* contribution BUGID 2996, testcase creation */ if (is_null($tproject_id) || $tproject_id == 0) { $tproject_id = $this->tree_mgr->getTreeRoot($srs_id); } if ($req_cfg->use_req_spec_as_testsuite_name) { $full_path = $this->tree_mgr->get_path($srs_id); $addition = " (" . lang_get("testsuite_title_addition") . ")"; $truncate_limit = $field_size->testsuite_name - strlen($addition); // REQ_SPEC_A // |-- REQ_SPEC_A1 // |-- REQ_SPEC_A2 // |- REQ100 // |- REQ101 // // We will try to check if a test suite has already been created for // top REQ_SPEC_A (we do search using automatic generated name as search criteria). // If not => we need to create all path till leaves (REQ100 and REQ200) // // // First search: we use test project $parent_id = $tproject_id; $deep_create = false; foreach ($full_path as $key => $node) { // follow hierarchy of test suites to create $tsuiteInfo = null; $testsuite_name = substr($node['name'], 0, $truncate_limit) . $addition; if (!$deep_create) { // child test suite with this name, already exists on current parent ? // At first a failure we will not check anymore an proceed with deep create $sql = "/* {$debugMsg} */ SELECT id,name FROM {$this->tables['nodes_hierarchy']} NH " . " WHERE name='" . $this->db->prepare_string($testsuite_name) . "' " . " AND node_type_id=" . $node_descr_type['testsuite'] . " AND parent_id = {$parent_id} "; // If returns more that one record use ALWAYS first $tsuiteInfo = $this->db->fetchRowsIntoMap($sql, 'id'); } if (is_null($tsuiteInfo)) { $tsuiteInfo = $tsuite_mgr->create($parent_id, $testsuite_name, $req_cfg->testsuite_details); $output[] = sprintf(lang_get('testsuite_name_created'), $testsuite_name); $deep_create = true; } else { $tsuiteInfo = current($tsuiteInfo); $tsuite_id = $tsuiteInfo['id']; } $tsuite_id = $tsuiteInfo['id']; // last value here will be used as parent for test cases $parent_id = $tsuite_id; } $output[] = sprintf(lang_get('created_on_testsuite'), $testsuite_name); } else { // don't use req_spec as testsuite name // Warning: // We are not maintaining hierarchy !!! $sql = " SELECT id FROM {$this->tables['nodes_hierarchy']} NH " . " WHERE name='" . $this->db->prepare_string($auto_testsuite_name) . "' " . " AND parent_id=" . $testproject_id . " " . " AND node_type_id=" . $node_descr_type['testsuite']; $result = $this->db->exec_query($sql); if ($this->db->num_rows($result) == 1) { $row = $this->db->fetch_array($result); $tsuite_id = $row['id']; $label = lang_get('created_on_testsuite'); } else { // not found -> create tLog('test suite:' . $auto_testsuite_name . ' was not found.'); $new_tsuite = $tsuite_mgr->create($testproject_id, $auto_testsuite_name, $req_cfg->testsuite_details); $tsuite_id = $new_tsuite['id']; $label = lang_get('testsuite_name_created'); } $output[] = sprintf($label, $auto_testsuite_name); } /* end contribution */ // create TC $createOptions = array(); $createOptions['check_names_for_duplicates'] = config_get('check_names_for_duplicates'); $createOptions['action_on_duplicate_name'] = config_get('action_on_duplicate_name'); $testcase_importance_default = config_get('testcase_importance_default'); // compute test case order $testcase_order = config_get('treemenu_default_testcase_order'); $nt2exclude = array('testplan' => 'exclude_me', 'requirement_spec' => 'exclude_me', 'requirement' => 'exclude_me'); $siblings = $this->tree_mgr->get_children($tsuite_id, $nt2exclude); if (!is_null($siblings)) { $dummy = end($siblings); $testcase_order = $dummy['node_order']; } foreach ($reqSet as $reqID) { $reqData = $this->get_by_id($reqID, requirement_mgr::LATEST_VERSION); $count = !is_null($tc_count) ? $tc_count[$reqID] : 1; $reqData = $reqData[0]; // Generate name with progessive $instance = 1; $getOptions = array('check_criteria' => 'like', 'access_key' => 'name'); $itemSet = $tcase_mgr->getDuplicatesByName($reqData['title'], $tsuite_id, $getOptions); $nameSet = null; if (!is_null($itemSet)) { $nameSet = array_flip(array_keys($itemSet)); } for ($idx = 0; $idx < $count; $idx++) { $testcase_order++; // We have a little problem to work on: // suppose you have created: // TC [1] // TC [2] // TC [3] // If we delete TC [2] // When I got siblings il will got 2, if I create new progressive using next, // it will be 3 => I will get duplicated name. // // Seems better option can be: // Get all siblings names, put on array, create name an check if exists, if true // generate a new name. // This may be at performance level is better than create name then check on db, // because this approach will need more queries to DB // $tcase_name = $reqData['title'] . " [{$instance}]"; if (!is_null($nameSet)) { while (isset($nameSet[$tcase_name])) { $instance++; $tcase_name = $reqData['title'] . " [{$instance}]"; } } $nameSet[$tcase_name] = $tcase_name; // 20100106 - franciscom - multiple test case steps feature - removed expected_results // Julian - BUGID 2995 $tcase = $tcase_mgr->create($tsuite_id, $tcase_name, $req_cfg->testcase_summary_prefix . $reqData['scope'], $empty_preconditions, $empty_steps, $user_id, null, $testcase_order, testcase::AUTOMATIC_ID, TESTCASE_EXECUTION_TYPE_MANUAL, $testcase_importance_default, $createOptions); $tcase_name = $tcase['new_name'] == '' ? $tcase_name : $tcase['new_name']; $output[] = sprintf($labels['tc_created'], $tcase_name); // create coverage dependency if (!$this->assign_to_tcase($reqData['id'], $tcase['id'])) { $output[] = 'Test case: ' . $tcase_name . " was not created"; } } } return $output; }
/** * create a test suite * * @param struct $args * @param string $args["devKey"] * @param int $args["testprojectid"] * @param string $args["testsuitename"] * @param string $args["details"] * @param int $args["parentid"] optional, if do not provided means test suite must be top level. * @param int $args["order"] optional. Order inside parent container * @param int $args["checkduplicatedname"] optional, default true. * will check if there are siblings with same name. * * @param int $args["actiononduplicatedname"] optional * applicable only if $args["checkduplicatedname"]=true * what to do if already a sibling exists with same name. * * @return mixed $resultInfo */ public function createTestSuite($args) { $result = array(); $this->_setArgs($args); $operation = __FUNCTION__; $msg_prefix = "({$operation}) - "; $checkFunctions = array('authenticate', 'checkTestSuiteName', 'checkTestProjectID'); $status_ok = $this->_runChecks($checkFunctions, $msg_prefix) && $this->userHasRight("mgt_modify_tc", self::CHECK_PUBLIC_PRIVATE_ATTR); if ($status_ok) { // Optional parameters $opt = array(self::$orderParamName => testsuite::DEFAULT_ORDER, self::$checkDuplicatedNameParamName => testsuite::CHECK_DUPLICATE_NAME, self::$actionOnDuplicatedNameParamName => 'block'); foreach ($opt as $key => $value) { if ($this->_isParamPresent($key)) { $opt[$key] = $this->args[$key]; } } } if ($status_ok) { $parent_id = $args[self::$testProjectIDParamName]; $tprojectInfo = $this->tprojectMgr->get_by_id($args[self::$testProjectIDParamName]); $tsuiteMgr = new testsuite($this->dbObj); if ($this->_isParamPresent(self::$parentIDParamName)) { $parent_id = $args[self::$parentIDParamName]; // if parentid exists it must: // be a test suite id $node_info = $tsuiteMgr->get_by_id($args[self::$parentIDParamName]); if (!($status_ok = !is_null($node_info))) { $msg = sprintf(INVALID_PARENT_TESTSUITEID_STR, $args[self::$parentIDParamName], $args[self::$testSuiteNameParamName]); $this->errors[] = new IXR_Error(INVALID_PARENT_TESTSUITEID, $msg_prefix . $msg); } if ($status_ok) { // Must belong to target test project $root_node_id = $tsuiteMgr->getTestProjectFromTestSuite($args[self::$parentIDParamName], null); if (!($status_ok = $root_node_id == $args[self::$testProjectIDParamName])) { $msg = sprintf(TESTSUITE_DONOTBELONGTO_TESTPROJECT_STR, $args[self::$parentIDParamName], $tprojectInfo['name'], $args[self::$testProjectIDParamName]); $this->errors[] = new IXR_Error(TESTSUITE_DONOTBELONGTO_TESTPROJECT, $msg_prefix . $msg); } } } } if ($status_ok) { $op = $tsuiteMgr->create($parent_id, $args[self::$testSuiteNameParamName], $args[self::$detailsParamName], $opt[self::$orderParamName], $opt[self::$checkDuplicatedNameParamName], $opt[self::$actionOnDuplicatedNameParamName]); if ($status_ok = $op['status_ok']) { $op['status'] = $op['status_ok'] ? true : false; $op['operation'] = $operation; $op['additionalInfo'] = ''; $op['message'] = $op['msg']; unset($op['msg']); unset($op['status_ok']); $result[] = $op; } else { $op['msg'] = sprintf($op['msg'], $args[self::$testSuiteNameParamName]); $this->errors = $op; } } return $status_ok ? $result : $this->errors; }
function importTestSuitesFromSimpleXML(&$dbHandler, &$xml, $parentID, $tproject_id, $userID, $kwMap, $importIntoProject = 0, $duplicateLogic) { static $tsuiteXML; static $tsuiteMgr; static $myself; static $callCounter = 0; static $cfSpec; static $doCF; $resultMap = array(); if (is_null($tsuiteXML)) { $myself = __FUNCTION__; $tsuiteXML = array(); $tsuiteXML['elements'] = array('string' => array("details" => null), 'integer' => array("node_order" => null)); $tsuiteXML['attributes'] = array('string' => array("name" => 'trim')); $tsuiteMgr = new testsuite($dbHandler); $doCF = !is_null($cfSpec = $tsuiteMgr->get_linked_cfields_at_design(null, null, null, $tproject_id, 'name')); } if ($xml->getName() == 'testsuite') { // getItemsFromSimpleXMLObj() first argument must be an array $dummy = getItemsFromSimpleXMLObj(array($xml), $tsuiteXML); $tsuite = current($dummy); $tsuiteID = $parentID; // hmmm, not clear if ($tsuite['name'] != "") { // Check if Test Suite with this name exists on this container // if yes -> update instead of create $info = $tsuiteMgr->get_by_name($tsuite['name'], $parentID); if (is_null($info)) { $ret = $tsuiteMgr->create($parentID, $tsuite['name'], $tsuite['details'], $tsuite['node_order']); $tsuite['id'] = $ret['id']; } else { $ret = $tsuiteMgr->update($tsuite['id'] = $info[0]['id'], $tsuite['name'], $tsuite['details'], null, $tsuite['node_order']); } unset($dummy); $tsuiteID = $tsuite['id']; // $tsuiteID is needed on more code pieces => DO NOT REMOVE if (!$tsuite['id']) { return null; } if ($doCF) { $cf = getCustomFieldsFromSimpleXMLObj($xml->custom_fields->custom_field); if (!is_null($cf)) { processTestSuiteCF($tsuiteMgr, $xml, $cfSpec, $cf, $tsuite, $tproject_id); } } if ($keywords = getKeywordsFromSimpleXMLObj($xml->keywords->keyword)) { $kwIDs = buildKeywordList($kwMap, $keywords); $tsuiteMgr->addKeywords($tsuite['id'], $kwIDs); } unset($tsuite); } else { if ($importIntoProject) { $tsuiteID = intval($tproject_id); } } $childrenNodes = $xml->children(); $loop2do = sizeof($childrenNodes); for ($idx = 0; $idx < $loop2do; $idx++) { $target = $childrenNodes[$idx]; switch ($target->getName()) { case 'testcase': // getTestCaseSetFromSimpleXMLObj() first argument must be an array $tcData = getTestCaseSetFromSimpleXMLObj(array($target)); $resultMap = array_merge($resultMap, saveImportedTCData($dbHandler, $tcData, $tproject_id, $tsuiteID, $userID, $kwMap, $duplicateLogic)); unset($tcData); break; case 'testsuite': $resultMap = array_merge($resultMap, $myself($dbHandler, $target, $tsuiteID, $tproject_id, $userID, $kwMap, $importIntoProject, $duplicateLogic)); break; // Important Development Notice // Due to XML file structure, while looping // we will find also this children: // node_order,keywords,custom_fields,details // // It's processing to get and save values is done // on other pieces of this code. // // Form a logical point of view seems the better // to consider and process here testcase and testsuite as children. // } } } return $resultMap; }
function importTestSuitesFromSimpleXML(&$dbHandler, &$xml, $parentID, $tproject_id, $userID, $kwMap, $importIntoProject = 0, $duplicateLogic) { static $tsuiteXML; static $tsuiteMgr; static $myself; static $callCounter = 0; $resultMap = array(); // $callCounter++; if (is_null($tsuiteXML)) { $tsuiteXML = array(); $tsuiteXML['elements'] = array('string' => array("details"), 'integer' => array("node_order")); $tsuiteXML['attributes'] = array('string' => array("name")); $tsuiteMgr = new testsuite($dbHandler); $myself = __FUNCTION__; } if ($xml->getName() == 'testsuite') { // getItemsFromSimpleXMLObj() first argument must be an array $dummy = getItemsFromSimpleXMLObj(array($xml), $tsuiteXML); $tsuite = current($dummy); $tsuiteID = $parentID; // hmmm, not clear if ($tsuite['name'] != "") { // Check if Test Suite with this name exists on this container // if yes -> update instead of create $info = $tsuiteMgr->get_by_name($tsuite['name'], $parentID); if (is_null($info)) { $ret = $tsuiteMgr->create($parentID, $tsuite['name'], $tsuite['details'], $tsuite['node_order']); $tsuiteID = $ret['id']; } else { $tsuiteID = $info[0]['id']; $ret = $tsuiteMgr->update($tsuiteID, $tsuite['name'], $tsuite['details'], null, $tsuite['node_order']); } unset($tsuite); unset($dummy); if (!$tsuiteID) { return null; } } else { if ($importIntoProject) { $tsuiteID = $tproject_id; } } $childrenNodes = $xml->children(); $loop2do = sizeof($childrenNodes); for ($idx = 0; $idx < $loop2do; $idx++) { $target = $childrenNodes[$idx]; switch ($target->getName()) { case 'testcase': // getTestCaseSetFromSimpleXMLObj() first argument must be an array $tcData = getTestCaseSetFromSimpleXMLObj(array($target)); // 20100904 - francisco.mancardi@gruppotesi.com // echo 'Going to work on Test Case INSIDE Test Suite:' . $tsuite['name'] . '<br>'; $resultMap = array_merge($resultMap, saveImportedTCData($dbHandler, $tcData, $tproject_id, $tsuiteID, $userID, $kwMap, $duplicateLogic)); unset($tcData); break; case 'testsuite': $resultMap = array_merge($resultMap, $myself($dbHandler, $target, $tsuiteID, $tproject_id, $userID, $kwMap, $importIntoProject, $duplicateLogic)); break; // do not understand why we need to do this particular logic. // Need to understand // do not understand why we need to do this particular logic. // Need to understand case 'details': if (!$importIntoProject) { $keywords = getKeywordsFromSimpleXMLObj($target->xpath("//keyword")); if ($keywords) { $kwIDs = buildKeywordList($kwMap, $keywords); $tsuiteMgr->addKeywords($tsuiteID, $kwIDs); } } break; } } } return $resultMap; }
function importTestSuitesFromSimpleXML(&$dbHandler, &$xml, $parentID, $tproject_id, $userID, $kwMap, $importIntoProject = 0) { static $tsuiteXML; static $tsuiteMgr; static $myself; static $callCounter = 0; $resultMap = array(); // $callCounter++; if (is_null($tsuiteXML)) { $tsuiteXML = array(); $tsuiteXML['elements'] = array('string' => array("details"), 'integer' => array("node_order")); $tsuiteXML['attributes'] = array('string' => array("name")); $tsuiteMgr = new testsuite($dbHandler); $myself = __FUNCTION__; } if ($xml->getName() == 'testsuite') { // getItemsFromSimpleXMLObj() first argument must be an array $dummy = getItemsFromSimpleXMLObj(array($xml), $tsuiteXML); $tsuite = current($dummy); $tsuiteID = $parentID; if ($tsuite['name'] != "") { $ret = $tsuiteMgr->create($parentID, $tsuite['name'], $tsuite['details'], $tsuite['node_order']); $tsuiteID = $ret['id']; unset($tsuite); unset($dummy); if (!$tsuiteID) { return null; } } else { if ($importIntoProject) { $tsuiteID = $tproject_id; } } $childrenNodes = $xml->children(); $loop2do = sizeof($childrenNodes); for ($idx = 0; $idx < $loop2do; $idx++) { $target = $childrenNodes[$idx]; switch ($target->getName()) { case 'testcase': // getTestCaseSetFromSimpleXMLObj() first argument must be an array $tcData = getTestCaseSetFromSimpleXMLObj(array($target)); // TEST $resultMap = array_merge($resultMap, saveImportedTCData($dbHandler, $tcData, $tproject_id, $tsuiteID, $userID, $kwMap)); unset($tcData); break; case 'testsuite': $resultMap = array_merge($resultMap, $myself($dbHandler, $target, $tsuiteID, $tproject_id, $userID, $kwMap)); break; // do not understand why we need to do this particular logic. // Need to understand // do not understand why we need to do this particular logic. // Need to understand case 'details': if (!$importIntoProject) { $keywords = getKeywordsFromSimpleXMLObj($target->xpath("//keyword")); if ($keywords) { $kwIDs = buildKeywordList($kwMap, $keywords); $tsuiteMgr->addKeywords($tsuiteID, $kwIDs); } } break; } } } return $resultMap; }