/** * * */ 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 initializeGui(&$db, $args) { $tcaseCfg = config_get('testcase_cfg'); $reqCfg = config_get('req_cfg'); $gui = new stdClass(); $gui->mainTitle = ''; $tprojectMgr = new testproject($db); $tcasePrefix = $tprojectMgr->getTestCasePrefix($args->tproject_id); $gui->tree_title = ''; $gui->ajaxTree = new stdClass(); $gui->ajaxTree->root_node = new stdClass(); $gui->ajaxTree->dragDrop = new stdClass(); $gui->ajaxTree->dragDrop->enabled = false; $gui->ajaxTree->dragDrop->BackEndUrl = null; $gui->ajaxTree->children = ''; // Prefix for cookie used to save tree state $gui->ajaxTree->cookiePrefix = 'print' . str_replace(' ', '_', $args->doc_type) . '_'; $gui->doc_type = $args->doc_type; switch ($args->doc_type) { // BUGID 3067 case 'reqspec': $gui->tree_title = lang_get('title_req_print_navigator'); $gui->ajaxTree->loader = $args->basehref . 'lib/ajax/getrequirementnodes.php?' . "root_node={$args->tproject_id}&" . "show_children=0&operation=print"; $gui->ajaxTree->loadFromChildren = 0; $gui->ajaxTree->root_node->href = "javascript:TPROJECT_PTP_RS({$args->tproject_id})"; $gui->ajaxTree->root_node->id = $args->tproject_id; $req_qty = $tprojectMgr->count_all_requirements($args->tproject_id); $gui->ajaxTree->root_node->name = htmlspecialchars($args->tproject_name) . " ({$req_qty})"; $gui->ajaxTree->cookiePrefix .= $gui->ajaxTree->root_node->id . "_"; $gui->mainTitle = lang_get('requirement_specification_report'); break; // end BUGID 3067 // end BUGID 3067 case 'testspec': $gui->tree_title = lang_get('title_tc_print_navigator'); $gui->ajaxTree->loader = $args->basehref . 'lib/ajax/gettprojectnodes.php?' . "root_node={$args->tproject_id}&" . "show_tcases=0&operation=print&" . "tcprefix=" . urlencode($tcasePrefix . $tcaseCfg->glue_character) . "}"; $gui->ajaxTree->loadFromChildren = 0; $gui->ajaxTree->root_node->href = "javascript:TPROJECT_PTP({$args->tproject_id})"; $gui->ajaxTree->root_node->id = $args->tproject_id; $tcase_qty = $tprojectMgr->count_testcases($args->tproject_id); $gui->ajaxTree->root_node->name = htmlspecialchars($args->tproject_name) . " ({$tcase_qty})"; $gui->ajaxTree->cookiePrefix .= $gui->ajaxTree->root_node->id . "_"; $gui->mainTitle = lang_get('testspecification_report'); break; case 'testreport': $gui->mainTitle = lang_get('test_report'); break; case 'testplan': $gui->tree_title = lang_get('title_tp_print_navigator'); $gui->ajaxTree->loadFromChildren = 1; $gui->ajaxTree->loader = ''; $gui->mainTitle = lang_get('test_plan'); break; } $gui->mainTitle .= ' - ' . lang_get('doc_opt_title'); $gui->outputFormat = array(FORMAT_HTML => lang_get('format_html'), FORMAT_ODT => lang_get('format_odt'), FORMAT_MSWORD => lang_get('format_msword')); return $gui; }
/** * Initialize gui (stdClass) object that will be used as argument * in call to Template Engine. * * @param class pointer args: object containing User Input and some session values * TBD structure * * ? tprojectMgr: test project manager object. * ? treeDragDropEnabled: true/false. Controls Tree drag and drop behaivor. * * @return stdClass TBD structure */ function initializeGui(&$db, $args) { $tcaseCfg = config_get('testcase_cfg'); $reqCfg = config_get('req_cfg'); $gui = new stdClass(); $gui->showOptionsCheckBoxes = $gui->showOptions = $args->showOptions; $gui->showHelpIcon = $args->showHelpIcon; $gui->mainTitle = ''; $gui->outputFormat = array(FORMAT_HTML => lang_get('format_html'), FORMAT_MSWORD => lang_get('format_pseudo_msword')); $gui->outputOptions = init_checkboxes($args); if ($gui->showOptions == false) { $loop2do = count($gui->outputOptions); for ($idx = 0; $idx < $loop2do; $idx++) { $gui->outputOptions[$idx]['checked'] = 'y'; } } $tprojectMgr = new testproject($db); $tcasePrefix = $tprojectMgr->getTestCasePrefix($args->tproject_id); $gui->tree_title = ''; $gui->ajaxTree = new stdClass(); $gui->ajaxTree->root_node = new stdClass(); $gui->ajaxTree->dragDrop = new stdClass(); $gui->ajaxTree->dragDrop->enabled = false; $gui->ajaxTree->dragDrop->BackEndUrl = null; $gui->ajaxTree->children = ''; // improved cookie prefix for test spec doc and req spec doc $gui->ajaxTree->cookiePrefix = $args->doc_type . '_doc_'; $gui->doc_type = $args->doc_type; $addTestPlanID = false; switch ($args->doc_type) { case DOC_REQ_SPEC: $gui->showOptions = true; $gui->showOptionsCheckBoxes = false; $gui->tree_title = lang_get('title_req_print_navigator'); $gui->ajaxTree->loader = $args->basehref . 'lib/ajax/getrequirementnodes.php?' . "root_node={$args->tproject_id}&show_children=0&operation=print"; $gui->ajaxTree->loadFromChildren = 0; $gui->ajaxTree->root_node->href = "javascript:TPROJECT_PTP_RS({$args->tproject_id})"; $gui->ajaxTree->root_node->id = $args->tproject_id; $req_qty = $tprojectMgr->count_all_requirements($args->tproject_id); $gui->ajaxTree->root_node->name = htmlspecialchars($args->tproject_name) . " ({$req_qty})"; $gui->ajaxTree->cookiePrefix .= "tproject_id_" . $gui->ajaxTree->root_node->id . "_"; $gui->mainTitle = lang_get('requirement_specification_report'); break; case DOC_TEST_SPEC: $gui->tree_title = lang_get('title_tc_print_navigator'); $gui->ajaxTree->loader = $args->basehref . 'lib/ajax/gettprojectnodes.php?' . "root_node={$args->tproject_id}&" . "show_tcases=0&operation=print&" . "tcprefix=" . urlencode($tcasePrefix . $tcaseCfg->glue_character) . "}"; $gui->ajaxTree->loadFromChildren = 0; $gui->ajaxTree->root_node->href = "javascript:TPROJECT_PTP({$args->tproject_id})"; $gui->ajaxTree->root_node->id = $args->tproject_id; $tcase_qty = $tprojectMgr->count_testcases($args->tproject_id); $gui->ajaxTree->root_node->name = htmlspecialchars($args->tproject_name) . " ({$tcase_qty})"; $gui->ajaxTree->cookiePrefix .= "tproject_id_" . $gui->ajaxTree->root_node->id . "_"; $gui->mainTitle = lang_get('testspecification_report'); break; case DOC_TEST_PLAN_EXECUTION: $addTestPlanID = true; $gui->mainTitle = lang_get('test_report'); break; case DOC_TEST_PLAN_DESIGN: $addTestPlanID = true; $gui->tree_title = lang_get('title_tp_print_navigator'); $gui->ajaxTree->loadFromChildren = 1; $gui->ajaxTree->loader = ''; $gui->mainTitle = lang_get('test_plan'); break; case DOC_TEST_PLAN_EXECUTION_ON_BUILD: $addTestPlanID = true; $gui->mainTitle = lang_get('test_report_on_build'); break; } // Do not move if ($args->mainTitle == '') { $gui->mainTitle .= ' - ' . lang_get('doc_opt_title'); } else { $gui->mainTitle = $args->mainTitle; } $gui->getArguments = "&type=" . $args->doc_type; if ($addTestPlanID) { $gui->getArguments .= '&docTestPlanId=' . $args->tplan_id; } return $gui; }
$testplanID = isset($_SESSION['testplanID']) ? intval($_SESSION['testplanID']) : 0; $accessibleItems = $tproject_mgr->get_accessible_for_user($user->dbID, array('output' => 'map_name_with_inactive_mark')); $tprojectQty = $tproject_mgr->getItemCount(); $userIsBlindFolded = (is_null($accessibleItems) || count($accessibleItems) == 0) && $tprojectQty > 0; if ($userIsBlindFolded) { $testprojectID = $testplanID = 0; $_SESSION['testprojectTopMenu'] = ''; } $tplan2check = null; $currentUser = $_SESSION['currentUser']; $userID = $currentUser->dbID; $gui = new stdClass(); $gui->grants = getGrants($db, $user, $userIsBlindFolded); $gui->hasTestCases = false; if ($gui->grants['view_tc']) { $gui->hasTestCases = $tproject_mgr->count_testcases($testprojectID) > 0 ? 1 : 0; } $gui->hasKeywords = false; if ($gui->hasTestCases) { $gui->hasKeywords = $tproject_mgr->hasKeywords($testprojectID); } // ----- Test Plan Section -------------------------------------------------------------- /** * @TODO - franciscom - we must understand if these two calls are really needed, * or is enough just call to getAccessibleTestPlans() */ $filters = array('plan_status' => ACTIVE); $gui->num_active_tplans = $tproject_mgr->getActiveTestPlansCount($testprojectID); //sizeof($tproject_mgr->get_all_testplans($testprojectID,$filters)); // get Test Plans available for the user $arrPlans = $currentUser->getAccessibleTestPlans($db, $testprojectID);
/** * @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; }