📄 client_round2_interop.php
字号:
} $namespace = false; $soapaction = false; } else { $namespace = $soapaction = 'http://soapinterop.org/'; // hack to make tests work with MS SoapToolkit // it's the only one that uses this soapaction, and breaks if // it isn't right. Can't wait for soapaction to be fully depricated if ($this->currentTest == 'base' && strstr($endpoint_info['endpointName'],'MS SOAP ToolKit 2.0')) { $soapaction = 'urn:soapinterop'; } if (!array_key_exists('client',$endpoint_info)) { $endpoint_info['client'] = new SoapClient(null,array('location'=>$endpoint_info['endpointURL'],'uri'=>$soapaction,'trace'=>1)); } $soap = $endpoint_info['client']; }// // add headers to the test// if ($soap_test->headers) {// // $header is already a SOAP_Header class// foreach ($soap_test->headers as $header) {// $soap->addHeader($header);// }// } // XXX no way to set encoding // this lets us set UTF-8, US-ASCII or other //$soap->setEncoding($soap_test->encoding);try { if ($this->useWSDL && !$soap_test->headers && !$soap_test->headers_expect) { $args = ''; foreach ($soap_test->method_params as $pname => $param) { $arg = '$soap_test->method_params["'.$pname.'"]'; $args .= $args?','.$arg:$arg; } $return = eval('return $soap->'.$soap_test->method_name.'('.$args.');'); } else { if ($soap_test->headers || $soap_test->headers_expect) { $return = $soap->__soapCall($soap_test->method_name,$soap_test->method_params,array('soapaction'=>$soapaction,'uri'=>$namespace), $soap_test->headers, $result_headers); } else { $return = $soap->__soapCall($soap_test->method_name,$soap_test->method_params,array('soapaction'=>$soapaction,'uri'=>$namespace)); } }} catch (SoapFault $ex) { $return = $ex;} if(!is_soap_fault($return)){ if ($soap_test->expect !== NULL) { $sent = $soap_test->expect; } else if (is_array($soap_test->method_params) && count($soap_test->method_params) == 1) { reset($soap_test->method_params); $sent = current($soap_test->method_params); } else if (is_array($soap_test->method_params) && count($soap_test->method_params) == 0) { $sent = null; } else { $sent = $soap_test->method_params; } // compare header results $headers_ok = TRUE; if ($soap_test->headers || $soap_test->headers_expect) { $headers_ok = $this->compareResult($soap_test->headers_expect, $result_headers); } # we need to decode what we sent so we can compare! $sent_d = $this->decodeSoapval($sent); $soap_test->result['sent'] = $sent; $soap_test->result['return'] = $return; // compare the results with what we sent if ($soap_test->cmp_func !== NULL) { $cmp_func = $soap_test->cmp_func; $ok = $cmp_func($sent_d,$return); } else { $ok = $this->compareResult($sent_d,$return, $sent->type); if (!$ok && $soap_test->expect) { $ok = $this->compareResult($soap_test->expect,$return); } } // save the wire $wire = "REQUEST:\n".str_replace('" ',"\" \n",str_replace('>',">\n",$soap->__getlastrequest()))."\n\n". "RESPONSE:\n".str_replace('" ',"\" \n",str_replace('>',">\n",$soap->__getlastresponse()))."\n\n". "EXPECTED:\n".var_dump_str($sent_d)."\n". "RESULTL:\n".var_dump_str($return); if ($soap_test->headers_expect) { $wire .= "\nEXPECTED HEADERS:\n".var_dump_str($soap_test->headers_expect)."\n". "RESULT HEADERS:\n".var_dump_str($result_headers); } #print "Wire:".htmlentities($wire); if($ok){ if (!$headers_ok) { $fault = new SoapFault('HEADER','The returned result did not match what we expected to receive'); $soap_test->setResult(0,$fault->faultcode, $wire, $fault->faultstring, $fault ); } else { $soap_test->setResult(1,'OK',$wire); $success = TRUE; } } else { $fault = new SoapFault('RESULT','The returned result did not match what we expected to receive'); $soap_test->setResult(0,$fault->faultcode, $wire, $fault->faultstring, $fault ); } } else { $fault = $return; if ($soap_test->expect_fault) { $ok = 1; $res = 'OK'; } else { $ok = 0; $res =$fault->faultcode; $pos = strpos($res,':'); if ($pos !== false) { $res = substr($res,$pos+1); } } // save the wire $wire = "REQUEST:\n".str_replace('" ',"\" \n",str_replace('>',">\n",$soap->__getlastrequest()))."\n\n". "RESPONSE:\n".str_replace('" ',"\" \n",str_replace('>',">\n",$soap->__getlastresponse()))."\n". "RESULTL:\n".var_dump_str($return); #print "Wire:".htmlentities($wire); $soap_test->setResult($ok,$res, $wire,$fault->faultstring, $fault); } return $ok; } /** * doTest * run a single round of tests * * @access public */ function doTest() { global $soap_tests; // get endpoints for this test $this->getEndpoints($this->currentTest); #clear totals $this->totals = array(); $i = 0; foreach($this->endpoints as $endpoint => $endpoint_info){ // if we specify an endpoint, skip until we find it if ($this->specificEndpoint && $endpoint != $this->specificEndpoint) continue; if ($this->useWSDL && !$endpoint_info['endpointURL']) continue; $skipendpoint = FALSE; $this->totals['servers']++; #$endpoint_info['tests'] = array(); if ($this->show) { print "Processing $endpoint at {$endpoint_info['endpointURL']}"; if ($this->html) print "<br>\n"; else print "\n"; } foreach($soap_tests[$this->currentTest] as $soap_test) { //foreach(array_keys($method_params[$this->currentTest][$this->paramType]) as $method) // only run the type of test we're looking for (php or soapval) if ($soap_test->type != $this->paramType) continue; // if we haven't reached our startpoint, skip if ($this->startAt && $this->startAt != $endpoint_info['endpointName']) continue; $this->startAt = ''; // if this is in our skip list, skip it if (in_array($endpoint, $this->skipEndpointList)) { $skipendpoint = TRUE; $skipfault = new SoapFault('SKIP','endpoint skipped'); $soap_test->setResult(0,$fault->faultcode, '', $skipfault->faultstring, $skipfault ); #$endpoint_info['tests'][] = &$soap_test; #$soap_test->showTestResult($this->debug, $this->html); #$this->_saveResults($endpoint_info['id'], $soap_test->method_name); $soap_test->result = NULL; continue; } // if we're looking for a specific method, skip unless we have it if ($this->testMethod && strcmp($this->testMethod,$soap_test->test_name) != 0) continue; // if we are skipping the rest of the tests (due to error) note a fault if ($skipendpoint) { $soap_test->setResult(0,$fault->faultcode, '', $skipfault->faultstring, $skipfault ); #$endpoint_info['tests'][] = &$soap_test; $this->totals['fail']++; } else { // run the endpoint test if ($this->doEndpointMethod($endpoint_info, $soap_test)) { $this->totals['success']++; } else { $skipendpoint = $soap_test->result['fault']->faultcode=='HTTP' && strstr($soap_test->result['fault']->faultstring,'Connect Error'); $skipfault = $soap_test->result['fault']; $this->totals['fail']++; } #$endpoint_info['tests'][] = &$soap_test; } $soap_test->showTestResult($this->debug, $this->html); $this->_saveResults($endpoint_info['id'], $soap_test); $soap_test->result = NULL; $this->totals['calls']++; } if ($this->numservers && ++$i >= $this->numservers) break; } } function doGroupTests() { $dowsdl = array(0,1); foreach($dowsdl as $usewsdl) { $this->useWSDL = $usewsdl; foreach($this->paramTypes as $ptype) { // skip a pointless test if ($usewsdl && $ptype == 'soapval') break; $this->paramType = $ptype; $this->doTest(); } } } /** * doTests * go all out. This takes time. * * @access public */ function doTests() { // the mother of all interop tests $dowsdl = array(0,1); foreach($this->tests as $test) { $this->currentTest = $test; foreach($dowsdl as $usewsdl) { $this->useWSDL = $usewsdl; foreach($this->paramTypes as $ptype) { // skip a pointless test if ($usewsdl && $ptype == 'soapval') break; $this->paramType = $ptype; $this->doTest(); } } } } // *********************************************************** // output functions /** * getResults * retreive results from the database, stuff them into the endpoint array * * @access private */ function getMethodList($test = 'base') { // retreive the results and put them into the endpoint info $sql = "select distinct(function) from results where class='$test' order by function"; $results = $this->dbc->getAll($sql); $ar = array(); foreach($results as $result) { $ar[] = $result[0]; } return $ar; } function outputTable() { $methods = $this->getMethodList($this->currentTest); if (!$methods) return; $this->getResults($this->currentTest,$this->paramType,$this->useWSDL); echo "<b>Testing $this->currentTest "; if ($this->useWSDL) echo "using WSDL "; else echo "using Direct calls "; echo "with $this->paramType values</b><br>\n"; // calculate totals for this table $this->totals['success'] = 0; $this->totals['fail'] = 0; $this->totals['servers'] = 0; #count($this->endpoints); foreach ($this->endpoints as $endpoint => $endpoint_info) { if (count($endpoint_info['methods']) > 0) { $this->totals['servers']++; foreach ($methods as $method) { $r = $endpoint_info['methods'][$method]['result']; if ($r == 'OK') $this->totals['success']++; else $this->totals['fail']++; } } else { unset($this->endpoints[$endpoint]); } } $this->totals['calls'] = count($methods) * $this->totals['servers']; echo "\n\n<b>Servers: {$this->totals['servers']} Calls: {$this->totals['calls']} Success: {$this->totals['success']} Fail: {$this->totals['fail']}</b><br>\n"; echo "<table border=\"1\" cellspacing=\"0\" cellpadding=\"2\">\n"; echo "<tr><td class=\"BLANK\">Endpoint</td>\n"; foreach ($methods as $method) { $info = split(':', $method); echo "<td class='BLANK' valign='top'>"; foreach ($info as $m) { $hi = split(',',$m); echo '<b>'.$hi[0]."</b><br>\n"; if (count($hi) > 1) { echo " Actor=".($hi[1]?'Target':'Not Target')."<br>\n"; echo " MustUnderstand=$hi[2]<br>\n"; } } echo "</td>\n"; } echo "</tr>\n"; $faults = array(); $fi = 0; foreach ($this->endpoints as $endpoint => $endpoint_info) { if (array_key_exists('wsdlURL',$endpoint_info)) { echo "<tr><td class=\"BLANK\"><a href=\"{$endpoint_info['wsdlURL']}\">$endpoint</a></td>\n"; } else { echo "<tr><td class=\"BLANK\">$endpoint</td>\n"; } foreach ($methods as $method) { $id = $endpoint_info['methods'][$method]['id']; $r = $endpoint_info['methods'][$method]['result']; $e = $endpoint_info['methods'][$method]['error']; if ($e) { $faults[$fi++] = $e; } if ($r) { echo "<td class='$r'><a href='$PHP_SELF?wire=$id'>$r</a></td>\n"; } else { echo "<td class='untested'>untested</td>\n"; } } echo "</tr>\n"; } echo "</table><br>\n"; if ($this->showFaults && count($faults) > 0) { echo "<b>ERROR Details:</b><br>\n<ul>\n"; # output more error detail foreach ($faults as $fault) { echo '<li>'.HTMLSpecialChars($fault)."</li>\n"; } } echo "</ul><br><br>\n"; } function outputTables() { // the mother of all interop tests $dowsdl = array(0,1); foreach($this->tests as $test) { $this->currentTest = $test; foreach($dowsdl as $usewsdl) { $this->useWSDL = $usewsdl; foreach($this->paramTypes as $ptype) { // skip a pointless test if ($usewsdl && $ptype == 'soapval') break; $this->paramType = $ptype; $this->outputTable(); } } } } function showWire($id) { $results = $this->dbc->getAll("select * from results where id=$id",NULL, DB_FETCHMODE_ASSOC ); #$wire = preg_replace("/>/",">\n",$results[0]['wire']); $wire = $results[0]['wire']; if ($this->html) print "<pre>"; echo "\n".HTMLSpecialChars($wire); if ($this->html) print "</pre>"; print "\n"; }}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -