Skip to content

Commit

Permalink
feature/refactoring: #0008667: Possibility to use several different l…
Browse files Browse the repository at this point in the history
…ogic to compute test case exec status counters (present on tree)
  • Loading branch information
fmancardi committed Jul 30, 2019
1 parent 51541c6 commit 21b847f
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 12 deletions.
2 changes: 2 additions & 0 deletions cfg/const.inc.php
Expand Up @@ -956,5 +956,7 @@

define('USE_LATEST_EXEC_ON_CONTEX_FOR_COUNTERS', 1);
define('USE_LATEST_EXEC_ON_TESTPLAN_FOR_COUNTERS',2);
define('USE_LATEST_EXEC_ON_TESTPLAN_PLAT_FOR_COUNTERS',3);


// END
6 changes: 6 additions & 0 deletions config.inc.php
Expand Up @@ -999,9 +999,15 @@
// Default Value
// USE_LATEST_EXEC_ON_CONTEX_FOR_COUNTERS
// USE_LATEST_EXEC_ON_TESTPLAN_FOR_COUNTERS
// USE_LATEST_EXEC_ON_TESTPLAN_PLAT_FOR_COUNTERS
$tlCfg->exec_cfg->tcases_counters_mode =
USE_LATEST_EXEC_ON_CONTEX_FOR_COUNTERS;

$tlCfg->exec_cfg->tcases_counters_mode_domain =
array('USE_LATEST_EXEC_ON_CONTEX_FOR_COUNTERS',
'USE_LATEST_EXEC_ON_TESTPLAN_FOR_COUNTERS',
'USE_LATEST_EXEC_ON_TESTPLAN_PLAT_FOR_COUNTERS');



// ENABLED -> test cases will be coloured according to test case status
Expand Down
9 changes: 8 additions & 1 deletion install/sql/mysql/testlink_create_tables.sql
Expand Up @@ -891,4 +891,11 @@ AS SELECT
FROM /*prefix*/nodes_hierarchy NHTCV
WHERE NHTCV.node_type_id = 4 AND
NOT(EXISTS(SELECT 1 FROM /*prefix*/testcase_platforms TCPL
WHERE TCPL.tcversion_id = NHTCV.id));
WHERE TCPL.tcversion_id = NHTCV.id));


#
CREATE OR REPLACE VIEW /*prefix*/latest_exec_by_testplan_plat
AS SELECT tcversion_id, testplan_id,platform_id,max(id) AS id
FROM /*prefix*/executions
GROUP BY tcversion_id,testplan_id,platform_id;
17 changes: 15 additions & 2 deletions lib/functions/execTreeMenu.inc.php
Expand Up @@ -166,8 +166,21 @@ function execTree(&$dbHandler,&$menuUrl,$context,$objFilters,$objOptions)
}

