Пример #1
0
/**
 * 
 * 
 * @param integer $level
 * @param array &$node reference to recursive map
 * @param array &$tcases_map reference to map that contains info about testcase exec status
 *              when node is of testcase type.
 * 
 * @return datatype description
 * 
 */
function renderExecTreeNode($level, &$node, &$tcase_node, $hash_id_descr, $linkto, $testCasePrefix, $opt)
{
    static $resultsCfg;
    static $l18n;
    static $pf;
    static $doColouringOn;
    static $cssClasses;
    $node_type = $hash_id_descr[$node['node_type_id']];
    $menustring = '';
    if (!$resultsCfg) {
        $doColouringOn['testcase'] = 1;
        $doColouringOn['counters'] = 1;
        if (!is_null($opt['useColors'])) {
            $doColouringOn['testcase'] = $opt['useColors']->testcases;
            $doColouringOn['counters'] = $opt['useColors']->counters;
        }
        $resultsCfg = config_get('results');
        $status_descr_code = $resultsCfg['status_code'];
        foreach ($resultsCfg['status_label'] as $key => $value) {
            $l18n[$status_descr_code[$key]] = lang_get($value);
            // here we use ONLY key
            $cssClasses[$status_descr_code[$key]] = $doColouringOn['testcase'] ? 'class="light_' . $key . '"' : '';
        }
        // Very BAD CHOICE => SIDE EFFECT
        $pf['testsuite'] = $opt['hideTestCases'] ? 'TPLAN_PTS' : ($opt['showTestSuiteContents'] ? 'STS' : null);
        $pf['testproject'] = $opt['hideTestCases'] ? 'TPLAN_PTP' : 'SP';
        if (isset($opt['actionJS'])) {
            if (isset($opt['actionJS']['testproject'])) {
                $pf['testproject'] = $opt['actionJS']['testproject'];
            }
            if (isset($opt['actionJS']['testsuite'])) {
                $pf['testsuite'] = $opt['actionJS']['testsuite'];
            }
        }
        // manage defaults
        $opt['showTestCaseExecStatus'] = isset($opt['showTestCaseExecStatus']) ? $opt['showTestCaseExecStatus'] : true;
        $opt['nodeHelpText'] = isset($opt['nodeHelpText']) ? $opt['nodeHelpText'] : array();
    }
    $name = filterString($node['name']);
    // custom Property that will be accessed by EXT-JS using node.attributes
    $node['testlink_node_name'] = $name;
    $node['testlink_node_type'] = $node_type;
    switch ($node_type) {
        case 'testproject':
        case 'testsuite':
            $node['leaf'] = false;
            // $versionID = 0;
            $pfn = !is_null($pf[$node_type]) ? $pf[$node_type] . "({$node['id']})" : null;
            $testcase_count = isset($node['testcase_count']) ? $node['testcase_count'] : 0;
            $node['text'] = $name . " (" . $testcase_count . ")";
            if ($opt['useCounters']) {
                $node['text'] .= create_counters_info($node, $doColouringOn['counters']);
            }
            if (isset($opt['nodeHelpText'][$node_type])) {
                $node['text'] = '<span title="' . $opt['nodeHelpText'][$node_type] . '">' . $node['text'] . '</span>';
            }
            break;
        case 'testcase':
            $node['leaf'] = true;
            // $versionID = $node['tcversion_id'];
            $pfn = $opt['tc_action_enabled'] ? "ST({$node['id']},{$node['tcversion_id']})" : null;
            $node['text'] = "<span ";
            if (isset($tcase_node[$node['id']])) {
                if ($opt['showTestCaseExecStatus']) {
                    $status_code = $tcase_node[$node['id']]['exec_status'];
                    $node['text'] .= "{$cssClasses[$status_code]} " . '  title="' . $l18n[$status_code] . '" alt="' . $l18n[$status_code] . '">';
                }
            }
            if ($opt['showTestCaseID']) {
                $node['text'] .= "<b>" . htmlspecialchars($testCasePrefix . $node['external_id']) . "</b>:";
            }
            $node['text'] .= "{$name}</span>";
            break;
        default:
            $pfn = "ST({$node['id']})";
            break;
    }
    $node['position'] = isset($node['node_order']) ? $node['node_order'] : 0;
    $node['href'] = is_null($pfn) ? '' : "javascript:{$pfn}";
    // ----------------------------------------------------------------------------------------------
    if (isset($tcase_node[$node['id']])) {
        unset($tcase_node[$node['id']]);
        // dam it NO COMMENT!
    }
    if (isset($node['childNodes']) && $node['childNodes']) {
        // need to work always original object in order to change it's values using reference .
        // Can not assign anymore to intermediate variables.
        $nodes_qty = sizeof($node['childNodes']);
        for ($idx = 0; $idx < $nodes_qty; $idx++) {
            if (is_null($node['childNodes'][$idx])) {
                continue;
            }
            $menustring .= renderExecTreeNode($level + 1, $node['childNodes'][$idx], $tcase_node, $hash_id_descr, $linkto, $testCasePrefix, $opt);
        }
    }
    return $menustring;
}
Пример #2
0
/**
 * 
 * 
 * @param integer $level
 * @param array &$node reference to recursive map
 * @param array &$tcases_map reference to map that contains info about testcase exec status
 *              when node is of testcase type.
 * @param boolean $bHideTCs 1 -> hide testcase
 * 
 * @return datatype description
 * 
 * @internal Revisions:
 *	20100611 - franciscom - removed useless $getArguments
 *	20071229 - franciscom -added $useCounters,$useColors
 */
