$method = 'get_by_name'; echo "<pre> {$method}('{$tcase_name}','{$tsuite_name}','{$tproject_name}')"; echo "</pre>"; $info = $tcase_mgr->{$method}($tcase_name, $tsuite_name, $tproject_name); new dBug($info); die; $tcase_id = 4; echo "<pre> testcase - check_link_and_exec_status(\$id)"; echo "</pre>"; echo "<pre> check_link_and_exec_status({$tcase_id})"; echo "</pre>"; $link_and_exec_status = $tcase_mgr->check_link_and_exec_status($tcase_id); new dBug($link_and_exec_status); echo "<pre> testcase - get_linked_versions(\$id,\$exec_status='ALL',\$active_status='ALL')"; echo "<pre> get_linked_versions({$tcase_id})"; $linked_versions = $tcase_mgr->get_linked_versions($tcase_id); new dBug($linked_versions); $tcase_id = 4; echo "<pre> testcase - get_testproject(\$id)"; echo "<pre> get_testproject({$tcase_id})"; $testproject_id = $tcase_mgr->get_testproject($tcase_id); new dBug("testproject id=" . $testproject_id); $tcase_id = 4; echo "<pre> testcase - get_last_version_info(\$id)"; echo "<pre> get_last_version_info({$tcase_id})"; $last_version_info = $tcase_mgr->get_last_version_info($tcase_id); new dBug($last_version_info); echo "<pre> testcase - get_versions_status_quo(\$id,\$tcversion_id=null, \$testplan_id=null)"; echo "<pre> get_versions_status_quo({$tcase_id})"; $status_quo = $tcase_mgr->get_versions_status_quo($tcase_id); new dBug($status_quo);
$tcase_all_info = $tcase_mgr->get_by_id($args->tcase_id, testcase::ALL_VERSIONS, null, $options); if (!is_null($tcase_all_info)) { foreach ($tcase_all_info as $tcversion_info) { if ($tcversion_info['id'] == $args->tcversion_id) { $version = $tcversion_info['version']; $gui->pageTitle = lang_get('test_case') . ':' . $tcversion_info['name']; $gui->tcaseIdentity = $tproject_mgr->getTestCasePrefix($args->tproject_id); $gui->tcaseIdentity .= $glue . $tcversion_info['tc_external_id'] . ':' . $tcversion_info['name']; break; } } } // 20100514 - franciscom // Why I'm filter on NOT_EXECUTED ??? -> this causes BUGID 3189 // $link_info = $tcase_mgr->get_linked_versions($args->tcase_id,'NOT_EXECUTED'); $link_info = $tcase_mgr->get_linked_versions($args->tcase_id); // 20100124 - work only on ACTIVE TEST PLANS => array('plan_status' => 1) if (!is_null($tplanSet = $tproject_mgr->get_all_testplans($args->tproject_id, array('plan_status' => 1)))) { $has_links = array_fill_keys(array_keys($tplanSet), false); $linked_tplans = null; if (!is_null($link_info)) { foreach ($link_info as $tcversion_id => $info) { foreach ($info as $tplan_id => $platform_info) { $has_links[$tplan_id] = true; foreach ($platform_info as $platform_id => $value) { // $gui->tplans[$tplan_id][$platform_id]['tcversion_id']=$value['id']; $linked_tplans[$tplan_id][$platform_id]['tcversion_id'] = $value['tcversion_id']; $linked_tplans[$tplan_id][$platform_id]['version'] = $value['version']; $linked_tplans[$tplan_id][$platform_id]['draw_checkbox'] = false; } }
/** * @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; }