testlink1.9.6 /lib/requirements/reqTcAssign.php

Language PHP Lines 329
MD5 Hash 9823878fef19f24fab139502dfe1b638 Estimated Cost $6,196 (why?)
Repository https://bitbucket.org/pfernandez/testlink1.9.6 View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
<?php
/** 
 * TestLink Open Source Project - http://testlink.sourceforge.net/
 *  
 * @filesource $RCSfile: reqTcAssign.php,v $
 * @version $Revision: 1.21 $
 * @modified $Date: 2010/06/24 17:25:55 $  $Author: asimon83 $
 * 
 * @author Martin Havlat
 *
 * 20100602 - franciscom - BUGID 3495 - Requirements Bulk Assignment crash. (typo error)
 * 20100408 - franciscom - BUGID 3361 - FatalError after trying to assign requirements to an empty test suite
 * 20081130 - franciscom - BUGID 1852 - Bulk Assignment Feature
 *
**/
require_once("../../config.inc.php");
require_once("common.php");
require_once('requirements.inc.php');
testlinkInitPage($db,false,false,"checkRights");

$templateCfg = templateConfiguration();
$args = init_args();

$gui = new stdClass();
$gui->showCloseButton = $args->showCloseButton;
$gui->user_feedback = '';
$gui->tcTitle = null;
$gui->arrAssignedReq = null;
$gui->arrUnassignedReq = null;
$gui->arrReqSpec = null;
$gui->selectedReqSpec = $args->idReqSpec;

$bulkCounter = 0;
$bulkDone = false;
$bulkMsg = null;
$pfn = null;
switch($args->doAction)
{
    case 'assign':
	    $pfn = "assign_to_tcase";
	    break;  

    case 'unassign':
	    $pfn = "unassign_from_tcase";
	    break;  

    case 'bulkassign':
    	// BUGID 3361 - need to check if we have test cases to work on
       	// BUGID 3495 - Requirements Bulk Assignment crash. (typo error) (dbHandler -> db)
       	$tsuite_mgr = new testsuite($db);
        $tcase_set = $tsuite_mgr->get_testcases_deep($args->id,'only_id');
		$bulkCounter = 0;
      	$bulkDone = true;
      	$args->edit = 'testsuite';
		if( !is_null($tcase_set) && count($tcase_set) > 0 )
		{
      		$bulkCounter = doBulkAssignment($db,$args,$tcase_set);
      	}
	    break;  

    case 'switchspec':
      	$args->edit = 'testsuite';
	    break;  
}

if(!is_null($pfn))
{
    $gui = doSingleTestCaseOperation($db,$args,$gui,$pfn);
}

switch($args->edit)
{
    case 'testproject':
	    show_instructions('assignReqs');
	    exit();
    break;
    
    case 'testsuite':
         $gui = processTestSuite($db,$args,$gui);
         $templateCfg->default_template = 'reqTcBulkAssignment.tpl';
         if($bulkDone)
         {
             $gui->user_feedback = sprintf(lang_get('bulk_assigment_done'),$bulkCounter); 
         }    
    break;
      
   	case 'testcase':
        $gui = processTestCase($db,$args,$gui);
   	break;
  
	default:
		tlog("Wrong GET/POST arguments.", 'ERROR');
		exit();
	break;
}

$smarty = new TLSmarty();
$smarty->assign('gui', $gui);
$smarty->assign('modify_req_rights', has_rights($db,"mgt_modify_req")); 
$smarty->display($templateCfg->template_dir . $templateCfg->default_template);


