/** * @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 generateTestSpecTreeNew($env, $linkto, $filters = null, $options = null) { $chronos[] = microtime(true); $my = array(); $my['options'] = array('forPrinting' => 0, 'hideTestCases' => 0, 'tc_action_enabled' => 1, 'viewType' => 'testSpecTree'); $my['filters'] = array('keywords' => null, 'testplan' => null); $my['options'] = array_merge($my['options'], (array) $options); $my['filters'] = array_merge($my['filters'], (array) $filters); $treeMenu = new stdClass(); $treeMenu->rootnode = null; $treeMenu->menustring = ''; $menustring = null; $tproject_mgr = new testproject($db); $tree_manager =& $tproject_mgr->tree_manager; $hash_descr_id = $tree_manager->get_available_node_types(); $hash_id_descr = array_flip($hash_descr_id); $status_descr_code = $this->cfg->results['status_code']; $status_code_descr = $this->cfg->results['code_status']; $decoding_hash = array('node_id_descr' => $hash_id_descr, 'status_descr_code' => $status_descr_code, 'status_code_descr' => $status_code_descr); $tcase_prefix = $tproject_mgr->getTestCasePrefix($tproject_id) . $this->cfg->glueChar; $test_spec = getTestSpecTree($tproject_id, $tproject_mgr, $filters); //$chronos[] = microtime(true);$tnow = end($chronos);$tprev = prev($chronos); //$t_elapsed = number_format( $tnow - $tprev, 4); //echo '<br> ' . __FUNCTION__ . ' Elapsed (sec) (get_subtree()):' . $t_elapsed .'<br>'; //reset($chronos); // Added root node for test specification -> testproject $test_spec['name'] = $tproject_name; $test_spec['id'] = $tproject_id; $test_spec['node_type_id'] = $hash_descr_id['testproject']; $map_node_tccount = array(); $tplan_tcs = null; if ($test_spec) { if (isset($my['filters']['filter_custom_fields']) && isset($test_spec['childNodes'])) { $test_spec['childNodes'] = $this->tprojectMgr->filterByCFValues($test_spec['childNodes'], $my['filters']['filter_custom_fields']); } $pnFilters = array('keywords' => $my['filters']['filter_keywords'], 'keywords_filter_type' => $my['filters']['filter_keywords_filter_type']); // TICKET 4353 - added active/inactive filter $pnOptions = array('hideTestCases' => $my['options']['hideTestCases'], 'ignoreInactiveTestCases' => $my['options']['ignore_inactive_testcases'], 'ignoreActiveTestCases' => $my['options']['ignore_active_testcases']); // Important/CRITIC: // prepareTestSpecNode() will make changes to $test_spec like filtering by test case keywords. $testcase_counters = prepareTestSpecNode($db, $tproject_mgr, $tproject_id, $test_spec, $map_node_tccount, $pnFilters, $pnOptions); //$chronos[] = microtime(true);$tnow = end($chronos);$tprev = prev($chronos); //$t_elapsed = number_format( $tnow - $tprev, 4); //echo '<br> ' . __FUNCTION__ . ' Elapsed (sec) (get_subtree()):' . $t_elapsed .'<br>'; //reset($chronos); if (is_null($test_spec)) { $test_spec['name'] = $tproject_name; $test_spec['id'] = $tproject_id; $test_spec['node_type_id'] = $hash_descr_id['testproject']; } foreach ($testcase_counters as $key => $value) { $test_spec[$key] = $testcase_counters[$key]; } $showTestCaseID = config_get('treemenu_show_testcase_id'); $menustring = renderTreeNode(1, $test_spec, $hash_id_descr, $my['options']['tc_action_enabled'], $linkto, $tcase_prefix, $my['options']['forPrinting'], $showTestCaseID); } $menustring = ''; $treeMenu->rootnode = new stdClass(); $treeMenu->rootnode->name = $test_spec['text']; $treeMenu->rootnode->id = $test_spec['id']; $treeMenu->rootnode->leaf = isset($test_spec['leaf']) ? $test_spec['leaf'] : false; $treeMenu->rootnode->text = $test_spec['text']; $treeMenu->rootnode->position = $test_spec['position']; $treeMenu->rootnode->href = $test_spec['href']; // Change key ('childNodes') to the one required by Ext JS tree. if (isset($test_spec['childNodes'])) { $menustring = str_ireplace('childNodes', 'children', json_encode($test_spec['childNodes'])); } if (!is_null($menustring)) { // Remove null elements (Ext JS tree do not like it ). // :null happens on -> "children":null,"text" that must become "children":[],"text" $menustring = str_ireplace(array(':null', ',null', 'null,', 'null'), array(':[]', '', '', ''), $menustring); } $treeMenu->menustring = $menustring; return $treeMenu; }