phpDocumentor TestlinkAPI
[ class tree: TestlinkAPI ] [ index: TestlinkAPI ] [ all elements ]

php client sample

  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.  
  13. require_once 'util.php';
  14. require_once 'sample.inc.php';
  15.  
  16. $tcaseStatusCode['passed']='p';
  17. $tcaseStatusCode['blocked']='b';
  18. $tcaseStatusCode['failed']='f';
  19. $tcaseStatusCode['wrong']='w';
  20. $tcaseStatusCode['departed']='d';
  21.  
  22.  
  23.  
  24. // Substitute for tcid and tpid that apply to your project
  25. $unitTestDescription="Test - Call with valid parameters: testPlanID,testCaseID,buildID";
  26. $testPlanID=222;
  27. // $testCaseID=185;
  28. $testCaseID=58;
  29. $testCaseExternalID=null;
  30. $buildID=15;
  31. // $status=$tcaseStatusCode['departed'];
  32. $status=$tcaseStatusCode['blocked'];
  33. // $status=$tcaseStatusCode['wrong'];
  34. $exec_notes="Call using all INTERNAL ID's ({$testCaseID}) - status={$status}";
  35. $bug_id='999FF';
  36.  
  37. $debug=false;
  38. echo $unitTestDescription;
  39. $response reportResult($server_url,$testCaseID,$testCaseExternalID,$testPlanID,
  40.                          $buildID,null,$status,$exec_notes,$bug_id,$debug);
  41.  
  42. echo "<br> Result was: ";
  43. // Typically you'd want to validate the result here and probably do something more useful with it
  44. // print_r($response);
  45. new dBug($response);
  46. echo "<br>";
  47. // 
  48. // 
  49. // // Now do a wrong build call
  50. // $unitTestDescription="Test - Call with at least one NON EXISTENT parameters: testPlanID,testCaseID,buildID";
  51. // $testPlanID=95;
  52. // $testCaseID=86;
  53. // $testCaseExternalID=null;
  54. // $buildID=50;
  55. // $exec_notes="";
  56. // 
  57. // //$debug=true;
  58. // $debug=false;
  59. // echo $unitTestDescription;
  60. // $response = reportResult($server_url,$testCaseID,$testCaseExternalID,$testPlanID,
  61. //                          $buildID,null,$tcaseStatusCode['passed'],$exec_notes,$bug_id,$debug);
  62. // 
  63. // echo "<br> Result was: ";
  64. // new dBug($response);
  65. // echo "<br>";
  66. // 
  67. // // ----------------------------------------------------------------------------------------
  68. // // Now do a build name call
  69. // $unitTestDescription="Test - Call with valid parameters: testPlanID,testCaseID,buildName";
  70. // $testPlanID=95;
  71. // $testCaseID=83;
  72. // $testCaseExternalID='';
  73. // $buildName="Spock";
  74. // $exec_notes="Call using all Build by name ({$testCaseID})";
  75. // 
  76. // //$debug=true;
  77. // $debug=false;
  78. // echo $unitTestDescription;
  79. // $response = reportResult($server_url,$testCaseID,$testCaseExternalID,$testPlanID,null,
  80. //                          $buildName,$tcaseStatusCode['blocked'],$exec_notes,$bug_id,$debug);
  81. // 
  82. // echo "<br> Result was: ";
  83. // new dBug($response);
  84. // echo "<br>";
  85. // // ----------------------------------------------------------------------------------------
  86. // 
  87. // 
  88. // // Now do a build name call
  89. // $unitTestDescription="Test - Call with valid parameters: testPlanID,testCaseExternalID,buildName";
  90. // $testPlanID=95;
  91. // $testCaseID=null;
  92. // $testCaseExternalID='ESP-3';
  93. // $buildName="Spock";
  94. // // $exec_notes="Call using Test Case External ID and Build by Name";
  95. // $exec_notes=null;
  96. // 
  97. // //$debug=true;
  98. // $debug=false;
  99. // echo $unitTestDescription;
  100. // $response = reportResult($server_url,$testCaseID,$testCaseExternalID,$testPlanID,null,
  101. //                          $buildName,$tcaseStatusCode['failed'],$exec_notes,$bug_id,$debug);
  102. // 
  103. // echo "<br> Result was: ";
  104. // new dBug($response);
  105. // echo "<br>";
  106.  
  107.  
  108.  
  109. /*
  110.   function: 
  111.  
  112.   args:
  113.   
  114.   returns: 
  115.  
  116. */
  117. function reportResult($server_url,$tcaseid=null$tcaseexternalid=null,$tplanid$buildid=null
  118.                       $buildname=null$status,$notes=null,$bugid=null,$debug=false)
  119. {
  120.  
  121.     $client new IXR_Client($server_url);
  122.  
  123.   $client->debug=$debug;
  124.   
  125.     $data array();
  126.     $data["devKey"constant("DEV_KEY");
  127.     $data["testplanid"$tplanid;
  128.  
  129.   if!is_null($bugid) )
  130.   {
  131.       $data["bugid"$bugid;  
  132.   }
  133.  
  134.   if!is_null($tcaseid) )
  135.   {
  136.         $data["testcaseid"$tcaseid;
  137.     }
  138.     else if!is_null($tcaseexternalid) )
  139.     {
  140.         $data["testcaseexternalid"$tcaseexternalid;
  141.     }
  142.     
  143.     if!is_null($buildid) )
  144.     {
  145.         $data["buildid"$buildid;
  146.     }
  147.     else if !is_null($buildname) )
  148.     {
  149.           $data["buildname"$buildname;
  150.     }
  151.     
  152.     if!is_null($notes) )
  153.     {
  154.        $data["notes"$notes;  
  155.     }
  156.     $data["status"$status;
  157.  
  158.   new dBug($data);
  159.  
  160.     if(!$client->query('tl.reportTCResult'$data))
  161.     {
  162.         echo "something went wrong - " $client->getErrorCode(" - " $client->getErrorMessage();            
  163.     }
  164.     else
  165.     {
  166.         return $client->getResponse();
  167.     }
  168. }
  169.  
  170.  
  171. ?>

Documentation generated on Fri, 17 Feb 2012 16:07:50 -0500 by phpDocumentor 1.4.4