function init_args()
{
	$iParams = array("id" => array(tlInputParameter::INT_N),
			         "req_id" => array(tlInputParameter::ARRAY_INT),
			         "req" => array(tlInputParameter::INT_N),
			         "showCloseButton" => array(tlInputParameter::STRING_N,0,1),
			         "doAction" => array(tlInputParameter::STRING_N,0,100),
			         "edit" => array(tlInputParameter::STRING_N,0,100),
			         "unassign" => array(tlInputParameter::STRING_N,0,1),
			         "assign" => array(tlInputParameter::STRING_N,0,1),
			         "idSRS" => array(tlInputParameter::INT_N));	
		
	$args = new stdClass();
	R_PARAMS($iParams,$args);

	$args->idReqSpec = null;
    $args->idReq = $args->req;
    $args->reqIdSet = $args->req_id;
    if(is_null($args->doAction))
    {
    	$args->doAction = ($args->unassign != "") ? "unassign" : null;
    }
    if(is_null($args->doAction))
    {
        $args->doAction = ($args->assign != "") ? "assign" : null;
    }

	// 20081103 - sisajr - hold choosen SRS (saved for a session)
	if ($args->idSRS)
	{
	  	$args->idReqSpec = $args->idSRS;
	  	$_SESSION['currentSrsId'] = $args->idReqSpec;
	}
	else if(isset($_SESSION['currentSrsId']) && intval($_SESSION['currentSrsId']) > 0)
	{
		$args->idReqSpec = intval($_SESSION['currentSrsId']);
	}

    $args->tproject_id = isset($_SESSION['testprojectID']) ? $_SESSION['testprojectID'] : 0;
	
    return $args;
}

/**
 * 
 *
 */
function processTestSuite(&$dbHandler,&$argsObj,&$guiObj)
{
    $tproject_mgr = new testproject($dbHandler);

    $guiObj->bulkassign_warning_msg = '';
    $guiObj->tsuite_id = $argsObj->id;
    
    $tsuite_info = $tproject_mgr->tree_manager->get_node_hierarchy_info($guiObj->tsuite_id);
    $guiObj->pageTitle = lang_get('test_suite') . config_get('gui_title_separator_1') . $tsuite_info['name'];
     
	$guiObj->req_specs = $tproject_mgr->getOptionReqSpec($argsObj->tproject_id,testproject::GET_NOT_EMPTY_REQSPEC);
    $guiObj->selectedReqSpec = $argsObj->idReqSpec;
    $guiObj->tcase_number = 0;
    $guiObj->has_req_spec = false;
    $guiObj->tsuite_id = $argsObj->id;
    if(!is_null($guiObj->req_specs) && count($guiObj->req_specs))
    {  
		$guiObj->has_req_spec = true;
       
       	if(is_null($argsObj->idReqSpec))
       	{
			$guiObj->selectedReqSpec = key($guiObj->req_specs);
       	}
       
       	$req_spec_mgr = new requirement_spec_mgr($dbHandler);
       	$guiObj->requirements =$req_spec_mgr->get_requirements($guiObj->selectedReqSpec);
       	
       	$tsuite_mgr = new testsuite($dbHandler);
       	$tcase_set = $tsuite_mgr->get_testcases_deep($argsObj->id,'only_id');
       	$guiObj->tcase_number = count($tcase_set);    
       	if( $guiObj->tcase_number > 0 )
       	{
			$guiObj->bulkassign_warning_msg = sprintf(lang_get('bulk_req_assign_msg'),$guiObj->tcase_number);
		}
		else
		{
			$guiObj->bulkassign_warning_msg = lang_get('bulk_req_assign_no_test_cases');
		}	
    }
    return $guiObj;
}

/**
 * 
 *
 */
function doBulkAssignment(&$dbHandler,&$argsObj,$targetTestCaseSet = null)
{
	$req_mgr = new requirement_mgr($dbHandler);
    $assignmentCounter = 0;
	$requirements = array_keys($argsObj->reqIdSet);
    if(!is_null($requirements) && count($requirements) > 0)
    {
		$tcase_set = $targetTestCaseSet;
    	if( is_null($tcase_set) )
    	{
        	$tsuite_mgr = new testsuite($dbHandler);
        	echo 'DEBUG BEFORE';
        	$tcase_set = $tsuite_mgr->get_testcases_deep($argsObj->id,'only_id');
   		}
   		if( !is_null($tcase_set) && count($tcase_set) )
   		{
        	$assignmentCounter = $req_mgr->bulk_assignment($requirements,$tcase_set);
        }

    } 
    return $assignmentCounter;
}

