AutoDiscoverTest.php 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904
  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. /** Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence */
  14. require_once "Zend/Soap/Wsdl/Strategy/ArrayOfTypeSequence.php";
  15. /** Include Common TestTypes */
  16. require_once "_files/commontypes.php";
  17. /**
  18. * Test cases for Zend_Soap_AutoDiscover
  19. *
  20. * @package Zend_Soap
  21. * @subpackage UnitTests
  22. */
  23. class Zend_Soap_AutoDiscoverTest extends PHPUnit_Framework_TestCase
  24. {
  25. public function setUp()
  26. {
  27. // This has to be done because some CLI setups don't have $_SERVER variables
  28. // to simuulate that we have an actual webserver.
  29. if(!isset($_SERVER) || !is_array($_SERVER)) {
  30. $_SERVER = array();
  31. }
  32. $_SERVER['HTTP_HOST'] = 'localhost';
  33. $_SERVER['REQUEST_URI'] = '/my_script.php?wsdl';
  34. $_SERVER['SCRIPT_NAME'] = '/my_script.php';
  35. $_SERVER['HTTPS'] = "off";
  36. }
  37. protected function sanitizeWsdlXmlOutputForOsCompability($xmlstring)
  38. {
  39. $xmlstring = str_replace(array("\r", "\n"), "", $xmlstring);
  40. $xmlstring = preg_replace('/(>[\s]{1,}<)/', '', $xmlstring);
  41. return $xmlstring;
  42. }
  43. function testSetClass()
  44. {
  45. $scriptUri = 'http://localhost/my_script.php';
  46. $server = new Zend_Soap_AutoDiscover();
  47. $server->setClass('Zend_Soap_AutoDiscover_Test');
  48. $dom = new DOMDocument();
  49. ob_start();
  50. $server->handle();
  51. $dom->loadXML(ob_get_clean());
  52. ob_end_clean();
  53. $wsdl = '<?xml version="1.0"?>'
  54. . '<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" '
  55. . 'xmlns:tns="' . $scriptUri . '" '
  56. . 'xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" '
  57. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  58. . 'xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" '
  59. . 'xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" '
  60. . 'name="Zend_Soap_AutoDiscover_Test" '
  61. . 'targetNamespace="' . $scriptUri . '">'
  62. . '<types>'
  63. . '<xsd:schema targetNamespace="' . $scriptUri . '"/>'
  64. . '</types>'
  65. . '<portType name="Zend_Soap_AutoDiscover_TestPort">'
  66. . '<operation name="testFunc1">'
  67. . '<documentation>Test Function 1</documentation>'
  68. . '<input message="tns:testFunc1In"/>'
  69. . '<output message="tns:testFunc1Out"/>'
  70. . '</operation>'
  71. . '<operation name="testFunc2">'
  72. . '<documentation>Test Function 2</documentation>'
  73. . '<input message="tns:testFunc2In"/>'
  74. . '<output message="tns:testFunc2Out"/>'
  75. . '</operation>'
  76. . '<operation name="testFunc3">'
  77. . '<documentation>Test Function 3</documentation>'
  78. . '<input message="tns:testFunc3In"/>'
  79. . '<output message="tns:testFunc3Out"/>'
  80. . '</operation><operation name="testFunc4">'
  81. . '<documentation>Test Function 4</documentation>'
  82. . '<input message="tns:testFunc4In"/>'
  83. . '<output message="tns:testFunc4Out"/>'
  84. . '</operation>'
  85. . '</portType>'
  86. . '<binding name="Zend_Soap_AutoDiscover_TestBinding" type="tns:Zend_Soap_AutoDiscover_TestPort">'
  87. . '<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>'
  88. . '<operation name="testFunc1">'
  89. . '<soap:operation soapAction="' . $scriptUri . '#testFunc1"/>'
  90. . '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></input>'
  91. . '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></output>'
  92. . '</operation>'
  93. . '<operation name="testFunc2">'
  94. . '<soap:operation soapAction="' . $scriptUri . '#testFunc2"/>'
  95. . '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></input>'
  96. . '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></output>'
  97. . '</operation>'
  98. . '<operation name="testFunc3">'
  99. . '<soap:operation soapAction="' . $scriptUri . '#testFunc3"/>'
  100. . '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></input>'
  101. . '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></output>'
  102. . '</operation>'
  103. . '<operation name="testFunc4">'
  104. . '<soap:operation soapAction="' . $scriptUri . '#testFunc4"/>'
  105. . '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></input>'
  106. . '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></output>'
  107. . '</operation>'
  108. . '</binding>'
  109. . '<service name="Zend_Soap_AutoDiscover_TestService">'
  110. . '<port name="Zend_Soap_AutoDiscover_TestPort" binding="tns:Zend_Soap_AutoDiscover_TestBinding">'
  111. . '<soap:address location="' . $scriptUri . '"/>'
  112. . '</port>'
  113. . '</service>'
  114. . '<message name="testFunc1In"/>'
  115. . '<message name="testFunc1Out"><part name="return" type="xsd:string"/></message>'
  116. . '<message name="testFunc2In"><part name="who" type="xsd:string"/></message>'
  117. . '<message name="testFunc2Out"><part name="return" type="xsd:string"/></message>'
  118. . '<message name="testFunc3In"><part name="who" type="xsd:string"/><part name="when" type="xsd:int"/></message>'
  119. . '<message name="testFunc3Out"><part name="return" type="xsd:string"/></message>'
  120. . '<message name="testFunc4In"/>'
  121. . '<message name="testFunc4Out"><part name="return" type="xsd:string"/></message>'
  122. . '</definitions>';
  123. $dom->save(dirname(__FILE__).'/_files/setclass.wsdl');
  124. $this->assertEquals($wsdl, $this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML()));
  125. $this->assertTrue($dom->schemaValidate(dirname(__FILE__) .'/schemas/wsdl.xsd'), "WSDL Did not validate");
  126. unlink(dirname(__FILE__).'/_files/setclass.wsdl');
  127. }
  128. function testSetClassWithDifferentStyles()
  129. {
  130. $scriptUri = 'http://localhost/my_script.php';
  131. $server = new Zend_Soap_AutoDiscover();
  132. $server->setBindingStyle(array('style' => 'document', 'transport' => 'http://framework.zend.com'));
  133. $server->setOperationBodyStyle(array('use' => 'literal', 'namespace' => 'http://framework.zend.com'));
  134. $server->setClass('Zend_Soap_AutoDiscover_Test');
  135. $dom = new DOMDocument();
  136. ob_start();
  137. $server->handle();
  138. $dom->loadXML(ob_get_clean());
  139. ob_end_clean();
  140. $wsdl = '<?xml version="1.0"?>'
  141. . '<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" '
  142. . 'xmlns:tns="' . $scriptUri . '" '
  143. . 'xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" '
  144. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  145. . 'xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" '
  146. . 'xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" '
  147. . 'name="Zend_Soap_AutoDiscover_Test" '
  148. . 'targetNamespace="' . $scriptUri . '">'
  149. . '<types>'
  150. . '<xsd:schema targetNamespace="' . $scriptUri . '">'
  151. . '<xsd:element name="testFunc1">'
  152. . '<xsd:complexType/>'
  153. . '</xsd:element>'
  154. . '<xsd:element name="testFunc1Response">'
  155. . '<xsd:complexType>'
  156. . '<xsd:sequence>'
  157. . '<xsd:element name="testFunc1Result" type="xsd:string"/>'
  158. . '</xsd:sequence>'
  159. . '</xsd:complexType>'
  160. . '</xsd:element>'
  161. . '<xsd:element name="testFunc2">'
  162. . '<xsd:complexType>'
  163. . '<xsd:sequence>'
  164. . '<xsd:element name="who" type="xsd:string"/>'
  165. . '</xsd:sequence>'
  166. . '</xsd:complexType>'
  167. . '</xsd:element>'
  168. . '<xsd:element name="testFunc2Response">'
  169. . '<xsd:complexType>'
  170. . '<xsd:sequence>'
  171. . '<xsd:element name="testFunc2Result" type="xsd:string"/>'
  172. . '</xsd:sequence>'
  173. . '</xsd:complexType>'
  174. . '</xsd:element>'
  175. . '<xsd:element name="testFunc3">'
  176. . '<xsd:complexType>'
  177. . '<xsd:sequence>'
  178. . '<xsd:element name="who" type="xsd:string"/>'
  179. . '<xsd:element name="when" type="xsd:int"/>'
  180. . '</xsd:sequence>'
  181. . '</xsd:complexType>'
  182. . '</xsd:element>'
  183. . '<xsd:element name="testFunc3Response">'
  184. . '<xsd:complexType>'
  185. . '<xsd:sequence>'
  186. . '<xsd:element name="testFunc3Result" type="xsd:string"/>'
  187. . '</xsd:sequence>'
  188. . '</xsd:complexType>'
  189. . '</xsd:element>'
  190. . '<xsd:element name="testFunc4">'
  191. . '<xsd:complexType/>'
  192. . '</xsd:element>'
  193. . '<xsd:element name="testFunc4Response">'
  194. . '<xsd:complexType>'
  195. . '<xsd:sequence>'
  196. . '<xsd:element name="testFunc4Result" type="xsd:string"/>'
  197. . '</xsd:sequence>'
  198. . '</xsd:complexType>'
  199. . '</xsd:element>'
  200. . '</xsd:schema>'
  201. . '</types>'
  202. . '<portType name="Zend_Soap_AutoDiscover_TestPort">'
  203. . '<operation name="testFunc1">'
  204. . '<documentation>Test Function 1</documentation>'
  205. . '<input message="tns:testFunc1In"/>'
  206. . '<output message="tns:testFunc1Out"/>'
  207. . '</operation>'
  208. . '<operation name="testFunc2">'
  209. . '<documentation>Test Function 2</documentation>'
  210. . '<input message="tns:testFunc2In"/>'
  211. . '<output message="tns:testFunc2Out"/>'
  212. . '</operation>'
  213. . '<operation name="testFunc3">'
  214. . '<documentation>Test Function 3</documentation>'
  215. . '<input message="tns:testFunc3In"/>'
  216. . '<output message="tns:testFunc3Out"/>'
  217. . '</operation><operation name="testFunc4">'
  218. . '<documentation>Test Function 4</documentation>'
  219. . '<input message="tns:testFunc4In"/>'
  220. . '<output message="tns:testFunc4Out"/>'
  221. . '</operation>'
  222. . '</portType>'
  223. . '<binding name="Zend_Soap_AutoDiscover_TestBinding" type="tns:Zend_Soap_AutoDiscover_TestPort">'
  224. . '<soap:binding style="document" transport="http://framework.zend.com"/>'
  225. . '<operation name="testFunc1">'
  226. . '<soap:operation soapAction="' . $scriptUri . '#testFunc1"/>'
  227. . '<input><soap:body use="literal" namespace="http://framework.zend.com"/></input>'
  228. . '<output><soap:body use="literal" namespace="http://framework.zend.com"/></output>'
  229. . '</operation>'
  230. . '<operation name="testFunc2">'
  231. . '<soap:operation soapAction="' . $scriptUri . '#testFunc2"/>'
  232. . '<input><soap:body use="literal" namespace="http://framework.zend.com"/></input>'
  233. . '<output><soap:body use="literal" namespace="http://framework.zend.com"/></output>'
  234. . '</operation>'
  235. . '<operation name="testFunc3">'
  236. . '<soap:operation soapAction="' . $scriptUri . '#testFunc3"/>'
  237. . '<input><soap:body use="literal" namespace="http://framework.zend.com"/></input>'
  238. . '<output><soap:body use="literal" namespace="http://framework.zend.com"/></output>'
  239. . '</operation>'
  240. . '<operation name="testFunc4">'
  241. . '<soap:operation soapAction="' . $scriptUri . '#testFunc4"/>'
  242. . '<input><soap:body use="literal" namespace="http://framework.zend.com"/></input>'
  243. . '<output><soap:body use="literal" namespace="http://framework.zend.com"/></output>'
  244. . '</operation>'
  245. . '</binding>'
  246. . '<service name="Zend_Soap_AutoDiscover_TestService">'
  247. . '<port name="Zend_Soap_AutoDiscover_TestPort" binding="tns:Zend_Soap_AutoDiscover_TestBinding">'
  248. . '<soap:address location="' . $scriptUri . '"/>'
  249. . '</port>'
  250. . '</service>'
  251. . '<message name="testFunc1In">'
  252. . '<part name="parameters" element="tns:testFunc1"/>'
  253. . '</message>'
  254. . '<message name="testFunc1Out">'
  255. . '<part name="parameters" element="tns:testFunc1Response"/>'
  256. . '</message>'
  257. . '<message name="testFunc2In">'
  258. . '<part name="parameters" element="tns:testFunc2"/>'
  259. . '</message>'
  260. . '<message name="testFunc2Out">'
  261. . '<part name="parameters" element="tns:testFunc2Response"/>'
  262. . '</message>'
  263. . '<message name="testFunc3In">'
  264. . '<part name="parameters" element="tns:testFunc3"/>'
  265. . '</message>'
  266. . '<message name="testFunc3Out">'
  267. . '<part name="parameters" element="tns:testFunc3Response"/>'
  268. . '</message>'
  269. . '<message name="testFunc4In">'
  270. . '<part name="parameters" element="tns:testFunc4"/>'
  271. . '</message>'
  272. . '<message name="testFunc4Out">'
  273. . '<part name="parameters" element="tns:testFunc4Response"/>'
  274. . '</message>'
  275. . '</definitions>';
  276. $dom->save(dirname(__FILE__).'/_files/setclass.wsdl');
  277. $this->assertEquals($wsdl, $this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML()));
  278. $this->assertTrue($dom->schemaValidate(dirname(__FILE__) .'/schemas/wsdl.xsd'), "WSDL Did not validate");
  279. unlink(dirname(__FILE__).'/_files/setclass.wsdl');
  280. }
  281. /**
  282. * @group ZF-5072
  283. */
  284. function testSetClassWithResponseReturnPartCompabilityMode()
  285. {
  286. $scriptUri = 'http://localhost/my_script.php';
  287. $server = new Zend_Soap_AutoDiscover();
  288. $server->setClass('Zend_Soap_AutoDiscover_Test');
  289. $dom = new DOMDocument();
  290. ob_start();
  291. $server->handle();
  292. $dom->loadXML(ob_get_clean());
  293. ob_end_clean();
  294. $dom->save(dirname(__FILE__).'/_files/setclass.wsdl');
  295. $this->assertContains('<message name="testFunc1Out"><part name="return"', $this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML()));
  296. $this->assertContains('<message name="testFunc2Out"><part name="return"', $this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML()));
  297. $this->assertContains('<message name="testFunc3Out"><part name="return"', $this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML()));
  298. $this->assertContains('<message name="testFunc4Out"><part name="return"', $this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML()));
  299. unlink(dirname(__FILE__).'/_files/setclass.wsdl');
  300. }
  301. function testAddFunctionSimple()
  302. {
  303. $scriptUri = 'http://localhost/my_script.php';
  304. $server = new Zend_Soap_AutoDiscover();
  305. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
  306. $dom = new DOMDocument();
  307. ob_start();
  308. $server->handle();
  309. $dom->loadXML(ob_get_contents());
  310. $dom->save(dirname(__FILE__).'/_files/addfunction.wsdl');
  311. ob_end_clean();
  312. $parts = explode('.', basename($_SERVER['SCRIPT_NAME']));
  313. $name = $parts[0];
  314. $wsdl = '<?xml version="1.0"?>'.
  315. '<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 . '">'.
  316. '<types><xsd:schema targetNamespace="' . $scriptUri . '"/></types>'.
  317. '<portType name="' .$name. 'Port">'.
  318. '<operation name="Zend_Soap_AutoDiscover_TestFunc"><documentation>Test Function</documentation><input message="tns:Zend_Soap_AutoDiscover_TestFuncIn"/><output message="tns:Zend_Soap_AutoDiscover_TestFuncOut"/></operation>'.
  319. '</portType>'.
  320. '<binding name="' .$name. 'Binding" type="tns:' .$name. 'Port">'.
  321. '<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>'.
  322. '<operation name="Zend_Soap_AutoDiscover_TestFunc">'.
  323. '<soap:operation soapAction="' . $scriptUri . '#Zend_Soap_AutoDiscover_TestFunc"/>'.
  324. '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost/my_script.php"/></input>'.
  325. '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost/my_script.php"/></output>'.
  326. '</operation>'.
  327. '</binding>'.
  328. '<service name="' .$name. 'Service">'.
  329. '<port name="' .$name. 'Port" binding="tns:' .$name. 'Binding">'.
  330. '<soap:address location="' . $scriptUri . '"/>'.
  331. '</port>'.
  332. '</service>'.
  333. '<message name="Zend_Soap_AutoDiscover_TestFuncIn"><part name="who" type="xsd:string"/></message>'.
  334. '<message name="Zend_Soap_AutoDiscover_TestFuncOut"><part name="return" type="xsd:string"/></message>'.
  335. '</definitions>';
  336. $this->assertEquals($wsdl, $this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML()), "Bad WSDL generated");
  337. $this->assertTrue($dom->schemaValidate(dirname(__FILE__) .'/schemas/wsdl.xsd'), "WSDL Did not validate");
  338. unlink(dirname(__FILE__).'/_files/addfunction.wsdl');
  339. }
  340. function testAddFunctionSimpleWithDifferentStyle()
  341. {
  342. $scriptUri = 'http://localhost/my_script.php';
  343. $server = new Zend_Soap_AutoDiscover();
  344. $server->setBindingStyle(array('style' => 'document', 'transport' => 'http://framework.zend.com'));
  345. $server->setOperationBodyStyle(array('use' => 'literal', 'namespace' => 'http://framework.zend.com'));
  346. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
  347. $dom = new DOMDocument();
  348. ob_start();
  349. $server->handle();
  350. $dom->loadXML(ob_get_contents());
  351. $dom->save(dirname(__FILE__).'/_files/addfunction.wsdl');
  352. ob_end_clean();
  353. $parts = explode('.', basename($_SERVER['SCRIPT_NAME']));
  354. $name = $parts[0];
  355. $wsdl = '<?xml version="1.0"?>'.
  356. '<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 . '">'.
  357. '<types>'.
  358. '<xsd:schema targetNamespace="' . $scriptUri . '">'.
  359. '<xsd:element name="Zend_Soap_AutoDiscover_TestFunc"><xsd:complexType><xsd:sequence><xsd:element name="who" type="xsd:string"/></xsd:sequence></xsd:complexType></xsd:element>'.
  360. '<xsd:element name="Zend_Soap_AutoDiscover_TestFuncResponse"><xsd:complexType><xsd:sequence><xsd:element name="Zend_Soap_AutoDiscover_TestFuncResult" type="xsd:string"/></xsd:sequence></xsd:complexType></xsd:element>'.
  361. '</xsd:schema>'.
  362. '</types>'.
  363. '<portType name="' .$name. 'Port">'.
  364. '<operation name="Zend_Soap_AutoDiscover_TestFunc"><documentation>Test Function</documentation><input message="tns:Zend_Soap_AutoDiscover_TestFuncIn"/><output message="tns:Zend_Soap_AutoDiscover_TestFuncOut"/></operation>'.
  365. '</portType>'.
  366. '<binding name="' .$name. 'Binding" type="tns:' .$name. 'Port">'.
  367. '<soap:binding style="document" transport="http://framework.zend.com"/>'.
  368. '<operation name="Zend_Soap_AutoDiscover_TestFunc">'.
  369. '<soap:operation soapAction="' . $scriptUri . '#Zend_Soap_AutoDiscover_TestFunc"/>'.
  370. '<input><soap:body use="literal" namespace="http://framework.zend.com"/></input>'.
  371. '<output><soap:body use="literal" namespace="http://framework.zend.com"/></output>'.
  372. '</operation>'.
  373. '</binding>'.
  374. '<service name="' .$name. 'Service">'.
  375. '<port name="' .$name. 'Port" binding="tns:' .$name. 'Binding">'.
  376. '<soap:address location="' . $scriptUri . '"/>'.
  377. '</port>'.
  378. '</service>'.
  379. '<message name="Zend_Soap_AutoDiscover_TestFuncIn"><part name="parameters" element="tns:Zend_Soap_AutoDiscover_TestFunc"/></message>'.
  380. '<message name="Zend_Soap_AutoDiscover_TestFuncOut"><part name="parameters" element="tns:Zend_Soap_AutoDiscover_TestFuncResponse"/></message>'.
  381. '</definitions>';
  382. $this->assertEquals($wsdl, $this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML()), "Bad WSDL generated");
  383. $this->assertTrue($dom->schemaValidate(dirname(__FILE__) .'/schemas/wsdl.xsd'), "WSDL Did not validate");
  384. unlink(dirname(__FILE__).'/_files/addfunction.wsdl');
  385. }
  386. /**
  387. * @group ZF-5072
  388. */
  389. function testAddFunctionSimpleInReturnNameCompabilityMode()
  390. {
  391. $scriptUri = 'http://localhost/my_script.php';
  392. $server = new Zend_Soap_AutoDiscover();
  393. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
  394. $dom = new DOMDocument();
  395. ob_start();
  396. $server->handle();
  397. $dom->loadXML(ob_get_contents());
  398. $dom->save(dirname(__FILE__).'/_files/addfunction.wsdl');
  399. ob_end_clean();
  400. $parts = explode('.', basename($_SERVER['SCRIPT_NAME']));
  401. $name = $parts[0];
  402. $wsdl = $this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML());
  403. $this->assertContains('<message name="Zend_Soap_AutoDiscover_TestFuncOut"><part name="return" type="xsd:string"/>', $wsdl);
  404. $this->assertNotContains('<message name="Zend_Soap_AutoDiscover_TestFuncOut"><part name="Zend_Soap_AutoDiscover_TestFuncReturn"', $wsdl);
  405. $this->assertTrue($dom->schemaValidate(dirname(__FILE__) .'/schemas/wsdl.xsd'), "WSDL Did not validate");
  406. unlink(dirname(__FILE__).'/_files/addfunction.wsdl');
  407. }
  408. function testAddFunctionMultiple()
  409. {
  410. $scriptUri = 'http://localhost/my_script.php';
  411. $server = new Zend_Soap_AutoDiscover();
  412. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
  413. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc2');
  414. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc3');
  415. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc4');
  416. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc5');
  417. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc6');
  418. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc7');
  419. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc9');
  420. $dom = new DOMDocument();
  421. ob_start();
  422. $server->handle();
  423. $dom->loadXML(ob_get_contents());
  424. $dom->save(dirname(__FILE__).'/_files/addfunction2.wsdl');
  425. ob_end_clean();
  426. $parts = explode('.', basename($_SERVER['SCRIPT_NAME']));
  427. $name = $parts[0];
  428. $wsdl = '<?xml version="1.0"?>'.
  429. '<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 . '">'.
  430. '<types><xsd:schema targetNamespace="' . $scriptUri . '"/></types>'.
  431. '<portType name="' .$name. 'Port">'.
  432. '<operation name="Zend_Soap_AutoDiscover_TestFunc"><documentation>Test Function</documentation><input message="tns:Zend_Soap_AutoDiscover_TestFuncIn"/><output message="tns:Zend_Soap_AutoDiscover_TestFuncOut"/></operation>'.
  433. '<operation name="Zend_Soap_AutoDiscover_TestFunc2"><documentation>Test Function 2</documentation><input message="tns:Zend_Soap_AutoDiscover_TestFunc2In"/></operation>'.
  434. '<operation name="Zend_Soap_AutoDiscover_TestFunc3"><documentation>Return false</documentation><input message="tns:Zend_Soap_AutoDiscover_TestFunc3In"/><output message="tns:Zend_Soap_AutoDiscover_TestFunc3Out"/></operation>'.
  435. '<operation name="Zend_Soap_AutoDiscover_TestFunc4"><documentation>Return true</documentation><input message="tns:Zend_Soap_AutoDiscover_TestFunc4In"/><output message="tns:Zend_Soap_AutoDiscover_TestFunc4Out"/></operation>'.
  436. '<operation name="Zend_Soap_AutoDiscover_TestFunc5"><documentation>Return integer</documentation><input message="tns:Zend_Soap_AutoDiscover_TestFunc5In"/><output message="tns:Zend_Soap_AutoDiscover_TestFunc5Out"/></operation>'.
  437. '<operation name="Zend_Soap_AutoDiscover_TestFunc6"><documentation>Return string</documentation><input message="tns:Zend_Soap_AutoDiscover_TestFunc6In"/><output message="tns:Zend_Soap_AutoDiscover_TestFunc6Out"/></operation>'.
  438. '<operation name="Zend_Soap_AutoDiscover_TestFunc7"><documentation>Return array</documentation><input message="tns:Zend_Soap_AutoDiscover_TestFunc7In"/><output message="tns:Zend_Soap_AutoDiscover_TestFunc7Out"/></operation>'.
  439. '<operation name="Zend_Soap_AutoDiscover_TestFunc9"><documentation>Multiple Args</documentation><input message="tns:Zend_Soap_AutoDiscover_TestFunc9In"/><output message="tns:Zend_Soap_AutoDiscover_TestFunc9Out"/></operation>'.
  440. '</portType>'.
  441. '<binding name="' .$name. 'Binding" type="tns:' .$name. 'Port">'.
  442. '<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>'.
  443. '<operation name="Zend_Soap_AutoDiscover_TestFunc">'.
  444. '<soap:operation soapAction="' . $scriptUri . '#Zend_Soap_AutoDiscover_TestFunc"/>'.
  445. '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></input>'.
  446. '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></output>'.
  447. '</operation>'.
  448. '<operation name="Zend_Soap_AutoDiscover_TestFunc2">'.
  449. '<soap:operation soapAction="' . $scriptUri . '#Zend_Soap_AutoDiscover_TestFunc2"/>'.
  450. '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></input>'.
  451. '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></output>'.
  452. '</operation>'.
  453. '<operation name="Zend_Soap_AutoDiscover_TestFunc3">'.
  454. '<soap:operation soapAction="' . $scriptUri . '#Zend_Soap_AutoDiscover_TestFunc3"/>'.
  455. '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></input>'.
  456. '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></output>'.
  457. '</operation>'.
  458. '<operation name="Zend_Soap_AutoDiscover_TestFunc4">'.
  459. '<soap:operation soapAction="' . $scriptUri . '#Zend_Soap_AutoDiscover_TestFunc4"/>'.
  460. '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></input>'.
  461. '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></output>'.
  462. '</operation>'.
  463. '<operation name="Zend_Soap_AutoDiscover_TestFunc5">'.
  464. '<soap:operation soapAction="' . $scriptUri . '#Zend_Soap_AutoDiscover_TestFunc5"/>'.
  465. '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></input>'.
  466. '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></output>'.
  467. '</operation>'.
  468. '<operation name="Zend_Soap_AutoDiscover_TestFunc6">'.
  469. '<soap:operation soapAction="' . $scriptUri . '#Zend_Soap_AutoDiscover_TestFunc6"/>'.
  470. '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></input>'.
  471. '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></output>'.
  472. '</operation>'.
  473. '<operation name="Zend_Soap_AutoDiscover_TestFunc7">'.
  474. '<soap:operation soapAction="' . $scriptUri . '#Zend_Soap_AutoDiscover_TestFunc7"/>'.
  475. '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></input>'.
  476. '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></output>'.
  477. '</operation>'.
  478. '<operation name="Zend_Soap_AutoDiscover_TestFunc9">'.
  479. '<soap:operation soapAction="' . $scriptUri . '#Zend_Soap_AutoDiscover_TestFunc9"/>'.
  480. '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></input>'.
  481. '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></output>'.
  482. '</operation>'.
  483. '</binding>'.
  484. '<service name="' .$name. 'Service">'.
  485. '<port name="' .$name. 'Port" binding="tns:' .$name. 'Binding">'.
  486. '<soap:address location="' . $scriptUri . '"/>'.
  487. '</port>'.
  488. '</service>'.
  489. '<message name="Zend_Soap_AutoDiscover_TestFuncIn"><part name="who" type="xsd:string"/></message>'.
  490. '<message name="Zend_Soap_AutoDiscover_TestFuncOut"><part name="return" type="xsd:string"/></message>'.
  491. '<message name="Zend_Soap_AutoDiscover_TestFunc2In"/>'.
  492. '<message name="Zend_Soap_AutoDiscover_TestFunc3In"/>'.
  493. '<message name="Zend_Soap_AutoDiscover_TestFunc3Out"><part name="return" type="xsd:boolean"/></message>'.
  494. '<message name="Zend_Soap_AutoDiscover_TestFunc4In"/>'.
  495. '<message name="Zend_Soap_AutoDiscover_TestFunc4Out"><part name="return" type="xsd:boolean"/></message>'.
  496. '<message name="Zend_Soap_AutoDiscover_TestFunc5In"/>'.
  497. '<message name="Zend_Soap_AutoDiscover_TestFunc5Out"><part name="return" type="xsd:int"/></message>'.
  498. '<message name="Zend_Soap_AutoDiscover_TestFunc6In"/>'.
  499. '<message name="Zend_Soap_AutoDiscover_TestFunc6Out"><part name="return" type="xsd:string"/></message>'.
  500. '<message name="Zend_Soap_AutoDiscover_TestFunc7In"/>'.
  501. '<message name="Zend_Soap_AutoDiscover_TestFunc7Out"><part name="return" type="soap-enc:Array"/></message>'.
  502. '<message name="Zend_Soap_AutoDiscover_TestFunc9In"><part name="foo" type="xsd:string"/><part name="bar" type="xsd:string"/></message>'.
  503. '<message name="Zend_Soap_AutoDiscover_TestFunc9Out"><part name="return" type="xsd:string"/></message>'.
  504. '</definitions>';
  505. $this->assertEquals($wsdl, $this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML()), "Generated WSDL did not match expected XML");
  506. $this->assertTrue($dom->schemaValidate(dirname(__FILE__) .'/schemas/wsdl.xsd'), "WSDL Did not validate");
  507. unlink(dirname(__FILE__).'/_files/addfunction2.wsdl');
  508. }
  509. /**
  510. * @group ZF-4117
  511. */
  512. public function testUseHttpsSchemaIfAccessedThroughHttps()
  513. {
  514. $_SERVER['HTTPS'] = "on";
  515. $httpsScriptUri = 'https://localhost/my_script.php';
  516. $server = new Zend_Soap_AutoDiscover();
  517. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
  518. ob_start();
  519. $server->handle();
  520. $wsdlOutput = ob_get_contents();
  521. ob_end_clean();
  522. $this->assertContains($httpsScriptUri, $wsdlOutput);
  523. }
  524. /**
  525. * @group ZF-4117
  526. */
  527. public function testChangeWsdlUriInConstructor()
  528. {
  529. $scriptUri = 'http://localhost/my_script.php';
  530. $server = new Zend_Soap_AutoDiscover(true, "http://example.com/service.php");
  531. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
  532. ob_start();
  533. $server->handle();
  534. $wsdlOutput = ob_get_contents();
  535. ob_end_clean();
  536. $this->assertNotContains($scriptUri, $wsdlOutput);
  537. $this->assertContains("http://example.com/service.php", $wsdlOutput);
  538. }
  539. /**
  540. * @group ZF-4117
  541. */
  542. public function testChangeWsdlUriViaSetUri()
  543. {
  544. $scriptUri = 'http://localhost/my_script.php';
  545. $server = new Zend_Soap_AutoDiscover(true);
  546. $server->setUri("http://example.com/service.php");
  547. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
  548. ob_start();
  549. $server->handle();
  550. $wsdlOutput = ob_get_contents();
  551. ob_end_clean();
  552. $this->assertNotContains($scriptUri, $wsdlOutput);
  553. $this->assertContains("http://example.com/service.php", $wsdlOutput);
  554. }
  555. public function testSetNonStringNonZendUriUriThrowsException()
  556. {
  557. $server = new Zend_Soap_AutoDiscover();
  558. try {
  559. $server->setUri(array("bogus"));
  560. $this->fail();
  561. } catch(Zend_Soap_AutoDiscover_Exception $e) {
  562. }
  563. }
  564. /**
  565. * @group ZF-4117
  566. */
  567. public function testChangingWsdlUriAfterGenerationIsPossible()
  568. {
  569. $scriptUri = 'http://localhost/my_script.php';
  570. $server = new Zend_Soap_AutoDiscover(true);
  571. $server->setUri("http://example.com/service.php");
  572. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
  573. ob_start();
  574. $server->handle();
  575. $wsdlOutput = ob_get_contents();
  576. ob_end_clean();
  577. $this->assertNotContains($scriptUri, $wsdlOutput);
  578. $this->assertContains("http://example.com/service.php", $wsdlOutput);
  579. $server->setUri("http://example2.com/service2.php");
  580. ob_start();
  581. $server->handle();
  582. $wsdlOutput = ob_get_contents();
  583. ob_end_clean();
  584. $this->assertNotContains($scriptUri, $wsdlOutput);
  585. $this->assertNotContains("http://example.com/service.php", $wsdlOutput);
  586. $this->assertContains("http://example2.com/service2.php", $wsdlOutput);
  587. }
  588. /**
  589. * @group ZF-4688
  590. * @group ZF-4125
  591. *
  592. */
  593. public function testUsingClassWithMultipleMethodPrototypesProducesValidWsdl()
  594. {
  595. $scriptUri = 'http://localhost/my_script.php';
  596. $server = new Zend_Soap_AutoDiscover();
  597. $server->setClass('Zend_Soap_AutoDiscover_TestFixingMultiplePrototypes');
  598. ob_start();
  599. $server->handle();
  600. $wsdlOutput = ob_get_contents();
  601. ob_end_clean();
  602. $this->assertEquals(1, substr_count($wsdlOutput, '<message name="testFuncIn">'));
  603. $this->assertEquals(1, substr_count($wsdlOutput, '<message name="testFuncOut">'));
  604. }
  605. public function testUnusedFunctionsOfAutoDiscoverThrowException()
  606. {
  607. $server = new Zend_Soap_AutoDiscover();
  608. try {
  609. $server->setPersistence("bogus");
  610. $this->fail();
  611. } catch(Zend_Soap_AutoDiscover_Exception $e) {
  612. }
  613. try {
  614. $server->fault();
  615. $this->fail();
  616. } catch(Zend_Soap_AutoDiscover_Exception $e) {
  617. }
  618. try {
  619. $server->loadFunctions("bogus");
  620. $this->fail();
  621. } catch(Zend_Soap_AutoDiscover_Exception $e) {
  622. }
  623. }
  624. public function testGetFunctions()
  625. {
  626. $server = new Zend_Soap_AutoDiscover();
  627. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
  628. $server->setClass('Zend_Soap_AutoDiscover_Test');
  629. $functions = $server->getFunctions();
  630. $this->assertEquals(
  631. array('Zend_Soap_AutoDiscover_TestFunc', 'testFunc1', 'testFunc2', 'testFunc3', 'testFunc4'),
  632. $functions
  633. );
  634. }
  635. /**
  636. * @group ZF-4835
  637. */
  638. public function testUsingRequestUriWithoutParametersAsDefault()
  639. {
  640. // Apache
  641. $_SERVER = array('REQUEST_URI' => '/my_script.php?wsdl', 'HTTP_HOST' => 'localhost');
  642. $server = new Zend_Soap_AutoDiscover();
  643. $uri = $server->getUri()->getUri();
  644. $this->assertNotContains("?wsdl", $uri);
  645. $this->assertEquals("http://localhost/my_script.php", $uri);
  646. // Apache plus SSL
  647. $_SERVER = array('REQUEST_URI' => '/my_script.php?wsdl', 'HTTP_HOST' => 'localhost', 'HTTPS' => 'on');
  648. $server = new Zend_Soap_AutoDiscover();
  649. $uri = $server->getUri()->getUri();
  650. $this->assertNotContains("?wsdl", $uri);
  651. $this->assertEquals("https://localhost/my_script.php", $uri);
  652. // IIS 5 + PHP as FastCGI
  653. $_SERVER = array('ORIG_PATH_INFO' => '/my_script.php?wsdl', 'SERVER_NAME' => 'localhost');
  654. $server = new Zend_Soap_AutoDiscover();
  655. $uri = $server->getUri()->getUri();
  656. $this->assertNotContains("?wsdl", $uri);
  657. $this->assertEquals("http://localhost/my_script.php", $uri);
  658. // IIS
  659. $_SERVER = array('HTTP_X_REWRITE_URL' => '/my_script.php?wsdl', 'SERVER_NAME' => 'localhost');
  660. $server = new Zend_Soap_AutoDiscover();
  661. $uri = $server->getUri()->getUri();
  662. $this->assertNotContains("?wsdl", $uri);
  663. $this->assertEquals("http://localhost/my_script.php", $uri);
  664. }
  665. /**
  666. * @group ZF-4937
  667. */
  668. public function testComplexTypesThatAreUsedMultipleTimesAreRecoginzedOnce()
  669. {
  670. $server = new Zend_Soap_AutoDiscover('Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex');
  671. $server->setClass('Zend_Soap_AutoDiscoverTestClass2');
  672. ob_start();
  673. $server->handle();
  674. $wsdlOutput = ob_get_contents();
  675. ob_end_clean();
  676. $this->assertEquals(1,
  677. substr_count($wsdlOutput, 'wsdl:arrayType="tns:Zend_Soap_AutoDiscoverTestClass1[]"'),
  678. 'wsdl:arrayType definition of TestClass1 has to occour once.'
  679. );
  680. $this->assertEquals(1,
  681. substr_count($wsdlOutput, '<xsd:complexType name="Zend_Soap_AutoDiscoverTestClass1">'),
  682. 'Zend_Soap_AutoDiscoverTestClass1 has to be defined once.'
  683. );
  684. $this->assertEquals(1,
  685. substr_count($wsdlOutput, '<xsd:complexType name="ArrayOfZend_Soap_AutoDiscoverTestClass1">'),
  686. 'ArrayOfZend_Soap_AutoDiscoverTestClass1 should be defined once.'
  687. );
  688. $this->assertTrue(
  689. substr_count($wsdlOutput, '<part name="test" type="tns:Zend_Soap_AutoDiscoverTestClass1"/>') >= 1,
  690. 'Zend_Soap_AutoDiscoverTestClass1 appears once or more than once in the message parts section.'
  691. );
  692. }
  693. /**
  694. * @group ZF-5330
  695. */
  696. public function testDumpOrXmlOfAutoDiscover()
  697. {
  698. $server = new Zend_Soap_AutoDiscover();
  699. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
  700. ob_start();
  701. $server->handle();
  702. $wsdlOutput = ob_get_contents();
  703. ob_end_clean();
  704. $this->assertEquals(
  705. $this->sanitizeWsdlXmlOutputForOsCompability($wsdlOutput),
  706. $this->sanitizeWsdlXmlOutputForOsCompability($server->toXml())
  707. );
  708. ob_start();
  709. $server->dump(false);
  710. $wsdlOutput = ob_get_contents();
  711. ob_end_clean();
  712. $this->assertEquals(
  713. $this->sanitizeWsdlXmlOutputForOsCompability($wsdlOutput),
  714. $this->sanitizeWsdlXmlOutputForOsCompability($server->toXml())
  715. );
  716. }
  717. /**
  718. * @group ZF-5330
  719. */
  720. public function testDumpOrXmlOnlyAfterGeneratedAutoDiscoverWsdl()
  721. {
  722. $server = new Zend_Soap_AutoDiscover();
  723. try {
  724. $server->dump(false);
  725. $this->fail();
  726. } catch(Exception $e) {
  727. $this->assertTrue($e instanceof Zend_Soap_AutoDiscover_Exception);
  728. }
  729. try {
  730. $server->toXml();
  731. $this->fail();
  732. } catch(Exception $e) {
  733. $this->assertTrue($e instanceof Zend_Soap_AutoDiscover_Exception);
  734. }
  735. }
  736. /**
  737. * @group ZF-5604
  738. */
  739. public function testReturnSameArrayOfObjectsResponseOnDifferentMethodsWhenArrayComplex()
  740. {
  741. $autodiscover = new Zend_Soap_AutoDiscover('Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex');
  742. $autodiscover->setClass('Zend_Soap_AutoDiscover_MyService');
  743. $wsdl = $autodiscover->toXml();
  744. $this->assertEquals(1, substr_count($wsdl, '<xsd:complexType name="ArrayOfZend_Soap_AutoDiscover_MyResponse">'));
  745. $this->assertEquals(0, substr_count($wsdl, 'tns:My_Response[]'));
  746. }
  747. /**
  748. * @group ZF-5430
  749. */
  750. public function testReturnSameArrayOfObjectsResponseOnDifferentMethodsWhenArraySequence()
  751. {
  752. $autodiscover = new Zend_Soap_AutoDiscover('Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence');
  753. $autodiscover->setClass('Zend_Soap_AutoDiscover_MyServiceSequence');
  754. $wsdl = $autodiscover->toXml();
  755. $this->assertEquals(1, substr_count($wsdl, '<xsd:complexType name="ArrayOfString">'));
  756. $this->assertEquals(1, substr_count($wsdl, '<xsd:complexType name="ArrayOfArrayOfString">'));
  757. $this->assertEquals(1, substr_count($wsdl, '<xsd:complexType name="ArrayOfArrayOfArrayOfString">'));
  758. $this->assertEquals(0, substr_count($wsdl, 'tns:string[]'));
  759. }
  760. /**
  761. * @group ZF-5736
  762. */
  763. public function testAmpersandInUrlIsCorrectlyEncoded()
  764. {
  765. $autodiscover = new Zend_Soap_AutoDiscover();
  766. $autodiscover->setUri("http://example.com/?a=b&amp;b=c");
  767. $autodiscover->setClass("Zend_Soap_AutoDiscover_Test");
  768. $wsdl = $autodiscover->toXml();
  769. $this->assertContains("http://example.com/?a=b&amp;b=c", $wsdl);
  770. }
  771. /**
  772. * @group ZF-6689
  773. */
  774. public function testNoReturnIsOneWayCallInSetClass()
  775. {
  776. $autodiscover = new Zend_Soap_AutoDiscover();
  777. $autodiscover->setClass('Zend_Soap_AutoDiscover_NoReturnType');
  778. $wsdl = $autodiscover->toXml();
  779. $this->assertContains(
  780. '<operation name="pushOneWay"><documentation>@param string $message</documentation><input message="tns:pushOneWayIn"/></operation>',
  781. $wsdl
  782. );
  783. }
  784. /**
  785. * @group ZF-6689
  786. */
  787. public function testNoReturnIsOneWayCallInAddFunction()
  788. {
  789. $autodiscover = new Zend_Soap_AutoDiscover();
  790. $autodiscover->addFunction('Zend_Soap_AutoDiscover_OneWay');
  791. $wsdl = $autodiscover->toXml();
  792. $this->assertContains(
  793. '<operation name="Zend_Soap_AutoDiscover_OneWay"><documentation>@param string $message</documentation><input message="tns:Zend_Soap_AutoDiscover_OneWayIn"/></operation>',
  794. $wsdl
  795. );
  796. }
  797. }