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

Documentation generated on Thu, 16 Oct 2008 13:08:52 -0600 by phpDocumentor 1.4.2