client_round2_interop.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783
  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4 |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2018 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 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. require_once 'DB.php'; // PEAR/DB
  19. require_once 'client_round2_params.php';
  20. require_once 'test.utility.php';
  21. require_once 'config.php';
  22. error_reporting(E_ALL ^ E_NOTICE);
  23. class Interop_Client
  24. {
  25. // database DNS
  26. var $DSN = "";
  27. var $baseURL = "";
  28. // our central interop server, where we can get the list of endpoints
  29. var $interopServer = "http://www.whitemesa.net/wsdl/interopInfo.wsdl";
  30. // our local endpoint, will always get added to the database for all tests
  31. var $localEndpoint;
  32. // specify testing
  33. var $currentTest = 'base'; // see $tests above
  34. var $paramType = 'php'; // 'php' or 'soapval'
  35. var $useWSDL = 0; // 1= do wsdl tests
  36. var $numServers = 0; // 0 = all
  37. var $specificEndpoint = ''; // test only this endpoint
  38. var $testMethod = ''; // test only this method
  39. var $skipEndpointList = array(); // endpoints to skip
  40. var $nosave = 0;
  41. var $startAt = ''; // start in list at this endpoint
  42. // debug output
  43. var $show = 1;
  44. var $debug = 0;
  45. var $showFaults = 0; // used in result table output
  46. // PRIVATE VARIABLES
  47. var $dbc = NULL;
  48. var $totals = array();
  49. var $tests = array('base','GroupB', 'GroupC');
  50. var $paramTypes = array('php', 'soapval');
  51. var $endpoints = array();
  52. var $html = 1;
  53. function Interop_Client() {
  54. global $interopConfig;
  55. $this->DSN = $interopConfig['DSN'];
  56. $this->baseURL = $interopConfig['baseURL'];
  57. //$this->baseURL = 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
  58. // set up the database connection
  59. $this->dbc = DB::connect($this->DSN, true);
  60. // if it errors out, just ignore it and rely on regular methods
  61. if (DB::isError($this->dbc)) {
  62. echo $this->dbc->getMessage();
  63. $this->dbc = NULL;
  64. }
  65. // set up local endpoint
  66. $this->localEndpoint['base'] = (object)array(
  67. 'endpointName'=>'PHP ext/soap',
  68. 'endpointURL'=>$this->baseURL.'/server_round2_base.php',
  69. 'wsdlURL'=>$this->baseURL.'/interop.wsdl.php'
  70. );
  71. $this->localEndpoint['GroupB'] = (object)array(
  72. 'endpointName'=>'PHP ext/soap',
  73. 'endpointURL'=>$this->baseURL.'/server_round2_groupB.php',
  74. 'wsdlURL'=>$this->baseURL.'/interopB.wsdl.php'
  75. );
  76. $this->localEndpoint['GroupC'] = (object)array(
  77. 'endpointName'=>'PHP ext/soap',
  78. 'endpointURL'=>$this->baseURL.'/server_round2_groupC.php',
  79. 'wsdlURL'=>$this->baseURL.'/echoheadersvc.wsdl.php');
  80. }
  81. function _fetchEndpoints(&$soapclient, $test) {
  82. $this->_getEndpoints($test, 1);
  83. // retrieve endpoints from the endpoint server
  84. $endpointArray = $soapclient->__soapCall("GetEndpointInfo",array("groupName"=>$test),array('soapaction'=>"http://soapinterop.org/",'uri'=>"http://soapinterop.org/"));
  85. if (is_soap_fault($endpointArray) || PEAR::isError($endpointArray)) {
  86. if ($this->html) print "<pre>";
  87. print $soapclient->wire."\n";
  88. print_r($endpointArray);
  89. if ($this->html) print "</pre>";
  90. print "\n";
  91. return;
  92. }
  93. // add our local endpoint
  94. if ($this->localEndpoint[$test]) {
  95. array_push($endpointArray, $this->localEndpoint[$test]);
  96. }
  97. if (!$endpointArray) return;
  98. // reset the status to zero
  99. $res = $this->dbc->query("update endpoints set status = 0 where class='$test'");
  100. if (DB::isError($res)) {
  101. die ($res->getMessage());
  102. }
  103. if (is_object($res)) $res->free();
  104. // save new endpoints into database
  105. foreach($endpointArray as $k => $v){
  106. if (array_key_exists($v->endpointName,$this->endpoints)) {
  107. $res = $this->dbc->query("update endpoints set endpointURL='{$v->endpointURL}', wsdlURL='{$v->wsdlURL}', status=1 where id={$this->endpoints[$v->endpointName]['id']}");
  108. } else {
  109. $res = $this->dbc->query("insert into endpoints (endpointName,endpointURL,wsdlURL,class) values('{$v->endpointName}','{$v->endpointURL}','{$v->wsdlURL}','$test')");
  110. }
  111. if (DB::isError($res)) {
  112. die ($res->getMessage());
  113. }
  114. if (is_object($res)) $res->free();
  115. }
  116. }
  117. /**
  118. * fetchEndpoints
  119. * retrieve endpoints interop server
  120. *
  121. * @return boolean result
  122. * @access private
  123. */
  124. function fetchEndpoints($test = NULL) {
  125. // fetch from the interop server
  126. try {
  127. $soapclient = new SoapClient($this->interopServer);
  128. if ($test) {
  129. $this->_fetchEndpoints($soapclient, $test);
  130. } else {
  131. foreach ($this->tests as $test) {
  132. $this->_fetchEndpoints($soapclient, $test);
  133. }
  134. $test = 'base';
  135. }
  136. } catch (SoapFault $fault) {
  137. if ($this->html) {
  138. echo "<pre>$fault</pre>\n";
  139. } else {
  140. echo "$fault\n";
  141. }
  142. return NULL;
  143. }
  144. // retrieve all endpoints now
  145. $this->currentTest = $test;
  146. $x = $this->_getEndpoints($test);
  147. return $x;
  148. }
  149. /**
  150. * getEndpoints
  151. * retrieve endpoints from either database or interop server
  152. *
  153. * @param string base (see local var $tests)
  154. * @param boolean all (if false, only get valid endpoints, status=1)
  155. * @return boolean result
  156. * @access private
  157. */
  158. function getEndpoints($base = 'base', $all = 0) {
  159. if (!$this->_getEndpoints($base, $all)) {
  160. return $this->fetchEndpoints($base);
  161. }
  162. return TRUE;
  163. }
  164. /**
  165. * _getEndpoints
  166. * retrieve endpoints from database
  167. *
  168. * @param string base (see local var $tests)
  169. * @param boolean all (if false, only get valid endpoints, status=1)
  170. * @return boolean result
  171. * @access private
  172. */
  173. function _getEndpoints($base = "", $all = 0) {
  174. $this->endpoints = array();
  175. // build sql
  176. $sql = "select * from endpoints ";
  177. if ($base) {
  178. $sql .= "where class='$base' ";
  179. if (!$all) $sql .= "and status=1";
  180. } else
  181. if (!$all) $sql .= "where status=1";
  182. $sql .= " order by endpointName";
  183. $db_ep = $this->dbc->getAll($sql,NULL, DB_FETCHMODE_ASSOC );
  184. if (DB::isError($db_ep)) {
  185. echo $sql."\n";
  186. echo $db_ep->getMessage();
  187. return FALSE;
  188. }
  189. // rearange the array
  190. foreach ($db_ep as $entry) {
  191. $this->endpoints[$entry['endpointName']] = $entry;
  192. }
  193. if (count($this->endpoints) > 0) {
  194. $this->currentTest = $base;
  195. return TRUE;
  196. }
  197. return FALSE;
  198. }
  199. /**
  200. * getResults
  201. * retrieve results from the database, stuff them into the endpoint array
  202. *
  203. * @access private
  204. */
  205. function getResults($test = 'base', $type = 'php', $wsdl = 0) {
  206. // be sure we have the right endpoints for this test result
  207. $this->getEndpoints($test);
  208. // retrieve the results and put them into the endpoint info
  209. $sql = "select * from results where class='$test' and type='$type' and wsdl=$wsdl";
  210. $results = $this->dbc->getAll($sql,NULL, DB_FETCHMODE_ASSOC );
  211. foreach ($results as $result) {
  212. // find the endpoint
  213. foreach ($this->endpoints as $epn => $epi) {
  214. if ($epi['id'] == $result['endpoint']) {
  215. // store the info
  216. $this->endpoints[$epn]['methods'][$result['function']] = $result;
  217. break;
  218. }
  219. }
  220. }
  221. }
  222. /**
  223. * saveResults
  224. * save the results of a method test into the database
  225. *
  226. * @access private
  227. */
  228. function _saveResults($endpoint_id, &$soap_test) {
  229. if ($this->nosave) return;
  230. $result = $soap_test->result;
  231. $wire = $result['wire'];
  232. if ($result['success']) {
  233. $success = 'OK';
  234. $error = '';
  235. } else {
  236. $success = $result['fault']->faultcode;
  237. $pos = strpos($success,':');
  238. if ($pos !== false) {
  239. $success = substr($success,$pos+1);
  240. }
  241. $error = $result['fault']->faultstring;
  242. if (!$wire) $wire= $result['fault']->detail;
  243. }
  244. $test_name = $soap_test->test_name;
  245. $sql = "delete from results where endpoint=$endpoint_id ".
  246. "and class='$this->currentTest' and type='$this->paramType' ".
  247. "and wsdl=$this->useWSDL and function=".
  248. $this->dbc->quote($test_name);
  249. #echo "\n".$sql;
  250. $res = $this->dbc->query($sql);
  251. if (DB::isError($res)) {
  252. die ($res->getMessage());
  253. }
  254. if (is_object($res)) $res->free();
  255. $sql = "insert into results (endpoint,stamp,class,type,wsdl,function,result,error,wire) ".
  256. "values($endpoint_id,".time().",'$this->currentTest',".
  257. "'$this->paramType',$this->useWSDL,".
  258. $this->dbc->quote($test_name).",".
  259. $this->dbc->quote($success).",".
  260. $this->dbc->quote($error).",".
  261. ($wire?$this->dbc->quote($wire):"''").")";
  262. #echo "\n".$sql;
  263. $res = $this->dbc->query($sql);
  264. if (DB::isError($res)) {
  265. die ($res->getMessage());
  266. }
  267. if (is_object($res)) $res->free();
  268. }
  269. /**
  270. * decodeSoapval
  271. * decodes a soap value to php type, used for test result comparisons
  272. *
  273. * @param SOAP_Value soapval
  274. * @return mixed result
  275. * @access public
  276. */
  277. function decodeSoapval($soapval)
  278. {
  279. if (gettype($soapval) == "object" &&
  280. (strcasecmp(get_class($soapval),"SoapParam") == 0 ||
  281. strcasecmp(get_class($soapval),"SoapVar") == 0)) {
  282. if (strcasecmp(get_class($soapval),"SoapParam") == 0)
  283. $val = $soapval->param_data->enc_value;
  284. else
  285. $val = $soapval->enc_value;
  286. } else {
  287. $val = $soapval;
  288. }
  289. if (is_array($val)) {
  290. foreach($val as $k => $v) {
  291. if (gettype($v) == "object" &&
  292. (strcasecmp(get_class($soapval),"SoapParam") == 0 ||
  293. strcasecmp(get_class($soapval),"SoapVar") == 0)) {
  294. $val[$k] = $this->decodeSoapval($v);
  295. }
  296. }
  297. }
  298. return $val;
  299. }
  300. /**
  301. * compareResult
  302. * compare two php types for a match
  303. *
  304. * @param string expect
  305. * @param string test_result
  306. * @return boolean result
  307. * @access public
  308. */
  309. function compareResult($expect, $result, $type = NULL)
  310. {
  311. return compare($expect, $result);
  312. }
  313. /**
  314. * doEndpointMethod
  315. * run a method on an endpoint and store it's results to the database
  316. *
  317. * @param array endpoint_info
  318. * @param SOAP_Test test
  319. * @return boolean result
  320. * @access public
  321. */
  322. function doEndpointMethod(&$endpoint_info, &$soap_test) {
  323. $ok = FALSE;
  324. // prepare a holder for the test results
  325. $soap_test->result['class'] = $this->currentTest;
  326. $soap_test->result['type'] = $this->paramType;
  327. $soap_test->result['wsdl'] = $this->useWSDL;
  328. if ($this->useWSDL) {
  329. if (array_key_exists('wsdlURL',$endpoint_info)) {
  330. if (!array_key_exists('client',$endpoint_info)) {
  331. try {
  332. $endpoint_info['client'] = new SoapClient($endpoint_info['wsdlURL'], array("trace"=>1));
  333. } catch (SoapFault $ex) {
  334. $endpoint_info['client']->wsdl->fault = $ex;
  335. }
  336. }
  337. $soap =& $endpoint_info['client'];
  338. # XXX how do we determine a failure on retrieving/parsing wsdl?
  339. if ($soap->wsdl->fault) {
  340. $fault = $soap->wsdl->fault;
  341. $soap_test->setResult(0,'WSDL',
  342. $fault->faultstring."\n\n".$fault->detail,
  343. $fault->faultstring,
  344. $fault
  345. );
  346. return FALSE;
  347. }
  348. } else {
  349. $fault = new SoapFault('WSDL',"no WSDL defined for $endpoint");
  350. $soap_test->setResult(0,'WSDL',
  351. $fault->faultstring,
  352. $fault->faultstring,
  353. $fault
  354. );
  355. return FALSE;
  356. }
  357. $namespace = false;
  358. $soapaction = false;
  359. } else {
  360. $namespace = $soapaction = 'http://soapinterop.org/';
  361. // hack to make tests work with MS SoapToolkit
  362. // it's the only one that uses this soapaction, and breaks if
  363. // it isn't right. Can't wait for soapaction to be fully deprecated
  364. if ($this->currentTest == 'base' &&
  365. strstr($endpoint_info['endpointName'],'MS SOAP ToolKit 2.0')) {
  366. $soapaction = 'urn:soapinterop';
  367. }
  368. if (!array_key_exists('client',$endpoint_info)) {
  369. $endpoint_info['client'] = new SoapClient(null,array('location'=>$endpoint_info['endpointURL'],'uri'=>$soapaction,'trace'=>1));
  370. }
  371. $soap = $endpoint_info['client'];
  372. }
  373. // // add headers to the test
  374. // if ($soap_test->headers) {
  375. // // $header is already a SOAP_Header class
  376. // foreach ($soap_test->headers as $header) {
  377. // $soap->addHeader($header);
  378. // }
  379. // }
  380. // XXX no way to set encoding
  381. // this lets us set UTF-8, US-ASCII or other
  382. //$soap->setEncoding($soap_test->encoding);
  383. try {
  384. if ($this->useWSDL && !$soap_test->headers && !$soap_test->headers_expect) {
  385. $args = '';
  386. foreach ($soap_test->method_params as $pname => $param) {
  387. $arg = '$soap_test->method_params["'.$pname.'"]';
  388. $args .= $args?','.$arg:$arg;
  389. }
  390. $return = eval('return $soap->'.$soap_test->method_name.'('.$args.');');
  391. } else {
  392. if ($soap_test->headers || $soap_test->headers_expect) {
  393. $return = $soap->__soapCall($soap_test->method_name,$soap_test->method_params,array('soapaction'=>$soapaction,'uri'=>$namespace), $soap_test->headers, $result_headers);
  394. } else {
  395. $return = $soap->__soapCall($soap_test->method_name,$soap_test->method_params,array('soapaction'=>$soapaction,'uri'=>$namespace));
  396. }
  397. }
  398. } catch (SoapFault $ex) {
  399. $return = $ex;
  400. }
  401. if(!is_soap_fault($return)){
  402. if ($soap_test->expect !== NULL) {
  403. $sent = $soap_test->expect;
  404. } else if (is_array($soap_test->method_params) && count($soap_test->method_params) == 1) {
  405. reset($soap_test->method_params);
  406. $sent = current($soap_test->method_params);
  407. } else if (is_array($soap_test->method_params) && count($soap_test->method_params) == 0) {
  408. $sent = null;
  409. } else {
  410. $sent = $soap_test->method_params;
  411. }
  412. // compare header results
  413. $headers_ok = TRUE;
  414. if ($soap_test->headers || $soap_test->headers_expect) {
  415. $headers_ok = $this->compareResult($soap_test->headers_expect, $result_headers);
  416. }
  417. # we need to decode what we sent so we can compare!
  418. $sent_d = $this->decodeSoapval($sent);
  419. $soap_test->result['sent'] = $sent;
  420. $soap_test->result['return'] = $return;
  421. // compare the results with what we sent
  422. if ($soap_test->cmp_func !== NULL) {
  423. $cmp_func = $soap_test->cmp_func;
  424. $ok = $cmp_func($sent_d,$return);
  425. } else {
  426. $ok = $this->compareResult($sent_d,$return, $sent->type);
  427. if (!$ok && $soap_test->expect) {
  428. $ok = $this->compareResult($soap_test->expect,$return);
  429. }
  430. }
  431. // save the wire
  432. $wire = "REQUEST:\n".str_replace('" ',"\" \n",str_replace('>',">\n",$soap->__getlastrequest()))."\n\n".
  433. "RESPONSE:\n".str_replace('" ',"\" \n",str_replace('>',">\n",$soap->__getlastresponse()))."\n\n".
  434. "EXPECTED:\n".var_dump_str($sent_d)."\n".
  435. "RESULTL:\n".var_dump_str($return);
  436. if ($soap_test->headers_expect) {
  437. $wire .= "\nEXPECTED HEADERS:\n".var_dump_str($soap_test->headers_expect)."\n".
  438. "RESULT HEADERS:\n".var_dump_str($result_headers);
  439. }
  440. #print "Wire:".htmlentities($wire);
  441. if($ok){
  442. if (!$headers_ok) {
  443. $fault = new SoapFault('HEADER','The returned result did not match what we expected to receive');
  444. $soap_test->setResult(0,$fault->faultcode,
  445. $wire,
  446. $fault->faultstring,
  447. $fault
  448. );
  449. } else {
  450. $soap_test->setResult(1,'OK',$wire);
  451. $success = TRUE;
  452. }
  453. } else {
  454. $fault = new SoapFault('RESULT','The returned result did not match what we expected to receive');
  455. $soap_test->setResult(0,$fault->faultcode,
  456. $wire,
  457. $fault->faultstring,
  458. $fault
  459. );
  460. }
  461. } else {
  462. $fault = $return;
  463. if ($soap_test->expect_fault) {
  464. $ok = 1;
  465. $res = 'OK';
  466. } else {
  467. $ok = 0;
  468. $res =$fault->faultcode;
  469. $pos = strpos($res,':');
  470. if ($pos !== false) {
  471. $res = substr($res,$pos+1);
  472. }
  473. }
  474. // save the wire
  475. $wire = "REQUEST:\n".str_replace('" ',"\" \n",str_replace('>',">\n",$soap->__getlastrequest()))."\n\n".
  476. "RESPONSE:\n".str_replace('" ',"\" \n",str_replace('>',">\n",$soap->__getlastresponse()))."\n".
  477. "RESULTL:\n".var_dump_str($return);
  478. #print "Wire:".htmlentities($wire);
  479. $soap_test->setResult($ok,$res, $wire,$fault->faultstring, $fault);
  480. }
  481. return $ok;
  482. }
  483. /**
  484. * doTest
  485. * run a single round of tests
  486. *
  487. * @access public
  488. */
  489. function doTest() {
  490. global $soap_tests;
  491. // get endpoints for this test
  492. $this->getEndpoints($this->currentTest);
  493. #clear totals
  494. $this->totals = array();
  495. $i = 0;
  496. foreach($this->endpoints as $endpoint => $endpoint_info){
  497. // if we specify an endpoint, skip until we find it
  498. if ($this->specificEndpoint && $endpoint != $this->specificEndpoint) continue;
  499. if ($this->useWSDL && !$endpoint_info['endpointURL']) continue;
  500. $skipendpoint = FALSE;
  501. $this->totals['servers']++;
  502. #$endpoint_info['tests'] = array();
  503. if ($this->show) {
  504. print "Processing $endpoint at {$endpoint_info['endpointURL']}";
  505. if ($this->html) print "<br>\n"; else print "\n";
  506. }
  507. foreach($soap_tests[$this->currentTest] as $soap_test) {
  508. //foreach(array_keys($method_params[$this->currentTest][$this->paramType]) as $method)
  509. // only run the type of test we're looking for (php or soapval)
  510. if ($soap_test->type != $this->paramType) continue;
  511. // if we haven't reached our startpoint, skip
  512. if ($this->startAt && $this->startAt != $endpoint_info['endpointName']) continue;
  513. $this->startAt = '';
  514. // if this is in our skip list, skip it
  515. if (in_array($endpoint, $this->skipEndpointList)) {
  516. $skipendpoint = TRUE;
  517. $skipfault = new SoapFault('SKIP','endpoint skipped');
  518. $soap_test->setResult(0,$fault->faultcode, '',
  519. $skipfault->faultstring,
  520. $skipfault
  521. );
  522. #$endpoint_info['tests'][] = &$soap_test;
  523. #$soap_test->showTestResult($this->debug, $this->html);
  524. #$this->_saveResults($endpoint_info['id'], $soap_test->method_name);
  525. $soap_test->result = NULL;
  526. continue;
  527. }
  528. // if we're looking for a specific method, skip unless we have it
  529. if ($this->testMethod && strcmp($this->testMethod,$soap_test->test_name) != 0) continue;
  530. // if we are skipping the rest of the tests (due to error) note a fault
  531. if ($skipendpoint) {
  532. $soap_test->setResult(0,$fault->faultcode, '',
  533. $skipfault->faultstring,
  534. $skipfault
  535. );
  536. #$endpoint_info['tests'][] = &$soap_test;
  537. $this->totals['fail']++;
  538. } else {
  539. // run the endpoint test
  540. if ($this->doEndpointMethod($endpoint_info, $soap_test)) {
  541. $this->totals['success']++;
  542. } else {
  543. $skipendpoint = $soap_test->result['fault']->faultcode=='HTTP'
  544. && strstr($soap_test->result['fault']->faultstring,'Connect Error');
  545. $skipfault = $soap_test->result['fault'];
  546. $this->totals['fail']++;
  547. }
  548. #$endpoint_info['tests'][] = &$soap_test;
  549. }
  550. $soap_test->showTestResult($this->debug, $this->html);
  551. $this->_saveResults($endpoint_info['id'], $soap_test);
  552. $soap_test->result = NULL;
  553. $this->totals['calls']++;
  554. }
  555. if ($this->numservers && ++$i >= $this->numservers) break;
  556. }
  557. }
  558. function doGroupTests() {
  559. $dowsdl = array(0,1);
  560. foreach($dowsdl as $usewsdl) {
  561. $this->useWSDL = $usewsdl;
  562. foreach($this->paramTypes as $ptype) {
  563. // skip a pointless test
  564. if ($usewsdl && $ptype == 'soapval') break;
  565. $this->paramType = $ptype;
  566. $this->doTest();
  567. }
  568. }
  569. }
  570. /**
  571. * doTests
  572. * go all out. This takes time.
  573. *
  574. * @access public
  575. */
  576. function doTests() {
  577. // the mother of all interop tests
  578. $dowsdl = array(0,1);
  579. foreach($this->tests as $test) {
  580. $this->currentTest = $test;
  581. foreach($dowsdl as $usewsdl) {
  582. $this->useWSDL = $usewsdl;
  583. foreach($this->paramTypes as $ptype) {
  584. // skip a pointless test
  585. if ($usewsdl && $ptype == 'soapval') break;
  586. $this->paramType = $ptype;
  587. $this->doTest();
  588. }
  589. }
  590. }
  591. }
  592. // ***********************************************************
  593. // output functions
  594. /**
  595. * getResults
  596. * retrieve results from the database, stuff them into the endpoint array
  597. *
  598. * @access private
  599. */
  600. function getMethodList($test = 'base') {
  601. // retrieve the results and put them into the endpoint info
  602. $sql = "select distinct(function) from results where class='$test' order by function";
  603. $results = $this->dbc->getAll($sql);
  604. $ar = array();
  605. foreach($results as $result) {
  606. $ar[] = $result[0];
  607. }
  608. return $ar;
  609. }
  610. function outputTable()
  611. {
  612. $methods = $this->getMethodList($this->currentTest);
  613. if (!$methods) return;
  614. $this->getResults($this->currentTest,$this->paramType,$this->useWSDL);
  615. echo "<b>Testing $this->currentTest ";
  616. if ($this->useWSDL) echo "using WSDL ";
  617. else echo "using Direct calls ";
  618. echo "with $this->paramType values</b><br>\n";
  619. // calculate totals for this table
  620. $this->totals['success'] = 0;
  621. $this->totals['fail'] = 0;
  622. $this->totals['servers'] = 0; #count($this->endpoints);
  623. foreach ($this->endpoints as $endpoint => $endpoint_info) {
  624. if (count($endpoint_info['methods']) > 0) {
  625. $this->totals['servers']++;
  626. foreach ($methods as $method) {
  627. $r = $endpoint_info['methods'][$method]['result'];
  628. if ($r == 'OK') $this->totals['success']++;
  629. else $this->totals['fail']++;
  630. }
  631. } else {
  632. unset($this->endpoints[$endpoint]);
  633. }
  634. }
  635. $this->totals['calls'] = count($methods) * $this->totals['servers'];
  636. echo "\n\n<b>Servers: {$this->totals['servers']} Calls: {$this->totals['calls']} Success: {$this->totals['success']} Fail: {$this->totals['fail']}</b><br>\n";
  637. echo "<table border=\"1\" cellspacing=\"0\" cellpadding=\"2\">\n";
  638. echo "<tr><td class=\"BLANK\">Endpoint</td>\n";
  639. foreach ($methods as $method) {
  640. $info = split(':', $method);
  641. echo "<td class='BLANK' valign='top'>";
  642. foreach ($info as $m) {
  643. $hi = split(',',$m);
  644. echo '<b>'.$hi[0]."</b><br>\n";
  645. if (count($hi) > 1) {
  646. echo "&nbsp;&nbsp;Actor=".($hi[1]?'Target':'Not Target')."<br>\n";
  647. echo "&nbsp;&nbsp;MustUnderstand=$hi[2]<br>\n";
  648. }
  649. }
  650. echo "</td>\n";
  651. }
  652. echo "</tr>\n";
  653. $faults = array();
  654. $fi = 0;
  655. foreach ($this->endpoints as $endpoint => $endpoint_info) {
  656. if (array_key_exists('wsdlURL',$endpoint_info)) {
  657. echo "<tr><td class=\"BLANK\"><a href=\"{$endpoint_info['wsdlURL']}\">$endpoint</a></td>\n";
  658. } else {
  659. echo "<tr><td class=\"BLANK\">$endpoint</td>\n";
  660. }
  661. foreach ($methods as $method) {
  662. $id = $endpoint_info['methods'][$method]['id'];
  663. $r = $endpoint_info['methods'][$method]['result'];
  664. $e = $endpoint_info['methods'][$method]['error'];
  665. if ($e) {
  666. $faults[$fi++] = $e;
  667. }
  668. if ($r) {
  669. echo "<td class='$r'><a href='$PHP_SELF?wire=$id'>$r</a></td>\n";
  670. } else {
  671. echo "<td class='untested'>untested</td>\n";
  672. }
  673. }
  674. echo "</tr>\n";
  675. }
  676. echo "</table><br>\n";
  677. if ($this->showFaults && count($faults) > 0) {
  678. echo "<b>ERROR Details:</b><br>\n<ul>\n";
  679. # output more error detail
  680. foreach ($faults as $fault) {
  681. echo '<li>'.HTMLSpecialChars($fault)."</li>\n";
  682. }
  683. }
  684. echo "</ul><br><br>\n";
  685. }
  686. function outputTables() {
  687. // the mother of all interop tests
  688. $dowsdl = array(0,1);
  689. foreach($this->tests as $test) {
  690. $this->currentTest = $test;
  691. foreach($dowsdl as $usewsdl) {
  692. $this->useWSDL = $usewsdl;
  693. foreach($this->paramTypes as $ptype) {
  694. // skip a pointless test
  695. if ($usewsdl && $ptype == 'soapval') break;
  696. $this->paramType = $ptype;
  697. $this->outputTable();
  698. }
  699. }
  700. }
  701. }
  702. function showWire($id) {
  703. $results = $this->dbc->getAll("select * from results where id=$id",NULL, DB_FETCHMODE_ASSOC );
  704. #$wire = preg_replace("/>/",">\n",$results[0]['wire']);
  705. $wire = $results[0]['wire'];
  706. if ($this->html) print "<pre>";
  707. echo "\n".HTMLSpecialChars($wire);
  708. if ($this->html) print "</pre>";
  709. print "\n";
  710. }
  711. }
  712. ?>