PageRenderTime 72ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/execute/execSetResults.php

https://bitbucket.org/pfernandez/testlink1.9.6
PHP | 1432 lines | 843 code | 193 blank | 396 comment | 127 complexity | 4d4f3df7ceaa01e04b2b0cfa89e25cbf 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. *
  5. * Filename $RCSfile: execSetResults.php,v $
  6. *
  7. * @version $Revision: 1.166 $
  8. * @modified $Date: 2010/08/21 16:32:59 $ $Author: franciscom $
  9. *
  10. * rev:
  11. * 20100821 - franciscom - code layout refactoring
  12. * 20100812 - asimon - BUGID 3672
  13. * 20100709 - asimon - BUGID 3590, BUGID 3574: build_id set to 0 as default instead of null
  14. * 20100628 - asimon - removal of constants from filter control class
  15. * 20100625 - asimon - added parameters $bugInterfaceOn, $bugInterface to exec_additional_info()
  16. * to avoid warnings in event log,
  17. * fixed a little bug in platform id initializing in init_args()
  18. * (now number 0 instead of value null)
  19. * 20100624 - asimon - CVS merge (experimental branch to HEAD)
  20. * 20100624 - asimon - refactoring for new filters
  21. * 20100527 - franciscom - BUGID 3479: Bulk Execution - Custom Fields Bulk Assignment
  22. * 20100527 - Julian - platform description is now shown/hidden according to setting on config
  23. * 20100520 - franciscom - BUGID 3478 Testcase ID not updated when using save and move next
  24. * 20100428 - asimon - BUGID 3301 and related, added logic to refresh tree after tc execution
  25. * 20100313 - franciscom - BUGID 3276
  26. * 20100204 - asimon - BUGID 2455 & 3026, little changes for filtering
  27. * 20100121 - franciscom - missing platform feature refactoring
  28. * 20091205 - franciscom - BUGID 0002469: CFG-Parameters to show notes/details on test-execution
  29. * 20091111 - franciscom - BUGID 2938 - Feature: Save and Go to next test case in test suite.
  30. * 20090922 - franciscom - added contribution idea, when using bulk operation
  31. * display last execution status.
  32. *
  33. * 20090913 - franciscom - fixed bug on filter_status initialization
  34. * fixed bug on bulk execution due to bad option
  35. * on get_linked_tcversions() call.
  36. *
  37. * 20090815 - franciscom - platform feature
  38. * 20090808 - franciscom - gen_spec_view call refactoring
  39. * 20090526 - franciscom - now custom fields for testplan_design are managed
  40. *
  41. * 20090419 - franciscom - BUGID 2364 - added management of refreshTree
  42. * initializeRights() refactored
  43. * 20090409 - amkhullar - updated code not written properly.
  44. * 20090330 - franciscom - fixed bug on test plan custom field get.
  45. * 20090325 - amkhullar - BUGID 2267
  46. * 20090210 - amkhullar - BUGID 2068
  47. * 20080827 - franciscom - BUGID 1692
  48. * 20080811 - franciscom - BUGID 1650 (REQ)
  49. *
  50. * 20080104 - franciscom - REQ 1232 - web editor on execution notes
  51. * added createExecNotesWebEditor()
  52. *
  53. **/
  54. require_once('../../config.inc.php');
  55. require_once('common.php');
  56. require_once('exec.inc.php');
  57. require_once("attachments.inc.php");
  58. require_once("specview.php");
  59. require_once("web_editor.php");
  60. $cfg=getCfg();
  61. require_once(require_web_editor($cfg->editorCfg['type']));
  62. // BUGID 3276
  63. // CRITIC:
  64. // If call to testlinkInitPage() is done AFTER require_once for BTS
  65. // log to event viewer fails, but log to file works ok
  66. testlinkInitPage($db);
  67. if($cfg->bts_type != 'NO')
  68. {
  69. require_once(TL_ABS_PATH. 'lib' . DIRECTORY_SEPARATOR . 'bugtracking' .
  70. DIRECTORY_SEPARATOR . 'int_bugtracking.php');
  71. }
  72. $templateCfg = templateConfiguration();
  73. $tcversion_id = null;
  74. $submitResult = null;
  75. $args = init_args($cfg);
  76. $smarty = new TLSmarty();
  77. $tree_mgr = new tree($db);
  78. $tplan_mgr = new testplan($db);
  79. $tcase_mgr = new testcase($db);
  80. $exec_cfield_mgr = new exec_cfield_mgr($db,$args->tproject_id);
  81. $attachmentRepository = tlAttachmentRepository::create($db);
  82. $req_mgr = new requirement_mgr($db);
  83. $gui = initializeGui($db,$args,$cfg,$tplan_mgr,$tcase_mgr);
  84. $_SESSION['history_on'] = $gui->history_on;
  85. $attachmentInfos = null;
  86. $do_show_instructions = ($args->level == "" || $args->level == 'testproject') ? 1 : 0;
  87. if ($do_show_instructions)
  88. {
  89. show_instructions('executeTest');
  90. exit();
  91. }
  92. // ---------------------------------------------------------
  93. // Testplan executions and result archiving. Checks whether execute cases button was clicked
  94. //
  95. if($args->doExec == 1)
  96. {
  97. /** @note get testcase ids in an array */
  98. if(!is_null($args->tc_versions) && count($args->tc_versions))
  99. {
  100. $status_and_notes=do_remote_execution($db,$args->tc_versions);
  101. // Need to be added to $_REQUEST, because we are using $_REQUEST as input
  102. // for the function responsible of writing exec results. write_execution()
  103. $status_map = $status_and_notes['status'];
  104. $notes_map = $status_and_notes['notes'];
  105. if(count($status_map))
  106. {
  107. foreach($status_map as $key => $value)
  108. {
  109. $_REQUEST['status'][$key] = $value;
  110. $_REQUEST['notes'][$key] = $notes_map[$key];
  111. }
  112. }
  113. }
  114. }
  115. // -----------------------------------------------------------
  116. // When nullify filter_status - 20080504 - DO NOT REMOVE -
  117. //
  118. // May be in the following situation we do not HAVE to apply filter status:
  119. // 1. User have filter for Not Run on Tree
  120. // 2. Clicks on TC XXX
  121. // 3. Executes TC
  122. // 4. DO NOT UPDATE TREE.
  123. // we do not update automatically to avoid:
  124. // a) performance problems
  125. // b) delays on operations due to tree redraw
  126. // c) loose tree status due to lack of feature of tree engine
  127. //
  128. // 5. Clicks again on TC XXX
  129. // If we use filter, we will get No Data Available.
  130. //
  131. // When working on show_testsuite_contents mode (OLD MODE) when we show
  132. // all testcases inside a testsuite that verifies a filter criteria WE NEED TO APPLY FILTER
  133. //
  134. // We do not have this problem when this page is called after user have executed,
  135. // probably because filter_status is not send back.
  136. //
  137. // I will add logic to nullify filter_status on init_args()
  138. //
  139. // 20080224 - franciscom - BUGID 1056
  140. // 20070306 - franciscom - BUGID 705
  141. // 20070914 - jbarchibald - added $cf_selected parameter
  142. //
  143. // 20081221 - franciscom
  144. // BUGID 3406
  145. $options = array('only_executed' => true, 'output' => 'mapOfArray',
  146. 'include_unassigned' => $args->include_unassigned,
  147. 'user_assignments_per_build' => $args->build_id);
  148. if(is_null($args->filter_status) || in_array($cfg->tc_status['not_run'],$args->filter_status))
  149. {
  150. $options['only_executed'] = false;
  151. }
  152. // Added platform_id filter
  153. $filters = array('tcase_id' => $args->tc_id, 'keyword_id' => $args->keyword_id,
  154. 'assigned_to' => $args->filter_assigned_to, 'exec_status' => $args->filter_status,
  155. 'build_id' => $args->build_id, 'cf_hash' => $args->cf_selected,
  156. 'platform_id' => $args->platform_id);
  157. $linked_tcversions = $tplan_mgr->get_linked_tcversions($args->tplan_id,$filters,$options);
  158. $tcase_id = 0;
  159. $userid_array = null;
  160. if(!is_null($linked_tcversions))
  161. {
  162. $items_to_exec = array();
  163. $_SESSION['s_lastAttachmentInfos'] = null;
  164. if($args->level == 'testcase')
  165. {
  166. // Warning!!! - $gui is passed by reference to be updated inside function
  167. $tcase = null;
  168. list($tcase_id,$tcversion_id) = processTestCase($tcase,$gui,$args,$cfg,$linked_tcversions,
  169. $tree_mgr,$tcase_mgr,$attachmentRepository);
  170. }
  171. else
  172. {
  173. list($tcase_id,$tcversion_id) = processTestSuite($db,$gui,$args,$linked_tcversions,
  174. $tree_mgr,$tcase_mgr,$attachmentRepository);
  175. }
  176. // will create a record even if the testcase version has not been executed (GET_NO_EXEC)
  177. $gui->map_last_exec = getLastExecution($db,$tcase_id,$tcversion_id,$gui,$args,$tcase_mgr);
  178. // --------------------------------------------------------------------------------------------
  179. // Results to DB
  180. if ($args->save_results || $args->do_bulk_save || $args->save_and_next)
  181. {
  182. // this has to be done to do not break logic present on write_execution()
  183. $args->save_results = $args->save_and_next ? $args->save_and_next : $args->save_results;
  184. $_REQUEST['save_results'] = $args->save_results;
  185. $submitResult = write_execution($db,$args,$_REQUEST,$gui->map_last_exec);
  186. // Need to re-read to update test case status
  187. if ($args->save_and_next)
  188. {
  189. $nextItem = $tplan_mgr->getTestCaseNextSibling($args->tplan_id,$tcversion_id,$args->platform_id);
  190. if( !is_null($nextItem) )
  191. {
  192. $tcase_id = $nextItem['tcase_id'];
  193. $tcversion_id = $nextItem['tcversion_id'];
  194. // BUGID 3478
  195. processTestCase($nextItem,$gui,$args,$cfg,$linked_tcversions,$tree_mgr,$tcase_mgr,$attachmentRepository);
  196. }
  197. }
  198. $gui->map_last_exec=getLastExecution($db,$tcase_id,$tcversion_id,$gui,$args,$tcase_mgr);
  199. }
  200. if ($args->doDelete)
  201. {
  202. delete_execution($db,$args->exec_to_delete);
  203. }
  204. // --------------------------------------------------------------------------------------------
  205. $gui->map_last_exec_any_build = null;
  206. $gui->other_execs=null;
  207. $testerid = null;
  208. if($args->level == 'testcase')
  209. {
  210. // @TODO 20090815 - franciscom check what to do with platform
  211. if( $cfg->exec_cfg->show_last_exec_any_build )
  212. {
  213. // 20090716 - franciscom - get_last_execution() interface changes
  214. $options=array('getNoExecutions' => 1, 'groupByBuild' => 0);
  215. $gui->map_last_exec_any_build = $tcase_mgr->get_last_execution($tcase_id,$tcversion_id,$args->tplan_id,
  216. testcase::ANY_BUILD,
  217. $args->platform_id,$options);
  218. //Get UserID and Updater ID for current Version
  219. $tc_current = $gui->map_last_exec_any_build;
  220. foreach ($tc_current as $key => $value)
  221. {
  222. $testerid = $value['tester_id'];
  223. $userid_array[$testerid] = $testerid;
  224. }
  225. }
  226. $gui->req_details = $req_mgr->get_all_for_tcase($tcase_id); //Bug 2068
  227. $gui->other_execs=getOtherExecutions($db,$tcase_id,$tcversion_id,$gui,$args,$cfg,$tcase_mgr);
  228. // Get attachment,bugs, etc
  229. if(!is_null($gui->other_execs))
  230. {
  231. //Get the Tester ID for all previous executions
  232. foreach ($gui->other_execs as $key => $execution)
  233. {
  234. foreach ($execution as $singleExecution)
  235. {
  236. $testerid = $singleExecution['tester_id'];
  237. $userid_array[$testerid] = $testerid;
  238. }
  239. }
  240. // asimon - added $g_bugInterfaceOn, $g_bugInterface
  241. $other_info=exec_additional_info($db,$attachmentRepository,$tcase_mgr,$gui->other_execs,
  242. $args->tplan_id,$args->tproject_id, $g_bugInterfaceOn, $g_bugInterface);
  243. $gui->attachments=$other_info['attachment'];
  244. $gui->bugs=$other_info['bugs'];
  245. $gui->other_exec_cfields=$other_info['cfexec_values'];
  246. // this piece of code is useful to avoid error on smarty template due to undefined value
  247. if( is_array($tcversion_id) && (count($gui->other_execs) != count($gui->map_last_exec)) )
  248. {
  249. foreach($tcversion_id as $version_id)
  250. {
  251. if( !isset($gui->other_execs[$version_id]) )
  252. {
  253. $gui->other_execs[$version_id]=null;
  254. }
  255. }
  256. }
  257. } // if(!is_null($gui->other_execs))
  258. }
  259. } // if(!is_null($linked_tcversions))
  260. // Removing duplicate and NULL id's
  261. unset($userid_array['']);
  262. $userSet = null;
  263. if ($userid_array)
  264. {
  265. foreach($userid_array as $value)
  266. {
  267. $userSet[] = $value;
  268. }
  269. }
  270. smarty_assign_tsuite_info($smarty,$_REQUEST,$db,$tree_mgr,$tcase_id,$args->tproject_id);
  271. // BUGID 2455, BUGID 3026
  272. // BUGID 3516
  273. // remove testcases which shall not be displayed because they were filtered out
  274. if (!is_null($args->testcases_to_show) && $args->level == 'testsuite') {
  275. foreach($gui->map_last_exec as $key => $tc) {
  276. if (!in_array($tc['testcase_id'], $args->testcases_to_show)) {
  277. unset($gui->map_last_exec[$key]); // tc shall not be displayed
  278. }
  279. }
  280. // fix indexes for smarty
  281. $gui->map_last_exec = array_values($gui->map_last_exec);
  282. }
  283. // $gui->can_use_bulk_op=$args->level == 'testsuite' && (!is_null($gui->map_last_exec) && count($gui->map_last_exec) > 1) ? 1 : 0;
  284. $gui->can_use_bulk_op = ($args->level == 'testsuite' && count($gui->map_last_exec) > 1) ? 1 : 0;
  285. if( $gui->can_use_bulk_op )
  286. {
  287. $gui->execStatusValues=createResultsMenu();
  288. if( isset($gui->execStatusValues[$cfg->tc_status['all']]) )
  289. {
  290. unset($gui->execStatusValues[$cfg->tc_status['all']]);
  291. }
  292. $of=web_editor("bulk_exec_notes",$_SESSION['basehref'],$cfg->editorCfg);
  293. $of->Value = getItemTemplateContents('execution_template', $of->InstanceName, null);
  294. // Magic numbers that can be determined by trial and error
  295. $gui->bulk_exec_notes_editor=$of->CreateHTML(10,60);
  296. unset($of);
  297. }
  298. else
  299. {
  300. $gui->exec_notes_editors=createExecNotesWebEditor($gui->map_last_exec,$_SESSION['basehref'],$cfg->editorCfg);
  301. }
  302. // To silence smarty errors
  303. // future must be initialized in a right way
  304. $smarty->assign('test_automation_enabled',0);
  305. $smarty->assign('cfg',$cfg);
  306. $smarty->assign('users',tlUser::getByIDs($db,$userSet,'id'));
  307. $smarty->assign('gui',$gui);
  308. $smarty->assign('g_bugInterface', $g_bugInterface);
  309. // pf
  310. if(BT_USE) {
  311. require_once '../../plugin/BTexecSetResults.php';
  312. }
  313. $smarty->display($templateCfg->template_dir . $templateCfg->default_template);
  314. /*
  315. function:
  316. args:
  317. returns:
  318. rev:
  319. 20100625 - asimon - fixed a little bug in platform id initializing when no platform is used
  320. (now number 0 instead of value null)
  321. 20090913 - franciscom - fixed bug on filter_status initialization
  322. */
  323. function init_args($cfgObj)
  324. {
  325. $args = new stdClass();
  326. $_REQUEST = strings_stripSlashes($_REQUEST);
  327. // BUGID 3516
  328. $mode = 'execution_mode';
  329. $form_token = isset($_REQUEST['form_token']) ? $_REQUEST['form_token'] : 0;
  330. $session_data = isset($_SESSION[$mode]) && isset($_SESSION[$mode][$form_token]) ? $_SESSION[$mode][$form_token] : null;
  331. $args->doExec = isset($_REQUEST['execute_cases']) ? 1 : 0;
  332. $args->doDelete = isset($_REQUEST['do_delete']) ? $_REQUEST['do_delete'] : 0;
  333. $args->cf_selected = isset($_REQUEST['cfields']) ? unserialize($_REQUEST['cfields']) : null;
  334. // can be a list, will arrive via form POST
  335. $args->tc_versions = isset($_REQUEST['tc_version']) ? $_REQUEST['tc_version'] : null;
  336. // BUGID 3516,3590, 3574, 3672
  337. $key2null = array('filter_status' => 'filter_result_result','filter_assigned_to' => 'filter_assigned_user',
  338. 'build_id' => 'setting_build', 'platform_id' => 'setting_platform');
  339. foreach($key2null as $key => $sessionKey)
  340. {
  341. $args->$key = isset($session_data[$sessionKey]) ? $session_data[$sessionKey] : null;
  342. }
  343. if (is_null($args->build_id)) {
  344. $args->build_id = (isset($_REQUEST['build_id']) && is_numeric($_REQUEST['build_id'])) ? $_REQUEST['build_id'] : 0;
  345. }
  346. if (is_null($args->platform_id)) {
  347. $args->platform_id = (isset($_REQUEST['platform_id']) && is_numeric($_REQUEST['platform_id'])) ? $_REQUEST['platform_id'] : 0;
  348. }
  349. $key2loop = array('level' => '','status' => null, 'do_bulk_save' => 0, 'save_results' => 0, 'save_and_next' => 0);
  350. foreach($key2loop as $key => $value)
  351. {
  352. $args->$key = isset($_REQUEST[$key]) ? $_REQUEST[$key] : $value;
  353. }
  354. // See details on: "When nullify filter_status - 20080504" in this file
  355. if(is_null($args->filter_status) || trim($args->filter_status) || $args->level == 'testcase')
  356. {
  357. $args->filter_status = null;
  358. }
  359. else
  360. {
  361. $args->filter_status = unserialize($args->filter_status);
  362. }
  363. $args->id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
  364. $cookiePrefix = 'TL_execSetResults_';
  365. // IMPORTANT: logic for test suite notes CAN NOT BE IMPLEMENTED HERE
  366. // see smarty_assign_tsuite_info() in this file.
  367. $key4cookies = array('tpn_view_status' => 'testplan_notes','bn_view_status' => 'build_description',
  368. 'platform_notes_view_status' => 'platform_description');
  369. // BUGID 3516, 3590, 3574
  370. $key2loop = array('id' => 0, 'exec_to_delete' => 0, 'version_id' => 0, 'tpn_view_status' => 0,
  371. 'bn_view_status' => 0, 'bc_view_status' => 1,'platform_notes_view_status' => 0);
  372. foreach($key4cookies as $key => $cfgKey)
  373. {
  374. $cookieKey = $cookiePrefix . $key;
  375. if( !isset($_REQUEST[$key]) )
  376. {
  377. // First time we are entered here => we can need to understand how to proceed
  378. switch($cfgObj->exec_cfg->expand_collapse->$cfgKey )
  379. {
  380. case LAST_USER_CHOICE:
  381. if (isset($_COOKIE[$cookieKey]) )
  382. {
  383. $key2loop[$key] = $_COOKIE[$cookieKey];
  384. }
  385. break;
  386. default:
  387. $key2loop[$key] = $cfgObj->exec_cfg->expand_collapse->$cfgKey;
  388. break;
  389. }
  390. }
  391. }
  392. foreach($key2loop as $key => $value)
  393. {
  394. $args->$key = isset($_REQUEST[$key]) ? intval($_REQUEST[$key]) : $value;
  395. if( isset($key4cookies[$key]) )
  396. {
  397. setcookie($cookiePrefix . $key,$args->$key,TL_COOKIE_KEEPTIME, '/');
  398. }
  399. }
  400. switch($args->level)
  401. {
  402. case 'testcase':
  403. $args->tc_id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : null;
  404. // some problems with $_GET that has impact on logic 'Save and Go to next test case';
  405. if( !is_null($args->tc_versions) )
  406. {
  407. $args->tc_id = current($args->tc_versions);
  408. $args->id = $args->tc_id;
  409. $args->version_id = key($args->tc_versions);
  410. }
  411. $args->tsuite_id = null;
  412. break;
  413. case 'testsuite':
  414. $args->tsuite_id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : null;
  415. $args->tc_id = null;
  416. break;
  417. }
  418. // BUGID 3516
  419. $args->keyword_id = 0;
  420. if (isset($session_data['filter_keywords'])) {
  421. $args->keyword_id = $session_data['filter_keywords'];
  422. if (is_array($args->keyword_id) && count($args->keyword_id) == 1) {
  423. $args->keyword_id = $args->keyword_id[0];
  424. }
  425. }
  426. $args->keywordsFilterType = null;
  427. if (isset($session_data['filter_keywords_filter_type'])) {
  428. $args->keywordsFilterType = $session_data['filter_keywords_filter_type'];
  429. }
  430. // Checkbox
  431. $args->include_unassigned = isset($session_data['filter_assigned_user_include_unassigned'])
  432. && $session_data['filter_assigned_user_include_unassigned'] != 0 ? 1 : 0;
  433. // 20090419 - franciscom - BUGID
  434. // BUGID 3301 and related - asimon - changed refresh tree logic
  435. // to adapt behavior of other forms (like tc edit)
  436. // additionally modified to only refresh on saving of test results, not on every click
  437. $args->refreshTree = isset($session_data['setting_refresh_tree_on_action'])
  438. ? $session_data['setting_refresh_tree_on_action'] : 0;
  439. $args->tproject_id = isset($_REQUEST['tproject_id']) ? $_REQUEST['tproject_id'] : $_SESSION['testprojectID'];
  440. // BUGID 2267
  441. $args->tplan_id = isset($_REQUEST['tplan_id']) ? $_REQUEST['tplan_id'] : $_SESSION['testplanID'];
  442. $args->user = $_SESSION['currentUser'];
  443. $args->user_id = $args->user->dbID;
  444. // BUGID 3516
  445. // BUGID 2455,BUGID 3026
  446. $args->testcases_to_show = null;
  447. if (isset($session_data['testcases_to_show'])) {
  448. $args->testcases_to_show = $session_data['testcases_to_show'];
  449. }
  450. return $args;
  451. }
  452. /*
  453. function:
  454. args :
  455. returns:
  456. */
  457. function manage_history_on($hash_REQUEST,$hash_SESSION,
  458. $exec_cfg,$btn_on_name,$btn_off_name,$hidden_on_name)
  459. {
  460. if( isset($hash_REQUEST[$btn_on_name]) )
  461. {
  462. $history_on = true;
  463. }
  464. elseif(isset($_REQUEST[$btn_off_name]))
  465. {
  466. $history_on = false;
  467. }
  468. elseif (isset($_REQUEST[$hidden_on_name]))
  469. {
  470. $history_on = $_REQUEST[$hidden_on_name];
  471. }
  472. elseif (isset($_SESSION[$hidden_on_name]))
  473. {
  474. $history_on = $_SESSION[$hidden_on_name];
  475. }
  476. else
  477. {
  478. $history_on = $exec_cfg->history_on;
  479. }
  480. return $history_on;
  481. }
  482. /*
  483. function: get_ts_name_details
  484. args :
  485. returns: map with key=TCID
  486. values= assoc_array([tsuite_id => 5341
  487. [details] => my detailas ts1
  488. [tcid] => 5343
  489. [tsuite_name] => ts1)
  490. */
  491. function get_ts_name_details(&$db,$tcase_id)
  492. {
  493. $tables['testsuites'] = DB_TABLE_PREFIX . 'testsuites';
  494. $tables['nodes_hierarchy'] = DB_TABLE_PREFIX . 'nodes_hierarchy';
  495. $rs = '';
  496. $do_query = true;
  497. $sql = "SELECT TS.id AS tsuite_id, TS.details,
  498. NHA.id AS tc_id, NHB.name AS tsuite_name
  499. FROM {$tables['testsuites']} TS, {$tables['nodes_hierarchy']} NHA,
  500. {$tables['nodes_hierarchy']} NHB
  501. WHERE TS.id=NHA.parent_id
  502. AND NHB.id=NHA.parent_id ";
  503. if( is_array($tcase_id) && count($tcase_id) > 0)
  504. {
  505. $in_list = implode(",",$tcase_id);
  506. $sql .= "AND NHA.id IN (" . $in_list . ")";
  507. }
  508. else if(!is_null($tcase_id))
  509. {
  510. $sql .= "AND NHA.id={$tcase_id}";
  511. }
  512. else
  513. {
  514. $do_query = false;
  515. }
  516. if($do_query)
  517. {
  518. $rs = $db->fetchRowsIntoMap($sql,'tc_id');
  519. }
  520. return $rs;
  521. }
  522. /*
  523. function:
  524. args :
  525. returns:
  526. */
  527. function smarty_assign_tsuite_info(&$smarty,&$request_hash, &$db,&$tree_mgr,$tcase_id,$tproject_id)
  528. {
  529. $fpath=$tree_mgr->get_full_path_verbose($tcase_id, array('output_format' => 'id_name'));
  530. $tsuite_info = get_ts_name_details($db,$tcase_id);
  531. foreach($fpath as $key => $value)
  532. {
  533. unset($value['name'][0]); // Remove test plan name
  534. unset($value['node_id'][0]); // Remove test plan name
  535. $str='';
  536. foreach($value['name'] as $jdx => $elem)
  537. {
  538. $str .= "<a href=\"javascript:openTestSuiteWindow(" . $value['node_id'][$jdx] . ")\"> ";
  539. $str .= htmlentities($elem) . '</a>/';
  540. }
  541. $tsuite_info[$key]['tsuite_name']=$str;
  542. }
  543. $smarty->assign('tsuite_info',$tsuite_info);
  544. // --------------------------------------------------------------------------------
  545. if(!is_null($tsuite_info))
  546. {
  547. $cookieKey = 'TL_execSetResults_tsdetails_view_status';
  548. $exec_cfg = config_get('exec_cfg');
  549. $a_tsvw=array();
  550. $a_ts=array();
  551. $a_tsval=array();
  552. $tsuite_mgr = New testsuite($db);
  553. foreach($tsuite_info as $key => $elem)
  554. {
  555. $main_k = 'tsdetails_view_status_' . $key;
  556. $a_tsvw[] = $main_k;
  557. $a_ts[] = 'tsdetails_' . $key;
  558. $expand_collapse = 0;
  559. if( !isset($request_hash[$main_k]) )
  560. {
  561. // First time we are entered here => we can need to understand how to proceed
  562. switch($exec_cfg->expand_collapse->testsuite_details)
  563. {
  564. case LAST_USER_CHOICE:
  565. if (isset($_COOKIE[$cookieKey]) )
  566. {
  567. $expand_collapse = $_COOKIE[$cookieKey];
  568. }
  569. break;
  570. default:
  571. $expand_collapse = $exec_cfg->expand_collapse->testsuite_details;
  572. break;
  573. }
  574. }
  575. $a_tsval[] = isset($request_hash[$main_k]) ? $request_hash[$main_k] : $expand_collapse;
  576. $tsuite_id = $elem['tsuite_id'];
  577. $tc_id = $elem['tc_id'];
  578. if(!isset($cached_cf[$tsuite_id]))
  579. {
  580. $cached_cf[$tsuite_id] = $tsuite_mgr->html_table_of_custom_field_values($tsuite_id,'design',null,$tproject_id);
  581. }
  582. $ts_cf_smarty[$tc_id] = $cached_cf[$tsuite_id];
  583. }
  584. if( count($a_tsval) > 0 )
  585. {
  586. setcookie($cookieKey,$a_tsval[0],TL_COOKIE_KEEPTIME, '/');
  587. }
  588. $smarty->assign('tsd_div_id_list',implode(",",$a_ts));
  589. $smarty->assign('tsd_hidden_id_list',implode(",",$a_tsvw));
  590. $smarty->assign('tsd_val_for_hidden_list',implode(",",$a_tsval));
  591. $smarty->assign('ts_cf_smarty',$ts_cf_smarty);
  592. }
  593. }
  594. // --------------------------------------------------------------------------------
  595. /*
  596. function:
  597. args :
  598. returns:
  599. @internal revisions:
  600. 20100625 - asimon - added parameters $bugInterfaceOn, $bugInterface
  601. to get rid of warning in event log
  602. */
  603. function exec_additional_info(&$db, $attachmentRepository, &$tcase_mgr, $other_execs,
  604. $tplan_id, $tproject_id, $bugInterfaceOn, $bugInterface)
  605. {
  606. // $bugInterfaceOn = config_get('bugInterfaceOn');
  607. // $bugInterface = config_get('bugInterface');
  608. $attachmentInfos = null;
  609. $bugs = null;
  610. $cfexec_values = null;
  611. foreach($other_execs as $tcversion_id => $execInfo)
  612. {
  613. $num_elem = sizeof($execInfo);
  614. for($idx = 0;$idx < $num_elem;$idx++)
  615. {
  616. $exec_id = $execInfo[$idx]['execution_id'];
  617. $aInfo = getAttachmentInfos($attachmentRepository,$exec_id,'executions',true,1);
  618. if ($aInfo)
  619. $attachmentInfos[$exec_id] = $aInfo;
  620. if($bugInterfaceOn)
  621. {
  622. $the_bugs = get_bugs_for_exec($db,$bugInterface,$exec_id);
  623. if(count($the_bugs) > 0)
  624. {
  625. $bugs[$exec_id] = $the_bugs;
  626. }
  627. }
  628. // Custom fields
  629. $cfexec_values[$exec_id] = $tcase_mgr->html_table_of_custom_field_values($tcversion_id,'execution',null,
  630. $exec_id,$tplan_id,$tproject_id);
  631. }
  632. }
  633. $info = array( 'attachment' => $attachmentInfos,
  634. 'bugs' => $bugs,
  635. 'cfexec_values' => $cfexec_values);
  636. return $info;
  637. } //function end
  638. /*
  639. function:
  640. args :
  641. returns:
  642. */
  643. function do_remote_execution(&$db,$tc_versions)
  644. {
  645. $resultsCfg = config_get('results');
  646. $tc_status = $resultsCfg['status_code'];
  647. $tree_mgr = new tree($db);
  648. $cfield_mgr = new cfield_mgr($db);
  649. $ret=array();
  650. $ret["status"]=array();
  651. $ret["notes"]=array();
  652. $executionResults = array();
  653. $myResult = array();
  654. foreach($tc_versions as $version_id => $tcase_id)
  655. {
  656. // RPC call
  657. $executionResults[$tcase_id] = executeTestCase($tcase_id,$tree_mgr,$cfield_mgr);
  658. if($executionResults){
  659. $myResult = $executionResults[$tcase_id]['result'];
  660. $myNotes = $executionResults[$tcase_id]['notes'];
  661. if ($myResult != -1 && $myNotes != -1) {
  662. $db_now = $db->db_now();
  663. $my_notes = $db->prepare_string(trim($myNotes));
  664. $my_result = strtolower($myResult);
  665. $my_result = $my_result{0};
  666. if( $my_result != $tc_status['passed'] &&
  667. $my_result != $tc_status['failed'] &&
  668. $my_result != $tc_status['blocked'])
  669. {
  670. $my_result = $tc_status['blocked'];
  671. }
  672. //
  673. $ret["status"][$version_id] = $myResult;
  674. $ret["notes"][$version_id] = $my_notes;
  675. //
  676. $sql = "INSERT INTO executions (build_id,tester_id,status,testplan_id,tcversion_id,execution_ts,notes) ".
  677. "VALUES ({$build_id},{$user_id},'{$my_result}',{$tplan_id},{$version_id},{$db_now},'{$my_notes}')";
  678. $db->exec_query($sql);
  679. }
  680. }
  681. }
  682. return $ret;
  683. }
  684. /*
  685. function: initializeExecMode
  686. args:
  687. returns:
  688. */
  689. function initializeExecMode(&$db,$exec_cfg,$userObj,$tproject_id,$tplan_id)
  690. {
  691. $simple_tester_roles=array_flip($exec_cfg->simple_tester_roles);
  692. $effective_role = $userObj->getEffectiveRole($db,$tproject_id,$tplan_id);
  693. // SCHLUNDUS: hmm, for user defined roles, this wont work correctly
  694. // 20080104 - franciscom - Please explain why do you think will not work ok ?
  695. // do you prefer to check for exec right ?
  696. //
  697. // SCHLUNDUS: jep, exactly. If a user defines it own roles than a check for the tester
  698. // role will not do the desired effect of putting the logged in user in tester-view-mode
  699. // instead we must check for presence (and or absence) the right(s) which mades a user a tester
  700. //
  701. // 20080310 - franciscom -
  702. // Role is considered tester if:
  703. // role == TL_ROLES_TESTER OR Role has Test Plan execute but not Test Plan planning
  704. //
  705. //
  706. $can_execute = $effective_role->hasRight('testplan_execute');
  707. $can_manage = $effective_role->hasRight('testplan_planning');
  708. // 20081217 - franciscom
  709. // $use_exec_cfg = $effective_role->dbID == TL_ROLES_TESTER || ($can_execute && !$can_manage);
  710. $use_exec_cfg = isset($simple_tester_roles[$effective_role->dbID]) || ($can_execute && !$can_manage);
  711. return $use_exec_cfg ? $exec_cfg->exec_mode->tester : 'all';
  712. } // function end
  713. /*
  714. function: setTesterAssignment
  715. args:
  716. returns:
  717. rev: 20100121 - franciscom - platform refactoring
  718. */
  719. function setTesterAssignment(&$db,$exec_info,&$tcase_mgr,$tplan_id,$platform_id)
  720. {
  721. foreach($exec_info as $version_id => $value)
  722. {
  723. $exec_info[$version_id]['assigned_user'] = '';
  724. $exec_info[$version_id]['assigned_user_id'] = 0;
  725. // map of map: main key version_id, secondary key: platform_id
  726. $p3 = $tcase_mgr->get_version_exec_assignment($version_id,$tplan_id);
  727. $assignedTesterId = intval($p3[$version_id][$platform_id]['user_id']);
  728. if($assignedTesterId)
  729. {
  730. $user = tlUser::getByID($db,$assignedTesterId);
  731. if ($user)
  732. {
  733. $exec_info[$version_id]['assigned_user']= $user->getDisplayName();
  734. }
  735. $exec_info[$version_id]['assigned_user_id'] = $assignedTesterId;
  736. }
  737. }
  738. return $exec_info;
  739. } //function end
  740. /*
  741. function:
  742. Reorder executions to mantaing correct visualization order.
  743. args:
  744. returns:
  745. */
  746. function reorderExecutions(&$tcversion_id,&$exec_info)
  747. {
  748. $dummy = array();
  749. foreach($tcversion_id as $key => $value)
  750. {
  751. $dummy[$key] = $exec_info[$value];
  752. }
  753. return $dummy;
  754. }
  755. /*
  756. function: setCanExecute
  757. args:
  758. returns:
  759. */
  760. function setCanExecute($exec_info,$execution_mode,$can_execute,$tester_id)
  761. {
  762. foreach($exec_info as $key => $tc_exec)
  763. {
  764. $execution_enabled = 0;
  765. if($can_execute == 1 && $tc_exec['active'] == 1)
  766. {
  767. $assigned_to_me = $tc_exec['assigned_user_id'] == $tester_id ? 1 : 0;
  768. $is_free = $tc_exec['assigned_user_id'] == '' ? 1 : 0;
  769. switch($execution_mode)
  770. {
  771. case 'assigned_to_me':
  772. $execution_enabled = $assigned_to_me;
  773. break;
  774. case 'assigned_to_me_or_free':
  775. $execution_enabled = $assigned_to_me || $is_free;
  776. break;
  777. case 'all':
  778. $execution_enabled = 1;
  779. break;
  780. default:
  781. $execution_enabled = 0;
  782. break;
  783. } // switch
  784. }
  785. $exec_info[$key]['can_be_executed']=$execution_enabled;
  786. }
  787. return $exec_info;
  788. } //function end
  789. /*
  790. function: createExecNotesWebEditor
  791. creates map of html needed to display web editors
  792. for execution notes.
  793. args: tcversions: array where each element has information
  794. about testcase version that can be executed.
  795. basehref: URL
  796. editorCfg:
  797. returns: map
  798. key: testcase id
  799. value: html to display web editor.
  800. rev : 20080104 - creation
  801. */
  802. function createExecNotesWebEditor(&$tcversions,$basehref,$editorCfg)
  803. {
  804. if(is_null($tcversions) || count($tcversions) == 0 )
  805. {
  806. return null; // nothing todo >>>------> bye!
  807. }
  808. // Important Notice:
  809. //
  810. // When using tinymce or none as web editor, we need to set rows and cols
  811. // to appropriate values, to avoid an ugly ui.
  812. // null => use default values defined on editor class file
  813. //
  814. // Rows and Cols values are useless for FCKeditor.
  815. //
  816. $itemTemplateValue = getItemTemplateContents('execution_template', 'notes', null);
  817. foreach($tcversions as $key => $tcv)
  818. {
  819. $tcversion_id=$tcv['id'];
  820. $tcase_id=$tcv['testcase_id'];
  821. $of=web_editor("notes[{$tcversion_id}]",$basehref,$editorCfg) ;
  822. $of->Value = $itemTemplateValue;
  823. // Magic numbers that can be determined by trial and error
  824. $editors[$tcase_id]=$of->CreateHTML(10,60);
  825. unset($of);
  826. }
  827. return $editors;
  828. }
  829. /*
  830. function: getCfg
  831. args:
  832. returns:
  833. */
  834. function getCfg()
  835. {
  836. $cfg = new stdClass();
  837. $cfg->exec_cfg = config_get('exec_cfg');
  838. $cfg->gui_cfg = config_get('gui');
  839. $cfg->bts_type = config_get('interface_bugs');
  840. $results = config_get('results');
  841. $cfg->tc_status = $results['status_code'];
  842. $cfg->testcase_cfg = config_get('testcase_cfg');
  843. $cfg->editorCfg = getWebEditorCfg('execution');
  844. return $cfg;
  845. }
  846. /*
  847. function: initializeRights
  848. create object with rights useful for this feature
  849. args:
  850. dbHandler: reference to db object
  851. $userObj: reference to current user object
  852. tproject_id:
  853. tplan_id
  854. Warning: this is right interface for this function, but
  855. has_rights() can works in a mode (that i consider a dirty one)
  856. using SESSION to achieve global coupling.
  857. returns:
  858. */
  859. function initializeRights(&$dbHandler,&$userObj,$tproject_id,$tplan_id)
  860. {
  861. $exec_cfg = config_get('exec_cfg');
  862. $grants = new stdClass();
  863. $grants->execute = $userObj->hasRight($dbHandler,"testplan_execute",$tproject_id,$tplan_id);
  864. $grants->execute = $grants->execute=="yes" ? 1 : 0;
  865. // may be in the future this can be converted to a role right
  866. $grants->delete_execution=$exec_cfg->can_delete_execution;
  867. // may be in the future this can be converted to a role right
  868. // Important:
  869. // Execution right must be present to consider this configuration option.
  870. $grants->edit_exec_notes = $grants->execute && $exec_cfg->edit_notes;
  871. // 20090419 - franciscom - BUGID
  872. $grants->edit_testcase = $userObj->hasRight($dbHandler,"mgt_modify_tc",$tproject_id,$tplan_id);
  873. $grants->edit_testcase = $grants->edit_testcase=="yes" ? 1 : 0;
  874. // pf
  875. require_once '../../plugin/add_bugtracker_rights.php';
  876. return $grants;
  877. }
  878. /*
  879. function: initializeGui
  880. args :
  881. returns:
  882. rev: 20080429 - franciscom
  883. */
  884. function initializeGui(&$dbHandler,&$argsObj,&$cfgObj,&$tplanMgr,&$tcaseMgr)
  885. {
  886. $buildMgr = new build_mgr($dbHandler);
  887. $platformMgr = new tlPlatform($dbHandler,$argsObj->tproject_id);
  888. $gui = new stdClass();
  889. $gui->tplan_id=$argsObj->tplan_id;
  890. $gui->tproject_id=$argsObj->tproject_id;
  891. $gui->build_id = $argsObj->build_id;
  892. $gui->platform_id = $argsObj->platform_id;
  893. $gui->execStatusValues=null;
  894. $gui->can_use_bulk_op=0;
  895. $gui->exec_notes_editors=null;
  896. $gui->bulk_exec_notes_editor=null;
  897. $gui->req_details=null;
  898. $gui->attachmentInfos=null;
  899. $gui->bugs=null;
  900. $gui->other_exec_cfields=null;
  901. $gui->ownerDisplayName = null;
  902. $gui->editorType=$cfgObj->editorCfg['type'];
  903. $gui->filter_assigned_to=$argsObj->filter_assigned_to;
  904. $gui->tester_id=$argsObj->user_id;
  905. $gui->include_unassigned=$argsObj->include_unassigned;
  906. $gui->tpn_view_status=$argsObj->tpn_view_status;
  907. $gui->bn_view_status=$argsObj->bn_view_status;
  908. $gui->bc_view_status=$argsObj->bc_view_status;
  909. $gui->platform_notes_view_status=$argsObj->platform_notes_view_status;
  910. $gui->refreshTree = $argsObj->refreshTree;
  911. if (!$argsObj->status || $argsObj->status == $cfgObj->tc_status['not_run']) {
  912. $gui->refreshTree = 0;
  913. }
  914. $gui->map_last_exec_any_build=null;
  915. $gui->map_last_exec=null;
  916. // 20081122 - franciscom
  917. // Just for the record:
  918. // doing this here, we avoid to do on processTestSuite() and processTestCase(),
  919. // but absolutely this will not improve in ANY WAY perfomance, because we do not loop
  920. // over these two functions.
  921. $tprojectMgr = new testproject($dbHandler);
  922. $gui->tcasePrefix = $tprojectMgr->getTestCasePrefix($argsObj->tproject_id);
  923. $build_info = $buildMgr->get_by_id($argsObj->build_id);
  924. $gui->build_notes=$build_info['notes'];
  925. $gui->build_is_open=($build_info['is_open'] == 1 ? 1 : 0);
  926. $gui->execution_types=$tcaseMgr->get_execution_types();
  927. if($argsObj->filter_assigned_to)
  928. {
  929. $userSet = tlUser::getByIds($dbHandler,array_values($argsObj->filter_assigned_to));
  930. if ($userSet)
  931. {
  932. foreach($userSet as $key => $userObj)
  933. {
  934. $gui->ownerDisplayName[$key] = $userObj->getDisplayName();
  935. }
  936. }
  937. }
  938. // ------------------------------------------------------------------
  939. $the_builds = $tplanMgr->get_builds_for_html_options($argsObj->tplan_id);
  940. $gui->build_name = isset($the_builds[$argsObj->build_id]) ? $the_builds[$argsObj->build_id] : '';
  941. // 20090419 - franciscom
  942. $gui->grants = initializeRights($dbHandler,$argsObj->user,$argsObj->tproject_id,$argsObj->tplan_id);
  943. $gui->exec_mode = initializeExecMode($dbHandler,$cfgObj->exec_cfg,
  944. $argsObj->user,$argsObj->tproject_id,$argsObj->tplan_id);
  945. $rs = $tplanMgr->get_by_id($argsObj->tplan_id);
  946. $gui->testplan_notes = $rs['notes'];
  947. // Important note:
  948. // custom fields for test plan can be edited ONLY on design, that's reason why we are using
  949. // scope = 'design' instead of 'execution'
  950. $gui->testplan_cfields = $tplanMgr->html_table_of_custom_field_values($argsObj->tplan_id,'design',
  951. array('show_on_execution' => 1));
  952. $gui->history_on = manage_history_on($_REQUEST,$_SESSION,$cfgObj->exec_cfg,
  953. 'btn_history_on','btn_history_off','history_on');
  954. $gui->history_status_btn_name = $gui->history_on ? 'btn_history_off' : 'btn_history_on';
  955. $dummy = $platformMgr->getLinkedToTestplan($argsObj->tplan_id);
  956. $gui->has_platforms = !is_null($dummy) ? 1 : 0;
  957. $gui->platform_info['id']=0;
  958. $gui->platform_info['name']='';
  959. if(!is_null($argsObj->platform_id) && $argsObj->platform_id > 0 )
  960. {
  961. $gui->platform_info = $platformMgr->getByID($argsObj->platform_id);
  962. }
  963. return $gui;
  964. }
  965. /*
  966. function: processTestCase
  967. args :
  968. returns:
  969. rev:
  970. 20090913 - franciscom - changes due to platform feature
  971. 20090718 - franciscom - cfield location management
  972. 20080811 - franciscom - BUGID 1650 (REQ)
  973. */
  974. function processTestCase($tcase,&$guiObj,&$argsObj,&$cfgObj,$linked_tcversions,
  975. &$treeMgr,&$tcaseMgr,&$docRepository)
  976. {
  977. // IMPORTANT due to platform feature
  978. // every element on linked_tcversions will be an array.
  979. $cf_filters=array('show_on_execution' => 1); // BUGID 1650 (REQ)
  980. $locationFilters=$tcaseMgr->buildCFLocationMap();
  981. $guiObj->design_time_cfields='';
  982. $guiObj->testplan_design_time_cfields='';
  983. $tcase_id = isset($tcase['tcase_id']) ? $tcase['tcase_id'] : $argsObj->id;
  984. $items_to_exec[$tcase_id] = $linked_tcversions[$tcase_id][0]['tcversion_id'];
  985. // $tcversion_id = $linked_tcversions[$tcase_id][0]['tcversion_id'];
  986. $tcversion_id = isset($tcase['tcversion_id']) ? $tcase['tcversion_id'] : $items_to_exec[$tcase_id];
  987. $link_id = $linked_tcversions[$tcase_id][0]['feature_id'];
  988. $guiObj->tcAttachments[$tcase_id] = getAttachmentInfos($docRepository,$tcase_id,'nodes_hierarchy',1);
  989. foreach($locationFilters as $locationKey => $filterValue)
  990. {
  991. // 20090718 - franciscom
  992. $finalFilters=$cf_filters+$filterValue;
  993. $guiObj->design_time_cfields[$tcase_id][$locationKey] =
  994. $tcaseMgr->html_table_of_custom_field_values($tcase_id,'design',$finalFilters,
  995. null,null,$argsObj->tproject_id);
  996. // 20090718 - franciscom - TO BE refactored
  997. $guiObj->testplan_design_time_cfields[$tcase_id] =
  998. $tcaseMgr->html_table_of_custom_field_values($tcversion_id,'testplan_design',$cf_filters,
  999. null,null,$argsObj->tproject_id,null,$link_id);
  1000. }
  1001. // BUGID 856: Guest user can execute test case
  1002. if($guiObj->grants->execute)
  1003. {
  1004. $guiObj->execution_time_cfields[$tcase_id] =
  1005. $tcaseMgr->html_table_of_custom_field_inputs($tcase_id,null,'execution',"_{$tcase_id}",null,
  1006. null,$argsObj->tproject_id);
  1007. }
  1008. $tc_info=$treeMgr->get_node_hierarchy_info($tcase_id);
  1009. $guiObj->tSuiteAttachments[$tc_info['parent_id']] = getAttachmentInfos($docRepository,$tc_info['parent_id'],
  1010. 'nodes_hierarchy',true,1);
  1011. return array($tcase_id,$tcversion_id);
  1012. }
  1013. /*
  1014. function: getLastExecution
  1015. args :
  1016. returns:
  1017. rev:
  1018. */
  1019. function getLastExecution(&$dbHandler,$tcase_id,$tcversion_id,$guiObj,$argsObj,&$tcaseMgr)
  1020. {
  1021. // 20090716 - franciscom - get_last_execution() interface changes
  1022. $options=array('getNoExecutions' => 1, 'groupByBuild' => 0);
  1023. $last_exec = $tcaseMgr->get_last_execution($tcase_id,$tcversion_id,$argsObj->tplan_id,
  1024. $argsObj->build_id,$argsObj->platform_id,$options);
  1025. if( !is_null($last_exec) )
  1026. {
  1027. $last_exec=setTesterAssignment($dbHandler,$last_exec,$tcaseMgr,
  1028. $argsObj->tplan_id,$argsObj->platform_id);
  1029. // Warning: setCanExecute() must be called AFTER setTesterAssignment()
  1030. $can_execute=$guiObj->grants->execute && ($guiObj->build_is_open);
  1031. $last_exec=setCanExecute($last_exec,$guiObj->exec_mode,
  1032. $can_execute,$argsObj->user_id);
  1033. }
  1034. // Reorder executions to mantaing correct visualization order.
  1035. if( is_array($tcversion_id) )
  1036. {
  1037. $last_exec=reorderExecutions($tcversion_id,$last_exec);
  1038. }
  1039. return $last_exec;
  1040. }
  1041. /*
  1042. function: getOtherExecutions
  1043. args :
  1044. returns:
  1045. rev:
  1046. */
  1047. function getOtherExecutions(&$dbHandler,$tcase_id,$tcversion_id,$guiObj,$argsObj,&$cfgObj,&$tcaseMgr)
  1048. {
  1049. $other_execs = null;
  1050. if($guiObj->history_on)
  1051. {
  1052. $filters['build_id'] = $argsObj->build_id;
  1053. $filters['platform_id'] = $argsObj->platform_id;
  1054. if($cfgObj->exec_cfg->show_history_all_builds )
  1055. {
  1056. $filters['build_id'] = ANY_BUILD;
  1057. }
  1058. if($cfgObj->exec_cfg->show_history_all_platforms )
  1059. {
  1060. $filters['platform_id'] = null;
  1061. }
  1062. $options = array('exec_id_order' => $cfgObj->exec_cfg->history_order);
  1063. $other_execs = $tcaseMgr->get_executions($tcase_id,$tcversion_id,$argsObj->tplan_id,
  1064. $filters['build_id'],$filters['platform_id'],$options);
  1065. }
  1066. else
  1067. {
  1068. // Warning!!!:
  1069. // we can't use the data we have got with previous call to get_last_execution()
  1070. // because if user have asked to save results last execution data may be has changed
  1071. $aux_map = $tcaseMgr->get_last_execution($tcase_id,$tcversion_id,$argsObj->tplan_id,
  1072. $argsObj->build_id,$argsObj->platform_id);
  1073. if(!is_null($aux_map))
  1074. {
  1075. $other_execs = array();
  1076. foreach($aux_map as $key => $value )
  1077. {
  1078. $other_execs[$key] = array($value);
  1079. }
  1080. }
  1081. }
  1082. return $other_execs;
  1083. }
  1084. /*
  1085. function: processTestSuite
  1086. args :
  1087. returns:
  1088. rev: 20080811 - franciscom - BUGID 1650 (REQ)
  1089. */
  1090. function processTestSuite(&$dbHandler,&$guiObj,&$argsObj,$linked_tcversions,
  1091. &$treeMgr,&$tcaseMgr,&$docRepository)
  1092. {
  1093. $locationFilters=$tcaseMgr->buildCFLocationMap();
  1094. $testSet=new stdClass();
  1095. $cf_filters=array('show_on_execution' => 1); // BUGID 1650 (REQ)
  1096. $tsuite_mgr=new testsuite($dbHandler);
  1097. $tsuite_data = $tsuite_mgr->get_by_id($argsObj->id);
  1098. $opt = array('write_button_only_if_linked' => 1, 'prune_unlinked_tcversions' => 1);
  1099. // @TODO - 20090815 - franciscom
  1100. // why here we do not have filtered by tester ?
  1101. // same for platform_id
  1102. $filters = array('keywords' => $argsObj->keyword_id);
  1103. $out = gen_spec_view($dbHandler,'testplan',$argsObj->tplan_id,$argsObj->id,$tsuite_data['name'],
  1104. $linked_tcversions,null,$filters,$opt);
  1105. $testSet->tcase_id = array();
  1106. $testSet->tcversion_id = array();
  1107. foreach($out['spec_view'] as $key => $value)
  1108. {
  1109. if( count($value['testcases']) > 0 )
  1110. {
  1111. foreach($value['testcases'] as $xkey => $xvalue)
  1112. {
  1113. $testSet->tcase_id[]=$xkey;
  1114. $testSet->tcversion_id[]=$xvalue['linked_version_id'];
  1115. }
  1116. }
  1117. }
  1118. // ---------------------------------------------------------------------------------
  1119. // Get the path for every test case, grouping test cases that have same parent.
  1120. $testCaseQty = count($testSet->tcase_id);
  1121. if( $testCaseQty > 0 )
  1122. {
  1123. $dummy = $tcaseMgr->cfield_mgr->getLocations();
  1124. $verboseLocationCode = array_flip($dummy['testcase']);
  1125. $filters=null;
  1126. foreach($verboseLocationCode as $key => $value)
  1127. {
  1128. $filters[$key]['location']=$value;
  1129. }
  1130. $dummy_id = current($testSet->tcase_id);
  1131. $index = $testCaseQty == 1 ? $dummy_id : 0; // 0 => BULK
  1132. $suffix = '_' . $index;
  1133. $execution_time_cfields =
  1134. $tcaseMgr->html_table_of_custom_field_inputs($dummy_id,$argsObj->tproject_id,'execution',$suffix,
  1135. null,null,$argsObj->tproject_id);
  1136. $guiObj->execution_time_cfields[$index] = $execution_time_cfields;
  1137. foreach($testSet->tcase_id as $testcase_id)
  1138. {
  1139. $path_f = $treeMgr->get_path($testcase_id,null,'full');
  1140. foreach($path_f as $key => $path_elem)
  1141. {
  1142. if( $path_elem['parent_id'] == $argsObj->id )
  1143. {
  1144. // Can be added because is present in the branch the user wants to view
  1145. // ID of branch starting node is in $argsObj->id
  1146. $guiObj->tcAttachments[$testcase_id] = getAttachmentInfos($docRepository,$testcase_id,
  1147. 'nodes_hierarchy',true,1);
  1148. foreach($locationFilters as $locationKey => $filterValue)
  1149. {
  1150. $finalFilters=$cf_filters+$filterValue;
  1151. $guiObj->design_time_cfields[$testcase_id][$locationKey] =
  1152. $tcaseMgr->html_table_of_custom_field_values($testcase_id,'design',$finalFilters);
  1153. $guiObj->testplan_design_time_cfields[$testcase_id] =
  1154. $tcaseMgr->html_table_of_custom_field_values($testcase_id,'testplan_design',$cf_filters,
  1155. null,null,$argsObj->tproject_id);
  1156. }
  1157. // BUGID 856: Guest user can execute test case
  1158. if($guiObj->grants->execute)
  1159. {
  1160. $guiObj->execution_time_cfields[$testcase_id] =
  1161. $tcaseMgr->html_table_of_custom_field_inputs($testcase_id, null,'execution',
  1162. "_".$testcase_id,null,null,
  1163. $argsObj->tproject_id);
  1164. }
  1165. } // if( $path_elem['parent_id'] == $argsObj->id )
  1166. // We do this because do not know if some test case not yet analised will be direct
  1167. // child of this test suite, then we get this info in advance.
  1168. // In situations where only last test suite on branch have test cases, we are colleting
  1169. // info we will never use.
  1170. if($path_elem['node_table'] == 'testsuites' && !isset($guiObj->tSuiteAttachments[$path_elem['id']]))
  1171. {
  1172. $guiObj->tSuiteAttachments[$path_elem['id']] =
  1173. getAttachmentInfos($docRepository,$path_elem['id'],'nodes_hierarchy',true,1);
  1174. }
  1175. } //foreach($path_f as $key => $path_elem)
  1176. }
  1177. }
  1178. return array($testSet->tcase_id,$testSet->tcversion_id);
  1179. }
  1180. ?>