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

/lib/requirements/reqTcAssign.php

https://github.com/testlinkjp/testlink-japanese-localization
PHP | 340 lines | 246 code | 47 blank | 47 comment | 29 complexity | 5e700974bd2e790e4069453d3b2646c0 MD5 | raw file
  1. <?php
  2. /**
  3. * TestLink Open Source Project - http://testlink.sourceforge.net/
  4. *
  5. * @filesource reqTcAssign.php
  6. * @author Martin Havlat
  7. *
  8. * @internal revisions
  9. * 20110401 - franciscom - BUGID 3615 - right to allow ONLY MANAGEMENT of requirements link to testcases
  10. * 20100602 - franciscom - BUGID 3495 - Requirements Bulk Assignment crash. (typo error)
  11. * 20100408 - franciscom - BUGID 3361 - FatalError after trying to assign requirements to an empty test suite
  12. *
  13. **/
  14. require_once("../../config.inc.php");
  15. require_once("common.php");
  16. require_once('requirements.inc.php');
  17. testlinkInitPage($db);
  18. $templateCfg = templateConfiguration();
  19. $args = init_args();
  20. checkRights($db,$_SESSION['currentUser'],$args);
  21. $gui = new stdClass();
  22. $gui->showCloseButton = $args->showCloseButton;
  23. $gui->user_feedback = '';
  24. $gui->tcTitle = null;
  25. $gui->arrAssignedReq = null;
  26. $gui->arrUnassignedReq = null;
  27. $gui->arrReqSpec = null;
  28. $gui->selectedReqSpec = $args->idReqSpec;
  29. $bulkCounter = 0;
  30. $bulkDone = false;
  31. $bulkMsg = null;
  32. $pfn = null;
  33. switch($args->doAction)
  34. {
  35. case 'assign':
  36. $pfn = "assign_to_tcase";
  37. break;
  38. case 'unassign':
  39. $pfn = "unassign_from_tcase";
  40. break;
  41. case 'bulkassign':
  42. // BUGID 3361 - need to check if we have test cases to work on
  43. // BUGID 3495 - Requirements Bulk Assignment crash. (typo error) (dbHandler -> db)
  44. $tsuite_mgr = new testsuite($db);
  45. $tcase_set = $tsuite_mgr->get_testcases_deep($args->id,'only_id');
  46. $bulkCounter = 0;
  47. $bulkDone = true;
  48. $args->edit = 'testsuite';
  49. if( !is_null($tcase_set) && count($tcase_set) > 0 )
  50. {
  51. $bulkCounter = doBulkAssignment($db,$args,$tcase_set);
  52. }
  53. break;
  54. case 'switchspec':
  55. $args->edit = 'testsuite';
  56. break;
  57. }
  58. if(!is_null($pfn))
  59. {
  60. $gui = doSingleTestCaseOperation($db,$args,$gui,$pfn);
  61. }
  62. switch($args->edit)
  63. {
  64. case 'testproject':
  65. show_instructions('assignReqs');
  66. exit();
  67. break;
  68. case 'testsuite':
  69. $gui = processTestSuite($db,$args,$gui);
  70. $templateCfg->default_template = 'reqTcBulkAssignment.tpl';
  71. if($bulkDone)
  72. {
  73. $gui->user_feedback = sprintf(lang_get('bulk_assigment_done'),$bulkCounter);
  74. }
  75. break;
  76. case 'testcase':
  77. $gui = processTestCase($db,$args,$gui);
  78. break;
  79. default:
  80. tlog("Wrong GET/POST arguments.", 'ERROR');
  81. exit();
  82. break;
  83. }
  84. $smarty = new TLSmarty();
  85. $smarty->assign('gui', $gui);
  86. $smarty->assign('modify_req_rights', has_rights($db,"mgt_modify_req"));
  87. $smarty->display($templateCfg->template_dir . $templateCfg->default_template);
  88. function init_args()
  89. {
  90. // BUGID 4066 - take care of proper escaping when magic_quotes_gpc is enabled
  91. $_REQUEST=strings_stripSlashes($_REQUEST);
  92. $iParams = array("id" => array(tlInputParameter::INT_N),
  93. "req_id" => array(tlInputParameter::ARRAY_INT),
  94. "req" => array(tlInputParameter::INT_N),
  95. "showCloseButton" => array(tlInputParameter::STRING_N,0,1),
  96. "doAction" => array(tlInputParameter::STRING_N,0,100),
  97. "edit" => array(tlInputParameter::STRING_N,0,100),
  98. "unassign" => array(tlInputParameter::STRING_N,0,1),
  99. "assign" => array(tlInputParameter::STRING_N,0,1),
  100. "idSRS" => array(tlInputParameter::INT_N),
  101. "tproject_id" => array(tlInputParameter::INT_N) );
  102. $args = new stdClass();
  103. R_PARAMS($iParams,$args);
  104. $args->idReqSpec = null;
  105. $args->idReq = $args->req;
  106. $args->reqIdSet = $args->req_id;
  107. if(is_null($args->doAction))
  108. {
  109. $args->doAction = ($args->unassign != "") ? "unassign" : null;
  110. }
  111. if(is_null($args->doAction))
  112. {
  113. $args->doAction = ($args->assign != "") ? "assign" : null;
  114. }
  115. // using session creates issue when using TABBED BROWSING => has to be avoided
  116. // 20081103 - sisajr - hold choosen SRS (saved for a session)
  117. if ($args->idSRS)
  118. {
  119. $args->idReqSpec = $args->idSRS;
  120. // $_SESSION['currentSrsId'] = $args->idReqSpec;
  121. }
  122. // else if(isset($_SESSION['currentSrsId']) && intval($_SESSION['currentSrsId']) > 0)
  123. // {
  124. // $args->idReqSpec = intval($_SESSION['currentSrsId']);
  125. // }
  126. return $args;
  127. }
  128. /**
  129. *
  130. *
  131. */
  132. function processTestSuite(&$dbHandler,&$argsObj,&$guiObj)
  133. {
  134. $tproject_mgr = new testproject($dbHandler);
  135. $guiObj->bulkassign_warning_msg = '';
  136. $guiObj->tsuite_id = $argsObj->id;
  137. $tsuite_info = $tproject_mgr->tree_manager->get_node_hierarchy_info($guiObj->tsuite_id);
  138. $guiObj->pageTitle = lang_get('test_suite') . config_get('gui_title_separator_1') . $tsuite_info['name'];
  139. $guiObj->req_specs = $tproject_mgr->getOptionReqSpec($argsObj->tproject_id,testproject::GET_NOT_EMPTY_REQSPEC);
  140. $guiObj->selectedReqSpec = $argsObj->idReqSpec;
  141. $guiObj->tcase_number = 0;
  142. $guiObj->has_req_spec = false;
  143. $guiObj->tsuite_id = $argsObj->id;
  144. if(!is_null($guiObj->req_specs) && count($guiObj->req_specs))
  145. {
  146. $guiObj->has_req_spec = true;
  147. if(is_null($argsObj->idReqSpec))
  148. {
  149. $guiObj->selectedReqSpec = key($guiObj->req_specs);
  150. }
  151. $req_spec_mgr = new requirement_spec_mgr($dbHandler);
  152. $guiObj->requirements =$req_spec_mgr->get_requirements($guiObj->selectedReqSpec);
  153. $tsuite_mgr = new testsuite($dbHandler);
  154. $tcase_set = $tsuite_mgr->get_testcases_deep($argsObj->id,'only_id');
  155. $guiObj->tcase_number = count($tcase_set);
  156. if( $guiObj->tcase_number > 0 )
  157. {
  158. $guiObj->bulkassign_warning_msg = sprintf(lang_get('bulk_req_assign_msg'),$guiObj->tcase_number);
  159. }
  160. else
  161. {
  162. $guiObj->bulkassign_warning_msg = lang_get('bulk_req_assign_no_test_cases');
  163. }
  164. }
  165. return $guiObj;
  166. }
  167. /**
  168. *
  169. *
  170. */
  171. function doBulkAssignment(&$dbHandler,&$argsObj,$targetTestCaseSet = null)
  172. {
  173. $req_mgr = new requirement_mgr($dbHandler);
  174. $assignmentCounter = 0;
  175. $requirements = array_keys($argsObj->reqIdSet);
  176. if(!is_null($requirements) && count($requirements) > 0)
  177. {
  178. $tcase_set = $targetTestCaseSet;
  179. if( is_null($tcase_set) )
  180. {
  181. $tsuite_mgr = new testsuite($dbHandler);
  182. echo 'DEBUG BEFORE';
  183. $tcase_set = $tsuite_mgr->get_testcases_deep($argsObj->id,'only_id');
  184. }
  185. if( !is_null($tcase_set) && count($tcase_set) )
  186. {
  187. $assignmentCounter = $req_mgr->bulk_assignment($requirements,$tcase_set);
  188. }
  189. }
  190. return $assignmentCounter;
  191. }
  192. function doSingleTestCaseOperation(&$dbHandler,&$argsObj,&$guiObj,$pfn)
  193. {
  194. $msg = '';
  195. $req_ids = array_keys($argsObj->reqIdSet);
  196. if (count($req_ids))
  197. {
  198. $req_mgr = new requirement_mgr($dbHandler);
  199. foreach ($req_ids as $idOneReq)
  200. {
  201. $result = $req_mgr->$pfn($idOneReq,$argsObj->id);
  202. if (!$result)
  203. {
  204. $msg .= $idOneReq . ', ';
  205. }
  206. }
  207. if (!empty($msg))
  208. {
  209. $guiObj->user_feedback = lang_get('req_msg_notupdated_coverage') . $msg;
  210. }
  211. }
  212. else
  213. {
  214. $guiObj->user_feedback = lang_get('req_msg_noselect');
  215. }
  216. return $guiObj;
  217. }
  218. /** @todo should be refactored; used by function processTestCase only */
  219. // Old comment: MHT: I'm not able find a simple SQL (subquery is not supported
  220. // in MySQL 4.0.x); probably temporary table should be used instead of the next
  221. function array_diff_byId ($arrAll, $arrPart)
  222. {
  223. // solve empty arrays
  224. if (!count($arrAll) || is_null($arrAll))
  225. {
  226. return(null);
  227. }
  228. if (!count($arrPart) || is_null($arrPart))
  229. {
  230. return $arrAll;
  231. }
  232. $arrTemp = array();
  233. $arrTemp2 = array();
  234. // converts to associated arrays
  235. foreach ($arrAll as $penny) {
  236. $arrTemp[$penny['id']] = $penny;
  237. }
  238. foreach ($arrPart as $penny) {
  239. $arrTemp2[$penny['id']] = $penny;
  240. }
  241. // exec diff
  242. $arrTemp3 = array_diff_assoc($arrTemp, $arrTemp2);
  243. $arrTemp4 = null;
  244. // convert to numbered array
  245. foreach ($arrTemp3 as $penny) {
  246. $arrTemp4[] = $penny;
  247. }
  248. return $arrTemp4;
  249. }
  250. /**
  251. * processTestCase
  252. *
  253. */
  254. function processTestCase(&$dbHandler,&$argsObj,&$guiObj)
  255. {
  256. $tproject_mgr = new testproject($dbHandler);
  257. // $guiObj->arrReqSpec = $tproject_mgr->getOptionReqSpec($argsObj->tproject_id,testproject::GET_NOT_EMPTY_REQSPEC);
  258. $guiObj->arrReqSpec = $tproject_mgr->genComboReqSpec($argsObj->tproject_id);
  259. $SRS_qty = count($guiObj->arrReqSpec);
  260. if($SRS_qty > 0)
  261. {
  262. $tc_mgr = new testcase($dbHandler);
  263. $arrTc = $tc_mgr->get_by_id($argsObj->id);
  264. if($arrTc)
  265. {
  266. $guiObj->tcTitle = $arrTc[0]['name'];
  267. // get first ReqSpec if not defined
  268. if(is_null($argsObj->idReqSpec))
  269. {
  270. reset($guiObj->arrReqSpec);
  271. $argsObj->idReqSpec = key($guiObj->arrReqSpec);
  272. }
  273. if($argsObj->idReqSpec)
  274. {
  275. $req_spec_mgr = new requirement_spec_mgr($dbHandler);
  276. $guiObj->arrAssignedReq = $req_spec_mgr->get_requirements($argsObj->idReqSpec, 'assigned', $argsObj->id);
  277. $guiObj->arrAllReq = $req_spec_mgr->get_requirements($argsObj->idReqSpec);
  278. $guiObj->arrUnassignedReq = array_diff_byId($guiObj->arrAllReq, $guiObj->arrAssignedReq);
  279. }
  280. }
  281. }
  282. return $guiObj;
  283. }
  284. /**
  285. * checkRights ?>
  286. *
  287. */
  288. function checkRights(&$db,&$userObj,$argsObj)
  289. {
  290. $env['tproject_id'] = isset($argsObj->tproject_id) ? $argsObj->tproject_id : 0;
  291. $env['tplan_id'] = isset($argsObj->tplan_id) ? $argsObj->tplan_id : 0;
  292. checkSecurityClearance($db,$userObj,$env,array('mgt_view_req','req_tcase_link_management','mgt_modify_req'),'and');
  293. }