PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/functions/testPlanUrgency.class.php

https://bitbucket.org/pfernandez/testlink1.9.6
PHP | 236 lines | 135 code | 22 blank | 79 comment | 6 complexity | 95515847dc6162e90346d765333142bf 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 Martin Havlat
  8. * @copyright 2007-2009, TestLink community
  9. * @version CVS: $Id: testPlanUrgency.class.php,v 1.4 2010/02/11 18:49:58 franciscom Exp $
  10. * @link http://www.teamst.org/index.php
  11. *
  12. * @internal Revisions:
  13. * 20100204 - eloff - fixed typo error $break => break
  14. * 20091017 - franciscom - moved method getPriority() from result.class.php
  15. * 20081212 - BUGID 1922 - franciscom
  16. * 20080901 - franciscom - getSuiteUrgency() - changes in return data
  17. *
  18. */
  19. /** parent class */
  20. require_once('testplan.class.php');
  21. /**
  22. * Class testPlanUrgency extends testPlan functionality by Test Urgency functions
  23. * - modify and list Test Urgency
  24. *
  25. * @package TestLink
  26. * @author Martin Havlat
  27. * @since 1.8 - 17.7.2008
  28. */
  29. class testPlanUrgency extends testPlan
  30. {
  31. /**
  32. * Set Test urgency for test case version in a Test Plan
  33. *
  34. * @param integer $testplan_id Test Plan ID
  35. * @param integer $tc_id Test Case version to set Urgency
  36. * @param integer $urgency
  37. *
  38. * @return integer result code
  39. */
  40. public function setTestUrgency($testplan_id, $tc_id, $urgency)
  41. {
  42. $sql = "UPDATE {$this->tables['testplan_tcversions']} SET urgency={$urgency} " .
  43. "WHERE testplan_id={$testplan_id} AND tcversion_id={$tc_id}";
  44. $result = $this->db->exec_query($sql);
  45. return $result ? tl::OK : tl::ERROR;
  46. }
  47. /**
  48. * Set urgency for TCs (direct child only) within a Test Suite and Test Plan
  49. *
  50. * @param integer $testplan_id Test Plan ID
  51. * @param integer $node_id Test Suite to set Urgency
  52. * @param integer $urgency
  53. *
  54. * @return integer result code
  55. *
  56. * @internal
  57. * 20081212 - franciscom - Postgres do not like SQL syntax with JOIN
  58. * $sql = 'UPDATE testplan_tcversions ' .
  59. * ' JOIN nodes_hierarchy NHA ON testplan_tcversions.tcversion_id = NHA.id '.
  60. * ' JOIN nodes_hierarchy NHB ON NHA.parent_id = NHB.id' .
  61. * ' SET urgency=' . $urgency .
  62. * ' WHERE testplan_tcversions.testplan_id=' . $testplan_id .
  63. * ' AND NHB.parent_id=' . $node_id;
  64. */
  65. public function setSuiteUrgency($testplan_id, $node_id, $urgency)
  66. {
  67. $sql = " UPDATE {$this->tables['testplan_tcversions']} " .
  68. " SET urgency={$urgency} ".
  69. " WHERE testplan_id= {$testplan_id} " .
  70. " AND tcversion_id IN (" .
  71. " SELECT NHB.id " .
  72. " FROM {$this->tables['nodes_hierarchy']} NHA, " .
  73. " {$this->tables['nodes_hierarchy']} NHB, {$this->tables['node_types']} NT " .
  74. " WHERE NHA.node_type_id = NT.id " .
  75. " AND NT.description='testcase' " .
  76. " AND NHB.parent_id = NHA.id " .
  77. " AND NHA.parent_id = {$node_id} )";
  78. $result = $this->db->exec_query($sql);
  79. $retval=$result ? OK : ERROR;
  80. return $retval;
  81. }
  82. /**
  83. * Collect urgency for a Test Suite within a Test Plan
  84. *
  85. * @param integer $testplan_id Test Plan ID
  86. * @param integer $node_id Test Suite
  87. * @param integer $testproject_id
  88. *
  89. * @return array of array testcase_id, name, urgency, tcprefix, tc_external_id
  90. *
  91. * @internal Revisions:
  92. * 20090616 - Eloff - added tcversion id in return data
  93. * 20081210 - franciscom - added testproject_id argument to avoid
  94. * subquery when testproject_id is available
  95. * 20080901 - franciscom - added tcprefix, tc_external_id in return data
  96. */
  97. public function getSuiteUrgency($testplan_id, $node_id, $testproject_id=null)
  98. {
  99. $testcase_cfg = config_get('testcase_cfg');
  100. $sql = " SELECT testprojects.prefix FROM {$this->tables['testprojects']} testprojects " .
  101. " WHERE testprojects.id = ";
  102. if( !is_null($testproject_id) )
  103. {
  104. $sql .= $testproject_id;
  105. }
  106. else
  107. {
  108. $sql .= "( SELECT parent_id AS testproject_id FROM {$this->tables['nodes_hierarchy']} " .
  109. " WHERE id={$testplan_id} ) ";
  110. }
  111. $tcprefix = $this->db->fetchOneValue($sql) . $testcase_cfg->glue_character;
  112. $tcprefix = $this->db->prepare_string($tcprefix);
  113. $sql = " SELECT DISTINCT '{$tcprefix}' AS tcprefix, NHB.name, NHB.node_order," .
  114. " NHA.parent_id AS testcase_id, TCV.tc_external_id, testplan_tcversions.tcversion_id, testplan_tcversions.urgency".
  115. " FROM {$this->tables['nodes_hierarchy']} NHA " .
  116. " JOIN {$this->tables['nodes_hierarchy']} NHB ON NHA.parent_id = NHB.id " .
  117. " JOIN {$this->tables['testplan_tcversions']} testplan_tcversions " .
  118. " ON testplan_tcversions.tcversion_id=NHA.id " .
  119. " JOIN {$this->tables['tcversions']} TCV ON TCV.id = testplan_tcversions.tcversion_id " .
  120. " WHERE testplan_tcversions.testplan_id={$testplan_id}" .
  121. " AND NHB.parent_id={$node_id}" .
  122. " ORDER BY NHB.node_order";
  123. return $this->db->get_recordset($sql);
  124. }
  125. /**
  126. * Returns priority (urgency * importance) as HIGH, MEDUIM or LOW depending on value
  127. *
  128. *
  129. * @param integer $testplan_id Test Plan ID
  130. * @param $filters: optional, map with following keys
  131. * @param $options: optional, map with following keys
  132. *
  133. * @return
  134. */
  135. public function getPriority($testplan_id, $filters=null, $options=null)
  136. {
  137. // Order is important for algorithm
  138. $level2check=array(HIGH,MEDIUM);
  139. $priorityLevelsCfg = config_get('priority_levels');
  140. $debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__;
  141. $rs = null;
  142. $my = array ('filters' => array('platform_id' => null, 'tcversion_id' =>null),
  143. 'options' => array('details' => 'tcversion'));
  144. $my['filters'] = array_merge($my['filters'], (array)$filters);
  145. $my['options'] = array_merge($my['options'], (array)$options);
  146. $sqlFilter = '';
  147. if( !is_null($my['filters']['platform_id']) )
  148. {
  149. $sqlFilter .= " AND TPTCV.platform_id = {$my['filters']['platform_id']} ";
  150. }
  151. if( !is_null($my['filters']['tcversion_id']) )
  152. {
  153. $dummy = implode(',',(array)$my['filters']['tcversion_id']);
  154. $sqlFilter .= " AND TPTCV.tcversion_id IN ({$dummy}) ";
  155. }
  156. $sql = "/* $debugMsg */ ";
  157. $sql .= " SELECT (urgency * importance) AS priority, " .
  158. " urgency,importance, " .
  159. LOW . " AS priority_level, TPTCV.tcversion_id %CLAUSE%" .
  160. " FROM {$this->tables['testplan_tcversions']} TPTCV " .
  161. " JOIN {$this->tables['tcversions']} TCV ON TPTCV.tcversion_id = TCV.id " .
  162. " WHERE TPTCV.testplan_id = {$testplan_id} {$sqlFilter}";
  163. switch($my['options']['details'])
  164. {
  165. case 'tcversion':
  166. $sql = str_ireplace("%CLAUSE%", "", $sql);
  167. $rs = $this->db->fetchRowsIntoMap($sql,'tcversion_id');
  168. break;
  169. case 'platform':
  170. $sql = str_ireplace("%CLAUSE%", ", TPTCV.platform_id", $sql);
  171. $rs = $this->db->fetchMapRowsIntoMap($sql,'tcversion_id','platform_id');
  172. break;
  173. }
  174. if( !is_null($rs) )
  175. {
  176. $key2loop = array_keys($rs);
  177. switch($my['options']['details'])
  178. {
  179. case 'tcversion':
  180. foreach($key2loop as $key)
  181. {
  182. foreach( $level2check as $level)
  183. {
  184. if($rs[$key]['priority'] >= $priorityLevelsCfg[$level])
  185. {
  186. $rs[$key]['priority_level']=$level;
  187. break;
  188. }
  189. }
  190. }
  191. break;
  192. case 'platform':
  193. foreach($key2loop as $key)
  194. {
  195. $platformSet = array_keys($rs[$key]);
  196. foreach($platformSet as $platform_id)
  197. {
  198. foreach( $level2check as $level)
  199. {
  200. if ( $rs[$key][$platform_id]['priority'] >= $priorityLevelsCfg[$level])
  201. {
  202. $rs[$key][$platform_id]['priority_level'] = $level;
  203. break;
  204. }
  205. }
  206. }
  207. }
  208. break;
  209. } // switch
  210. } // !is_null
  211. return $rs;
  212. } // end public function getPriority
  213. } // end of class
  214. ?>