PageRenderTime 38ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/api/sample_clients/php/clientSample.php

https://bitbucket.org/pfernandez/testlink1.9.6
PHP | 171 lines | 70 code | 19 blank | 82 comment | 9 complexity | ccf6e549c53b4bf03139bb379a277af4 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, GPL-3.0
  1. <?php
  2. /**
  3. * A sample client implementation in php
  4. *
  5. * @author Asiel Brumfield <asielb@users.sourceforge.net>
  6. * @package TestlinkAPI
  7. * @link http://testlink.org/api/
  8. *
  9. * rev: 20080306 - franciscom - added dBug to improve diagnostic info.
  10. * 20080305 - franciscom - refactored
  11. */
  12. require_once 'util.php';
  13. require_once 'sample.inc.php';
  14. $tcaseStatusCode['passed']='p';
  15. $tcaseStatusCode['blocked']='b';
  16. $tcaseStatusCode['failed']='f';
  17. $tcaseStatusCode['wrong']='w';
  18. $tcaseStatusCode['departed']='d';
  19. // Substitute for tcid and tpid that apply to your project
  20. $unitTestDescription="Test - Call with valid parameters: testPlanID,testCaseID,buildID";
  21. $testPlanID=222;
  22. // $testCaseID=185;
  23. $testCaseID=58;
  24. $testCaseExternalID=null;
  25. $buildID=15;
  26. // $status=$tcaseStatusCode['departed'];
  27. $status=$tcaseStatusCode['blocked'];
  28. // $status=$tcaseStatusCode['wrong'];
  29. $exec_notes="Call using all INTERNAL ID's ({$testCaseID}) - status={$status}";
  30. $bug_id='999FF';
  31. $debug=false;
  32. echo $unitTestDescription;
  33. $response = reportResult($server_url,$testCaseID,$testCaseExternalID,$testPlanID,
  34. $buildID,null,$status,$exec_notes,$bug_id,$debug);
  35. echo "<br> Result was: ";
  36. // Typically you'd want to validate the result here and probably do something more useful with it
  37. // print_r($response);
  38. new dBug($response);
  39. echo "<br>";
  40. //
  41. //
  42. // // Now do a wrong build call
  43. // $unitTestDescription="Test - Call with at least one NON EXISTENT parameters: testPlanID,testCaseID,buildID";
  44. // $testPlanID=95;
  45. // $testCaseID=86;
  46. // $testCaseExternalID=null;
  47. // $buildID=50;
  48. // $exec_notes="";
  49. //
  50. // //$debug=true;
  51. // $debug=false;
  52. // echo $unitTestDescription;
  53. // $response = reportResult($server_url,$testCaseID,$testCaseExternalID,$testPlanID,
  54. // $buildID,null,$tcaseStatusCode['passed'],$exec_notes,$bug_id,$debug);
  55. //
  56. // echo "<br> Result was: ";
  57. // new dBug($response);
  58. // echo "<br>";
  59. //
  60. // // ----------------------------------------------------------------------------------------
  61. // // Now do a build name call
  62. // $unitTestDescription="Test - Call with valid parameters: testPlanID,testCaseID,buildName";
  63. // $testPlanID=95;
  64. // $testCaseID=83;
  65. // $testCaseExternalID='';
  66. // $buildName="Spock";
  67. // $exec_notes="Call using all Build by name ({$testCaseID})";
  68. //
  69. // //$debug=true;
  70. // $debug=false;
  71. // echo $unitTestDescription;
  72. // $response = reportResult($server_url,$testCaseID,$testCaseExternalID,$testPlanID,null,
  73. // $buildName,$tcaseStatusCode['blocked'],$exec_notes,$bug_id,$debug);
  74. //
  75. // echo "<br> Result was: ";
  76. // new dBug($response);
  77. // echo "<br>";
  78. // // ----------------------------------------------------------------------------------------
  79. //
  80. //
  81. // // Now do a build name call
  82. // $unitTestDescription="Test - Call with valid parameters: testPlanID,testCaseExternalID,buildName";
  83. // $testPlanID=95;
  84. // $testCaseID=null;
  85. // $testCaseExternalID='ESP-3';
  86. // $buildName="Spock";
  87. // // $exec_notes="Call using Test Case External ID and Build by Name";
  88. // $exec_notes=null;
  89. //
  90. // //$debug=true;
  91. // $debug=false;
  92. // echo $unitTestDescription;
  93. // $response = reportResult($server_url,$testCaseID,$testCaseExternalID,$testPlanID,null,
  94. // $buildName,$tcaseStatusCode['failed'],$exec_notes,$bug_id,$debug);
  95. //
  96. // echo "<br> Result was: ";
  97. // new dBug($response);
  98. // echo "<br>";
  99. /*
  100. function:
  101. args:
  102. returns:
  103. */
  104. function reportResult($server_url,$tcaseid=null, $tcaseexternalid=null,$tplanid, $buildid=null,
  105. $buildname=null, $status,$notes=null,$bugid=null,$debug=false)
  106. {
  107. $client = new IXR_Client($server_url);
  108. $client->debug=$debug;
  109. $data = array();
  110. $data["devKey"] = constant("DEV_KEY");
  111. $data["testplanid"] = $tplanid;
  112. if( !is_null($bugid) )
  113. {
  114. $data["bugid"] = $bugid;
  115. }
  116. if( !is_null($tcaseid) )
  117. {
  118. $data["testcaseid"] = $tcaseid;
  119. }
  120. else if( !is_null($tcaseexternalid) )
  121. {
  122. $data["testcaseexternalid"] = $tcaseexternalid;
  123. }
  124. if( !is_null($buildid) )
  125. {
  126. $data["buildid"] = $buildid;
  127. }
  128. else if ( !is_null($buildname) )
  129. {
  130. $data["buildname"] = $buildname;
  131. }
  132. if( !is_null($notes) )
  133. {
  134. $data["notes"] = $notes;
  135. }
  136. $data["status"] = $status;
  137. new dBug($data);
  138. if(!$client->query('tl.reportTCResult', $data))
  139. {
  140. echo "something went wrong - " . $client->getErrorCode() . " - " . $client->getErrorMessage();
  141. }
  142. else
  143. {
  144. return $client->getResponse();
  145. }
  146. }
  147. ?>