PageRenderTime 56ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/results/resultsByStatus.php

https://bitbucket.org/pfernandez/testlink1.9.6
PHP | 451 lines | 319 code | 48 blank | 84 comment | 42 complexity | 0f9f375f83ae25e65e3c1a64fd9c5339 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, GPL-3.0
  1. <?php
  2. /**
  3. * TestLink Open Source Project - http://testlink.sourceforge.net/
  4. * This script is distributed under the GNU General Public License 2 or later.
  5. *
  6. * Manages test plan operations and related items like Custom fields,
  7. * Builds, Custom fields, etc
  8. *
  9. * @package TestLink
  10. * @author Martin Havlat <havlat@users.sourceforge.net>
  11. * @author Chad Rosen
  12. * @author kevyn levy
  13. *
  14. * @copyright 2007-2010, TestLink community
  15. * @version CVS: $Id: resultsByStatus.php,v 1.93 2010/08/31 19:40:15 mx-julian Exp $
  16. * @link http://www.teamst.org/index.php
  17. *
  18. *
  19. * @internal Revisions:
  20. * 20100831 - Julian - BUGID 3722 - fixed not run report
  21. * - BUGID 3721 - added without_bugs_counter again
  22. * - BUGID 3731 - fixed failed blocked test cases report
  23. * 20100823 - Julian - changed default grouping and sorting
  24. * 20100823 - Julian - table now uses a unique table id per test project and report type
  25. * 20100816 - Julian - changed default width for table columns
  26. * - added default sorting
  27. * 20100719 - Eloff - Implement extTable for this report
  28. * 20100617 - eloff - BUGID 3255 - fix bug links if available
  29. * 201005 - Julian - BUGID 3492 - show only test case summary for not run test cases
  30. * else show exec notes
  31. * 20100425 - franciscom - BUGID 3356
  32. * 20100124 - eloff - use buildExternalIdString()
  33. * 20091016 - franciscom - work still is needed to display LINK to BUG
  34. * 20091011 - franciscom - refactoring to do not use result.class
  35. * 20090517 - franciscom - fixed management of deleted testers
  36. * 20090414 - amikhullar - BUGID: 2374 - Show Assigned User in the Not Run Test Cases Report
  37. * 20090325 - amkhullar - BUGID 2249
  38. * 20090325 - amkhullar - BUGID 2267
  39. * 20080602 - franciscom - changes due to BUGID 1504
  40. * 20070623 - franciscom - BUGID 911
  41. */
  42. require('../../config.inc.php');
  43. require_once('common.php');
  44. require_once('displayMgr.php');
  45. require_once('users.inc.php');
  46. require_once('exttable.class.php');
  47. require_once('exec.inc.php'); // used for bug string lookup
  48. if (config_get('interface_bugs') != 'NO')
  49. {
  50. require_once(TL_ABS_PATH. 'lib' . DIRECTORY_SEPARATOR . 'bugtracking' .
  51. DIRECTORY_SEPARATOR . 'int_bugtracking.php');
  52. }
  53. testlinkInitPage($db,true,false,"checkRights");
  54. $templateCfg = templateConfiguration();
  55. $resultsCfg = config_get('results');
  56. $statusCode = $resultsCfg['status_code'];
  57. $args = init_args($statusCode);
  58. $gui = initializeGui($statusCode,$args);
  59. $tplan_mgr = new testplan($db);
  60. $tproject_mgr = new testproject($db);
  61. $tcase_mgr = new testcase($db);
  62. $tplan_info = $tplan_mgr->get_by_id($args->tplan_id);
  63. $tproject_info = $tproject_mgr->get_by_id($args->tproject_id);
  64. $getOpt = array('outputFormat' => 'map');
  65. $gui->platformSet = $tplan_mgr->getPlatforms($args->tplan_id,$getOpt);
  66. $show_platforms = !is_null($gui->platformSet);
  67. if( is_null($gui->platformSet) )
  68. {
  69. $gui->platformSet = array('');
  70. }
  71. $gui->bugInterfaceOn = config_get('bugInterfaceOn');
  72. $bugInterface = null;
  73. if ($gui->bugInterfaceOn) {
  74. $bugInterface = config_get('bugInterface');
  75. }
  76. $deleted_user_label = lang_get('deleted_user');
  77. $gui->tplan_name = $tplan_info['name'];
  78. $gui->tproject_name = $tproject_info['name'];
  79. $testCaseCfg = config_get('testcase_cfg');
  80. $mailCfg = buildMailCfg($gui);
  81. $arrOwners = getUsersForHtmlOptions($db);
  82. $fl=$tproject_mgr->tree_manager->get_children($args->tproject_id,
  83. array( 'testcase', 'exclude_me',
  84. 'testplan' => 'exclude_me',
  85. 'requirement_spec' => 'exclude_me' ));
  86. $loop2do = count($fl);
  87. $topLevelSuites=null;
  88. $myRBB = null;
  89. for($idx=0 ; $idx < $loop2do; $idx++)
  90. {
  91. $topLevelSuites[$fl[$idx]['id']]=array('name' => $fl[$idx]['name'], 'items' => null);
  92. }
  93. if( $args->type == $statusCode['not_run'] )
  94. {
  95. //BUGID 3722
  96. $cfg = config_get('results');
  97. $filters = array('exec_status' => $cfg['status_code']['not_run']);
  98. $options = array('output' => 'array', 'details' => 'summary');
  99. $myRBB = $tplan_mgr->get_linked_tcversions($args->tplan_id,$filters, $options);
  100. $user_key='user_id';
  101. //to be able to use only one php file to generate not run and failed/blocked report
  102. //we need to manipulate the myRBB array for not run report to match the same array
  103. //structure as on failed/blocked report: output-array vs output-mapOfMap
  104. //only manipulate the array if it has results to not pretend the array has content
  105. if(count($myRBB) > 0 ) {
  106. $myRBB = array(0 => $myRBB);
  107. }
  108. }
  109. else
  110. {
  111. $filters = array('exec_status' => array($args->type));
  112. //mapOfMapPlatformBuild because we need all executions of all builds for each platform
  113. $options = array('output' => 'mapOfMapExecPlatform' , 'last_execution' => true, 'only_executed' => true, 'details' => 'summary',
  114. 'execution_details' => 'add_build');
  115. $myRBB = $tplan_mgr->get_linked_tcversions($args->tplan_id,$filters,$options);
  116. $user_key='tester_id';
  117. }
  118. if( !is_null($myRBB) and count($myRBB) > 0 )
  119. {
  120. $pathCache=null;
  121. $topCache=null;
  122. $levelCache=null;
  123. $gdx=0;
  124. foreach($myRBB as $item)
  125. {
  126. foreach($item as $testcase) {
  127. $suiteName='';
  128. $bugString='';
  129. if( $testcase[$user_key] == 0 )
  130. {
  131. $testerName = lang_get('nobody');
  132. }
  133. else
  134. {
  135. if (array_key_exists($testcase[$user_key], $arrOwners))
  136. {
  137. $testerName = $arrOwners[$testcase[$user_key]];
  138. }
  139. else
  140. {
  141. // user id has been deleted
  142. $testerName = sprintf($deleted_user_label,$testcase[$user_key]);
  143. }
  144. }
  145. $tcaseName = buildExternalIdString($tproject_info['prefix'], $testcase['external_id']). ':' . $testcase['name'];
  146. if( !isset($pathCache[$testcase['tc_id']]) )
  147. {
  148. $dummy=$tcase_mgr->getPathLayered(array($testcase['tc_id']));
  149. $pathCache[$testcase['tc_id']] = $dummy[$testcase['testsuite_id']]['value'];
  150. $levelCache[$testcase['tc_id']] = $dummy[$testcase['testsuite_id']]['level'];
  151. $ky=current(array_keys($dummy));
  152. $topCache[$testcase['tc_id']]=$ky;
  153. }
  154. $verbosePath = $pathCache[$testcase['tc_id']];
  155. $level = $levelCache[$testcase['tc_id']];
  156. if( $args->type == $statusCode['not_run'] )
  157. {
  158. $build_mgr = new build_mgr($db);
  159. if (isset($testcase['assigned_build_id'])) {
  160. $build_info = $build_mgr->get_by_id($testcase['assigned_build_id']);
  161. $testcase['assigned_build_name'] = $build_info['name'];
  162. } else {
  163. $testcase['assigned_build_name'] = lang_get('unassigned');
  164. }
  165. // When not run, test case version, is the version currently linked to test plan
  166. $topLevelSuites[$topCache[$testcase['tc_id']]]['items'][$level][] =
  167. array('suiteName' => $verbosePath, 'level' => $level,
  168. 'testTitle' => htmlspecialchars($tcaseName),
  169. 'testVersion' => $testcase['version'],
  170. 'platformName' => htmlspecialchars($testcase['platform_name']),
  171. 'buildName' => htmlspecialchars($testcase['assigned_build_name']),
  172. 'testerName' => htmlspecialchars($testerName),
  173. 'notes' => strip_tags($testcase['summary']),
  174. 'platformID' => $testcase['platform_id']);
  175. }
  176. else
  177. {
  178. // BUGID 3492
  179. // BUGID 3356
  180. // When test case has been runned, version must be get from executions.tcversion_number
  181. if ($gui->bugInterfaceOn) {
  182. $bugs = get_bugs_for_exec($db, $bugInterface, $testcase['exec_id']);
  183. //count all test cases that have no bug linked
  184. if (count($bugs) == 0) {
  185. $gui->without_bugs_counter += 1;
  186. }
  187. foreach ($bugs as $bug) {
  188. $bugString .= $bug['link_to_bts'] . '<br/>';
  189. }
  190. }
  191. $topLevelSuites[$topCache[$testcase['tc_id']]]['items'][$level][] =
  192. array('suiteName' => $verbosePath, 'testTitle' => htmlspecialchars($tcaseName),
  193. 'testVersion' => $testcase['tcversion_number'],
  194. 'platformName' => htmlspecialchars($testcase['platform_name']),
  195. 'buildName' => htmlspecialchars($testcase['build_name']),
  196. 'testerName' => htmlspecialchars($testerName),
  197. 'localizedTS' => $testcase['execution_ts'],
  198. 'notes' => strip_tags($testcase['execution_notes']),
  199. 'bugString' => $bugString,
  200. 'platformID' => $testcase['platform_id']);
  201. }
  202. } //END foreach item
  203. }//END foreach MyRBB
  204. // Rearrange for display
  205. $key2loop=array_keys($topLevelSuites);
  206. foreach($key2loop as $key)
  207. {
  208. if( is_null($topLevelSuites[$key]['items']) )
  209. {
  210. unset($topLevelSuites[$key]);
  211. }
  212. }
  213. $key2loop=array_keys($topLevelSuites);
  214. $idx=0;
  215. foreach($key2loop as $key)
  216. {
  217. $elem=&$topLevelSuites[$key]['items'];
  218. $levelSet=array_keys($topLevelSuites[$key]['items']);
  219. foreach($levelSet as $level)
  220. {
  221. foreach ($elem[$level] as $item)
  222. {
  223. unset($item['level']);
  224. unset($item['platformID']);
  225. if (!$show_platforms)
  226. {
  227. unset($item['platformName']);
  228. }
  229. $gui->dataSet[] = $item;
  230. $idx++;
  231. }
  232. }
  233. }
  234. } else {
  235. if($args->type == $statusCode['not_run']) {
  236. $gui->warning_msg = lang_get('no_notrun');
  237. }
  238. if($args->type == $statusCode['failed']) {
  239. $gui->warning_msg = lang_get('no_failed');
  240. }
  241. if($args->type == $statusCode['blocked']) {
  242. $gui->warning_msg = lang_get('no_blocked');
  243. }
  244. }
  245. new dBug($gui->dataSet);
  246. $gui->tableSet[] = buildMatrix($gui->dataSet, $args, array(
  247. 'status_not_run' => ($args->type == $statusCode['not_run']),
  248. 'bugInterfaceOn' => $gui->bugInterfaceOn,
  249. 'format' => $args->format,
  250. 'show_platforms' => $show_platforms,
  251. ));
  252. $smarty = new TLSmarty();
  253. $smarty->assign('gui', $gui );
  254. displayReport($templateCfg->template_dir . $templateCfg->default_template, $smarty, $args->format,$mailCfg);
  255. /**
  256. * Function returns number of Test Cases in the Test Plan
  257. * @return string Link of Test ID + Title
  258. */
  259. function buildTCLink($tcID,$tcversionID, $title, $buildID,$testCaseExternalId, $tplanId)
  260. {
  261. $title = htmlspecialchars($title);
  262. $suffix = htmlspecialchars($testCaseExternalId) . ":&nbsp;<b>" . $title. "</b></a>";
  263. //Added tplan_id as a parameter - amitkhullar -BUGID 2267
  264. $testTitle = '<a href="lib/execute/execSetResults.php?level=testcase&build_id='
  265. . $buildID . '&id=' . $tcID . '&version_id='. $tcversionID . '&tplan_id=' . $tplanId .'">';
  266. $testTitle .= $suffix;
  267. return $testTitle;
  268. }
  269. /**
  270. *
  271. *
  272. */
  273. function init_args($statusCode)
  274. {
  275. $iParams = array("format" => array(tlInputParameter::INT_N),
  276. "tplan_id" => array(tlInputParameter::INT_N),
  277. "type" => array(tlInputParameter::STRING_N,0,1));
  278. $args = new stdClass();
  279. R_PARAMS($iParams,$args);
  280. $args->tproject_id = isset($_SESSION['testprojectID']) ? intval($_SESSION['testprojectID']) : 0;
  281. $args->user = $_SESSION['currentUser'];
  282. return $args;
  283. }
  284. /**
  285. * initializeGui
  286. *
  287. */
  288. function initializeGui($statusCode,&$argsObj)
  289. {
  290. $guiObj = new stdClass();
  291. // Count for the Failed Issues whose bugs have to be raised/not linked.
  292. $guiObj->without_bugs_counter = 0;
  293. $guiObj->dataSet = null;
  294. $guiObj->title = null;
  295. $guiObj->type = $argsObj->type;
  296. $guiObj->warning_msg = '';
  297. // Humm this may be can be configured ???
  298. foreach(array('failed','blocked','not_run') as $verbose_status)
  299. {
  300. if($argsObj->type == $statusCode[$verbose_status])
  301. {
  302. $guiObj->title = lang_get('list_of_' . $verbose_status);
  303. break;
  304. }
  305. }
  306. if(is_null($guiObj->title))
  307. {
  308. tlog('wrong value of GET type');
  309. exit();
  310. }
  311. return $guiObj;
  312. }
  313. function checkRights(&$db,&$user)
  314. {
  315. return $user->hasRight($db,'testplan_metrics');
  316. }
  317. /**
  318. *
  319. *
  320. */
  321. function buildMailCfg(&$guiObj)
  322. {
  323. $labels = array('testplan' => lang_get('testplan'), 'testproject' => lang_get('testproject'));
  324. $cfg = new stdClass();
  325. $cfg->cc = '';
  326. $cfg->subject = $guiObj->title . ' : ' . $labels['testproject'] . ' : ' . $guiObj->tproject_name .
  327. ' : ' . $labels['testplan'] . ' : ' . $guiObj->tplan_name;
  328. return $cfg;
  329. }
  330. /**
  331. * Builds ext-js rich table to display matrix results
  332. *
  333. * @param map dataSet: data to be displayed on matrix
  334. *
  335. * return tlExtTable
  336. *
  337. */
  338. function buildMatrix($dataSet, &$args, $options = array())
  339. {
  340. $default_options = array(
  341. 'bugInterfaceOn' => false,
  342. 'show_platforms' => false,
  343. 'status_not_run' => false,
  344. 'format' => FORMAT_HTML,
  345. );
  346. $options = array_merge($default_options, $options);
  347. $columns = array();
  348. $columns[] = array('title' => lang_get('title_test_suite_name'), 'width' => 80, 'type' => 'text');
  349. $columns[] = array('title' => lang_get('title_test_case_title'), 'width' => 80, 'type' => 'text');
  350. $columns[] = array('title' => lang_get('version'), 'width' => 30);
  351. if ($options['show_platforms'])
  352. {
  353. $columns[] = array('title' => lang_get('platform'), 'width' => 60);
  354. }
  355. if( $options['status_not_run'] )
  356. {
  357. $columns[] = array('title' => lang_get('th_build'), 'width' => 35);
  358. $columns[] = array('title' => lang_get('assigned_to'), 'width' => 60);
  359. $columns[] = array('title' => lang_get('summary'), 'width' => 150, 'type' => 'text');
  360. }
  361. else
  362. {
  363. $columns[] = array('title' => lang_get('th_build'), 'width' => 35);
  364. $columns[] = array('title' => lang_get('th_run_by'), 'width' => 60);
  365. $columns[] = array('title' => lang_get('th_date'), 'width' => 60);
  366. $columns[] = array('title' => lang_get('title_execution_notes'), 'width' => 150, 'type' => 'text');
  367. if ($options['bugInterfaceOn'])
  368. {
  369. $columns[] = array('title' => lang_get('th_bugs'), 'type' => 'text');
  370. }
  371. }
  372. if ($options['format'] == FORMAT_HTML)
  373. {
  374. //create unique tableid for each project. as columns differ on not run report make it part of id
  375. $table_id = 'tl_'.$args->tproject_id.'_table_results_by_';
  376. $table_id .= ($options['status_not_run']) ? 'not_run' : 'status';
  377. $matrix = new tlExtTable($columns, $dataSet, $table_id);
  378. //if not run report: sort by test suite
  379. //blocked, failed report: sort by platform (if enabled) else sort by date
  380. $sort_name = 0;
  381. if ($options['status_not_run']) {
  382. $sort_name = lang_get('assigned_to');
  383. } else {
  384. if ($options['show_platforms']) {
  385. $sort_name = lang_get('platform');
  386. } else {
  387. $sort_name = lang_get('th_date');
  388. }
  389. }
  390. $matrix->setSortByColumnName($sort_name);
  391. $matrix->setGroupByColumnName(lang_get('th_build'));
  392. $matrix->addCustomBehaviour('text', array('render' => 'columnWrap'));
  393. //define table toolbar
  394. $matrix->showToolbar = true;
  395. $matrix->toolbarExpandCollapseGroupsButton = true;
  396. $matrix->toolbarShowAllColumnsButton = true;
  397. }
  398. else
  399. {
  400. $matrix = new tlHTMLTable($columns, $dataSet, 'tl_table_results_by_status');
  401. }
  402. return $matrix;
  403. }