home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / SOAP / Interop / interop_client.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  31.8 KB  |  806 lines

  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license,      |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Shane Caraveo <Shane@Caraveo.com>                           |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: interop_client.php,v 1.16 2007/01/26 17:21:26 yunosh Exp $
  20. //
  21. require_once 'DB.php'; // PEAR/DB
  22. require_once 'SOAP/Client.php';
  23.  
  24. require_once 'config.php';
  25. require_once 'interop_test_functions.php';
  26. require_once 'interop_test.php';
  27. require_once 'params_Round2Base.php';
  28. require_once 'params_Round2GroupB.php';
  29. require_once 'params_Round2GroupC.php';
  30. require_once 'params_Round3GroupD.php';
  31. require_once 'registrationAndNotification.php';
  32.  
  33. error_reporting(E_ALL ^ E_NOTICE);
  34. $INTEROP_LOCAL_SERVER = false;
  35.  
  36. class Interop_Client
  37. {
  38.     // database DNS
  39.     var $DSN;
  40.  
  41.     // our central interop server, where we can get the list of endpoints
  42.     var $registrationDB;
  43.     
  44.     // our local endpoint, will always get added to the database for all tests
  45.     var $localEndpoint;
  46.     
  47.     // specify testing
  48.     var $currentTest = '';      // see $tests above
  49.     var $paramType = 'php';     // 'php' or 'soapval'
  50.     var $useWSDL = false;       // true: do wsdl tests
  51.     var $numServers = 0;        // 0: all
  52.     var $specificEndpoint = ''; // test only this endpoint
  53.     var $testMethod = '';       // test only this method
  54.     var $skipEndpointList = array(); // endpoints to skip
  55.     var $nosave = false;
  56.     var $client_type = 'pear'; //  name of client
  57.     
  58.     // debug output
  59.     var $show = 1;
  60.     var $debug = 0;
  61.     var $showFaults = 0; // used in result table output
  62.     
  63.     // PRIVATE VARIABLES
  64.     var $dbc = null;
  65.     var $totals = array();
  66.     var $tests = array('Round 2 Base',
  67.                        'Round 2 Group B', 
  68.                        'Round 2 Group C', 
  69.                        'Round 3 Group D Compound 1',
  70.                        'Round 3 Group D Compound 2',
  71.                        'Round 3 Group D DocLit',
  72.                        'Round 3 Group D DocLitParams',
  73.                        'Round 3 Group D Import 1',
  74.                        'Round 3 Group D Import 2',
  75.                        'Round 3 Group D Import 3',
  76.                        'Round 3 Group D RpcEnc'
  77.             );
  78.     var $paramTypes = array('php', 'soapval');
  79.     var $endpoints = array();
  80.     
  81.     function Interop_Client() {
  82.         global $interopConfig;
  83.         $this->DSN = $interopConfig['DSN'];
  84.         $this->registrationDB =& new SOAP_Interop_registrationDB();
  85.         
  86.         // XXX for now, share the database for results also
  87.         $this->dbc =& $this->registrationDB->dbc;
  88.     }
  89.     
  90.     /**
  91.     *  fetchEndpoints
  92.     * retreive endpoints interop server
  93.     *
  94.     * @return boolean result
  95.     * @access private
  96.     */    
  97.     function fetchEndpoints($name = 'Round 2 Base') {
  98.         $service =& $this->registrationDB->findService($name);
  99.         $this->endpoints =& $this->registrationDB->getServerList($service->id,true);
  100.         return true;
  101.     }
  102.     
  103.     /**
  104.     *  getEndpoints
  105.     * retreive endpoints from either database or interop server
  106.     *
  107.     * @param string name (see local var $tests)
  108.     * @param boolean all (if false, only get valid endpoints, status=1)
  109.     * @return boolean result
  110.     * @access private
  111.     */    
  112.     function getEndpoints($name = 'Round 2 Base', $all = 0) {
  113.         $service =& $this->registrationDB->findService($name);
  114.         $this->endpoints =& $this->registrationDB->getServerList($service->id);
  115.         return true;
  116.     }
  117.  
  118.     /**
  119.      * Retreives results from the database and stuffs them into the endpoint
  120.      * array.
  121.      *
  122.      * @access private
  123.      */
  124.     function getResults($test = 'Round 2 Base', $type = 'php', $wsdl = 0)
  125.     {
  126.         // Be sure we have the right endpoints for this test result.
  127.         $this->getEndpoints($test);
  128.         $c = count($this->endpoints);
  129.  
  130.         // Retreive the results and put them into the endpoint info.
  131.         $sql = "SELECT * FROM results WHERE class='$test' AND type='$type' AND wsdl=$wsdl";
  132.         $results = $this->dbc->getAll($sql, null, DB_FETCHMODE_ASSOC);
  133.         for ($j = 0, $rc = count($results); $j < $rc; ++$j) {
  134.             $result = $results[$j];
  135.             // Find the endpoint.
  136.             for ($i = 0; $i < $c; $i++) {
  137.                 if ($this->endpoints[$i]->id == $result['endpoint']) {
  138.                     // Store the info.
  139.                     if (!isset($this->endpoints[$i]->methods)) {
  140.                         $this->endpoints[$i]->methods = array();
  141.                     }
  142.                     $this->endpoints[$i]->methods[$result['function']] = $result;
  143.                     break;
  144.                 }
  145.             }
  146.         }
  147.     }
  148.     
  149.     /**
  150.      * Saves the results of a method test into the database.
  151.      *
  152.      * @access private
  153.      */
  154.     function _saveResults($endpoint_id, &$soap_test)
  155.     {
  156.         if ($this->nosave) {
  157.             return;
  158.         }
  159.         
  160.         $result =& $soap_test->result;
  161.         $wire = $result['wire'];
  162.         if ($result['success']) {
  163.             $success = 'OK';
  164.             $error = '';
  165.         } else {
  166.             $success = $result['fault']->faultcode;
  167.             $error = $result['fault']->faultstring;
  168.             if (!$wire) {
  169.                 $wire = $result['fault']->faultdetail;
  170.             }
  171.             if (!$wire) {
  172.                 $wire = $result['fault']->faultstring;
  173.             }
  174.         }
  175.         
  176.         $test_name = $soap_test->test_name;
  177.         // add header info to the test name
  178.         if ($soap_test->headers) {
  179.             foreach ($soap_test->headers as $h) {
  180.                 $destination = 0;
  181.                 if (strtolower(get_class($h)) == 'soap_header') {
  182.                     if ($h->attributes['SOAP-ENV:actor'] == 'http://schemas.xmlsoap.org/soap/actor/next') {
  183.                         $destination = 1;
  184.                     }
  185.                     $test_name .= ":{$h->name},$destination,{$h->attributes['SOAP-ENV:mustUnderstand']}";
  186.                 } else {
  187.                     if (!$h[3] ||
  188.                         $h[3] == 'http://schemas.xmlsoap.org/soap/actor/next') {
  189.                         $destination = 1;
  190.                     }
  191.                     if (!$h[2]) {
  192.                         $h[2] = 0;
  193.                     }
  194.                     $qn = new QName($h[0]);
  195.                     $test_name .= ":{$qn->name},$destination," . (int)$h[2];
  196.                 }
  197.             }
  198.         }
  199.         
  200.         $sql = 'DELETE FROM results WHERE endpoint = ? AND class = ? AND type = ? AND wsdl = ? AND client = ? AND function = ?';
  201.         $values = array($endpoint_id, $this->currentTest, $this->paramType,
  202.                         $this->useWSDL, $this->client_type, $test_name);
  203.         $res = $this->dbc->query($sql, $values);
  204.         if (DB::isError($res)) {
  205.             die($res->getMessage());
  206.         }
  207.         if (is_object($res)) {
  208.             $res->free();
  209.         }
  210.         
  211.         $sql = 'INSERT INTO results (client, endpoint, stamp, class, type, wsdl, function, result, error, wire) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
  212.         $values = array($this->client_type, $endpoint_id, time(),
  213.                         $this->currentTest, $this->paramType, $this->useWSDL,
  214.                         $test_name, $success, $error,
  215.                         $wire ? $wire : '');
  216.         //echo "\n".$sql;
  217.         $res = $this->dbc->query($sql, $values);
  218.         if (DB::isError($res)) {
  219.             die($res->getMessage());
  220.         }
  221.         if (is_object($res)) {
  222.             $res->free();
  223.         }
  224.     }
  225.  
  226.     /**
  227.      * Compares two PHP types for a match.
  228.      *
  229.      * @param mixed $expect
  230.      * @param mixed $test_result
  231.      *
  232.      * @return boolean
  233.     */    
  234.     function compareResult(&$expect, &$result, $type = null)
  235.     {
  236.         $expect_type = gettype($expect);
  237.         $result_type = gettype($result);
  238.         if ($expect_type == 'array' && $result_type == 'array') {
  239.             // compare arrays
  240.             return array_compare($expect, $result);
  241.         }
  242.         if ($type == 'float') {
  243.             // We'll only compare to 3 digits of precision.
  244.             return number_compare($expect, $result);
  245.         }
  246.         if ($type == 'boolean') {
  247.             return boolean_compare($expect, $result);
  248.         }
  249.         return string_compare($expect, $result);
  250.     }
  251.  
  252.  
  253.     /**
  254.      * Runs a method on an endpoint and stores its results to the database.
  255.      *
  256.      * @param array $endpoint_info
  257.      * @param SOAP_Test $soap_test
  258.      *
  259.      * @return boolean result
  260.      */    
  261.     function doEndpointMethod(&$endpoint_info, &$soap_test)
  262.     {
  263.         $ok = false;
  264.         
  265.         // Prepare a holder for the test results.
  266.         $soap_test->result['class'] = $this->currentTest;
  267.         $soap_test->result['type'] = $this->paramType;
  268.         $soap_test->result['wsdl'] = $this->useWSDL;
  269.         $opdata = null;
  270.         //global $soap_value_total;
  271.         //echo "SOAP VALUES TEST-START: $soap_value_total\n";
  272.         
  273.         if ($this->useWSDL) {
  274.             if ($endpoint_info->wsdlURL) {
  275.                 if (!$endpoint_info->client) {
  276.                     if (0 /* dynamic client */) {
  277.                     $endpoint_info->wsdl = new SOAP_WSDL($endpoint_info->wsdlURL);
  278.                     $endpoint_info->wsdl->trace=1;
  279.                     $endpoint_info->client = $endpoint_info->wsdl->getProxy('', $endpoint_info->name);
  280.                     } else {
  281.                     $endpoint_info->client = new SOAP_Client($endpoint_info->wsdlURL, 1);
  282.                     }
  283.                     $endpoint_info->client->_auto_translation = true;
  284.                 }
  285.                 if ($endpoint_info->client->_wsdl->_isfault()) {
  286.                     $fault = $endpoint_info->client->_wsdl->fault->getFault();
  287.                     $detail = $fault->faultstring . "\n\n" . $fault->faultdetail;
  288.                     $soap_test->setResult(0,
  289.                                           'WSDL',
  290.                                           $detail,
  291.                                           $fault->faultstring,
  292.                                           $fault);
  293.                     return false;
  294.                 }
  295.                 if ($soap_test->service) {
  296.                     $endpoint_info->client->_wsdl->setService($soap_test->service);
  297.                 }
  298.                 $soap =& $endpoint_info->client;
  299.                 //$port = $soap->_wsdl->getPortName($soap_test->method_name);
  300.                 //$opdata = $soap->_wsdl->getOperationData($port, $soap_test->method_name);
  301.             } else {
  302.                 $fault = array('faultcode' => 'WSDL',
  303.                                'faultstring' => "no WSDL defined for $endpoint");
  304.                 $soap_test->setResult(0,
  305.                                       'WSDL',
  306.                                       $fault->faultstring,
  307.                                       $fault->faultstring,
  308.                                       $fault);
  309.                 return false;
  310.             }
  311.             $options = array('trace' => 1);
  312.         } else {
  313.             $namespace = $soapaction = 'http://soapinterop.org/';
  314.             // Hack to make tests work with MS SoapToolkit.
  315.             // It's the only one that uses this soapaction, and breaks if
  316.             // it isn't right. Can't wait for soapaction to be fully deprecated
  317.             // 8/25/2002, seems this is fixed now
  318.             //if ($this->currentTest == 'Round 2 Base' &&
  319.             //    strstr($endpoint_info->name,'MS SOAP ToolKit 2.0')) {
  320.             //    $soapaction = 'urn:soapinterop';
  321.             //}
  322.             if (!$endpoint_info->client) {
  323.                 $endpoint_info->client = new SOAP_Client($endpoint_info->endpointURL);
  324.                 $endpoint_info->client->_auto_translation = true;
  325.             }
  326.             $soap = &$endpoint_info->client;
  327.             $options = array('namespace' => $namespace, 
  328.                              'soapaction' => $soapaction,
  329.                              'trace' => 1);
  330.         }
  331.         
  332.         // Add headers to the test.
  333.         if ($soap_test->headers) {
  334.             // $header is already a SOAP_Header class
  335.             $soap->headersOut = array();
  336.             $soap->headersIn = array();
  337.             for ($i = 0, $hc = count($soap_test->headers); $i < $hc; $i++) {
  338.                 $soap->addHeader($soap_test->headers[$i]);
  339.             }
  340.         }
  341.         $soap->setEncoding($soap_test->encoding);
  342.  
  343.         //if ($opdata) {
  344.         //    if (isset($opdata['style'])) 
  345.         //        $options['style'] = $opdata['style'];
  346.         //    if (isset($opdata['soapAction'])) 
  347.         //        $options['soapaction'] = $opdata['soapAction'];
  348.         //    if (isset($opdata['input']) &&
  349.         //        isset($opdata['input']['use']))
  350.         //        $options['use'] = $opdata['input']['use'];
  351.         //    if (isset($opdata['input']) &&
  352.         //        isset($opdata['input']['namespace']))
  353.         //        $options['namespace'] = $soap->_wsdl->namespaces[$opdata['input']['namespace']];
  354.         //}
  355.         //if ($this->useWSDL) {
  356.         //    $wsdlcall = '$return = $soap->'.$soap_test->method_name.'(';
  357.         //    $args = '';
  358.         //    if ($soap_test->method_params) {
  359.         //    $pnames = array_keys($soap_test->method_params);
  360.         //    foreach ($pnames as $argname) {
  361.         //        if ($args) $args .=',';
  362.         //        $args .= '$soap_test->method_params[\''.$argname.'\']';
  363.         //    }
  364.         //    }
  365.         //    $wsdlcall = $wsdlcall.$args.');';
  366.         //    eval($wsdlcall);
  367.         //} else {
  368.             $return =& $soap->call($soap_test->method_name, $soap_test->method_params, $options);
  369.         //}
  370.         
  371.         if (!PEAR::isError($return)) {
  372.             if (is_array($soap_test->method_params) &&
  373.                 count($soap_test->method_params) == 1) {
  374.                 $sent = array_shift(array_values($soap_test->method_params));
  375.             } else {
  376.                 $sent = $soap_test->method_params;
  377.             }
  378.  
  379.             // Compare header results.
  380.             $header_result = array();
  381.             $headers_ok = true;
  382.             if ($soap_test->headers) {
  383.                 // $header is already a SOAP_Header class
  384.                 for ($i = 0, $hc = count($soap_test->headers); $i < $hc; $i++) {
  385.                     $header = $soap_test->headers[$i];
  386.                     if (strtolower(get_class($header)) != 'soap_header') {
  387.                         // Assume it's an array.
  388.                         $header = new SOAP_Header($header[0], null, $header[1], $header[2], $header[3], $header[4]);
  389.                     }
  390.                     $expect = $soap_test->headers_expect[$header->name];
  391.                     $header_result[$header->name] = array();
  392.                     // XXX need to fix need_result to identify the actor correctly
  393.                     $need_result = $hresult ||
  394.                         ($header->attributes['SOAP-ENV:actor'] == 'http://schemas.xmlsoap.org/soap/actor/next'
  395.                          && $header->attributes['SOAP-ENV:mustUnderstand']);
  396.                     if ($expect) {
  397.                         $hresult = $soap->headersIn[key($expect)];
  398.                         $ok = !$need_result || $this->compareResult($hresult ,$expect[key($expect)]);
  399.                     } else {
  400.                         $hresult = $soap->headersIn[$header->name];
  401.                         $expect =& $soap->_decode($header);
  402.                         $ok = !$need_result || $this->compareResult($hresult ,$expect);
  403.                     }
  404.                     $header_result[$header->name]['ok'] = $ok;
  405.                     if (!$ok) {
  406.                         $headers_ok = false;
  407.                     }
  408.                 }
  409.             }
  410.  
  411.             // We need to decode what we sent so we can compare!
  412.             if (gettype($sent) == 'object' &&
  413.                 (strtolower(get_class($sent)) == 'soap_value' ||
  414.                  is_subclass_of($sent, 'soap_value'))) {
  415.                 $sent_d =& $soap->_decode($sent);
  416.             } else {
  417.                 $sent_d =& $sent;
  418.             }
  419.             
  420.             // compare the results with what we sent
  421.             $ok = $this->compareResult($sent_d, $return, $sent->type);
  422.             $expected = $sent_d;
  423.             unset($sent_d);
  424.             unset($sent);
  425.             if (!$ok && $soap_test->expect) {
  426.                 $ok = $this->compareResult($soap_test->expect, $return);
  427.                 $expected = $soap_test->expect;
  428.             }
  429.             
  430.             if ($ok) {
  431.                 if (!$headers_ok) {
  432.                     $fault = new stdClass();
  433.                     $fault->faultcode = 'HEADER';
  434.                     $fault->faultstring = 'The returned result did not match what we expected to receive';
  435.                     $soap_test->setResult(0,
  436.                                           $fault->faultcode,
  437.                                           $soap->getWire(),
  438.                                           $fault->faultstring,
  439.                                           $fault);
  440.                 } else {
  441.                     $soap_test->setResult(1, 'OK', $soap->getWire());
  442.                     $success = true;
  443.                 }
  444.             } else {
  445.                 $fault = new stdClass();
  446.                 $fault->faultcode = 'RESULT';
  447.                 $fault->faultstring = 'The returned result did not match what we expected to receive';
  448.                 $fault->faultdetail = "RETURNED:\n" . var_export($return, true) . "\n\nEXPECTED:\n" . var_export($expected, true);
  449.                 $soap_test->setResult(0,
  450.                                       $fault->faultcode,
  451.                                       $soap->getWire(),
  452.                                       $fault->faultstring,
  453.                                       $fault);
  454.             }
  455.         } else {
  456.             $fault = $return->getFault();
  457.             if ($soap_test->expect_fault) {
  458.                 $ok = 1;
  459.                 $res = 'OK';
  460.             } else {
  461.                 $ok = 0;
  462.                 $res = $fault->faultcode;
  463.             }
  464.             $soap_test->setResult($ok,
  465.                                   $res,
  466.                                   $soap->getWire(),
  467.                                   $fault->faultstring,
  468.                                   $fault);
  469.         }
  470.         $soap->_reset();
  471.         unset($return);
  472.  
  473.         return $ok;
  474.     }
  475.  
  476.     /**
  477.      * Runs a single round of tests.
  478.      */    
  479.     function doTest()
  480.     {
  481.         global $soap_tests;
  482.  
  483.         $empty_string = '';
  484.         // Get endpoints for this test.
  485.         if (!$this->currentTest) {
  486.             die("Asked to run a test, but no testname!\n");
  487.         }
  488.         $this->getEndpoints($this->currentTest);
  489.         // Clear totals.
  490.         $this->totals = array();
  491.         
  492.         for ($i = 0, $c = count($this->endpoints); $i < $c; ++$i) {
  493.             $endpoint_info = $this->endpoints[$i];
  494.             // If we specify an endpoint, skip until we find it.
  495.             if (($this->specificEndpoint &&
  496.                  $endpoint_info->name != $this->specificEndpoint) ||
  497.                 ($this->useWSDL && !$endpoint_info->wsdlURL)) {
  498.                 continue;
  499.             }
  500.             
  501.             $skipendpoint = false;
  502.             $this->totals['servers']++;
  503.             //$endpoint_info['tests'] = array();
  504.             
  505.             if ($this->show) {
  506.                 echo "Processing {$endpoint_info->name} at {$endpoint_info->endpointURL}\n";
  507.             }
  508.             
  509.             for ($ti = 0, $tc = count($soap_tests[$this->currentTest]); $ti < $tc; ++$ti) {
  510.                 $soap_test = $soap_tests[$this->currentTest][$ti];
  511.             
  512.                 // Only run the type of test we're looking for (php or
  513.                 // soapval).
  514.                 if ($soap_test->type != $this->paramType) {
  515.                     continue;
  516.                 }
  517.             
  518.                 // If this is in our skip list, skip it.
  519.                 if (in_array($endpoint_info->name, $this->skipEndpointList)) {
  520.                     $skipendpoint = true;
  521.                     $skipfault = new stdClass();
  522.                     $skipfault->faultcode = 'SKIP';
  523.                     $skipfault->faultstring = 'endpoint skipped';
  524.                     $soap_test->setResult(0,
  525.                                           $skipfault->faultcode,
  526.                                           $empty_string,
  527.                                           $skipfault->faultstring,
  528.                                           $skipfault);
  529.                     //$endpoint_info['tests'][] = &$soap_test;
  530.                     //$soap_test->showTestResult($this->debug);
  531.                     //$this->_saveResults($endpoint_info['id'], $soap_test->method_name);
  532.                     $soap_test->result = null;
  533.                     continue;
  534.                 }
  535.                 
  536.                 // If we're looking for a specific method, skip unless we have
  537.                 // it.
  538.                 if ($this->testMethod &&
  539.                     strcmp($this->testMethod, $soap_test->test_name) != 0) {
  540.                     continue;
  541.                 }
  542.                 if ($this->testMethod &&
  543.                     $this->currentTest == 'Round 2 Group C') {
  544.                     // We have to figure things out now.
  545.                     if (!preg_match('/(.*):(.*),(\d),(\d)/', $this->testMethod, $m)) {
  546.                         continue;
  547.                     }
  548.                     
  549.                     // Is the header in the headers list?
  550.                     $gotit = false;
  551.                     $thc = count($soap_test->headers);
  552.                     for ($thi = 0; $thi < $thc; $thi++) {
  553.                         $header = $soap_test->headers[$thi];
  554.                         if (strtolower(get_class($header)) == 'soap_header') {
  555.                             if ($header->name == $m[2]) {
  556.                                 $gotit = $header->attributes['SOAP-ENV:actor'] == ($m[3] ? SOAP_TEST_ACTOR_NEXT : SOAP_TEST_ACTOR_OTHER);
  557.                                 $gotit = $gotit && $header->attributes['SOAP-ENV:mustUnderstand'] == $m[4];
  558.                             }
  559.                         } elseif ($header[0] == $m[2]) {
  560.                             $gotit = $gotit && $header[3] == ($m[3] ? SOAP_TEST_ACTOR_NEXT : SOAP_TEST_ACTOR_OTHER);
  561.                             $gotit = $gotit && $header[4] == $m[4];
  562.                         }
  563.                     }
  564.                     if (!$gotit) {
  565.                         continue;
  566.                     }
  567.                 }
  568.             
  569.                 // If we are skipping the rest of the tests (due to error)
  570.                 // note a fault.
  571.                 if ($skipendpoint) {
  572.                     $soap_test->setResult(0,
  573.                                           $skipfault->faultcode,
  574.                                           $empty_string,
  575.                                           $skipfault->faultstring,
  576.                                           $skipfault);
  577.                     //$endpoint_info['tests'][] = &$soap_test;
  578.                     $this->totals['fail']++;
  579.                 } else {
  580.                     // Run the endpoint test.
  581.                     unset($soap_test->result);
  582.                     if ($this->doEndpointMethod($endpoint_info, $soap_test)) {
  583.                         $this->totals['success']++;
  584.                     } else {
  585.                         $skipendpoint = $soap_test->result['fault']->faultcode == 'HTTP';
  586.                         $skipfault = $skipendpoint ? $soap_test->result['fault'] : null;
  587.                         $this->totals['fail']++;
  588.                     }
  589.                     //$endpoint_info['tests'][] = &$soap_test;
  590.                 }
  591.                 $soap_test->showTestResult($this->debug);
  592.                 $this->_saveResults($endpoint_info->id, $soap_test);
  593.                 $soap_test->reset();
  594.                 $this->totals['calls']++;
  595.             }
  596.             unset($endpoint_info->client);
  597.             if ($this->numservers && ++$i >= $this->numservers) {
  598.                 break;
  599.             }
  600.         }
  601.     }
  602.     
  603.     function doGroupTests() {
  604.         $dowsdl = array(0,1);
  605.         foreach($dowsdl as $usewsdl) {
  606.             $this->useWSDL = $usewsdl;
  607.             foreach($this->paramTypes as $ptype) {
  608.                 // skip a pointless test
  609.                 if ($usewsdl && $ptype == 'soapval') break;
  610.                 if (stristr($this->currentTest, 'Round 3') && !$usewsdl) break;
  611.                 $this->paramType = $ptype;
  612.                 $this->doTest();
  613.             }
  614.         }
  615.     }
  616.     
  617.     /**
  618.      * Go all out. This takes time.
  619.      */    
  620.     function doTests()
  621.     {
  622.         // The mother of all interop tests.
  623.         $dowsdl = array(0, 1);
  624.         foreach ($this->tests as $test) {
  625.             $this->currentTest = $test;
  626.             foreach ($dowsdl as $usewsdl) {
  627.                 $this->useWSDL = $usewsdl;
  628.                 foreach ($this->paramTypes as $ptype) {
  629.                     // Skip a pointless test.
  630.                     if ($usewsdl && $ptype == 'soapval') {
  631.                         break;
  632.                     }
  633.                     if (stristr($this->currentTest, 'Round 3') && !$usewsdl) {
  634.                         break;
  635.                     }
  636.                     $this->paramType = $ptype;
  637.                     $this->doTest();
  638.                 }
  639.             }
  640.         }
  641.     }
  642.     
  643.     /**
  644.      * @access private
  645.      */
  646.     function getMethodList($test = 'base')
  647.     {
  648.         $this->dbc->setFetchMode(DB_FETCHMODE_ORDERED);
  649.         // Retreive the results and put them into the endpoint info.
  650.         $sql = "SELECT DISTINCT(function) FROM results WHERE client='$this->client_type' AND class='$test' ORDER BY function";
  651.         $results = $this->dbc->getAll($sql);
  652.         $ar = array();
  653.         foreach($results as $result) {
  654.             $ar[] = $result[0];
  655.         }
  656.         return $ar;
  657.     }
  658.     
  659.     function outputTable()
  660.     {
  661.         $methods = $this->getMethodList($this->currentTest);
  662.         if (!$methods) {
  663.             return;
  664.         }
  665.         $this->getResults($this->currentTest,$this->paramType,$this->useWSDL);
  666.         
  667.         echo "<b>Testing $this->currentTest ";
  668.         if ($this->useWSDL) {
  669.             echo "using WSDL ";
  670.         } else {
  671.             echo "using Direct calls ";
  672.         }
  673.         echo "with $this->paramType values</b><br>\n";
  674.         
  675.         // Calculate totals for this table.
  676.         $this->totals['success'] = 0;
  677.         $this->totals['fail'] = 0;
  678.         $this->totals['result'] = 0;
  679.         $this->totals['wsdl'] = 0;
  680.         $this->totals['connect'] = 0;
  681.         $this->totals['servers'] = 0; //count($this->endpoints);
  682.         for ($i = 0, $c = count($this->endpoints); $i < $c; ++$i) {
  683.             $endpoint_info = $this->endpoints[$i];
  684.             if (!$endpoint_info->name) {
  685.                 continue;
  686.             }
  687.             if (count($endpoint_info->methods) > 0) {
  688.                 $this->totals['servers']++;
  689.                 foreach ($methods as $method) {
  690.                     $r = $endpoint_info->methods[$method]['result'];
  691.                     if ($r == 'OK') {
  692.                         $this->totals['success']++;
  693.                     } elseif (stristr($r, 'result')) {
  694.                         $this->totals['result']++;
  695.                     } elseif (stristr($r, 'wsdlcache')) {
  696.                         $this->totals['connect']++;
  697.                     } elseif (stristr($r, 'wsdl')) {
  698.                         $this->totals['wsdl']++;
  699.                     } elseif (stristr($r, 'http')) {
  700.                         $this->totals['connect']++;
  701.                     } else {
  702.                         $this->totals['fail']++;
  703.                     }
  704.                 }
  705.             } else {
  706.                 //unset($this->endpoints[$i]);
  707.             }
  708.         }
  709.         $this->totals['calls'] = count($methods) * $this->totals['servers'];
  710.  
  711.         //if ($this->totals['fail'] == $this->totals['calls']) {
  712.         //    // assume tests have not run, skip outputing table
  713.         //    echo "No Data Available<br>\n";
  714.         //    return;
  715.         //}
  716.         
  717.         echo "\n\n<b>Servers: {$this->totals['servers']} Calls: {$this->totals['calls']} Success: {$this->totals['success']} <br>\n"
  718.             . "System-Fail: {$this->totals['fail']} Result-Failure: {$this->totals['result']} Connect-Failure: {$this->totals['connect']} WSDL-Failure: {$this->totals['wsdl']} </b><br>\n"
  719.        
  720.             . "<table border=\"1\" cellspacing=\"0\" cellpadding=\"2\">\n"
  721.             . "<tr><td class=\"BLANK\">Endpoint</td>\n";
  722.         foreach ($methods as $method) {
  723.             $info = split(':', $method);
  724.             echo "<td class='BLANK' valign='top'>";
  725.             foreach ($info as $m) {
  726.                 $hi = split(',', $m);
  727.                 echo '<b>'. $hi[0] . "</b><br>\n";
  728.                 if (count($hi) > 1) {
  729.                     echo "  Actor="
  730.                         . ($hi[1] ? 'Target' : 'Not Target')
  731.                         . "<br>\n  MustUnderstand=$hi[2]<br>\n";
  732.                 }
  733.             }
  734.             echo "</td>\n";
  735.         }
  736.         echo "</tr>\n";
  737.         $faults = array();
  738.         $fi = 0;
  739.         for ($i = 0, $c = count($this->endpoints); $i < $c; ++$i) {
  740.             $endpoint_info = $this->endpoints[$i];
  741.             if (!$endpoint_info->name) {
  742.                 continue;
  743.             }
  744.             if ($endpoint_info->wsdlURL) {
  745.                 echo "<tr><td class=\"BLANK\"><a href=\"{$endpoint_info->wsdlURL}\">{$endpoint_info->name}</a></td>\n";
  746.             } else {
  747.                 echo "<tr><td class=\"BLANK\">{$endpoint_info->name}</td>\n";
  748.             }
  749.             foreach ($methods as $method) {
  750.                 $id = $endpoint_info->methods[$method]['id'];
  751.                 $r = $endpoint_info->methods[$method]['result'];
  752.                 $e = $endpoint_info->methods[$method]['error'];
  753.                 if ($e) {
  754.                     $faults[$fi++] = $e;
  755.                 }
  756.                 if ($r) {
  757.                     echo "<td class='$r'><a href='$PHP_SELF?wire=$id'>$r</a></td>\n";
  758.                 } else {
  759.                     echo "<td class='untested'>untested</td>\n";
  760.                 }
  761.             }
  762.             echo "</tr>\n";
  763.         }
  764.         echo "</table><br>\n";
  765.         if ($this->showFaults && count($faults) > 0) {
  766.             echo "<b>ERROR Details:</b><br>\n<ul>\n";
  767.             // output more error detail
  768.             foreach ($faults as $fault) {
  769.                 echo '<li>' . htmlspecialchars($fault) . "</li>\n";
  770.             }
  771.         }
  772.         echo "</ul><br><br>\n";
  773.     }
  774.     
  775.     function outputTables()
  776.     {
  777.         $dowsdl = array(0, 1);
  778.         foreach($this->tests as $test) {
  779.             $this->currentTest = $test;
  780.             foreach ($dowsdl as $usewsdl) {
  781.                 $this->useWSDL = $usewsdl;
  782.                 foreach ($this->paramTypes as $ptype) {
  783.                     // Skip a pointless test.
  784.                     if ($usewsdl && $ptype == 'soapval') {
  785.                         break;
  786.                     }
  787.                     if (stristr($this->currentTest, 'Round 3') && !$usewsdl) {
  788.                         break;
  789.                     }
  790.                     $this->paramType = $ptype;
  791.                     $this->outputTable();
  792.                 }
  793.             }
  794.         }
  795.     }
  796.     
  797.     function showWire($id)
  798.     {
  799.         $results = $this->dbc->getAll("SELECT * FROM results WHERE id=$id", null, DB_FETCHMODE_ASSOC );
  800.         //$wire = preg_replace("/>/",">\n",$results[0]['wire']);
  801.         $wire = $results[0]['wire'];
  802.         echo "<pre>\n" . htmlspecialchars($wire) . "</pre>\n";
  803.     }
  804.  
  805. }
  806.