if( $applyTCCAlgo ) {
$n3 =
$tplan_mgr->getLinkedForExecTreeIVU($context['tplan_id'],$filters,$options);

// But what algo?
switch ($objOptions->exec_tree_counters_logic) {
case USE_LATEST_EXEC_ON_TESTPLAN_FOR_COUNTERS:
$n3 =
$tplan_mgr->getLinkedForExecTreeCross($context['tplan_id'],
$filters,$options);
break;

case USE_LATEST_EXEC_ON_TESTPLAN_PLAT_FOR_COUNTERS:
$n3 =
$tplan_mgr->getLinkedForExecTreeIVU($context['tplan_id'],
$filters,$options);
break;
}
$ssx = $n3['exec'];
if( is_array($n3) ) {
$ssx .= ' UNION ' . $n3['not_run'];
Expand Down
149 changes: 144 additions & 5 deletions lib/functions/testplan.class.php
Expand Up @@ -6138,6 +6138,8 @@ function getLinkedForExecTree($id,$filters=null,$options=null) {
* getLinkedForExecTree()
* getLinkedForTesterAssignmentTree()
* getLinkedTCVersionsSQL()
* getLinkedForExecTreeCross()
* getLinkedForExecTreeIVU()
*
* filters =>
* 'tcase_id','keyword_id','assigned_to','exec_status','build_id',
Expand Down Expand Up @@ -7707,10 +7709,12 @@ function getVersionLinked($tplan_id, $tcase_id) {

}


//
// This method is intended to return minimal data useful
// to create Execution Tree.
// Status on Latest execution on Build,Platform is needed
//
// The Status on Latest execution:
// is computed considering only the selected Platform
//
// @param int $id test plan id
// @param mixed $filters
Expand All @@ -7736,11 +7740,12 @@ function getVersionLinked($tplan_id, $tcase_id) {
// [cf_hash]: default null => do not filter by Custom Fields values
//
//
// [urgencyImportance] : filter only Tc's with certain (urgency*importance)-value
// [urgencyImportance] :
// filter only Tc's with certain (urgency*importance)-value
//
// [tsuites_id]: default null.
// If present only tcversions that are children of this testsuites
// will be included
// If present only tcversions that are children
// of this testsuites will be included
//
// [exec_type] default null -> all types.
// [platform_id]
Expand All @@ -7749,6 +7754,138 @@ function getLinkedForExecTreeIVU($id,$filters=null,$options=null) {
$debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;


$safe['tplan_id'] = intval($id);
$my = $this->initGetLinkedForTree($safe['tplan_id'],$filters,$options);

if( !isset($my['filters']['platform_id']) ||
$my['filters']['platform_id'] == 0 ) {
throw new Exception(__FUNCTION__ . " Needs Platform ID", 1);
}


if( !$my['green_light'] ) {
// No query has to be run, because we know in advance that we are
// going to get NO RECORDS
return null;
}


$sqlLExecOnTPLANPL =
" SELECT LEBTPPL.tcversion_id,LEBTPPL.testplan_id, LEBTPPL.id
FROM {$this->views['latest_exec_by_testplan_plat']} LEBTPPL
WHERE LEBTPPL.testplan_id = {$safe['tplan_id']}
AND LEBTPPL.platform_id = {$safe['platform_id']} ";

// When there is request to filter by BUG ID,
// because BUGS are linked only to EXECUTED test case versions,
// the not_run piece of union is USELESS
$union['not_run'] = null;

$nht = $this->tables['nodes_hierarchy'];

if(!isset($my['filters']['bug_id'])) {
// adding tcversion on output can be useful for
// Filter on Custom Field values,
// because we are saving values at TCVERSION LEVEL
//

$notrun = $this->notRunStatusCode;
$union['not_run'] = "/* {$debugMsg} sqlUnion - not run */" .
" SELECT NH_TCASE.id AS tcase_id,TPTCV.tcversion_id,
COALESCE(E.status,'" . $notrun . "') AS exec_status
FROM {$this->tables['testplan_tcversions']} TPTCV
JOIN $nht NH_TCV ON NH_TCV.id = TPTCV.tcversion_id
JOIN $nht NH_TCASE ON NH_TCASE.id = NH_TCV.parent_id " .
$my['join']['keywords'] .
$my['join']['ua'] .
$my['join']['cf'] .

" /* Get REALLY NOT RUN =>
BOTH LE.id AND E.id ON LEFT OUTER see WHERE */ " .
" LEFT OUTER JOIN ({$sqlLExecOnTPLANPL}) AS LEXBTPLANPL " .
" ON LEXBTPLANPL.testplan_id = TPTCV.testplan_id " .
" AND LEXBTPLANPL.tcversion_id = TPTCV.tcversion_id " .
" AND LEXBTPLANPL.testplan_id = " . $safe['tplan_id'] .
" LEFT OUTER JOIN {$this->tables['executions']} E " .
" ON E.tcversion_id = TPTCV.tcversion_id " .
" AND E.testplan_id = TPTCV.testplan_id " .
" WHERE TPTCV.testplan_id =" . $safe['tplan_id'] .
$my['where']['not_run'] .
" /* Get REALLY NOT RUN => BOTH LE.id AND E.id NULL */ " .
" AND LEXBTPLANPL.id IS NULL";
}

$union['exec'] = "/* {$debugMsg} sqlUnion - executions */" .
" SELECT NH_TCASE.id AS tcase_id,TPTCV.tcversion_id,
COALESCE(E.status,'" . $this->notRunStatusCode . "') AS exec_status
FROM {$this->tables['testplan_tcversions']} TPTCV
JOIN {$this->tables['tcversions']} TCV ON TCV.id = TPTCV.tcversion_id
JOIN $nht NH_TCV ON NH_TCV.id = TPTCV.tcversion_id
JOIN $nht NH_TCASE ON NH_TCASE.id = NH_TCV.parent_id " .
$my['join']['keywords'] .
$my['join']['ua'] .
$my['join']['cf'] .

" JOIN ({$sqlLExecOnTPLANPL}) AS LEXBTPLANPL " .
" ON LEXBTPLANPL.testplan_id = TPTCV.testplan_id " .
" AND LEXBTPLANPL.tcversion_id = TPTCV.tcversion_id " .
" AND LEXBTPLANPL.testplan_id = " . $safe['tplan_id'] .
" JOIN {$this->tables['executions']} E " .
" ON E.id = LEXBTPLANPL.id " .
" AND E.testplan_id = LEXBTPLANPL.testplan_id " .
" AND E.platform_id = LEXBTPLANPL.platform_id " .
$my['where']['where'];

$xql = is_null($union['not_run']) ? $union['exec'] : $union;
return $xql;
}

//
// This method is intended to return minimal data useful
// to create Execution Tree.
//
// The Status on Latest execution:
// is computed considering only the test plan, doing
// logic ignoring selected build & selected platform
//
// @param int $id test plan id
// @param mixed $filters
// @param mixed $options
//
// [tcase_id]: default null => get any testcase
// numeric => just get info for this testcase
//
//
// [keyword_id]: default 0 => do not filter by keyword id
// numeric/array() => filter by keyword id
//
//
// [assigned_to]: default NULL => do not filter by user assign.
// array() with user id to be used on filter
// IMPORTANT NOTICE: this argument is affected by
// [assigned_on_build]
//
// [build_id]: default 0 or null => do not filter by build id
// numeric => filter by build id
//
//
// [cf_hash]: default null => do not filter by Custom Fields values
//
//
// [urgencyImportance] :
// filter only Tc's with certain (urgency*importance)-value
//
// [tsuites_id]: default null.
// If present only tcversions that are children
// of this testsuites will be included
//
// [exec_type] default null -> all types.
// [platform_id]
//
function getLinkedForExecTreeCross($id,$filters=null,$options=null) {
$debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;


$safe['tplan_id'] = intval($id);
$my = $this->initGetLinkedForTree($safe['tplan_id'],$filters,$options);

Expand Down Expand Up @@ -7827,6 +7964,8 @@ function getLinkedForExecTreeIVU($id,$filters=null,$options=null) {
return $xql;
}



} // end class testplan


Expand Down
9 changes: 5 additions & 4 deletions lib/functions/tlTestCaseFilterControl.class.php
Expand Up @@ -2052,19 +2052,20 @@ protected function init_setting_testsgroupby() {
protected function init_setting_exec_tree_counters_logic() {
$key = str_replace('init_','',__FUNCTION__);

$lblKS = $this->configuration->exec_cfg->tcases_counters_mode_domain;

$lblKS = array('use_latest_exec_on_contex_for_counters',
'use_latest_exec_on_testplan_for_counters');
foreach( $lblKS as $lblKey ) {
$code = constant(strtoupper($lblKey));
$this->settings[$key]['items'][$code] = lang_get($lblKey);
$code = constant($lblKey);
$ak = strtolower($lblKey);
$this->settings[$key]['items'][$code] = lang_get($ak);
}


$algo = intval( isset($_REQUEST[$key]) ? $_REQUEST[$key] : 0);
switch($algo) {
case USE_LATEST_EXEC_ON_CONTEX_FOR_COUNTERS:
case USE_LATEST_EXEC_ON_TESTPLAN_FOR_COUNTERS:
case USE_LATEST_EXEC_ON_TESTPLAN_PLAT_FOR_COUNTERS:
break;

default:
Expand Down
3 changes: 3 additions & 0 deletions locale/en_GB/strings.txt
Expand Up @@ -3950,6 +3950,9 @@ $TLS_copy_attachments_from_latest_exec = 'Copy Latest Exec Attachments';
$TLS_exec_tree_counters_logic = 'Tree Counters Latest Exec On';
$TLS_use_latest_exec_on_testplan_for_counters = 'Test Plan';
$TLS_use_latest_exec_on_contex_for_counters = 'Chosen Build';
$TLS_use_latest_exec_on_testplan_plat_for_counters =
'Test Plan on Platform';


$TLS_download_csv = 'Download As CSV';
$TLS_select_platforms = "Select Platforms";
Expand Down

0 comments on commit 21b847f

Please sign in to comment.