function renderExecTreeNode($level, &$node, &$tcase_node, $hash_id_descr, $tc_action_enabled, $linkto, $bHideTCs, $useCounters, $useColors, $showTestCaseID, $testCasePrefix, $showTestSuiteContents)
{
    $node_type = $hash_id_descr[$node['node_type_id']];
    $menustring = '';
    extjs_renderExecTreeNodeOnOpen($node, $node_type, $tcase_node, $tc_action_enabled, $bHideTCs, $useCounters, $useColors, $showTestCaseID, $testCasePrefix, $showTestSuiteContents);
    if (isset($tcase_node[$node['id']])) {
        unset($tcase_node[$node['id']]);
    }
    if (isset($node['childNodes']) && $node['childNodes']) {
        // 20080615 - franciscom - need to work always original object
        //                         in order to change it's values using reference .
        // Can not assign anymore to intermediate variables.
        $nodes_qty = sizeof($node['childNodes']);
        for ($idx = 0; $idx < $nodes_qty; $idx++) {
            if (is_null($node['childNodes'][$idx])) {
                continue;
            }
            $menustring .= renderExecTreeNode($level + 1, $node['childNodes'][$idx], $tcase_node, $hash_id_descr, $tc_action_enabled, $linkto, $bHideTCs, $useCounters, $useColors, $showTestCaseID, $testCasePrefix, $showTestSuiteContents);
        }
    }
    return $menustring;
}
Пример #3
0
function testPlanTree(&$dbHandler, &$menuUrl, $tproject_id, $tproject_name, $tplan_id, $tplan_name, $objFilters, $objOptions)
{
    $debugMsg = ' - Method: ' . __FUNCTION__;
    $chronos[] = $tstart = microtime(true);
    $treeMenu = new stdClass();
    $treeMenu->rootnode = null;
    $treeMenu->menustring = '';
    $resultsCfg = config_get('results');
    $glueChar = config_get('testcase_cfg')->glue_character;
    $menustring = null;
    $tplan_tcases = null;
    $renderTreeNodeOpt = null;
    $renderTreeNodeOpt['showTestCaseID'] = config_get('treemenu_show_testcase_id');
    list($filters, $options, $renderTreeNodeOpt['showTestSuiteContents'], $renderTreeNodeOpt['useCounters'], $renderTreeNodeOpt['useColors'], $colorBySelectedBuild) = initExecTree($objFilters, $objOptions);
    $tplan_mgr = new testplan($dbHandler);
    $tproject_mgr = new testproject($dbHandler);
    $tree_manager = $tplan_mgr->tree_manager;
    $tcase_node_type = $tree_manager->node_descr_id['testcase'];
    $hash_descr_id = $tree_manager->get_available_node_types();
    $hash_id_descr = array_flip($hash_descr_id);
    $tcase_prefix = $tproject_mgr->getTestCasePrefix($tproject_id) . $glueChar;
    $nt2exclude = array('testplan' => 'exclude_me', 'requirement_spec' => 'exclude_me', 'requirement' => 'exclude_me');
    $nt2exclude_children = array('testcase' => 'exclude_my_children', 'requirement_spec' => 'exclude_my_children');
    // remove test spec, test suites (or branches) that have ZERO test cases linked to test plan
    //
    // IMPORTANT:
    // using 'order_cfg' => array("type" =>'exec_order',"tplan_id" => $tplan_id))
    // makes the magic of ignoring test cases not linked to test plan.
    // This unexpected bonus can be useful on export test plan as XML.
    //
    $my['options'] = array('recursive' => true, 'remove_empty_nodes_of_type' => $tree_manager->node_descr_id['testsuite'], 'order_cfg' => array("type" => 'exec_order', "tplan_id" => $tplan_id), 'hideTestCases' => $options['hideTestCases'], 'tc_action_enabled' => $options['tc_action_enabled'], 'showTestCaseExecStatus' => $options['showTestCaseExecStatus']);
    $my['filters'] = array('exclude_node_types' => $nt2exclude, 'exclude_children_of' => $nt2exclude_children);
    if (isset($objFilters->filter_toplevel_testsuite) && is_array($objFilters->filter_toplevel_testsuite)) {
        $my['filters']['exclude_branches'] = $objFilters->filter_toplevel_testsuite;
    }
    if (isset($objFilters->filter_custom_fields) && is_array($objFilters->filter_custom_fields)) {
        $my['filters']['filter_custom_fields'] = $objFilters->filter_custom_fields;
    }
    if (property_exists($objOptions, 'actionJS')) {
        foreach (array('testproject', 'testsuite', 'testcase') as $nk) {
            if (isset($objOptions->actionJS[$nk])) {
                $renderTreeNodeOpt['actionJS'][$nk] = $objOptions->actionJS[$nk];
            }
        }
    }
    if (property_exists($objOptions, 'nodeHelpText')) {
        foreach (array('testproject', 'testsuite', 'testcase') as $nk) {
            if (isset($objOptions->nodeHelpText[$nk])) {
                $renderTreeNodeOpt['nodeHelpText'][$nk] = $objOptions->nodeHelpText[$nk];
            }
        }
    }
    $test_spec = $tplan_mgr->getSkeleton($tplan_id, $tproject_id, $my['filters'], $my['options']);
    $test_spec['name'] = $tproject_name . " / " . $tplan_name;
    // To be discussed
    $test_spec['id'] = $tproject_id;
    $test_spec['node_type_id'] = $hash_descr_id['testproject'];
    $test_spec['node_type'] = 'testproject';
    $map_node_tccount = array();
    $tplan_tcases = array();
    if ($test_spec) {
        if (is_null($filters['tcase_id']) || $filters['tcase_id'] > 0) {
            // Step 1 - get item set with exec status.
            // This has to scopes:
            // 1. tree coloring according exec status on (Test plan, platform, build ) context
            // 2. produce sql that can be used to reduce item set on combination with filters
            //    that can not be used on this step like:
            //    a. test cases belonging to branch with root TEST SUITE
            //    b. keyword filter on AND MODE
            //    c. execution results on other builds, any build etc
            //
            // WE NEED TO ADD FILTERING on CUSTOM FIELD VALUES, WE HAVE NOT REFACTORED
            // THIS YET.
            //
            if (!is_null($sql2do = $tplan_mgr->{$objOptions->getTreeMethod}($tplan_id, $filters, $options))) {
                $doPinBall = false;
                if (is_array($sql2do)) {
                    if ($doPinBall = $filters['keyword_filter_type'] == 'And') {
                        $kmethod = "fetchRowsIntoMapAddRC";
                        $unionClause = " UNION ALL ";
                    } else {
                        $kmethod = "fetchRowsIntoMap";
                        $unionClause = ' UNION ';
                    }
                    $sql2run = $sql2do['exec'] . $unionClause . $sql2do['not_run'];
                } else {
                    $kmethod = "fetchRowsIntoMap";
                    $sql2run = $sql2do;
                }
                $tplan_tcases = $dbHandler->{$kmethod}($sql2run, 'tcase_id');
                if ($doPinBall && !is_null($tplan_tcases)) {
                    $kwc = count($filters['keyword_id']);
                    $ak = array_keys($tplan_tcases);
                    $mx = null;
                    foreach ($ak as $tk) {
                        if ($tplan_tcases[$tk]['recordcount'] == $kwc) {
                            $mx[$tk] = $tplan_tcases[$tk];
                        }
                    }
                    $tplan_tcases = null;
                    $tplan_tcases = $mx;
                }
                $setTestCaseStatus = $tplan_tcases;
            }
        }
        if (is_null($tplan_tcases)) {
            $tplan_tcases = array();
        }
        // OK, now we need to work on status filters
        // if "any" was selected as filtering status, don't filter by status
        $targetExecStatus = (array) (isset($objFilters->filter_result_result) ? $objFilters->filter_result_result : null);
        if (!is_null($targetExecStatus) && !in_array($resultsCfg['status_code']['all'], $targetExecStatus)) {
            applyStatusFilters($tplan_id, $tplan_tcases, $objFilters, $tplan_mgr, $resultsCfg['status_code']);
        }
        if (isset($my['filters']['filter_custom_fields']) && isset($test_spec['childNodes'])) {
            $test_spec['childNodes'] = filter_by_cf_values($dbHandler, $test_spec['childNodes'], $my['filters']['filter_custom_fields'], $hash_descr_id);
        }
        // here we have LOT OF CONFUSION, sometimes we use $my['options'] other $options
        $pnFilters = null;
        $pnOptions = array('hideTestCases' => $my['options']['hideTestCases'], 'viewType' => 'executionTree');
        $testcase_counters = prepareExecTreeNode($dbHandler, $test_spec, $map_node_tccount, $tplan_tcases, $pnFilters, $pnOptions);
        foreach ($testcase_counters as $key => $value) {
            $test_spec[$key] = $testcase_counters[$key];
        }
        $keys = array_keys($tplan_tcases);
        $renderTreeNodeOpt['hideTestCases'] = $my['options']['hideTestCases'];
        // $renderTreeNodeOpt['tc_action_enabled'] = 1;
        $renderTreeNodeOpt['tc_action_enabled'] = isset($my['options']['tc_action_enabled']) ? $my['options']['tc_action_enabled'] : 1;
        // $renderTreeNodeOpt['nodeHelpText'] = $my['options']['nodeHelpText'];
        $renderTreeNodeOpt['showTestCaseExecStatus'] = $my['options']['showTestCaseExecStatus'];
        $menustring = renderExecTreeNode(1, $test_spec, $tplan_tcases, $hash_id_descr, $menuUrl, $tcase_prefix, $renderTreeNodeOpt);
    }
    // if($test_spec)
    $treeMenu->rootnode = new stdClass();
    $treeMenu->rootnode->name = $test_spec['text'];
    $treeMenu->rootnode->id = $test_spec['id'];
    $treeMenu->rootnode->leaf = $test_spec['leaf'];
    $treeMenu->rootnode->text = $test_spec['text'];
    $treeMenu->rootnode->position = $test_spec['position'];
    $treeMenu->rootnode->href = $test_spec['href'];
    if (!is_null($menustring)) {
        // 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']));
        }
        // 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,'),array(':[]','',''), $menustring);
        $menustring = str_ireplace(array(':null', ',null', 'null,', 'null'), array(':[]', '', '', ''), $menustring);
    }
    $treeMenu->menustring = $menustring;
    return array($treeMenu, $keys);
}
Пример #4
0
 /**
  * 
  * 
  * @param integer $level
  * @param array &$node reference to recursive map
  * @param array &$tcases_map reference to map that contains info about testcase exec status
  *              when node is of testcase type.
  * @param boolean $bHideTCs 1 -> hide testcase
  * 
  * @return datatype description
  * 
  * @internal revisions
  */
 function renderExecTreeNode($env, $level, &$node, &$tcase_node, $linkto, $options, $auxCfg)
 {
     $node_type = $auxCfg['hash_id_descr'][$node['node_type_id']];
     $nodeAttr = array('node_type' => $node_type, 'testCasePrefix' => $auxCfg['testCasePrefix']);
     extjs_renderExecTreeNodeOnOpen($node, $nodeAttr, $tcase_node, $options, $env);
     // echo $node['id'] . '<br>';
     // new dBug($tcase_node);
     if (isset($tcase_node[$node['id']])) {
         unset($tcase_node[$node['id']]);
     }
     if (isset($node['childNodes']) && $node['childNodes']) {
         // 20080615 - franciscom - need to work always original object
         //                         in order to change it's values using reference .
         // Can not assign anymore to intermediate variables.
         $nodes_qty = sizeof($node['childNodes']);
         for ($idx = 0; $idx < $nodes_qty; $idx++) {
             if (is_null($node['childNodes'][$idx])) {
                 continue;
             }
             renderExecTreeNode($env, $level + 1, $node['childNodes'][$idx], $tcase_node, $linkto, $options, $auxCfg);
         }
     }
 }