PageRenderTime 56ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/plan/planAddTC.php

https://bitbucket.org/pfernandez/testlink1.9.6
PHP | 818 lines | 487 code | 102 blank | 229 comment | 48 complexity | aaa001afb425823a2a171363dbd30844 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. * link/unlink test cases to a test plan
  7. *
  8. * @package TestLink
  9. * @copyright 2007-2009, TestLink community
  10. * @version CVS: $Id: planAddTC.php,v 1.102 2010/08/10 21:55:39 erikeloff Exp $
  11. * @filesource http://testlink.cvs.sourceforge.net/viewvc/testlink/testlink/lib/functions/object.class.php?view=markup
  12. * @link http://www.teamst.org/index.php
  13. *
  14. * @internal Revisions:
  15. * 20100721 - asimon - BUGID 3406: assign users per build when adding testcases to plan,
  16. * added init_build_selector()
  17. * 20100628 - asimon - removal of constants from filter control class
  18. * 20100625 - asimon - refactoring for new filter features and BUGID 3516
  19. * 20100624 - asimon - CVS merge (experimental branch to HEAD)
  20. * 20100417 - BUGDID 2498 - filter by test case importance
  21. * 20100411 - BUGID 2797 - filter by test case execution type
  22. * 20100225 - eloff - BUGID 3205 - Don't show "save platforms" when platforms aren't used
  23. * 20100129 - franciscom - moved here from template, logic to initialize:
  24. * drawSavePlatformsButton,drawSaveCFieldsButton
  25. * 20090922 - franciscom - add contribution - bulk tester assignment while adding test cases
  26. *
  27. **/
  28. require_once('../../config.inc.php');
  29. require_once("common.php");
  30. require_once('email_api.php');
  31. require_once("specview.php");
  32. testlinkInitPage($db);
  33. $tree_mgr = new tree($db);
  34. $tsuite_mgr = new testsuite($db);
  35. $tplan_mgr = new testplan($db);
  36. $tproject_mgr = new testproject($db);
  37. $tcase_mgr = new testcase($db);
  38. $templateCfg = templateConfiguration();
  39. $args = init_args();
  40. $gui = initializeGui($db,$args,$tplan_mgr,$tcase_mgr);
  41. // 3406
  42. $gui->build = init_build_selector($tplan_mgr, $args);
  43. $keywordsFilter = null;
  44. if(is_array($args->keyword_id))
  45. {
  46. $keywordsFilter = new stdClass();
  47. $keywordsFilter->items = $args->keyword_id;
  48. $keywordsFilter->type = $gui->keywordsFilterType->selected;
  49. }
  50. $do_display = 0;
  51. switch($args->item_level)
  52. {
  53. case 'testsuite':
  54. $do_display = 1;
  55. break;
  56. case 'testproject':
  57. show_instructions('planAddTC');
  58. exit();
  59. break;
  60. }
  61. switch($args->doAction)
  62. {
  63. case 'doAddRemove':
  64. // Remember: checkboxes exist only if are checked
  65. if(!is_null($args->testcases2add))
  66. {
  67. // items_to_link structure:
  68. // key: test case id , value: map
  69. // key: platform_id value: test case VERSION ID
  70. $items_to_link = null;
  71. foreach ($args->testcases2add as $tcase_id => $info)
  72. {
  73. foreach ($info as $platform_id => $tcase_id)
  74. {
  75. // $items_to_link[$tcase_id][$platform_id] = $args->tcversion_for_tcid[$tcase_id];
  76. if( isset($args->tcversion_for_tcid[$tcase_id]) )
  77. {
  78. $tcversion_id = $args->tcversion_for_tcid[$tcase_id];
  79. }
  80. else
  81. {
  82. $tcversion_id = $args->linkedVersion[$tcase_id];
  83. }
  84. $items_to_link['tcversion'][$tcase_id] = $tcversion_id;
  85. $items_to_link['platform'][$platform_id] = $platform_id;
  86. $items_to_link['items'][$tcase_id][$platform_id] = $tcversion_id;
  87. }
  88. }
  89. $linked_features=$tplan_mgr->link_tcversions($args->tplan_id,$items_to_link,$args->userID);
  90. if( $args->testerID > 0 )
  91. {
  92. $features2add = null;
  93. $status_map = $tplan_mgr->assignment_mgr->get_available_status();
  94. $types_map = $tplan_mgr->assignment_mgr->get_available_types();
  95. $db_now = $db->db_now();
  96. $tcversion_tcase = array_flip($items_to_link['tcversion']);
  97. $getOpt = array('outputFormat' => 'map', 'addIfNull' => true);
  98. $platformSet = $tplan_mgr->getPlatforms($args->tplan_id,$getOpt);
  99. foreach($linked_features as $platform_id => $tcversion_info)
  100. {
  101. foreach($tcversion_info as $tcversion_id => $feature_id)
  102. {
  103. $features2['add'][$feature_id]['user_id'] = $args->testerID;
  104. $features2['add'][$feature_id]['type'] = $types_map['testcase_execution']['id'];
  105. $features2['add'][$feature_id]['status'] = $status_map['open']['id'];
  106. $features2['add'][$feature_id]['assigner_id'] = $args->userID;
  107. $features2['add'][$feature_id]['tcase_id'] = $tcversion_tcase[$tcversion_id];
  108. $features2['add'][$feature_id]['tcversion_id'] = $tcversion_id;
  109. $features2['add'][$feature_id]['creation_ts'] = $db_now;
  110. $features2['add'][$feature_id]['platform_name'] = $platformSet[$platform_id];
  111. // 3406
  112. $features2['add'][$feature_id]['build_id'] = $args->build_id;
  113. }
  114. }
  115. foreach($features2 as $key => $values)
  116. {
  117. $tplan_mgr->assignment_mgr->assign($values);
  118. $called[$key]=true;
  119. }
  120. if($args->send_mail)
  121. {
  122. foreach($called as $ope => $ope_status)
  123. {
  124. if($ope_status)
  125. {
  126. send_mail_to_testers($db,$tcase_mgr,$gui,$args,$features2['add'],$ope);
  127. }
  128. }
  129. } // if($args->send_mail)
  130. }
  131. }
  132. if(!is_null($args->testcases2remove))
  133. {
  134. // remove without warning
  135. $items_to_unlink=null;
  136. foreach ($args->testcases2remove as $tcase_id => $info)
  137. {
  138. foreach ($info as $platform_id => $tcversion_id)
  139. {
  140. $items_to_unlink['tcversion'][$tcase_id] = $tcversion_id;
  141. $items_to_unlink['platform'][$platform_id] = $platform_id;
  142. $items_to_unlink['items'][$tcase_id][$platform_id] = $tcversion_id;
  143. }
  144. }
  145. $tplan_mgr->unlink_tcversions($args->tplan_id,$items_to_unlink);
  146. }
  147. doReorder($args,$tplan_mgr);
  148. $do_display = 1;
  149. break;
  150. case 'doReorder':
  151. doReorder($args,$tplan_mgr);
  152. $do_display = 1;
  153. break;
  154. case 'doSavePlatforms':
  155. doSavePlatforms($args,$tplan_mgr);
  156. $do_display = 1;
  157. break;
  158. case 'doSaveCustomFields':
  159. doSaveCustomFields($args,$_REQUEST,$tplan_mgr,$tcase_mgr);
  160. $do_display = 1;
  161. break;
  162. default:
  163. break;
  164. }
  165. $smarty = new TLSmarty();
  166. if($do_display)
  167. {
  168. $tsuite_data = $tsuite_mgr->get_by_id($args->object_id);
  169. // This does filter on keywords ALWAYS in OR mode.
  170. //
  171. // CRITIC:
  172. // We have arrived after clicking in a node of Test Spec Tree where we have two classes of filters
  173. // 1. filters on attribute COMMON to all test case versions => TEST CASE attribute like keyword_id
  174. // 2. filters on attribute that can change on each test case version => execution type.
  175. //
  176. // For attributes at Version Level, filter is done ON LAST ACTIVE version, that can be NOT the VERSION
  177. // already linked to test plan.
  178. // This can produce same weird effects like this:
  179. //
  180. // 1. Test Suite A - create TC1 - Version 1 - exec type MANUAL
  181. // 2. Test Suite A - create TC2 - Version 1 - exec type AUTO
  182. // 3. Test Suite A - create TC3 - Version 1 - exec type MANUAL
  183. // 4. Use feature ADD/REMOVE test cases from test plan.
  184. // 5. Add TC1 - Version 1 to test plan
  185. // 6. Apply filter on exec type AUTO
  186. // 7. Tree will display (Folder) Test Suite A with 1 element
  187. // 8. click on folder, then on RIGHT pane:
  188. // TC2 - Version 1 NOT ASSIGNED TO TEST PLAN is displayed
  189. // 9. Use feature edits test cases, to create a new version for TC1 -> Version 2 - exec type AUTO
  190. // 10. Use feature ADD/REMOVE test cases from test plan.
  191. // 11. Apply filter on exec type AUTO
  192. // 12. Tree will display (Folder) Test Suite A with 2 elements
  193. // 13. click on folder, then on RIGHT pane:
  194. // TC2 - Version 1 NOT ASSIGNED TO TEST PLAN is displayed
  195. // TC1 - Version 2 NOT ASSIGNED TO TEST PLAN is displayed ----> THIS IS RIGHT but WRONG
  196. // Only one TC version can be linked to test plan, and TC1 already is LINKED BUT with VERSION 1.
  197. // Version 2 is displayed because it has EXEC TYPE AUTO
  198. //
  199. // How to solve ?
  200. // Filters regarding this kind of attributes WILL BE NOT APPLIEDED to get linked items
  201. // In this way counters on Test Spec Tree and amount of TC displayed on right pane will be coherent.
  202. //
  203. $tplan_linked_tcversions = getFilteredLinkedVersions($args,$tplan_mgr,$tcase_mgr);
  204. $testCaseSet = null;
  205. if(!is_null($keywordsFilter) )
  206. {
  207. // With this pieces we implement the AND type of keyword filter.
  208. $keywordsTestCases = $tproject_mgr->get_keywords_tcases($args->tproject_id,$keywordsFilter->items,
  209. $keywordsFilter->type);
  210. if (sizeof($keywordsTestCases))
  211. {
  212. $testCaseSet = array_keys($keywordsTestCases);
  213. }
  214. }
  215. // Choose enable/disable display of custom fields, analysing if this kind of custom fields
  216. // exists on this test project.
  217. $cfields=$tsuite_mgr->cfield_mgr->get_linked_cfields_at_testplan_design($args->tproject_id,1,'testcase');
  218. $opt = array('write_button_only_if_linked' => 0, 'add_custom_fields' => 0);
  219. $opt['add_custom_fields'] = count($cfields) > 0 ? 1 : 0;
  220. // 20100411 - BUGID 2797 - filter by test case execution type
  221. $filters = array('keywords' => $args->keyword_id, 'testcases' => $testCaseSet,
  222. 'exec_type' => $args->executionType, 'importance' => $args->importance);
  223. $out = gen_spec_view($db,'testPlanLinking',$args->tproject_id,$args->object_id,$tsuite_data['name'],
  224. $tplan_linked_tcversions,null,$filters,$opt);
  225. $gui->has_tc = ($out['num_tc'] > 0 ? 1 : 0);
  226. $gui->items = $out['spec_view'];
  227. $gui->has_linked_items = $out['has_linked_items'];
  228. $gui->add_custom_fields = $opt['add_custom_fields'];
  229. $gui->drawSavePlatformsButton = false;
  230. $gui->drawSaveCFieldsButton = false;
  231. if( !is_null($gui->items) )
  232. {
  233. initDrawSaveButtons($gui);
  234. }
  235. // This has to be done ONLY AFTER has all data needed => after gen_spec_view() call
  236. setAdditionalGuiData($gui);
  237. $smarty->assign('gui', $gui);
  238. $smarty->display($templateCfg->template_dir . 'planAddTC_m1.tpl');
  239. }
  240. /*
  241. function: init_args
  242. creates a sort of namespace
  243. args:
  244. returns: object with some REQUEST and SESSION values as members
  245. */
  246. function init_args()
  247. {
  248. $_REQUEST = strings_stripSlashes($_REQUEST);
  249. $args = new stdClass();
  250. $args->tplan_id = isset($_REQUEST['tplan_id']) ? $_REQUEST['tplan_id'] : $_SESSION['testplanID'];
  251. $args->object_id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
  252. $args->item_level = isset($_REQUEST['edit']) ? trim($_REQUEST['edit']) : null;
  253. $args->doAction = isset($_REQUEST['doAction']) ? $_REQUEST['doAction'] : "default";
  254. $args->tproject_id = $_SESSION['testprojectID'];
  255. $args->tproject_name = $_SESSION['testprojectName'];
  256. $args->testcases2add = isset($_REQUEST['achecked_tc']) ? $_REQUEST['achecked_tc'] : null;
  257. $args->tcversion_for_tcid = isset($_REQUEST['tcversion_for_tcid']) ? $_REQUEST['tcversion_for_tcid'] : null;
  258. $args->testcases2remove = isset($_REQUEST['remove_checked_tc']) ? $_REQUEST['remove_checked_tc'] : null;
  259. // BUGID 3516
  260. // // Can be a list (string with , (comma) has item separator), that will be trasformed in an array.
  261. // $keywordSet = isset($_REQUEST['keyword_id']) ? $_REQUEST['keyword_id'] : null;
  262. //
  263. // $args->keyword_id = 0;
  264. // if(!is_null($keywordSet))
  265. // {
  266. // $args->keyword_id = explode(',',$keywordSet);
  267. // }
  268. // $args->keywordsFilterType = isset($_REQUEST['keywordsFilterType']) ? $_REQUEST['keywordsFilterType'] : 'OR';
  269. $args->testcases2order = isset($_REQUEST['exec_order']) ? $_REQUEST['exec_order'] : null;
  270. $args->linkedOrder = isset($_REQUEST['linked_exec_order']) ? $_REQUEST['linked_exec_order'] : null;
  271. $args->linkedVersion = isset($_REQUEST['linked_version']) ? $_REQUEST['linked_version'] : null;
  272. $args->linkedWithCF = isset($_REQUEST['linked_with_cf']) ? $_REQUEST['linked_with_cf'] : null;
  273. $args->feature2fix = isset($_REQUEST['feature2fix']) ? $_REQUEST['feature2fix'] : null;
  274. $args->userID = $_SESSION['currentUser']->dbID;
  275. $args->testerID = isset($_REQUEST['testerID']) ? intval($_REQUEST['testerID']) : 0;
  276. $args->send_mail = isset($_REQUEST['send_mail']) ? $_REQUEST['send_mail'] : false;
  277. // BUGID 3516
  278. // // BUGID 2797 - filter by test case execution type
  279. // // 0 -> Any, but has to be converter to null to be used on call to other functions
  280. // $args->executionType = isset($_REQUEST['executionType']) ? intval($_REQUEST['executionType']) : 0;
  281. // $args->executionType = ($args->executionType > 0) ? $args->executionType : null;
  282. //
  283. // // 0 -> Any, but has to be converter to null to be used on call to other functions
  284. // $args->importance = isset($_REQUEST['importance']) ? intval($_REQUEST['importance']) : 0;
  285. // $args->importance = ($args->importance > 0) ? $args->importance : null;
  286. // BUGID 3516
  287. // For more information about the data accessed in session here, see the comment
  288. // in the file header of lib/functions/tlTestCaseFilterControl.class.php.
  289. $form_token = isset($_REQUEST['form_token']) ? $_REQUEST['form_token'] : 0;
  290. $mode = 'plan_add_mode';
  291. $session_data = isset($_SESSION[$mode]) && isset($_SESSION[$mode][$form_token])
  292. ? $_SESSION[$mode][$form_token] : null;
  293. $args->refreshTree = isset($session_data['setting_refresh_tree_on_action']) ?
  294. $session_data['setting_refresh_tree_on_action'] : 0;
  295. $args->executionType = isset($session_data['filter_execution_type']) ?
  296. $session_data['filter_execution_type'] : 0;
  297. $args->importance = isset($session_data['filter_priority']) ?
  298. $session_data['filter_priority'] : 0;
  299. $args->importance = ($args->importance > 0) ? $args->importance : null;
  300. $args->keyword_id = 0;
  301. $fk = 'filter_keywords';
  302. if (isset($session_data[$fk])) {
  303. $args->keyword_id = $session_data[$fk];
  304. if (is_array($args->keyword_id) && count($args->keyword_id) == 1) {
  305. $args->keyword_id = $args->keyword_id[0];
  306. }
  307. }
  308. $args->keywordsFilterType = null;
  309. $ft = 'filter_keywords_filter_type';
  310. if (isset($session_data[$ft])) {
  311. $args->keywordsFilterType = $session_data[$ft];
  312. }
  313. // 3406
  314. $args->build_id = isset($_REQUEST['build_id']) ? intval($_REQUEST['build_id']) : 0;
  315. return $args;
  316. }
  317. /*
  318. function: doReorder
  319. writes to DB execution order of test case versions
  320. linked to testplan.
  321. args: argsObj: user input data collected via HTML inputs
  322. tplanMgr: testplan manager object
  323. returns: -
  324. */
  325. function doReorder(&$argsObj,&$tplanMgr)
  326. {
  327. $mapo = null;
  328. // Do this to avoid update if order has not been changed on already linked items
  329. if(!is_null($argsObj->linkedVersion))
  330. {
  331. // Using memory of linked test case, try to get order
  332. foreach($argsObj->linkedVersion as $tcid => $tcversion_id)
  333. {
  334. if($argsObj->linkedOrder[$tcid] != $argsObj->testcases2order[$tcid] )
  335. {
  336. $mapo[$tcversion_id] = $argsObj->testcases2order[$tcid];
  337. }
  338. }
  339. }
  340. // Now add info for new liked test cases if any
  341. if(!is_null($argsObj->testcases2add))
  342. {
  343. $tcaseSet = array_keys($argsObj->testcases2add);
  344. foreach($tcaseSet as $tcid)
  345. {
  346. // This check is needed because, after we have added test case
  347. // for a platform, this will not be present anymore
  348. // in tcversion_for_tcid, but it's present in linkedVersion.
  349. // IMPORTANT:
  350. // We do not allow link of different test case version on a
  351. // testplan no matter we are using or not platform feature.
  352. //
  353. $tcversion_id=null;
  354. if( isset($argsObj->tcversion_for_tcid[$tcid]) )
  355. {
  356. $tcversion_id = $argsObj->tcversion_for_tcid[$tcid];
  357. //$mapo[$tcversion_id] = $argsObj->testcases2order[$tcid];
  358. }
  359. else if( isset($argsObj->linkedVersion[$tcid]) &&
  360. !isset($mapo[$argsObj->linkedVersion[$tcid]]))
  361. {
  362. // $mapo[$argsObj->linkedVersion[$tcid]]=$argsObj->testcases2order[$tcid];
  363. $tcversion_id = $argsObj->linkedVersion[$tcid];
  364. }
  365. if( !is_null($tcversion_id))
  366. {
  367. $mapo[$tcversion_id] = $argsObj->testcases2order[$tcid];
  368. }
  369. }
  370. }
  371. if(!is_null($mapo))
  372. {
  373. $tplanMgr->setExecutionOrder($argsObj->tplan_id,$mapo);
  374. }
  375. }
  376. /*
  377. function: initializeGui
  378. args :
  379. returns:
  380. */
  381. function initializeGui(&$dbHandler,$argsObj,&$tplanMgr,&$tcaseMgr)
  382. {
  383. $tcase_cfg = config_get('testcase_cfg');
  384. $title_separator = config_get('gui_title_separator_1');
  385. $gui = new stdClass();
  386. $gui->testCasePrefix = $tcaseMgr->tproject_mgr->getTestCasePrefix($argsObj->tproject_id);
  387. $gui->testCasePrefix .= $tcase_cfg->glue_character;
  388. $gui->can_remove_executed_testcases=$tcase_cfg->can_remove_executed;
  389. $gui->keywordsFilterType = $argsObj->keywordsFilterType;
  390. $gui->keywords_filter = '';
  391. $gui->has_tc = 0;
  392. $gui->items = null;
  393. $gui->has_linked_items = false;
  394. $gui->keywordsFilterType = new stdClass();
  395. $gui->keywordsFilterType->options = array('OR' => 'Or' , 'AND' =>'And');
  396. $gui->keywordsFilterType->selected=$argsObj->keywordsFilterType;
  397. // full_control, controls the operations planAddTC_m1.tpl will allow
  398. // 1 => add/remove
  399. // 0 => just remove
  400. $gui->full_control = 1;
  401. $tplan_info = $tplanMgr->get_by_id($argsObj->tplan_id);
  402. $gui->testPlanName = $tplan_info['name'];
  403. $gui->pageTitle = lang_get('test_plan') . $title_separator . $gui->testPlanName;
  404. $gui->refreshTree = $argsObj->refreshTree;
  405. $gui->testers = getTestersForHtmlOptions($dbHandler,$argsObj->tplan_id,$argsObj->tproject_id);
  406. $gui->testerID = $argsObj->testerID;
  407. $gui->send_mail = $argsObj->send_mail;
  408. $gui->send_mail_checked = '';
  409. if($gui->send_mail)
  410. {
  411. $gui->send_mail_checked = ' checked="checked" ';
  412. }
  413. $platform_mgr = new tlPlatform($dbHandler, $argsObj->tproject_id);
  414. $gui->platforms = $platform_mgr->getLinkedToTestplan($argsObj->tplan_id);
  415. $gui->platformsForHtmlOptions = null;
  416. $gui->usePlatforms = $platform_mgr->platformsActiveForTestplan($argsObj->tplan_id);
  417. if($gui->usePlatforms)
  418. {
  419. // Create options for two different select boxes. $bulk_platforms
  420. // has "All platforms" on top and "$platformsForHtmlOptions" has an
  421. // empty item
  422. $gui->platformsForHtmlOptions[0]='';
  423. foreach($gui->platforms as $elem)
  424. {
  425. $gui->platformsForHtmlOptions[$elem['id']] =$elem['name'];
  426. }
  427. $gui->bulk_platforms = $platform_mgr->getLinkedToTestplanAsMap($argsObj->tplan_id);
  428. $gui->bulk_platforms[0] = lang_get("all_platforms");
  429. ksort($gui->bulk_platforms);
  430. }
  431. //
  432. $gui->warning_msg = new stdClass();
  433. $gui->warning_msg->executed = lang_get('executed_can_not_be_removed');
  434. if( $gui->can_remove_executed_testcases )
  435. {
  436. $gui->warning_msg->executed = lang_get('has_been_executed');
  437. }
  438. return $gui;
  439. }
  440. /*
  441. function: doSaveCustomFields
  442. writes to DB value of custom fields displayed
  443. for test case versions linked to testplan.
  444. args: argsObj: user input data collected via HTML inputs
  445. tplanMgr: testplan manager object
  446. returns: -
  447. */
  448. function doSaveCustomFields(&$argsObj,&$userInput,&$tplanMgr,&$tcaseMgr)
  449. {
  450. // N.B.: I've use this piece of code also on write_execution(), think is time to create
  451. // a method on cfield_mgr class.
  452. // One issue: find a good method name
  453. $cf_prefix = $tcaseMgr->cfield_mgr->get_name_prefix();
  454. $len_cfp = tlStringLen($cf_prefix);
  455. $cf_nodeid_pos=4;
  456. $nodeid_array_cfnames=null;
  457. // Example: two test cases (21 and 19 are testplan_tcversions.id => FEATURE_ID)
  458. // with 3 custom fields
  459. //
  460. // custom_field_[TYPE]_[CFIELD_ID]_[FEATURE_ID]
  461. //
  462. // (
  463. // [21] => Array
  464. // (
  465. // [0] => custom_field_0_3_21
  466. // [1] => custom_field_0_7_21
  467. // [5] => custom_field_6_9_21
  468. // )
  469. //
  470. // [19] => Array
  471. // (
  472. // [0] => custom_field_0_3_19
  473. // [1] => custom_field_0_7_19
  474. // [5] => custom_field_6_9_19
  475. // )
  476. // )
  477. //
  478. foreach($userInput as $input_name => $value)
  479. {
  480. if( strncmp($input_name,$cf_prefix,$len_cfp) == 0 )
  481. {
  482. $dummy=explode('_',$input_name);
  483. $nodeid_array_cfnames[$dummy[$cf_nodeid_pos]][]=$input_name;
  484. }
  485. }
  486. // foreach($argsObj->linkedWithCF as $key => $link_id)
  487. foreach( $nodeid_array_cfnames as $link_id => $customFieldsNames)
  488. {
  489. // Create a SubSet of userInput just with inputs regarding CF for a link_id
  490. // Example for link_id=21:
  491. //
  492. // $cfvalues=( 'custom_field_0_3_21' => A
  493. // 'custom_field_0_7_21' =>
  494. // 'custom_field_8_8_21_day' => 0
  495. // 'custom_field_8_8_21_month' => 0
  496. // 'custom_field_8_8_21_year' => 0
  497. // 'custom_field_6_9_21_' => Every day)
  498. //
  499. $cfvalues=null;
  500. foreach($customFieldsNames as $cf)
  501. {
  502. $cfvalues[$cf]=$userInput[$cf];
  503. }
  504. $tcaseMgr->cfield_mgr->testplan_design_values_to_db($cfvalues,null,$link_id);
  505. }
  506. }
  507. /*
  508. function: doSavePlatforms
  509. writes to DB execution ... of test case versions linked to testplan.
  510. args: argsObj: user input data collected via HTML inputs
  511. tplanMgr: testplan manager object
  512. returns: -
  513. */
  514. function doSavePlatforms(&$argsObj,&$tplanMgr)
  515. {
  516. foreach($argsObj->feature2fix as $feature_id => $tcversion_platform)
  517. {
  518. $tcversion_id = key($tcversion_platform);
  519. $platform_id = current($tcversion_platform);
  520. if( $platform_id != 0 )
  521. {
  522. $tplanMgr->changeLinkedTCVersionsPlatform($argsObj->tplan_id,0,$platform_id,$tcversion_id);
  523. }
  524. }
  525. }
  526. /**
  527. * send_mail_to_testers
  528. *
  529. *
  530. * @return void
  531. */
  532. function send_mail_to_testers(&$dbHandler,&$tcaseMgr,&$guiObj,&$argsObj,$features,$operation)
  533. {
  534. $testers['new']=null;
  535. $mail_details['new']=lang_get('mail_testcase_assigned') . "<br /><br />";
  536. $mail_subject['new']=lang_get('mail_subject_testcase_assigned');
  537. $use_testers['new']= true ;
  538. $tcaseSet=null;
  539. $tcnames=null;
  540. $email=array();
  541. $userSet[]=$argsObj->userID;
  542. $userSet[]=$argsObj->testerID;
  543. $userData=tlUser::getByIDs($dbHandler,$userSet);
  544. $assigner=$userData[$argsObj->userID]->firstName . ' ' . $userData[$argsObj->userID]->lastName ;
  545. $email['from_address']=config_get('from_email');
  546. $body_first_lines = lang_get('testproject') . ': ' . $argsObj->tproject_name . '<br />' .
  547. lang_get('testplan') . ': ' . $guiObj->testPlanName .'<br /><br />';
  548. // Get testers id
  549. foreach($features as $feature_id => $value)
  550. {
  551. if($use_testers['new'])
  552. {
  553. $testers['new'][$value['user_id']][$value['tcase_id']]=$value['tcase_id'];
  554. }
  555. $tcaseSet[$value['tcase_id']]=$value['tcase_id'];
  556. $tcversionSet[$value['tcversion_id']]=$value['tcversion_id'];
  557. }
  558. $infoSet=$tcaseMgr->get_by_id_bulk($tcaseSet,$tcversionSet);
  559. foreach($infoSet as $value)
  560. {
  561. $tcnames[$value['testcase_id']] = $guiObj->testCasePrefix . $value['tc_external_id'] . ' ' . $value['name'];
  562. }
  563. $path_info = $tcaseMgr->tree_manager->get_full_path_verbose($tcaseSet,array('output_format' => 'simple'));
  564. $flat_path=null;
  565. foreach($path_info as $tcase_id => $pieces)
  566. {
  567. $flat_path[$tcase_id]=implode('/',$pieces) . '/' . $tcnames[$tcase_id];
  568. }
  569. foreach($testers as $tester_type => $tester_set)
  570. {
  571. if( !is_null($tester_set) )
  572. {
  573. $email['subject'] = $mail_subject[$tester_type] . ' ' . $guiObj->testPlanName;
  574. foreach($tester_set as $user_id => $value)
  575. {
  576. $userObj=$userData[$user_id];
  577. $email['to_address']=$userObj->emailAddress;
  578. $email['body'] = $body_first_lines;
  579. $email['body'] .= sprintf($mail_details[$tester_type],
  580. $userObj->firstName . ' ' .$userObj->lastName,$assigner);
  581. foreach($value as $tcase_id)
  582. {
  583. $email['body'] .= $flat_path[$tcase_id] . '<br />';
  584. }
  585. $email['body'] .= '<br />' . date(DATE_RFC1123);
  586. $email_op = email_send($email['from_address'], $email['to_address'],
  587. $email['subject'], $email['body'], '', true, true);
  588. } // foreach($tester_set as $user_id => $value)
  589. }
  590. }
  591. }
  592. /**
  593. * initDrawSaveButtons
  594. *
  595. */
  596. function initDrawSaveButtons(&$guiObj)
  597. {
  598. $keySet = array_keys($guiObj->items);
  599. // 20100225 - eloff - BUGID 3205 - check only when platforms are active
  600. // Logic to initialize drawSavePlatformsButton.
  601. if ($guiObj->usePlatforms)
  602. {
  603. // Looks for a platform with id = 0
  604. foreach($keySet as $key)
  605. {
  606. $breakLoop = false;
  607. $testSuite = &$guiObj->items[$key];
  608. if($testSuite['linked_testcase_qty'] > 0)
  609. {
  610. $tcaseSet = array_keys($testSuite['testcases']);
  611. foreach($tcaseSet as $tcaseKey)
  612. {
  613. if( isset($testSuite['testcases'][$tcaseKey]['feature_id'][0]) )
  614. {
  615. $breakLoop = true;
  616. $guiObj->drawSavePlatformsButton = true;
  617. break;
  618. }
  619. }
  620. }
  621. if( $breakLoop )
  622. {
  623. break;
  624. }
  625. }
  626. }
  627. // Logic to initialize drawSaveCFieldsButton
  628. reset($keySet);
  629. foreach($keySet as $key)
  630. {
  631. $breakLoop = false;
  632. $tcaseSet = &$guiObj->items[$key]['testcases'];
  633. if( !is_null($tcaseSet) )
  634. {
  635. $tcversionSet = array_keys($tcaseSet);
  636. foreach($tcversionSet as $tcversionID)
  637. {
  638. if( isset($tcaseSet[$tcversionID]['custom_fields']) &&
  639. !is_null($tcaseSet[$tcversionID]['custom_fields']))
  640. {
  641. $breakLoop = true;
  642. $guiObj->drawSaveCFieldsButton = true;
  643. break;
  644. }
  645. }
  646. }
  647. if( $breakLoop )
  648. {
  649. break;
  650. }
  651. }
  652. }
  653. /**
  654. *
  655. *
  656. */
  657. function setAdditionalGuiData($guiObj)
  658. {
  659. $actionTitle = 'title_remove_test_from_plan';
  660. $buttonValue = 'btn_remove_selected_tc';
  661. $guiObj->exec_order_input_disabled = 'disabled="disabled"';
  662. if( $guiObj->full_control )
  663. {
  664. $actionTitle = 'title_add_test_to_plan';
  665. $buttonValue = 'btn_add_selected_tc';
  666. if( $guiObj->has_linked_items )
  667. {
  668. $actionTitle = 'title_add_remove_test_to_plan';
  669. $buttonValue = 'btn_add_remove_selected_tc';
  670. }
  671. $guiObj->exec_order_input_disabled = ' ';
  672. }
  673. $guiObj->actionTitle = lang_get($actionTitle);
  674. $guiObj->buttonValue = lang_get($buttonValue);
  675. }
  676. /**
  677. * Initialize the HTML select box for selection of a build to which
  678. * user wants to assign testers which are added to testplan.
  679. *
  680. * @author Andreas Simon
  681. * @param testplan $testplan_mgr reference to testplan manager object
  682. * @param object $argsObj reference to user input object
  683. * @return array $html_menu array structure with all information needed for the menu
  684. */
  685. function init_build_selector(&$testplan_mgr, &$argsObj) {
  686. // init array
  687. $html_menu = array('items' => null, 'selected' => null, 'count' => 0);
  688. $html_menu['items'] = $testplan_mgr->get_builds_for_html_options($argsObj->tplan_id,
  689. testplan::GET_ACTIVE_BUILD,
  690. testplan::GET_OPEN_BUILD);
  691. $html_menu['count'] = count($html_menu['items']);
  692. // if no build has been chosen yet, select the newest build by default
  693. $build_id = $argsObj->build_id;
  694. if (!$build_id && $html_menu['count']) {
  695. $keys = array_keys($html_menu['items']);
  696. $build_id = end($keys);
  697. }
  698. $html_menu['selected'] = $build_id;
  699. return $html_menu;
  700. } // end of method
  701. ?>