function doSingleTestCaseOperation(&$dbHandler,&$argsObj,&$guiObj,$pfn)
{
	$msg = '';
	$req_ids = array_keys($argsObj->reqIdSet);
	if (count($req_ids))
	{
    	$req_mgr = new requirement_mgr($dbHandler);
		foreach ($req_ids as $idOneReq)
		{
			$result = $req_mgr->$pfn($idOneReq,$argsObj->id);

			if (!$result)
			{
				$msg .= $idOneReq . ', ';
			}	
		}
		if (!empty($msg))
		{
			$guiObj->user_feedback = lang_get('req_msg_notupdated_coverage') . $msg;
		}	
	}
	else
	{
		$guiObj->user_feedback = lang_get('req_msg_noselect');
  	}
	return $guiObj;
} 


/** @todo should be refactored; used by function processTestCase only */
// Old comment: MHT: I'm not able find a simple SQL (subquery is not supported
// in MySQL 4.0.x); probably temporary table should be used instead of the next
function array_diff_byId ($arrAll, $arrPart)
{
	// solve empty arrays
	if (!count($arrAll) || is_null($arrAll))
	{
		return(null);
	}
	if (!count($arrPart) || is_null($arrPart))
	{
		return $arrAll;
	}

	$arrTemp = array();
	$arrTemp2 = array();

	// converts to associated arrays
	foreach ($arrAll as $penny) {
		$arrTemp[$penny['id']] = $penny;
	}
	foreach ($arrPart as $penny) {
		$arrTemp2[$penny['id']] = $penny;
	}

	// exec diff
	$arrTemp3 = array_diff_assoc($arrTemp, $arrTemp2);

	$arrTemp4 = null;
	// convert to numbered array
	foreach ($arrTemp3 as $penny) {
		$arrTemp4[] = $penny;
	}
	return $arrTemp4;
}


/**
 * processTestCase
 *
 */
function processTestCase(&$dbHandler,&$argsObj,&$guiObj)
{
   	$tproject_mgr = new testproject($dbHandler);
	// $guiObj->arrReqSpec = $tproject_mgr->getOptionReqSpec($argsObj->tproject_id,testproject::GET_NOT_EMPTY_REQSPEC);
    
    $guiObj->arrReqSpec = $tproject_mgr->genComboReqSpec($argsObj->tproject_id);
	$SRS_qty = count($guiObj->arrReqSpec);
  
	if($SRS_qty > 0)
	{
		$tc_mgr = new testcase($dbHandler);
	   	$arrTc = $tc_mgr->get_by_id($argsObj->id);
	   	if($arrTc)
	   	{
	   		$guiObj->tcTitle = $arrTc[0]['name'];
	   	
	   		// get first ReqSpec if not defined
	   		if(is_null($argsObj->idReqSpec))
	   		{
	   			reset($guiObj->arrReqSpec);
	   			$argsObj->idReqSpec = key($guiObj->arrReqSpec);
	   		}

	   		if($argsObj->idReqSpec)
	   		{
	   		  	$req_spec_mgr = new requirement_spec_mgr($dbHandler);
	   			$guiObj->arrAssignedReq = $req_spec_mgr->get_requirements($argsObj->idReqSpec, 'assigned', $argsObj->id);
	   			$guiObj->arrAllReq = $req_spec_mgr->get_requirements($argsObj->idReqSpec);
	   			$guiObj->arrUnassignedReq = array_diff_byId($guiObj->arrAllReq, $guiObj->arrAssignedReq);
	   		}
	   	}
	 } 
	 return $guiObj;
}

function checkRights(&$db,&$user)
{
	return ($user->hasRight($db,'mgt_view_req') && $user->hasRight($db,'mgt_modify_req'));
}
?>
Back to Top