PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/plan/tc_exec_assignment.php

https://bitbucket.org/pfernandez/testlink1.9.6
PHP | 451 lines | 298 code | 69 blank | 84 comment | 31 complexity | 3287f93e8d3b4d62b7fa6726e01b8f85 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. * @package TestLink
  7. * @author Francisco Mancardi (francisco.mancardi@gmail.com)
  8. * @copyright 2005-2009, TestLink community
  9. * @version CVS: $Id: tc_exec_assignment.php,v 1.56 2010/08/10 21:55:39 erikeloff Exp $
  10. * @link http://www.teamst.org/index.php
  11. *
  12. * @internal revisions:
  13. * 20100721 - asimon - BUGID 3406 - testcase execution assignment per build
  14. * 20100326 - amitkhullar - BUGID 3346: Update the date on updating test case asssigments
  15. * 20100228 - franciscom - BUGID 3226: Assignment of single test case not possible
  16. * 20100225 - eloff - remove unnecessary call to platformVisibleForTestplan
  17. * 20100215 - asimon - BUGID 2455, BUGID 3026
  18. * 20100212 - eloff - BUGID 3157 - fixes reassignment to other user
  19. * 20090807 - franciscom - new feature platforms
  20. * 20090201 - franciscom - new feature send mail to tester
  21. * 20080312 - franciscom - BUGID 1427
  22. * 20080114 - franciscom - added testcase external_id management
  23. * 20071228 - franciscom - BUG build combo of users using only users
  24. * that can execute test cases in testplan.
  25. * 20070912 - franciscom - BUGID 1041
  26. */
  27. require_once(dirname(__FILE__)."/../../config.inc.php");
  28. require_once("common.php");
  29. require_once("treeMenu.inc.php");
  30. require_once('email_api.php');
  31. require_once("specview.php");
  32. testlinkInitPage($db,false,false,"checkRights");
  33. $tree_mgr = new tree($db);
  34. $tplan_mgr = new testplan($db);
  35. $tcase_mgr = new testcase($db);
  36. $assignment_mgr = new assignment_mgr($db);
  37. $templateCfg = templateConfiguration();
  38. $args = init_args();
  39. $gui = initializeGui($db,$args,$tplan_mgr,$tcase_mgr);
  40. $keywordsFilter = new stdClass();
  41. $keywordsFilter->items = null;
  42. $keywordsFilter->type = null;
  43. if(is_array($args->keyword_id))
  44. {
  45. $keywordsFilter->items = $args->keyword_id;
  46. $keywordsFilter->type = $gui->keywordsFilterType;
  47. }
  48. $arrData = array();
  49. if(!is_null($args->doAction))
  50. {
  51. if(!is_null($args->achecked_tc))
  52. {
  53. $types_map = $assignment_mgr->get_available_types();
  54. $status_map = $assignment_mgr->get_available_status();
  55. $task_test_execution = $types_map['testcase_execution']['id'];
  56. $open = $status_map['open']['id'];
  57. $db_now = $db->db_now();
  58. $features2 = array( 'upd' => array(), 'ins' => array(), 'del' => array());
  59. $method2call = array( 'upd' => 'update', 'ins' => 'assign', 'del' => 'delete_by_feature_id');
  60. $called = array( 'upd' => false, 'ins' => false, 'del' => false);
  61. foreach($args->achecked_tc as $key_tc => $platform_tcversion)
  62. {
  63. foreach($platform_tcversion as $platform_id => $tcversion_id)
  64. {
  65. $feature_id = $args->feature_id[$key_tc][$platform_id];
  66. if($args->has_prev_assignment[$key_tc][$platform_id] > 0)
  67. {
  68. if($args->tester_for_tcid[$key_tc][$platform_id] > 0)
  69. {
  70. // Do only if tester has changed
  71. if( $args->has_prev_assignment[$key_tc][$platform_id] != $args->tester_for_tcid[$key_tc][$platform_id])
  72. {
  73. $op='upd';
  74. $features2[$op][$feature_id]['user_id'] = $args->tester_for_tcid[$key_tc][$platform_id];
  75. $features2[$op][$feature_id]['type'] = $task_test_execution;
  76. $features2[$op][$feature_id]['status'] = $open;
  77. $features2[$op][$feature_id]['assigner_id'] = $args->user_id;
  78. $features2[$op][$feature_id]['tcase_id'] = $key_tc;
  79. $features2[$op][$feature_id]['tcversion_id'] = $tcversion_id;
  80. $features2[$op][$feature_id]['previous_user_id'] = $args->has_prev_assignment[$key_tc][$platform_id];
  81. $features2[$op][$feature_id]['creation_ts'] = $db_now; //BUGID 3346
  82. $features2[$op][$feature_id]['build_id'] = $args->build_id; // BUGID 3406
  83. }
  84. }
  85. else
  86. {
  87. $op='del';
  88. $features2[$op][$feature_id]['tcase_id'] = $key_tc;
  89. $features2[$op][$feature_id]['tcversion_id'] = $tcversion_id;
  90. $features2[$op][$feature_id]['previous_user_id'] = $args->has_prev_assignment[$key_tc][$platform_id];
  91. $features2[$op][$feature_id]['build_id'] = $args->build_id; // BUGID 3406
  92. }
  93. }
  94. else if($args->tester_for_tcid[$key_tc][$platform_id] > 0)
  95. {
  96. $op='ins';
  97. $features2[$op][$feature_id]['user_id'] = $args->tester_for_tcid[$key_tc][$platform_id];
  98. $features2[$op][$feature_id]['type'] = $task_test_execution;
  99. $features2[$op][$feature_id]['status'] = $open;
  100. $features2[$op][$feature_id]['creation_ts'] = $db_now;
  101. $features2[$op][$feature_id]['assigner_id'] = $args->user_id;
  102. $features2[$op][$feature_id]['tcase_id'] = $key_tc;
  103. $features2[$op][$feature_id]['tcversion_id'] = $tcversion_id;
  104. $features2[$op][$feature_id]['build_id'] = $args->build_id; // BUGID 3406
  105. }
  106. }
  107. }
  108. foreach($features2 as $key => $values)
  109. {
  110. if( count($features2[$key]) > 0 )
  111. {
  112. if( $key == 'del' )
  113. {
  114. $assignment_mgr->$method2call[$key](array_keys($values));
  115. }
  116. else
  117. {
  118. $assignment_mgr->$method2call[$key]($values);
  119. }
  120. $called[$key]=true;
  121. }
  122. }
  123. if($args->send_mail)
  124. {
  125. foreach($called as $ope => $ope_status)
  126. {
  127. if($ope_status)
  128. {
  129. send_mail_to_testers($db,$tcase_mgr,$gui,$args,$features2[$ope],$ope);
  130. }
  131. }
  132. } // if($args->send_mail)
  133. }
  134. }
  135. switch($args->level)
  136. {
  137. case 'testcase':
  138. // build the data need to call gen_spec_view
  139. $xx=$tcase_mgr->getPathLayered(array($args->id));
  140. $yy = array_keys($xx); // done to silence warning on end()
  141. $tsuite_data['id'] = end($yy);
  142. $tsuite_data['name'] = $xx[$tsuite_data['id']]['value'];
  143. // 20100228 - franciscom - BUGID 3226: Assignment of single test case not possible
  144. $getFilters = array('tcase_id' => $args->id);
  145. // 3406
  146. //$getOptions = array('output' => 'mapOfArray');
  147. $getOptions = array('output' => 'mapOfArray', 'user_assignments_per_build' => $args->build_id);
  148. $linked_items = $tplan_mgr->get_linked_tcversions($args->tplan_id,$getFilters,$getOptions);
  149. $filters = array('keywords' => $keywordsFilter->items );
  150. // 3406
  151. //$opt = array('write_button_only_if_linked' => 1);
  152. $opt = array('write_button_only_if_linked' => 1, 'user_assignments_per_build' => $args->build_id);
  153. $my_out = gen_spec_view($db,'testplan',$args->tplan_id,$tsuite_data['id'],$tsuite_data['name'],
  154. $linked_items,null,$filters,$opt);
  155. // index 0 contains data for the parent test suite of this test case,
  156. // other elements are not needed.
  157. $out = array();
  158. $out['spec_view'][0] = $my_out['spec_view'][0];
  159. $out['num_tc'] = 1;
  160. break;
  161. case 'testsuite':
  162. // BUGID 3026
  163. // BUGID 3516
  164. $tcaseFilter = (isset($args->testcases_to_show)) ? $args->testcases_to_show : null;
  165. // 3406
  166. $opt = array('user_assignments_per_build' => $args->build_id);
  167. $out = keywordFilteredSpecView($db, $args, $keywordsFilter, $tplan_mgr,
  168. $tcase_mgr, $tcaseFilter, $opt);
  169. break;
  170. default:
  171. show_instructions('tc_exec_assignment');
  172. break;
  173. }
  174. $gui->items = $out['spec_view'];
  175. // useful to avoid error messages on smarty template.
  176. $gui->items_qty = is_null($gui->items) ? 0 : count($gui->items);
  177. $gui->has_tc = $out['num_tc'] > 0 ? 1:0;
  178. $gui->support_array = array_keys($gui->items);
  179. if ($_SESSION['testprojectOptions']->testPriorityEnabled)
  180. {
  181. $urgencyCfg = config_get('urgency');
  182. $gui->priority_labels = init_labels($urgencyCfg["code_label"]);
  183. }
  184. $smarty = new TLSmarty();
  185. $smarty->assign('gui', $gui);
  186. $smarty->display($templateCfg->template_dir . $templateCfg->default_template);
  187. /*
  188. function:
  189. args :
  190. returns:
  191. */
  192. function init_args()
  193. {
  194. $_REQUEST = strings_stripSlashes($_REQUEST);
  195. $args = new stdClass();
  196. $args->user_id = $_SESSION['userID'];
  197. $args->tproject_id = $_SESSION['testprojectID'];
  198. $args->tproject_name = $_SESSION['testprojectName'];
  199. // $args->tplan_id = isset($_REQUEST['tplan_id']) ? $_REQUEST['tplan_id'] : $_SESSION['testplanID'];
  200. // $key2loop = array('doAction' => null,'level' => null , 'achecked_tc' => null,
  201. // 'version_id' => 0, 'has_prev_assignment' => null, 'send_mail' => false,
  202. // 'tester_for_tcid' => null, 'feature_id' => null, 'id' => 0, 'filter_assigned_to' => null);
  203. $key2loop = array('doAction' => null,'level' => null , 'achecked_tc' => null,
  204. 'version_id' => 0, 'has_prev_assignment' => null, 'send_mail' => false,
  205. 'tester_for_tcid' => null, 'feature_id' => null, 'id' => 0);
  206. foreach($key2loop as $key => $value)
  207. {
  208. $args->$key = isset($_REQUEST[$key]) ? $_REQUEST[$key] : $value;
  209. }
  210. // Can be a list (string with , (comma) has item separator), that will be trasformed in an array.
  211. // $keywordSet = isset($_REQUEST['keyword_id']) ? $_REQUEST['keyword_id'] : null;
  212. // $args->keyword_id = is_null($keywordSet) ? 0 : explode(',',$keywordSet);
  213. // $args->keywordsFilterType = isset($_REQUEST['keywordsFilterType']) ? $_REQUEST['keywordsFilterType'] : 'OR';
  214. //
  215. // if( !is_null($args->filter_assigned_to) )
  216. // {
  217. // $args->filter_assigned_to = (array)$args->filter_assigned_to;
  218. // }
  219. // BUGID 2455, BUGID 3026
  220. // if (isset($_REQUEST['show_only_tcs']) && isset($_REQUEST['show_only_tcs']) != '')
  221. // {
  222. // $args->tcids_to_show = explode(",", $_REQUEST['show_only_tcs']);
  223. // }
  224. // BUGID 3516
  225. // For more information about the data accessed in session here, see the comment
  226. // in the file header of lib/functions/tlTestCaseFilterControl.class.php.
  227. $form_token = isset($_REQUEST['form_token']) ? $_REQUEST['form_token'] : 0;
  228. $mode = 'plan_mode';
  229. $session_data = isset($_SESSION[$mode]) && isset($_SESSION[$mode][$form_token])
  230. ? $_SESSION[$mode][$form_token] : null;
  231. $args->refreshTree = isset($session_data['setting_refresh_tree_on_action']) ?
  232. $session_data['setting_refresh_tree_on_action'] : 0;
  233. $args->keyword_id = 0;
  234. $fk = 'filter_keywords';
  235. if (isset($session_data[$fk])) {
  236. $args->keyword_id = $session_data[$fk];
  237. if (is_array($args->keyword_id) && count($args->keyword_id) == 1) {
  238. $args->keyword_id = $args->keyword_id[0];
  239. }
  240. }
  241. $args->keywordsFilterType = null;
  242. $ft = 'filter_keywords_filter_type';
  243. if (isset($session_data[$ft])) {
  244. $args->keywordsFilterType = $session_data[$ft];
  245. }
  246. $args->filter_assigned_to = isset($session_data['filter_assigned_user']) ?
  247. $session_data['filter_assigned_user'] : null;
  248. $args->testcases_to_show = null;
  249. if (isset($session_data['testcases_to_show'])) {
  250. $args->testcases_to_show = $session_data['testcases_to_show'];
  251. }
  252. // BUGID 3406
  253. $args->build_id = isset($session_data['setting_build']) ? $session_data['setting_build'] : 0;
  254. $args->tplan_id = isset($session_data['setting_testplan']) ? $session_data['setting_testplan'] : 0;
  255. if ($args->tplan_id) {
  256. $args->tplan_id = isset($_REQUEST['tplan_id']) ? $_REQUEST['tplan_id'] : $_SESSION['testplanID'];
  257. }
  258. return $args;
  259. }
  260. /*
  261. function: initializeGui
  262. args :
  263. returns:
  264. */
  265. function initializeGui(&$dbHandler,$argsObj,&$tplanMgr,&$tcaseMgr)
  266. {
  267. $platform_mgr = new tlPlatform($dbHandler,$argsObj->tproject_id);
  268. $tcase_cfg = config_get('testcase_cfg');
  269. $gui = new stdClass();
  270. $gui->platforms = $platform_mgr->getLinkedToTestplanAsMap($argsObj->tplan_id);
  271. $gui->usePlatforms = $platform_mgr->platformsActiveForTestplan($argsObj->tplan_id);
  272. $gui->bulk_platforms = $platform_mgr->getLinkedToTestplanAsMap($argsObj->tplan_id);
  273. $gui->bulk_platforms[0] = lang_get("all_platforms");
  274. ksort($gui->bulk_platforms);
  275. $gui->send_mail = $argsObj->send_mail;
  276. $gui->send_mail_checked = "";
  277. if($gui->send_mail)
  278. {
  279. $gui->send_mail_checked = ' checked="checked" ';
  280. }
  281. $gui->glueChar=$tcase_cfg->glue_character;
  282. if ($argsObj->level != 'testproject')
  283. {
  284. $gui->testCasePrefix = $tcaseMgr->tproject_mgr->getTestCasePrefix($argsObj->tproject_id);
  285. $gui->testCasePrefix .= $tcase_cfg->glue_character;
  286. $gui->keywordsFilterType = $argsObj->keywordsFilterType;
  287. $tplan_info = $tplanMgr->get_by_id($argsObj->tplan_id);
  288. $gui->testPlanName = $tplan_info['name'];
  289. // 3406
  290. $build_info = $tplanMgr->get_build_by_id($argsObj->tplan_id, $argsObj->build_id);
  291. $gui->buildName = $build_info['name'];
  292. $gui->main_descr = sprintf(lang_get('title_tc_exec_assignment'),
  293. $gui->buildName, $gui->testPlanName);
  294. $gui->all_users = tlUser::getAll($dbHandler,null,"id",null);
  295. $gui->users = getUsersForHtmlOptions($dbHandler,null,null,null,$gui->all_users);
  296. $gui->testers = getTestersForHtmlOptions($dbHandler,$argsObj->tplan_id,$argsObj->tproject_id,$gui->all_users);
  297. }
  298. return $gui;
  299. }
  300. /**
  301. * send_mail_to_testers
  302. *
  303. *
  304. * @return void
  305. */
  306. function send_mail_to_testers(&$dbHandler,&$tcaseMgr,&$guiObj,&$argsObj,$features,$operation)
  307. {
  308. $testers['new']=null;
  309. $testers['old']=null;
  310. $mail_details['new']=lang_get('mail_testcase_assigned') . "<br /><br />";
  311. $mail_details['old']=lang_get('mail_testcase_assignment_removed'). "<br /><br />";
  312. $mail_subject['new']=lang_get('mail_subject_testcase_assigned');
  313. $mail_subject['old']=lang_get('mail_subject_testcase_assignment_removed');
  314. $use_testers['new']= ($operation == 'del') ? false : true ;
  315. $use_testers['old']= ($operation == 'ins') ? false : true ;
  316. $tcaseSet=null;
  317. $tcnames=null;
  318. $email=array();
  319. $assigner=$guiObj->all_users[$argsObj->user_id]->firstName . ' ' .
  320. $guiObj->all_users[$argsObj->user_id]->lastName ;
  321. $email['from_address']=config_get('from_email');
  322. $body_first_lines = lang_get('testproject') . ': ' . $argsObj->tproject_name . '<br />' .
  323. lang_get('testplan') . ': ' . $guiObj->testPlanName .'<br /><br />';
  324. // Get testers id
  325. foreach($features as $feature_id => $value)
  326. {
  327. if($use_testers['new'])
  328. {
  329. $testers['new'][$value['user_id']][$value['tcase_id']]=$value['tcase_id'];
  330. }
  331. if( $use_testers['old'] )
  332. {
  333. $testers['old'][$value['previous_user_id']][$value['tcase_id']]=$value['tcase_id'];
  334. }
  335. $tcaseSet[$value['tcase_id']]=$value['tcase_id'];
  336. $tcversionSet[$value['tcversion_id']]=$value['tcversion_id'];
  337. }
  338. $infoSet=$tcaseMgr->get_by_id_bulk($tcaseSet,$tcversionSet);
  339. foreach($infoSet as $value)
  340. {
  341. $tcnames[$value['testcase_id']] = $guiObj->testCasePrefix . $value['tc_external_id'] . ' ' . $value['name'];
  342. }
  343. $path_info = $tcaseMgr->tree_manager->get_full_path_verbose($tcaseSet);
  344. $flat_path=null;
  345. foreach($path_info as $tcase_id => $pieces)
  346. {
  347. $flat_path[$tcase_id]=implode('/',$pieces) . '/' . $tcnames[$tcase_id];
  348. }
  349. foreach($testers as $tester_type => $tester_set)
  350. {
  351. if( !is_null($tester_set) )
  352. {
  353. $email['subject'] = $mail_subject[$tester_type] . ' ' . $guiObj->testPlanName;
  354. foreach($tester_set as $user_id => $value)
  355. {
  356. $userObj=$guiObj->all_users[$user_id];
  357. $email['to_address']=$userObj->emailAddress;
  358. $email['body'] = $body_first_lines;
  359. $email['body'] .= sprintf($mail_details[$tester_type],
  360. $userObj->firstName . ' ' .$userObj->lastName,$assigner);
  361. foreach($value as $tcase_id)
  362. {
  363. $email['body'] .= $flat_path[$tcase_id] . '<br />';
  364. }
  365. $email['body'] .= '<br />' . date(DATE_RFC1123);
  366. $email_op = email_send($email['from_address'], $email['to_address'],
  367. $email['subject'], $email['body'], '', true, true);
  368. } // foreach($tester_set as $user_id => $value)
  369. }
  370. }
  371. }
  372. function checkRights(&$db,&$user)
  373. {
  374. return $user->hasRight($db,'testplan_planning');
  375. }
  376. ?>