AutoDiscoverTest.php 46 KB

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