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. ifisset($_SERVER['HTTP_REFERER']) )
  22. {
  23.     $target $_SERVER['HTTP_REFERER'];
  24.     $prefix '';
  25. }
  26. else
  27. {
  28.     $target $_SERVER['REQUEST_URI'];
  29.     $prefix "http://" $_SERVER['HTTP_HOST'":" $_SERVER['SERVER_PORT'];
  30. $dummy=explode('sample_clients',$target);
  31. $server_url=$prefix $dummy[0"xmlrpc.php";
  32.  
  33. // substitute your Dev Key Here
  34. define("DEV_KEY""CLIENTSAMPLEDEVKEY");
  35. ifDEV_KEY == "CLIENTSAMPLEDEVKEY" )
  36. {
  37.     echo '<h1>Attention: DEVKEY is still setted to demo value</h1>';
  38.     echo 'Please check if this VALUE is defined for a user on yout DB Installation<b>';
  39.     echo '<hr>';
  40. }
  41.  
  42.  
  43. $tcaseStatusCode['passed']='p';
  44. $tcaseStatusCode['blocked']='b';
  45. $tcaseStatusCode['failed']='f';
  46. $tcaseStatusCode['wrong']='w';
  47. $tcaseStatusCode['departed']='d';
  48.  
  49.  
  50.  
  51. // Substitute for tcid and tpid that apply to your project
  52. $unitTestDescription="Test - Call with valid parameters: testPlanID,testCaseID,buildID";
  53. $testPlanID=222;
  54. // $testCaseID=185;
  55. $testCaseID=58;
  56. $testCaseExternalID=null;
  57. $buildID=15;
  58. // $status=$tcaseStatusCode['departed'];
  59. $status=$tcaseStatusCode['blocked'];
  60. // $status=$tcaseStatusCode['wrong'];
  61. $exec_notes="Call using all INTERNAL ID's ({$testCaseID}) - status={$status}";
  62. $bug_id='999FF';
  63.  
  64. $debug=false;
  65. echo $unitTestDescription;
  66. $response reportResult($server_url,$testCaseID,$testCaseExternalID,$testPlanID,
  67.                          $buildID,null,$status,$exec_notes,$bug_id,$debug);
  68.  
  69. echo "<br> Result was: ";
  70. // Typically you'd want to validate the result here and probably do something more useful with it
  71. // print_r($response);
  72. new dBug($response);
  73. echo "<br>";
  74. // 
  75. // 
  76. // // Now do a wrong build call
  77. // $unitTestDescription="Test - Call with at least one NON EXISTENT parameters: testPlanID,testCaseID,buildID";
  78. // $testPlanID=95;
  79. // $testCaseID=86;
  80. // $testCaseExternalID=null;
  81. // $buildID=50;
  82. // $exec_notes="";
  83. // 
  84. // //$debug=true;
  85. // $debug=false;
  86. // echo $unitTestDescription;
  87. // $response = reportResult($server_url,$testCaseID,$testCaseExternalID,$testPlanID,
  88. //                          $buildID,null,$tcaseStatusCode['passed'],$exec_notes,$bug_id,$debug);
  89. // 
  90. // echo "<br> Result was: ";
  91. // new dBug($response);
  92. // echo "<br>";
  93. // 
  94. // // ----------------------------------------------------------------------------------------
  95. // // Now do a build name call
  96. // $unitTestDescription="Test - Call with valid parameters: testPlanID,testCaseID,buildName";
  97. // $testPlanID=95;
  98. // $testCaseID=83;
  99. // $testCaseExternalID='';
  100. // $buildName="Spock";
  101. // $exec_notes="Call using all Build by name ({$testCaseID})";
  102. // 
  103. // //$debug=true;
  104. // $debug=false;
  105. // echo $unitTestDescription;
  106. // $response = reportResult($server_url,$testCaseID,$testCaseExternalID,$testPlanID,null,
  107. //                          $buildName,$tcaseStatusCode['blocked'],$exec_notes,$bug_id,$debug);
  108. // 
  109. // echo "<br> Result was: ";
  110. // new dBug($response);
  111. // echo "<br>";
  112. // // ----------------------------------------------------------------------------------------
  113. // 
  114. // 
  115. // // Now do a build name call
  116. // $unitTestDescription="Test - Call with valid parameters: testPlanID,testCaseExternalID,buildName";
  117. // $testPlanID=95;
  118. // $testCaseID=null;
  119. // $testCaseExternalID='ESP-3';
  120. // $buildName="Spock";
  121. // // $exec_notes="Call using Test Case External ID and Build by Name";
  122. // $exec_notes=null;
  123. // 
  124. // //$debug=true;
  125. // $debug=false;
  126. // echo $unitTestDescription;
  127. // $response = reportResult($server_url,$testCaseID,$testCaseExternalID,$testPlanID,null,
  128. //                          $buildName,$tcaseStatusCode['failed'],$exec_notes,$bug_id,$debug);
  129. // 
  130. // echo "<br> Result was: ";
  131. // new dBug($response);
  132. // echo "<br>";
  133.  
  134.  
  135.  
  136. /*
  137.   function: 
  138.  
  139.   args:
  140.   
  141.   returns: 
  142.  
  143. */
  144. function reportResult($server_url,$tcaseid=null$tcaseexternalid=null,$tplanid$buildid=null
  145.                       $buildname=null$status,$notes=null,$bugid=null,$debug=false)
  146. {
  147.  
  148.     $client new IXR_Client($server_url);
  149.  
  150.   $client->debug=$debug;
  151.   
  152.     $data array();
  153.     $data["devKey"constant("DEV_KEY");
  154.     $data["testplanid"$tplanid;
  155.  
  156.   if!is_null($bugid) )
  157.   {
  158.       $data["bugid"$bugid;  
  159.   }
  160.  
  161.   if!is_null($tcaseid) )
  162.   {
  163.         $data["testcaseid"$tcaseid;
  164.     }
  165.     else if!is_null($tcaseexternalid) )
  166.     {
  167.         $data["testcaseexternalid"$tcaseexternalid;
  168.     }
  169.     
  170.     if!is_null($buildid) )
  171.     {
  172.         $data["buildid"$buildid;
  173.     }
  174.     else if !is_null($buildname) )
  175.     {
  176.           $data["buildname"$buildname;
  177.     }
  178.     
  179.     if!is_null($notes) )
  180.     {
  181.        $data["notes"$notes;  
  182.     }
  183.     $data["status"$status;
  184.  
  185.   new dBug($data);
  186.  
  187.     if(!$client->query('tl.reportTCResult'$data))
  188.     {
  189.         echo "something went wrong - " $client->getErrorCode(" - " $client->getErrorMessage();            
  190.     }
  191.     else
  192.     {
  193.         return $client->getResponse();
  194.     }
  195. }
  196.  
  197.  
  198. ?>

Documentation generated on Fri, 03 Apr 2009 14:13:36 +0200 by phpDocumentor 1.4.1