PageRenderTime 48ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/DevApp/library/ServerLibraries/ZendFramework/1.7/tests/Zend/Soap/AutoDiscoverTest.php

http://firephp.googlecode.com/
PHP | 742 lines | 527 code | 86 blank | 129 comment | 2 complexity | 3395b7a50db1478374f1d1668b9a029f MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, MIT, Apache-2.0
  1. <?php
  2. /**
  3. * @package Zend_Soap
  4. * @subpackage UnitTests
  5. */
  6. require_once dirname(__FILE__)."/../../TestHelper.php";
  7. /** PHPUnit Test Case */
  8. require_once 'PHPUnit/Framework/TestCase.php';
  9. /** Zend_Soap_AutoDiscover */
  10. require_once 'Zend/Soap/AutoDiscover.php';
  11. /** Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex */
  12. require_once "Zend/Soap/Wsdl/Strategy/ArrayOfTypeComplex.php";
  13. require_once "_files/commontypes.php";
  14. /**
  15. * Test cases for Zend_Soap_AutoDiscover
  16. *
  17. * @package Zend_Soap
  18. * @subpackage UnitTests
  19. */
  20. class Zend_Soap_AutoDiscoverTest extends PHPUnit_Framework_TestCase
  21. {
  22. public function setUp()
  23. {
  24. // This has to be done because some CLI setups don't have $_SERVER variables
  25. // to simuulate that we have an actual webserver.
  26. if(!isset($_SERVER) || !is_array($_SERVER)) {
  27. $_SERVER = array();
  28. }
  29. $_SERVER['HTTP_HOST'] = 'localhost';
  30. $_SERVER['REQUEST_URI'] = '/my_script.php?wsdl';
  31. $_SERVER['SCRIPT_NAME'] = '/my_script.php';
  32. $_SERVER['HTTPS'] = "off";
  33. }
  34. protected function sanatizeWsdlXmlOutputForOsCompability($xmlstring)
  35. {
  36. $xmlstring = str_replace(array("\r", "\n"), "", $xmlstring);
  37. $xmlstring = preg_replace('/(>[\s]{1,}<)/', '', $xmlstring);
  38. return $xmlstring;
  39. }
  40. function testSetClass()
  41. {
  42. $scriptUri = 'http://localhost/my_script.php';
  43. $server = new Zend_Soap_AutoDiscover();
  44. $server->setClass('Zend_Soap_AutoDiscover_Test');
  45. $dom = new DOMDocument();
  46. ob_start();
  47. $server->handle();
  48. $dom->loadXML(ob_get_clean());
  49. $wsdl = '<?xml version="1.0"?>'
  50. . '<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" '
  51. . 'xmlns:tns="' . $scriptUri . '" '
  52. . 'xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" '
  53. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  54. . 'xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" '
  55. . 'xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" '
  56. . 'name="Zend_Soap_AutoDiscover_Test" '
  57. . 'targetNamespace="' . $scriptUri . '">'
  58. . '<portType name="Zend_Soap_AutoDiscover_TestPort">'
  59. . '<operation name="testFunc1">'
  60. . '<input message="tns:testFunc1Request"/>'
  61. . '<output message="tns:testFunc1Response"/>'
  62. . '</operation>'
  63. . '<operation name="testFunc2">'
  64. . '<input message="tns:testFunc2Request"/>'
  65. . '<output message="tns:testFunc2Response"/>'
  66. . '</operation>'
  67. . '<operation name="testFunc3">'
  68. . '<input message="tns:testFunc3Request"/>'
  69. . '<output message="tns:testFunc3Response"/>'
  70. . '</operation><operation name="testFunc4">'
  71. . '<input message="tns:testFunc4Request"/>'
  72. . '<output message="tns:testFunc4Response"/>'
  73. . '</operation>'
  74. . '</portType>'
  75. . '<binding name="Zend_Soap_AutoDiscover_TestBinding" type="tns:Zend_Soap_AutoDiscover_TestPort">'
  76. . '<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>'
  77. . '<operation name="testFunc1">'
  78. . '<soap:operation soapAction="' . $scriptUri . '#testFunc1"/>'
  79. . '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>'
  80. . '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output>'
  81. . '</operation>'
  82. . '<operation name="testFunc2">'
  83. . '<soap:operation soapAction="' . $scriptUri . '#testFunc2"/>'
  84. . '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>'
  85. . '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output>'
  86. . '</operation>'
  87. . '<operation name="testFunc3">'
  88. . '<soap:operation soapAction="' . $scriptUri . '#testFunc3"/>'
  89. . '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>'
  90. . '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output>'
  91. . '</operation>'
  92. . '<operation name="testFunc4">'
  93. . '<soap:operation soapAction="' . $scriptUri . '#testFunc4"/>'
  94. . '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>'
  95. . '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output>'
  96. . '</operation>'
  97. . '</binding>'
  98. . '<service name="Zend_Soap_AutoDiscover_TestService">'
  99. . '<port name="Zend_Soap_AutoDiscover_TestPort" binding="tns:Zend_Soap_AutoDiscover_TestBinding">'
  100. . '<soap:address location="' . $scriptUri . '"/>'
  101. . '</port>'
  102. . '</service>'
  103. . '<message name="testFunc1Request"/>'
  104. . '<message name="testFunc1Response"><part name="testFunc1Return" type="xsd:string"/></message>'
  105. . '<message name="testFunc2Request"><part name="who" type="xsd:string"/></message>'
  106. . '<message name="testFunc2Response"><part name="testFunc2Return" type="xsd:string"/></message>'
  107. . '<message name="testFunc3Request"><part name="who" type="xsd:string"/><part name="when" type="xsd:int"/></message>'
  108. . '<message name="testFunc3Response"><part name="testFunc3Return" type="xsd:string"/></message>'
  109. . '<message name="testFunc4Request"/>'
  110. . '<message name="testFunc4Response"><part name="testFunc4Return" type="xsd:string"/></message>'
  111. . '</definitions>';
  112. $dom->save(dirname(__FILE__).'/_files/setclass.wsdl');
  113. $this->assertEquals($wsdl, $this->sanatizeWsdlXmlOutputForOsCompability($dom->saveXML()));
  114. $this->assertTrue($dom->schemaValidate(dirname(__FILE__) .'/schemas/wsdl.xsd'), "WSDL Did not validate");
  115. unlink(dirname(__FILE__).'/_files/setclass.wsdl');
  116. }
  117. function testAddFunctionSimple()
  118. {
  119. $scriptUri = 'http://localhost/my_script.php';
  120. $server = new Zend_Soap_AutoDiscover();
  121. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
  122. $dom = new DOMDocument();
  123. ob_start();
  124. $server->handle();
  125. $dom->loadXML(ob_get_contents());
  126. $dom->save(dirname(__FILE__).'/_files/addfunction.wsdl');
  127. ob_end_clean();
  128. $parts = explode('.', basename($_SERVER['SCRIPT_NAME']));
  129. $name = $parts[0];
  130. $wsdl = '<?xml version="1.0"?>'.
  131. '<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="' . $scriptUri . '" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="' .$name. '" targetNamespace="' . $scriptUri . '">'.
  132. '<portType name="' .$name. 'Port">'.
  133. '<operation name="Zend_Soap_AutoDiscover_TestFunc"><input message="tns:Zend_Soap_AutoDiscover_TestFuncRequest"/><output message="tns:Zend_Soap_AutoDiscover_TestFuncResponse"/></operation>'.
  134. '</portType>'.
  135. '<binding name="' .$name. 'Binding" type="tns:' .$name. 'Port">'.
  136. '<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>'.
  137. '<operation name="Zend_Soap_AutoDiscover_TestFunc">'.
  138. '<soap:operation soapAction="' . $scriptUri . '#Zend_Soap_AutoDiscover_TestFunc"/>'.
  139. '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>'.
  140. '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output>'.
  141. '</operation>'.
  142. '</binding>'.
  143. '<service name="' .$name. 'Service">'.
  144. '<port name="' .$name. 'Port" binding="tns:' .$name. 'Binding">'.
  145. '<soap:address location="' . $scriptUri . '"/>'.
  146. '</port>'.
  147. '</service>'.
  148. '<message name="Zend_Soap_AutoDiscover_TestFuncRequest"><part name="who" type="xsd:string"/></message>'.
  149. '<message name="Zend_Soap_AutoDiscover_TestFuncResponse"><part name="Zend_Soap_AutoDiscover_TestFuncReturn" type="xsd:string"/></message>'.
  150. '</definitions>';
  151. $this->assertEquals($wsdl, $this->sanatizeWsdlXmlOutputForOsCompability($dom->saveXML()), "Bad WSDL generated");
  152. $this->assertTrue($dom->schemaValidate(dirname(__FILE__) .'/schemas/wsdl.xsd'), "WSDL Did not validate");
  153. unlink(dirname(__FILE__).'/_files/addfunction.wsdl');
  154. }
  155. function testAddFunctionMultiple()
  156. {
  157. $scriptUri = 'http://localhost/my_script.php';
  158. $server = new Zend_Soap_AutoDiscover();
  159. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
  160. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc2');
  161. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc3');
  162. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc4');
  163. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc5');
  164. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc6');
  165. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc7');
  166. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc9');
  167. $dom = new DOMDocument();
  168. ob_start();
  169. $server->handle();
  170. $dom->loadXML(ob_get_contents());
  171. $dom->save(dirname(__FILE__).'/_files/addfunction2.wsdl');
  172. ob_end_clean();
  173. $parts = explode('.', basename($_SERVER['SCRIPT_NAME']));
  174. $name = $parts[0];
  175. $wsdl = '<?xml version="1.0"?>'.
  176. '<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="' . $scriptUri . '" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="' .$name. '" targetNamespace="' . $scriptUri . '">'.
  177. '<portType name="' .$name. 'Port">'.
  178. '<operation name="Zend_Soap_AutoDiscover_TestFunc"><input message="tns:Zend_Soap_AutoDiscover_TestFuncRequest"/><output message="tns:Zend_Soap_AutoDiscover_TestFuncResponse"/></operation>'.
  179. '<operation name="Zend_Soap_AutoDiscover_TestFunc2"><input message="tns:Zend_Soap_AutoDiscover_TestFunc2Request"/><output message="tns:Zend_Soap_AutoDiscover_TestFunc2Response"/></operation>'.
  180. '<operation name="Zend_Soap_AutoDiscover_TestFunc3"><input message="tns:Zend_Soap_AutoDiscover_TestFunc3Request"/><output message="tns:Zend_Soap_AutoDiscover_TestFunc3Response"/></operation>'.
  181. '<operation name="Zend_Soap_AutoDiscover_TestFunc4"><input message="tns:Zend_Soap_AutoDiscover_TestFunc4Request"/><output message="tns:Zend_Soap_AutoDiscover_TestFunc4Response"/></operation>'.
  182. '<operation name="Zend_Soap_AutoDiscover_TestFunc5"><input message="tns:Zend_Soap_AutoDiscover_TestFunc5Request"/><output message="tns:Zend_Soap_AutoDiscover_TestFunc5Response"/></operation>'.
  183. '<operation name="Zend_Soap_AutoDiscover_TestFunc6"><input message="tns:Zend_Soap_AutoDiscover_TestFunc6Request"/><output message="tns:Zend_Soap_AutoDiscover_TestFunc6Response"/></operation>'.
  184. '<operation name="Zend_Soap_AutoDiscover_TestFunc7"><input message="tns:Zend_Soap_AutoDiscover_TestFunc7Request"/><output message="tns:Zend_Soap_AutoDiscover_TestFunc7Response"/></operation>'.
  185. '<operation name="Zend_Soap_AutoDiscover_TestFunc9"><input message="tns:Zend_Soap_AutoDiscover_TestFunc9Request"/><output message="tns:Zend_Soap_AutoDiscover_TestFunc9Response"/></operation>'.
  186. '</portType>'.
  187. '<binding name="' .$name. 'Binding" type="tns:' .$name. 'Port">'.
  188. '<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>'.
  189. '<operation name="Zend_Soap_AutoDiscover_TestFunc">'.
  190. '<soap:operation soapAction="' . $scriptUri . '#Zend_Soap_AutoDiscover_TestFunc"/>'.
  191. '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>'.
  192. '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output>'.
  193. '</operation>'.
  194. '<operation name="Zend_Soap_AutoDiscover_TestFunc2">'.
  195. '<soap:operation soapAction="' . $scriptUri . '#Zend_Soap_AutoDiscover_TestFunc2"/>'.
  196. '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>'.
  197. '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output>'.
  198. '</operation>'.
  199. '<operation name="Zend_Soap_AutoDiscover_TestFunc3">'.
  200. '<soap:operation soapAction="' . $scriptUri . '#Zend_Soap_AutoDiscover_TestFunc3"/>'.
  201. '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>'.
  202. '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output>'.
  203. '</operation>'.
  204. '<operation name="Zend_Soap_AutoDiscover_TestFunc4">'.
  205. '<soap:operation soapAction="' . $scriptUri . '#Zend_Soap_AutoDiscover_TestFunc4"/>'.
  206. '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>'.
  207. '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output>'.
  208. '</operation>'.
  209. '<operation name="Zend_Soap_AutoDiscover_TestFunc5">'.
  210. '<soap:operation soapAction="' . $scriptUri . '#Zend_Soap_AutoDiscover_TestFunc5"/>'.
  211. '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>'.
  212. '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output>'.
  213. '</operation>'.
  214. '<operation name="Zend_Soap_AutoDiscover_TestFunc6">'.
  215. '<soap:operation soapAction="' . $scriptUri . '#Zend_Soap_AutoDiscover_TestFunc6"/>'.
  216. '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>'.
  217. '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output>'.
  218. '</operation>'.
  219. '<operation name="Zend_Soap_AutoDiscover_TestFunc7">'.
  220. '<soap:operation soapAction="' . $scriptUri . '#Zend_Soap_AutoDiscover_TestFunc7"/>'.
  221. '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>'.
  222. '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output>'.
  223. '</operation>'.
  224. '<operation name="Zend_Soap_AutoDiscover_TestFunc9">'.
  225. '<soap:operation soapAction="' . $scriptUri . '#Zend_Soap_AutoDiscover_TestFunc9"/>'.
  226. '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>'.
  227. '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output>'.
  228. '</operation>'.
  229. '</binding>'.
  230. '<service name="' .$name. 'Service">'.
  231. '<port name="' .$name. 'Port" binding="tns:' .$name. 'Binding">'.
  232. '<soap:address location="' . $scriptUri . '"/>'.
  233. '</port>'.
  234. '</service>'.
  235. '<message name="Zend_Soap_AutoDiscover_TestFuncRequest"><part name="who" type="xsd:string"/></message>'.
  236. '<message name="Zend_Soap_AutoDiscover_TestFuncResponse"><part name="Zend_Soap_AutoDiscover_TestFuncReturn" type="xsd:string"/></message>'.
  237. '<message name="Zend_Soap_AutoDiscover_TestFunc2Request"/>'.
  238. '<message name="Zend_Soap_AutoDiscover_TestFunc3Request"/>'.
  239. '<message name="Zend_Soap_AutoDiscover_TestFunc3Response"><part name="Zend_Soap_AutoDiscover_TestFunc3Return" type="xsd:boolean"/></message>'.
  240. '<message name="Zend_Soap_AutoDiscover_TestFunc4Request"/>'.
  241. '<message name="Zend_Soap_AutoDiscover_TestFunc4Response"><part name="Zend_Soap_AutoDiscover_TestFunc4Return" type="xsd:boolean"/></message>'.
  242. '<message name="Zend_Soap_AutoDiscover_TestFunc5Request"/>'.
  243. '<message name="Zend_Soap_AutoDiscover_TestFunc5Response"><part name="Zend_Soap_AutoDiscover_TestFunc5Return" type="xsd:int"/></message>'.
  244. '<message name="Zend_Soap_AutoDiscover_TestFunc6Request"/>'.
  245. '<message name="Zend_Soap_AutoDiscover_TestFunc6Response"><part name="Zend_Soap_AutoDiscover_TestFunc6Return" type="xsd:string"/></message>'.
  246. '<message name="Zend_Soap_AutoDiscover_TestFunc7Request"/>'.
  247. '<message name="Zend_Soap_AutoDiscover_TestFunc7Response"><part name="Zend_Soap_AutoDiscover_TestFunc7Return" type="soap-enc:Array"/></message>'.
  248. '<message name="Zend_Soap_AutoDiscover_TestFunc9Request"><part name="foo" type="xsd:string"/><part name="bar" type="xsd:string"/></message>'.
  249. '<message name="Zend_Soap_AutoDiscover_TestFunc9Response"><part name="Zend_Soap_AutoDiscover_TestFunc9Return" type="xsd:string"/></message>'.
  250. '</definitions>';
  251. $this->assertEquals($wsdl, $this->sanatizeWsdlXmlOutputForOsCompability($dom->saveXML()), "Bad WSDL generated");
  252. $this->assertTrue($dom->schemaValidate(dirname(__FILE__) .'/schemas/wsdl.xsd'), "WSDL Did not validate");
  253. unlink(dirname(__FILE__).'/_files/addfunction2.wsdl');
  254. }
  255. /**
  256. * @group ZF-4117
  257. */
  258. public function testUseHttpsSchemaIfAccessedThroughHttps()
  259. {
  260. $_SERVER['HTTPS'] = "on";
  261. $httpsScriptUri = 'https://localhost/my_script.php';
  262. $server = new Zend_Soap_AutoDiscover();
  263. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
  264. ob_start();
  265. $server->handle();
  266. $wsdlOutput = ob_get_contents();
  267. ob_end_clean();
  268. $this->assertContains($httpsScriptUri, $wsdlOutput);
  269. }
  270. /**
  271. * @group ZF-4117
  272. */
  273. public function testChangeWsdlUriInConstructor()
  274. {
  275. $scriptUri = 'http://localhost/my_script.php';
  276. $server = new Zend_Soap_AutoDiscover(true, "http://example.com/service.php");
  277. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
  278. ob_start();
  279. $server->handle();
  280. $wsdlOutput = ob_get_contents();
  281. ob_end_clean();
  282. $this->assertNotContains($scriptUri, $wsdlOutput);
  283. $this->assertContains("http://example.com/service.php", $wsdlOutput);
  284. }
  285. /**
  286. * @group ZF-4117
  287. */
  288. public function testChangeWsdlUriViaSetUri()
  289. {
  290. $scriptUri = 'http://localhost/my_script.php';
  291. $server = new Zend_Soap_AutoDiscover(true);
  292. $server->setUri("http://example.com/service.php");
  293. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
  294. ob_start();
  295. $server->handle();
  296. $wsdlOutput = ob_get_contents();
  297. ob_end_clean();
  298. $this->assertNotContains($scriptUri, $wsdlOutput);
  299. $this->assertContains("http://example.com/service.php", $wsdlOutput);
  300. }
  301. public function testSetNonStringNonZendUriUriThrowsException()
  302. {
  303. $server = new Zend_Soap_AutoDiscover();
  304. try {
  305. $server->setUri(array("bogus"));
  306. $this->fail();
  307. } catch(Zend_Soap_AutoDiscover_Exception $e) {
  308. }
  309. }
  310. /**
  311. * @group ZF-4117
  312. */
  313. public function testChangingWsdlUriAfterGenerationIsPossible()
  314. {
  315. $scriptUri = 'http://localhost/my_script.php';
  316. $server = new Zend_Soap_AutoDiscover(true);
  317. $server->setUri("http://example.com/service.php");
  318. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
  319. ob_start();
  320. $server->handle();
  321. $wsdlOutput = ob_get_contents();
  322. ob_end_clean();
  323. $this->assertNotContains($scriptUri, $wsdlOutput);
  324. $this->assertContains("http://example.com/service.php", $wsdlOutput);
  325. $server->setUri("http://example2.com/service2.php");
  326. ob_start();
  327. $server->handle();
  328. $wsdlOutput = ob_get_contents();
  329. ob_end_clean();
  330. $this->assertNotContains($scriptUri, $wsdlOutput);
  331. $this->assertNotContains("http://example.com/service.php", $wsdlOutput);
  332. $this->assertContains("http://example2.com/service2.php", $wsdlOutput);
  333. }
  334. /**
  335. * @group ZF-4688
  336. * @group ZF-4125
  337. *
  338. */
  339. public function testUsingClassWithMultipleMethodPrototypesProducesValidWsdl()
  340. {
  341. $scriptUri = 'http://localhost/my_script.php';
  342. $server = new Zend_Soap_AutoDiscover();
  343. $server->setClass('Zend_Soap_AutoDiscover_TestFixingMultiplePrototypes');
  344. ob_start();
  345. $server->handle();
  346. $wsdlOutput = ob_get_contents();
  347. ob_end_clean();
  348. $this->assertEquals(1, substr_count($wsdlOutput, '<message name="testFuncRequest">'));
  349. $this->assertEquals(1, substr_count($wsdlOutput, '<message name="testFuncResponse">'));
  350. }
  351. public function testUnusedFunctionsOfAutoDiscoverThrowException()
  352. {
  353. $server = new Zend_Soap_AutoDiscover();
  354. try {
  355. $server->setPersistence("bogus");
  356. $this->fail();
  357. } catch(Zend_Soap_AutoDiscover_Exception $e) {
  358. }
  359. try {
  360. $server->fault();
  361. $this->fail();
  362. } catch(Zend_Soap_AutoDiscover_Exception $e) {
  363. }
  364. try {
  365. $server->loadFunctions("bogus");
  366. $this->fail();
  367. } catch(Zend_Soap_AutoDiscover_Exception $e) {
  368. }
  369. }
  370. public function testGetFunctions()
  371. {
  372. $server = new Zend_Soap_AutoDiscover();
  373. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
  374. $server->setClass('Zend_Soap_AutoDiscover_Test');
  375. $functions = $server->getFunctions();
  376. $this->assertEquals(
  377. array('Zend_Soap_AutoDiscover_TestFunc', 'testFunc1', 'testFunc2', 'testFunc3', 'testFunc4'),
  378. $functions
  379. );
  380. }
  381. /**
  382. * @group ZF-4835
  383. */
  384. public function testUsingRequestUriWithoutParametersAsDefault()
  385. {
  386. // Apache
  387. $_SERVER = array('REQUEST_URI' => '/my_script.php?wsdl', 'HTTP_HOST' => 'localhost');
  388. $server = new Zend_Soap_AutoDiscover();
  389. $uri = $server->getUri()->getUri();
  390. $this->assertNotContains("?wsdl", $uri);
  391. $this->assertEquals("http://localhost/my_script.php", $uri);
  392. // Apache plus SSL
  393. $_SERVER = array('REQUEST_URI' => '/my_script.php?wsdl', 'HTTP_HOST' => 'localhost', 'HTTPS' => 'on');
  394. $server = new Zend_Soap_AutoDiscover();
  395. $uri = $server->getUri()->getUri();
  396. $this->assertNotContains("?wsdl", $uri);
  397. $this->assertEquals("https://localhost/my_script.php", $uri);
  398. // IIS 5 + PHP as FastCGI
  399. $_SERVER = array('ORIG_PATH_INFO' => '/my_script.php?wsdl', 'SERVER_NAME' => 'localhost');
  400. $server = new Zend_Soap_AutoDiscover();
  401. $uri = $server->getUri()->getUri();
  402. $this->assertNotContains("?wsdl", $uri);
  403. $this->assertEquals("http://localhost/my_script.php", $uri);
  404. // IIS
  405. $_SERVER = array('HTTP_X_REWRITE_URL' => '/my_script.php?wsdl', 'SERVER_NAME' => 'localhost');
  406. $server = new Zend_Soap_AutoDiscover();
  407. $uri = $server->getUri()->getUri();
  408. $this->assertNotContains("?wsdl", $uri);
  409. $this->assertEquals("http://localhost/my_script.php", $uri);
  410. }
  411. /**
  412. * @group ZF-4937
  413. */
  414. public function testComplexTypesThatAreUsedMultipleTimesAreRecoginzedOnce()
  415. {
  416. $server = new Zend_Soap_AutoDiscover('Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex');
  417. $server->setClass('Zend_Soap_AutoDiscoverTestClass2');
  418. ob_start();
  419. $server->handle();
  420. $wsdlOutput = ob_get_contents();
  421. ob_end_clean();
  422. $this->assertEquals(1,
  423. substr_count($wsdlOutput, 'wsdl:arrayType="tns:Zend_Soap_AutoDiscoverTestClass1[]"'),
  424. 'wsdl:arrayType definition of TestClass1 has to occour once.'
  425. );
  426. $this->assertEquals(1,
  427. substr_count($wsdlOutput, '<xsd:complexType name="Zend_Soap_AutoDiscoverTestClass1">'),
  428. 'Zend_Soap_AutoDiscoverTestClass1 has to be defined once.'
  429. );
  430. $this->assertEquals(1,
  431. substr_count($wsdlOutput, '<xsd:complexType name="ArrayOfZend_Soap_AutoDiscoverTestClass1">'),
  432. 'ArrayOfZend_Soap_AutoDiscoverTestClass1 should be defined once.'
  433. );
  434. $this->assertTrue(
  435. substr_count($wsdlOutput, '<part name="test" type="tns:Zend_Soap_AutoDiscoverTestClass1"/>') >= 1,
  436. 'Zend_Soap_AutoDiscoverTestClass1 appears once or more than once in the message parts section.'
  437. );
  438. }
  439. /**
  440. * @group ZF-5604
  441. */
  442. public function testReturnSameArrayOfObjectsResponseOnDifferentMethodsWhenArrayComplex()
  443. {
  444. $autodiscover = new Zend_Soap_AutoDiscover('Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex');
  445. $autodiscover->setClass('Zend_Soap_AutoDiscover_MyService');
  446. ob_start();
  447. $autodiscover->handle();
  448. $wsdl = ob_get_contents();
  449. ob_end_clean();
  450. $this->assertEquals(1, substr_count($wsdl, '<xsd:complexType name="ArrayOfZend_Soap_AutoDiscover_MyResponse">'));
  451. $this->assertEquals(0, substr_count($wsdl, 'tns:My_Response[]'));
  452. }
  453. /**
  454. * @group ZF-5430
  455. */
  456. public function testReturnSameArrayOfObjectsResponseOnDifferentMethodsWhenArraySequence()
  457. {
  458. $autodiscover = new Zend_Soap_AutoDiscover('Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence');
  459. $autodiscover->setClass('Zend_Soap_AutoDiscover_MyServiceSequence');
  460. ob_start();
  461. $autodiscover->handle();
  462. $wsdl = ob_get_contents();
  463. ob_end_clean();
  464. $this->assertEquals(1, substr_count($wsdl, '<xsd:complexType name="ArrayOfString">'));
  465. $this->assertEquals(1, substr_count($wsdl, '<xsd:complexType name="ArrayOfArrayOfString">'));
  466. $this->assertEquals(1, substr_count($wsdl, '<xsd:complexType name="ArrayOfArrayOfArrayOfString">'));
  467. $this->assertEquals(0, substr_count($wsdl, 'tns:string[]'));
  468. }
  469. }
  470. /* Test Functions */
  471. /**
  472. * Test Function
  473. *
  474. * @param string $arg
  475. * @return string
  476. */
  477. function Zend_Soap_AutoDiscover_TestFunc($who)
  478. {
  479. return "Hello $who";
  480. }
  481. /**
  482. * Test Function 2
  483. */
  484. function Zend_Soap_AutoDiscover_TestFunc2()
  485. {
  486. return "Hello World";
  487. }
  488. /**
  489. * Return false
  490. *
  491. * @return bool
  492. */
  493. function Zend_Soap_AutoDiscover_TestFunc3()
  494. {
  495. return false;
  496. }
  497. /**
  498. * Return true
  499. *
  500. * @return bool
  501. */
  502. function Zend_Soap_AutoDiscover_TestFunc4()
  503. {
  504. return true;
  505. }
  506. /**
  507. * Return integer
  508. *
  509. * @return int
  510. */
  511. function Zend_Soap_AutoDiscover_TestFunc5()
  512. {
  513. return 123;
  514. }
  515. /**
  516. * Return string
  517. *
  518. * @return string
  519. */
  520. function Zend_Soap_AutoDiscover_TestFunc6()
  521. {
  522. return "string";
  523. }
  524. /**
  525. * Return array
  526. *
  527. * @return array
  528. */
  529. function Zend_Soap_AutoDiscover_TestFunc7()
  530. {
  531. return array('foo' => 'bar', 'baz' => true, 1 => false, 'bat' => 123);
  532. }
  533. /**
  534. * Return Object
  535. *
  536. * @return StdClass
  537. */
  538. function Zend_Soap_AutoDiscover_TestFunc8()
  539. {
  540. $return = (object) array('foo' => 'bar', 'baz' => true, 'bat' => 123, 'qux' => false);
  541. return $return;
  542. }
  543. /**
  544. * Multiple Args
  545. *
  546. * @param string $foo
  547. * @param string $bar
  548. * @return string
  549. */
  550. function Zend_Soap_AutoDiscover_TestFunc9($foo, $bar)
  551. {
  552. return "$foo $bar";
  553. }
  554. class Zend_Soap_AutoDiscover_TestFixingMultiplePrototypes
  555. {
  556. /**
  557. * Test function
  558. *
  559. * @param integer $a
  560. * @param integer $b
  561. * @param integer $d
  562. * @return integer
  563. */
  564. function testFunc($a=100, $b=200, $d=300)
  565. {
  566. }
  567. }
  568. /**
  569. * Test Class
  570. */
  571. class Zend_Soap_AutoDiscover_Test {
  572. /**
  573. * Test Function 1
  574. *
  575. * @return string
  576. */
  577. function testFunc1()
  578. {
  579. return "Hello World";
  580. }
  581. /**
  582. * Test Function 2
  583. *
  584. * @param string $who Some Arg
  585. * @return string
  586. */
  587. function testFunc2($who)
  588. {
  589. return "Hello $who!";
  590. }
  591. /**
  592. * Test Function 3
  593. *
  594. * @param string $who Some Arg
  595. * @param int $when Some
  596. * @return string
  597. */
  598. function testFunc3($who, $when)
  599. {
  600. return "Hello $who, How are you $when";
  601. }
  602. /**
  603. * Test Function 4
  604. *
  605. * @return string
  606. */
  607. static function testFunc4()
  608. {
  609. return "I'm Static!";
  610. }
  611. }
  612. class Zend_Soap_AutoDiscoverTestClass1
  613. {
  614. /**
  615. * @var integer $var
  616. */
  617. public $var = 1;
  618. /**
  619. * @var string $param
  620. */
  621. public $param = "hello";
  622. }
  623. class Zend_Soap_AutoDiscoverTestClass2
  624. {
  625. /**
  626. *
  627. * @param Zend_Soap_AutoDiscoverTestClass1 $test
  628. * @return boolean
  629. */
  630. public function add(Zend_Soap_AutoDiscoverTestClass1 $test)
  631. {
  632. return true;
  633. }
  634. /**
  635. * @return Zend_Soap_AutoDiscoverTestClass1[]
  636. */
  637. public function fetchAll()
  638. {
  639. return array(
  640. new Zend_Soap_AutoDiscoverTestClass1(),
  641. new Zend_Soap_AutoDiscoverTestClass1(),
  642. );
  643. }
  644. /**
  645. * @param Zend_Soap_AutoDiscoverTestClass1[]
  646. */
  647. public function addMultiple($test)
  648. {
  649. }
  650. }