PageRenderTime 39ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/testcases/tcAssign2Tplan.php

https://github.com/viglesiasce/testlink
PHP | 242 lines | 129 code | 21 blank | 92 comment | 13 complexity | 2f2f30de6616fb77386e16f1096d4673 MD5 | raw file
  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. * While in test specification feature, assign TEST CASE version to multiple
  7. * ACTIVE test plans
  8. *
  9. * @package TestLink
  10. * @author Amit Khullar - amkhullar@gmail.com
  11. * @copyright 2007-2009, TestLink community
  12. * @version CVS: $Id: tcAssign2Tplan.php,v 1.8 2010/05/20 18:20:46 franciscom Exp $
  13. * @link http://www.teamst.org/index.php
  14. *
  15. *
  16. * @internal revisions
  17. * 20100520 - franciscom - BUGID 3480 - add to test plan problem when platforms exist
  18. * 20100514 - franciscom - BUGID 3189
  19. * 20100124 - franciscom - BUGID 3064 - add logic to manage ONLY ACTIVE test plans
  20. **/
  21. require_once("../../config.inc.php");
  22. require_once("common.php");
  23. testlinkInitPage($db);
  24. $templateCfg = templateConfiguration();
  25. $tcase_mgr=new testcase($db);
  26. $tplan_mgr=new testplan($db);
  27. $tproject_mgr=new testproject($db);
  28. $glue = config_get('testcase_cfg')->glue_character;
  29. $args = init_args();
  30. $gui = initializeGui($args);
  31. $getOpt = array('outputFormat' => 'map', 'addIfNull' => true);
  32. $gui->platformSet = $tplan_mgr->getPlatforms($args->tplan_id,$getOpt);
  33. $options['output'] = 'essential';
  34. $tcase_all_info = $tcase_mgr->get_by_id($args->tcase_id,testcase::ALL_VERSIONS,null,$options);
  35. if( !is_null($tcase_all_info) )
  36. {
  37. foreach($tcase_all_info as $tcversion_info)
  38. {
  39. if($tcversion_info['id'] == $args->tcversion_id )
  40. {
  41. $version = $tcversion_info['version'];
  42. $gui->pageTitle=lang_get('test_case') . ':' . $tcversion_info['name'];
  43. $gui->tcaseIdentity = $tproject_mgr->getTestCasePrefix($args->tproject_id);
  44. $gui->tcaseIdentity .= $glue . $tcversion_info['tc_external_id'] . ':' . $tcversion_info['name'];
  45. break;
  46. }
  47. }
  48. }
  49. // 20100514 - franciscom
  50. // Why I'm filter on NOT_EXECUTED ??? -> this causes BUGID 3189
  51. // $link_info = $tcase_mgr->get_linked_versions($args->tcase_id,'NOT_EXECUTED');
  52. $link_info = $tcase_mgr->get_linked_versions($args->tcase_id);
  53. // 20100124 - work only on ACTIVE TEST PLANS => array('plan_status' => 1)
  54. if( !is_null($tplanSet = $tproject_mgr->get_all_testplans($args->tproject_id,array('plan_status' => 1))) )
  55. {
  56. $has_links = array_fill_keys(array_keys($tplanSet),false);
  57. $linked_tplans = null;
  58. if( !is_null($link_info) )
  59. {
  60. foreach($link_info as $tcversion_id => $info)
  61. {
  62. foreach($info as $tplan_id => $platform_info)
  63. {
  64. $has_links[$tplan_id] = true;
  65. foreach($platform_info as $platform_id => $value)
  66. {
  67. // $gui->tplans[$tplan_id][$platform_id]['tcversion_id']=$value['id'];
  68. $linked_tplans[$tplan_id][$platform_id]['tcversion_id']=$value['tcversion_id'];
  69. $linked_tplans[$tplan_id][$platform_id]['version']=$value['version'];
  70. $linked_tplans[$tplan_id][$platform_id]['draw_checkbox'] = false;
  71. }
  72. }
  73. }
  74. }
  75. // Initial situation, enable link of target test case version to all test plans
  76. $getOpt = array('outputFormat' => 'map', 'addIfNull' => true);
  77. foreach($tplanSet as $tplan_id => $value)
  78. {
  79. $gui->tplans[$tplan_id] = array();
  80. $platformSet = $tplan_mgr->getPlatforms($tplan_id,$getOpt);
  81. // $target_version_number = 0;
  82. // $target_version_id = 0;
  83. $target_version_number = $version;
  84. $target_version_id = $args->tcversion_id;
  85. $linked_platforms = null;
  86. // if a version of this Test Case has been linked to test plan, get it.
  87. if( $has_links[$tplan_id] )
  88. {
  89. $linked_platforms = array_flip(array_keys($linked_tplans[$tplan_id]));
  90. $dummy = current($linked_tplans[$tplan_id]);
  91. $target_version_number = $dummy['version'];
  92. $target_version_id = $dummy['tcversion_id'];
  93. }
  94. // do logic on test plan linked platforms to understand what to display
  95. // For situation like
  96. // Test Plan TPX - Platforms: P1,P2,P3
  97. // Test Case A - version 1 -> Test Plan TPX - Platform P1
  98. //
  99. // Create Test Case A - version 2
  100. //
  101. // Add to test plan on version 2
  102. // We CAN NOT DISPLAY Platforms P2 and P3, because P1 has been linked to version 1
  103. // and we DO NOT ALLOW different test case versions to be linked to ONE TEST PLAN.
  104. // Then we need to display only
  105. // [x](read only) version 1 - test plan TPX - platform P1
  106. //
  107. // But if we go to version 1 and choose add to test plan, will display:
  108. // [x](read only) version 1 - test plan TPX - platform P1
  109. // [ ] version 1 - test plan TPX - platform P2
  110. // [ ] version 1 - test plan TPX - platform P3
  111. //
  112. // Then we can add version 1 to other platform
  113. // Following logic try to implement this.
  114. //
  115. foreach($platformSet as $platform_id => $platform_info)
  116. {
  117. $doAdd = true;
  118. $draw_checkbox = true;
  119. if( $has_links[$tplan_id] )
  120. {
  121. if( isset($linked_platforms[$platform_id]) )
  122. {
  123. $draw_checkbox = false;
  124. }
  125. else if($target_version_number == $version)
  126. {
  127. $draw_checkbox = true;
  128. }
  129. else
  130. {
  131. $doAdd = false;
  132. }
  133. }
  134. if( $doAdd )
  135. {
  136. $gui->tplans[$tplan_id][$platform_id] = $value;
  137. $gui->tplans[$tplan_id][$platform_id]['tcversion_id'] = $target_version_id;
  138. $gui->tplans[$tplan_id][$platform_id]['version'] = $target_version_number;
  139. $gui->tplans[$tplan_id][$platform_id]['draw_checkbox'] = $draw_checkbox;
  140. $gui->tplans[$tplan_id][$platform_id]['platform'] = $platform_info;
  141. }
  142. // -------------------------------------------------------------------------------
  143. // if( !$has_links[$tplan_id] )
  144. // {
  145. // $gui->tplans[$tplan_id][$platform_id] = $value;
  146. // $gui->tplans[$tplan_id][$platform_id]['tcversion_id'] = $args->tcversion_id;
  147. // $gui->tplans[$tplan_id][$platform_id]['version'] = $version;
  148. // $gui->tplans[$tplan_id][$platform_id]['draw_checkbox'] = true;
  149. // $gui->tplans[$tplan_id][$platform_id]['platform'] = $platform_info;
  150. // }
  151. // else
  152. // {
  153. //
  154. // if( isset($linked_platforms[$platform_id]) )
  155. // {
  156. // $gui->tplans[$tplan_id][$platform_id] = $value;
  157. // $gui->tplans[$tplan_id][$platform_id]['tcversion_id'] = $target_version_id;
  158. // $gui->tplans[$tplan_id][$platform_id]['version'] = $target_version_number;
  159. // $gui->tplans[$tplan_id][$platform_id]['draw_checkbox'] = false;
  160. // $gui->tplans[$tplan_id][$platform_id]['platform'] = $platform_info;
  161. // }
  162. // else if($target_version_number == $version)
  163. // {
  164. // $gui->tplans[$tplan_id][$platform_id] = $value;
  165. // $gui->tplans[$tplan_id][$platform_id]['tcversion_id'] = $target_version_id;
  166. // $gui->tplans[$tplan_id][$platform_id]['version'] = $target_version_number;
  167. // $gui->tplans[$tplan_id][$platform_id]['draw_checkbox'] = true;
  168. // $gui->tplans[$tplan_id][$platform_id]['platform'] = $platform_info;
  169. // }
  170. // }
  171. }
  172. }
  173. // Check if submit button can be displayed.
  174. // Condition there is at least one test plan where no version of
  175. // target test cases has been linked.
  176. $gui->can_do=false; // because an OR logic will be used
  177. foreach($gui->tplans as $tplan_id => $platform_info)
  178. {
  179. foreach($platform_info as $platform_id => $value)
  180. {
  181. $gui->can_do = $gui->can_do || $gui->tplans[$tplan_id][$platform_id]['draw_checkbox'];
  182. }
  183. }
  184. }
  185. $smarty = new TLSmarty();
  186. $smarty->assign('gui',$gui);
  187. $smarty->display($templateCfg->template_dir . $templateCfg->default_template);
  188. /**
  189. * init_args
  190. * creates a sort of namespace
  191. *
  192. * @return object with some REQUEST and SESSION values as members.
  193. */
  194. function init_args()
  195. {
  196. $_REQUEST = strings_stripSlashes($_REQUEST);
  197. $args = new stdClass();
  198. $args->tplan_id = isset($_REQUEST['tplan_id']) ? $_REQUEST['tplan_id'] : $_SESSION['testplanID'];
  199. $args->tproject_id = isset($_REQUEST['tproject_id']) ? $_REQUEST['tproject_id'] : $_SESSION['testprojectID'];
  200. $args->tcase_id = isset($_REQUEST['tcase_id']) ? $_REQUEST['tcase_id'] : 0;
  201. $args->tcversion_id = isset($_REQUEST['tcversion_id']) ? $_REQUEST['tcversion_id'] : 0;
  202. // $args->goback_url = isset($_REQUEST['goback_url']) ? $_REQUEST['goback_url'] : null;
  203. return $args;
  204. }
  205. /**
  206. *
  207. *
  208. */
  209. function initializeGui($argsObj)
  210. {
  211. $guiObj = new stdClass();
  212. $guiObj->pageTitle='';
  213. $guiObj->tcaseIdentity='';
  214. $guiObj->mainDescription=lang_get('add_tcversion_to_plans');;
  215. $guiObj->tcase_id=$argsObj->tcase_id;
  216. $guiObj->tcversion_id=$argsObj->tcversion_id;
  217. $guiObj->can_do=false;
  218. $guiObj->item_sep=config_get('gui')->title_separator_2;
  219. return $guiObj;
  220. }
  221. ?>