Skip to content
Permalink
Browse files

#0008331: XML-RPC API - reportTCResult() with overwrite on test case …

…steps execution result
  • Loading branch information...
fmancardi committed Jul 21, 2018
1 parent 23d4e6d commit d05548c9d7818f6b5bff7c64fb9d849f4193c934
@@ -0,0 +1,161 @@
<?php
/**
* A sample client implementation in php
*
* @author Francisco Mancardi
* @package TestlinkAPI
* @link http://testlink.org/api/
*
*/
require_once 'util.php';
require_once 'sample.inc.php';
show_api_db_sample_msg();
$tcaseStatusCode['passed']='p';
$tcaseStatusCode['blocked']='b';
$tcaseStatusCode['failed']='f';
$tcaseStatusCode['wrong']='w';
$tcaseStatusCode['departed']='d';
// Substitute for tcid and tpid that apply to your project
$unitTestDescription =
"XMLRPC -Test - Call with valid parameters: testPlanID,testCaseID,buildID";
$context = new stdClass();
$context->testplanid=434;
// $context->buildid=1;
$context->buildname='1.0';
// $context->platformname=null;
$context->testcaseexternalid='ZS-1';
// $context->testcaseid=null;
$exec = new stdClass();
$exec->status = $tcaseStatusCode['blocked'];
$exec->notes="Call using all EXTERNAL ID";
//$exec->customfields = null;
//$exec->bugid = null;
//$exec->user = 'QQ';
$exec->overwrite=true;
$exec->steps=array( array('step_number' => 1,
'result' => 'f', 'notes' => 'no') );
$debug=false;
echo '<br><b>' . $unitTestDescription . '</b>';
echo '<br>';
$response = executeTestCase($server_url,$context,$exec,$debug);
echo "<br> Result was: ";
new dBug($response);
echo "<br>";
$exec->steps=array( array('step_number' => 2,
'result' => 'p', 'notes' => 'no for 2') );
$debug=false;
echo '<br><b>' . $unitTestDescription . '</b>';
echo '<br>';
$response = executeTestCase($server_url,$context,$exec,$debug);
echo "<br> Result was: ";
new dBug($response);
echo "<br>";
/*
function:
args:
returns:
*/
function executeTestCase($server_url,$context,$exec,$debug=false)
{
echo '<br> Context is:';
new dBug($context);
echo '<br> Execution data is:';
new dBug($exec);
echo '<br>';
$client = new IXR_Client($server_url);
$client->debug=$debug;
$data = array();
$data["devKey"] = '3c41cb6d3c39f263b6bade693f8f7fa7';
$data["status"] = $exec->status;
if( property_exists($exec, 'steps') && !is_null($exec->steps) )
{
$data["steps"] = $exec->steps;
}
if( property_exists($exec, 'user') && !is_null($exec->user) )
{
$data["user"]=$exec->user;
}
if( property_exists($exec, 'notes') && !is_null($exec->notes) )
{
$data["notes"] = $exec->notes;
}
if( property_exists($exec, 'bugid') && !is_null($exec->bugid) )
{
$data["bugid"] = $exec->bugid;
}
if( property_exists($exec, 'overwrite') && !is_null($exec->overwrite) )
{
$data["overwrite"]=$exec->overwrite;
}
if( property_exists($exec, 'customfields') && !is_null($exec->customfields) )
{
$data["customfields"]=$customfields;
}
$data["testplanid"] = $context->testplanid;
if( property_exists($context, 'testcaseid') && !is_null($context->testcaseid) )
{
$data["testcaseid"] = $context->testcaseid;
}
else if( property_exists($context, 'testcaseexternalid') && !is_null($context->testcaseexternalid) )
{
$data["testcaseexternalid"] = $context->testcaseexternalid;
}
if( property_exists($context, 'buildid') && !is_null($context->buildid) )
{
$data["buildid"] = $context->buildid;
}
else if ( property_exists($context, 'buildname') && !is_null($context->buildname) )
{
$data["buildname"] = $context->buildname;
}
if( property_exists($context, 'platformname') && !is_null($context->platformname) )
{
$data["platformname"]=$context->platformname;
}
echo '<br> Method will be called with following data:';
new dBug($data);
if(!$client->query('tl.reportTCResult', $data)) {
echo "something went wrong - " . $client->getErrorCode() . " - " . $client->getErrorMessage();
}
else {
return $client->getResponse();
}
}
@@ -2471,6 +2471,12 @@ public function createTestCase($args)
*
* @param int $args["testplanid"]
* @param string $args["status"] - status is {@link $validStatusList}
*
* @param array $args["steps"] - each element is an array with following
* structure:
* array('step_number' => 1, 'result' => 'p', 'notes' => 'the notes')
*
*
* @param int $args["buildid"] - optional.
* if not present and $args["buildname"] exists
* then
@@ -2606,14 +2612,20 @@ public function reportTCResult($args)
$resultInfo[0]["message"] = GENERAL_SUCCESS_STR;
if($this->_isParamPresent(self::$overwriteParamName) && $this->args[self::$overwriteParamName])
{
$doOverwrite = $this->_isParamPresent(self::$overwriteParamName) &&
$this->args[self::$overwriteParamName];
if($doOverwrite) {
$resultInfo[0]["overwrite"] = true;
$executionID = $this->_updateResult($tester_id,$exec_ts);
$resultInfo[0]["overwrite"] = true;
if( $executionID != 0 && $this->_isParamPresent(self::$stepsParamName) ) {
$resultInfo[0]["steps"] = 'yes!';
$resultInfo[0]["steps_sql"] = $this->_updateStepsResult($executionID);
}
}
if($executionID == 0)
{
if($executionID == 0) {
$executionID = $this->_insertResultToDB($tester_id,$exec_ts);
}
@@ -2651,14 +2663,13 @@ public function reportTCResult($args)
'renderGhostSteps' => false,
'renderImageInline' => false);
// return array('tcx' => $this->tcVersionID); //gretel
$steps = $this->tcaseMgr->getStepsSimple($this->tcVersionID,0,$r2d2);
$target = DB_TABLE_PREFIX . 'execution_tcsteps';
$resultsCfg = config_get('results');
foreach($nst as $spnum => $spdata)
{
// check if step exists, if not ignore
if( isset($steps[$spnum]) )
{
@@ -8563,6 +8574,128 @@ public function closeBuild($args)
}
/**
* update result of LATEST execution for each
* step.
*
* If step is not present, exec status will not be changed.
*
* @access protected
*/
protected function _updateStepsResult($execID=null) {
$tcversion_id = $this->tcVersionID;
$tcase_id = $this->args[self::$testCaseIDParamName];
$stepExecStatus = $this->args[self::$stepsParamName];
$exec_id = $execID;
if( is_null($exec_id) ) {
$execContext = array('tplan_id' => $this->args[self::$testPlanIDParamName],
'platform_id' => $this->args[self::$platformIDParamName],
'build_id' => $this->args[self::$buildIDParamName]);
$opt = array('output' => 'exec_id');
$identity = array('id' => $tcase_id, 'version_id' => $tcversion_id);
$exec_id = $this->tcaseMgr->getLatestExecSingleContext($identity,
$execContext, $opt);
}
if( !is_null($exec_id) ) {
$exec_id = intval($exec_id);
$execution_type = constant("TESTCASE_EXECUTION_TYPE_AUTO");
$st = &$this->args[self::$stepsParamName];
// needed to get tcstep_id from step number
$r2d2 = array('fields2get' => 'TCSTEPS.step_number,TCSTEPS.id',
'accessKey' => 'step_number',
'renderGhostSteps' => false, 'renderImageInline' => false);
$steps = $this->tcaseMgr->getStepsSimple($this->tcVersionID,0,$r2d2);
$xx = null;
foreach($st as $spdata) {
$dbField = null;
$dbVal = null;
foreach ($spdata as $keyF => $value) {
switch($keyF) {
case 'result':
$status = strtolower(trim($spdata['result']));
$dbField[] = 'status';
$dbVal[] = "'" . $status[0] . "'";
break;
case 'notes':
$dbField[] = $keyF;
$dbVal[] = "'" . $this->dbObj->prepare_string($spdata[$keyF]) ."'";
break;
}
}
$spnum = $spdata['step_number'];
if( !is_null($dbField) && isset($steps[$spnum]) ) {
$target = DB_TABLE_PREFIX . 'execution_tcsteps';
$where = " WHERE execution_id=" . $exec_id . " AND " .
" tcstep_id=" . intval($steps[$spnum]['id']);
// Manage Insert
$sql = "SELECT id FROM $target $where";
$rs = $this->dbObj->get_recordset($sql);
if( is_null($rs) or count($rs) != 1 ) {
$sql = " INSERT INTO $target (";
$dbField[] = 'tcstep_id';
$dbVal[] = intval($steps[$spnum]['id']);
$dbField[] = 'execution_id';
$dbVal[] = $exec_id;
foreach($dbField as $idx => $kf) {
if( $idx > 0 ) {
$sql .= ',';
}
$sql .= $kf;
}
$sql .= ') VALUES( ';
foreach($dbVal as $idx => $kv) {
if( $idx > 0 ) {
$sql .= ',';
}
$sql .= $kv;
}
$sql .= ") ";
} else {
$sql = " UPDATE " . DB_TABLE_PREFIX . 'execution_tcsteps' .
" SET ";
foreach($dbField as $idx => $kf) {
if( $idx > 0 ) {
$sql .= ',';
}
$sql .= $kf . '=' . $dbVal[$idx];
}
$sql .= $where;
}
try {
$xx[] = $sql;
$this->dbObj->exec_query($sql);
} catch (Exception $e) {
return $e;
}
}
}
}
return $xx;
}
/**
*

0 comments on commit d05548c

Please sign in to comment.
You can’t perform that action at this time.