client_round2_interop.php 30 KB

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