AutoDiscoverTest.php 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887
  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_clean());
  307. $dom->save(dirname(__FILE__).'/_files/addfunction.wsdl');
  308. $parts = explode('.', basename($_SERVER['SCRIPT_NAME']));
  309. $name = $parts[0];
  310. $wsdl = '<?xml version="1.0"?>'.
  311. '<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 . '">'.
  312. '<types><xsd:schema targetNamespace="' . $scriptUri . '"/></types>'.
  313. '<portType name="' .$name. 'Port">'.
  314. '<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>'.
  315. '</portType>'.
  316. '<binding name="' .$name. 'Binding" type="tns:' .$name. 'Port">'.
  317. '<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>'.
  318. '<operation name="Zend_Soap_AutoDiscover_TestFunc">'.
  319. '<soap:operation soapAction="' . $scriptUri . '#Zend_Soap_AutoDiscover_TestFunc"/>'.
  320. '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost/my_script.php"/></input>'.
  321. '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost/my_script.php"/></output>'.
  322. '</operation>'.
  323. '</binding>'.
  324. '<service name="' .$name. 'Service">'.
  325. '<port name="' .$name. 'Port" binding="tns:' .$name. 'Binding">'.
  326. '<soap:address location="' . $scriptUri . '"/>'.
  327. '</port>'.
  328. '</service>'.
  329. '<message name="Zend_Soap_AutoDiscover_TestFuncIn"><part name="who" type="xsd:string"/></message>'.
  330. '<message name="Zend_Soap_AutoDiscover_TestFuncOut"><part name="return" type="xsd:string"/></message>'.
  331. '</definitions>';
  332. $this->assertEquals($wsdl, $this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML()), "Bad WSDL generated");
  333. $this->assertTrue($dom->schemaValidate(dirname(__FILE__) .'/schemas/wsdl.xsd'), "WSDL Did not validate");
  334. unlink(dirname(__FILE__).'/_files/addfunction.wsdl');
  335. }
  336. function testAddFunctionSimpleWithDifferentStyle()
  337. {
  338. $scriptUri = 'http://localhost/my_script.php';
  339. $server = new Zend_Soap_AutoDiscover();
  340. $server->setBindingStyle(array('style' => 'document', 'transport' => 'http://framework.zend.com'));
  341. $server->setOperationBodyStyle(array('use' => 'literal', 'namespace' => 'http://framework.zend.com'));
  342. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
  343. $dom = new DOMDocument();
  344. ob_start();
  345. $server->handle();
  346. $dom->loadXML(ob_get_clean());
  347. $dom->save(dirname(__FILE__).'/_files/addfunction.wsdl');
  348. $parts = explode('.', basename($_SERVER['SCRIPT_NAME']));
  349. $name = $parts[0];
  350. $wsdl = '<?xml version="1.0"?>'.
  351. '<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 . '">'.
  352. '<types>'.
  353. '<xsd:schema targetNamespace="' . $scriptUri . '">'.
  354. '<xsd:element name="Zend_Soap_AutoDiscover_TestFunc"><xsd:complexType><xsd:sequence><xsd:element name="who" type="xsd:string"/></xsd:sequence></xsd:complexType></xsd:element>'.
  355. '<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>'.
  356. '</xsd:schema>'.
  357. '</types>'.
  358. '<portType name="' .$name. 'Port">'.
  359. '<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>'.
  360. '</portType>'.
  361. '<binding name="' .$name. 'Binding" type="tns:' .$name. 'Port">'.
  362. '<soap:binding style="document" transport="http://framework.zend.com"/>'.
  363. '<operation name="Zend_Soap_AutoDiscover_TestFunc">'.
  364. '<soap:operation soapAction="' . $scriptUri . '#Zend_Soap_AutoDiscover_TestFunc"/>'.
  365. '<input><soap:body use="literal" namespace="http://framework.zend.com"/></input>'.
  366. '<output><soap:body use="literal" namespace="http://framework.zend.com"/></output>'.
  367. '</operation>'.
  368. '</binding>'.
  369. '<service name="' .$name. 'Service">'.
  370. '<port name="' .$name. 'Port" binding="tns:' .$name. 'Binding">'.
  371. '<soap:address location="' . $scriptUri . '"/>'.
  372. '</port>'.
  373. '</service>'.
  374. '<message name="Zend_Soap_AutoDiscover_TestFuncIn"><part name="parameters" element="tns:Zend_Soap_AutoDiscover_TestFunc"/></message>'.
  375. '<message name="Zend_Soap_AutoDiscover_TestFuncOut"><part name="parameters" element="tns:Zend_Soap_AutoDiscover_TestFuncResponse"/></message>'.
  376. '</definitions>';
  377. $this->assertEquals($wsdl, $this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML()), "Bad WSDL generated");
  378. $this->assertTrue($dom->schemaValidate(dirname(__FILE__) .'/schemas/wsdl.xsd'), "WSDL Did not validate");
  379. unlink(dirname(__FILE__).'/_files/addfunction.wsdl');
  380. }
  381. /**
  382. * @group ZF-5072
  383. */
  384. function testAddFunctionSimpleInReturnNameCompabilityMode()
  385. {
  386. $scriptUri = 'http://localhost/my_script.php';
  387. $server = new Zend_Soap_AutoDiscover();
  388. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
  389. $dom = new DOMDocument();
  390. ob_start();
  391. $server->handle();
  392. $dom->loadXML(ob_get_clean());
  393. $dom->save(dirname(__FILE__).'/_files/addfunction.wsdl');
  394. $parts = explode('.', basename($_SERVER['SCRIPT_NAME']));
  395. $name = $parts[0];
  396. $wsdl = $this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML());
  397. $this->assertContains('<message name="Zend_Soap_AutoDiscover_TestFuncOut"><part name="return" type="xsd:string"/>', $wsdl);
  398. $this->assertNotContains('<message name="Zend_Soap_AutoDiscover_TestFuncOut"><part name="Zend_Soap_AutoDiscover_TestFuncReturn"', $wsdl);
  399. $this->assertTrue($dom->schemaValidate(dirname(__FILE__) .'/schemas/wsdl.xsd'), "WSDL Did not validate");
  400. unlink(dirname(__FILE__).'/_files/addfunction.wsdl');
  401. }
  402. function testAddFunctionMultiple()
  403. {
  404. $scriptUri = 'http://localhost/my_script.php';
  405. $server = new Zend_Soap_AutoDiscover();
  406. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
  407. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc2');
  408. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc3');
  409. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc4');
  410. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc5');
  411. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc6');
  412. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc7');
  413. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc9');
  414. $dom = new DOMDocument();
  415. ob_start();
  416. $server->handle();
  417. $dom->loadXML(ob_get_clean());
  418. $dom->save(dirname(__FILE__).'/_files/addfunction2.wsdl');
  419. $parts = explode('.', basename($_SERVER['SCRIPT_NAME']));
  420. $name = $parts[0];
  421. $wsdl = '<?xml version="1.0"?>'.
  422. '<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 . '">'.
  423. '<types><xsd:schema targetNamespace="' . $scriptUri . '"/></types>'.
  424. '<portType name="' .$name. 'Port">'.
  425. '<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>'.
  426. '<operation name="Zend_Soap_AutoDiscover_TestFunc2"><documentation>Test Function 2</documentation><input message="tns:Zend_Soap_AutoDiscover_TestFunc2In"/></operation>'.
  427. '<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>'.
  428. '<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>'.
  429. '<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>'.
  430. '<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>'.
  431. '<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>'.
  432. '<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>'.
  433. '</portType>'.
  434. '<binding name="' .$name. 'Binding" type="tns:' .$name. 'Port">'.
  435. '<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>'.
  436. '<operation name="Zend_Soap_AutoDiscover_TestFunc">'.
  437. '<soap:operation soapAction="' . $scriptUri . '#Zend_Soap_AutoDiscover_TestFunc"/>'.
  438. '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></input>'.
  439. '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></output>'.
  440. '</operation>'.
  441. '<operation name="Zend_Soap_AutoDiscover_TestFunc2">'.
  442. '<soap:operation soapAction="' . $scriptUri . '#Zend_Soap_AutoDiscover_TestFunc2"/>'.
  443. '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></input>'.
  444. '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></output>'.
  445. '</operation>'.
  446. '<operation name="Zend_Soap_AutoDiscover_TestFunc3">'.
  447. '<soap:operation soapAction="' . $scriptUri . '#Zend_Soap_AutoDiscover_TestFunc3"/>'.
  448. '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></input>'.
  449. '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></output>'.
  450. '</operation>'.
  451. '<operation name="Zend_Soap_AutoDiscover_TestFunc4">'.
  452. '<soap:operation soapAction="' . $scriptUri . '#Zend_Soap_AutoDiscover_TestFunc4"/>'.
  453. '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></input>'.
  454. '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></output>'.
  455. '</operation>'.
  456. '<operation name="Zend_Soap_AutoDiscover_TestFunc5">'.
  457. '<soap:operation soapAction="' . $scriptUri . '#Zend_Soap_AutoDiscover_TestFunc5"/>'.
  458. '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></input>'.
  459. '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></output>'.
  460. '</operation>'.
  461. '<operation name="Zend_Soap_AutoDiscover_TestFunc6">'.
  462. '<soap:operation soapAction="' . $scriptUri . '#Zend_Soap_AutoDiscover_TestFunc6"/>'.
  463. '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></input>'.
  464. '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></output>'.
  465. '</operation>'.
  466. '<operation name="Zend_Soap_AutoDiscover_TestFunc7">'.
  467. '<soap:operation soapAction="' . $scriptUri . '#Zend_Soap_AutoDiscover_TestFunc7"/>'.
  468. '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></input>'.
  469. '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></output>'.
  470. '</operation>'.
  471. '<operation name="Zend_Soap_AutoDiscover_TestFunc9">'.
  472. '<soap:operation soapAction="' . $scriptUri . '#Zend_Soap_AutoDiscover_TestFunc9"/>'.
  473. '<input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></input>'.
  474. '<output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="' . $scriptUri . '"/></output>'.
  475. '</operation>'.
  476. '</binding>'.
  477. '<service name="' .$name. 'Service">'.
  478. '<port name="' .$name. 'Port" binding="tns:' .$name. 'Binding">'.
  479. '<soap:address location="' . $scriptUri . '"/>'.
  480. '</port>'.
  481. '</service>'.
  482. '<message name="Zend_Soap_AutoDiscover_TestFuncIn"><part name="who" type="xsd:string"/></message>'.
  483. '<message name="Zend_Soap_AutoDiscover_TestFuncOut"><part name="return" type="xsd:string"/></message>'.
  484. '<message name="Zend_Soap_AutoDiscover_TestFunc2In"/>'.
  485. '<message name="Zend_Soap_AutoDiscover_TestFunc3In"/>'.
  486. '<message name="Zend_Soap_AutoDiscover_TestFunc3Out"><part name="return" type="xsd:boolean"/></message>'.
  487. '<message name="Zend_Soap_AutoDiscover_TestFunc4In"/>'.
  488. '<message name="Zend_Soap_AutoDiscover_TestFunc4Out"><part name="return" type="xsd:boolean"/></message>'.
  489. '<message name="Zend_Soap_AutoDiscover_TestFunc5In"/>'.
  490. '<message name="Zend_Soap_AutoDiscover_TestFunc5Out"><part name="return" type="xsd:int"/></message>'.
  491. '<message name="Zend_Soap_AutoDiscover_TestFunc6In"/>'.
  492. '<message name="Zend_Soap_AutoDiscover_TestFunc6Out"><part name="return" type="xsd:string"/></message>'.
  493. '<message name="Zend_Soap_AutoDiscover_TestFunc7In"/>'.
  494. '<message name="Zend_Soap_AutoDiscover_TestFunc7Out"><part name="return" type="soap-enc:Array"/></message>'.
  495. '<message name="Zend_Soap_AutoDiscover_TestFunc9In"><part name="foo" type="xsd:string"/><part name="bar" type="xsd:string"/></message>'.
  496. '<message name="Zend_Soap_AutoDiscover_TestFunc9Out"><part name="return" type="xsd:string"/></message>'.
  497. '</definitions>';
  498. $this->assertEquals($wsdl, $this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML()), "Generated WSDL did not match expected XML");
  499. $this->assertTrue($dom->schemaValidate(dirname(__FILE__) .'/schemas/wsdl.xsd'), "WSDL Did not validate");
  500. unlink(dirname(__FILE__).'/_files/addfunction2.wsdl');
  501. }
  502. /**
  503. * @group ZF-4117
  504. */
  505. public function testUseHttpsSchemaIfAccessedThroughHttps()
  506. {
  507. $_SERVER['HTTPS'] = "on";
  508. $httpsScriptUri = 'https://localhost/my_script.php';
  509. $server = new Zend_Soap_AutoDiscover();
  510. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
  511. ob_start();
  512. $server->handle();
  513. $wsdlOutput = ob_get_clean();
  514. $this->assertContains($httpsScriptUri, $wsdlOutput);
  515. }
  516. /**
  517. * @group ZF-4117
  518. */
  519. public function testChangeWsdlUriInConstructor()
  520. {
  521. $scriptUri = 'http://localhost/my_script.php';
  522. $server = new Zend_Soap_AutoDiscover(true, "http://example.com/service.php");
  523. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
  524. ob_start();
  525. $server->handle();
  526. $wsdlOutput = ob_get_clean();
  527. $this->assertNotContains($scriptUri, $wsdlOutput);
  528. $this->assertContains("http://example.com/service.php", $wsdlOutput);
  529. }
  530. /**
  531. * @group ZF-4117
  532. */
  533. public function testChangeWsdlUriViaSetUri()
  534. {
  535. $scriptUri = 'http://localhost/my_script.php';
  536. $server = new Zend_Soap_AutoDiscover(true);
  537. $server->setUri("http://example.com/service.php");
  538. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
  539. ob_start();
  540. $server->handle();
  541. $wsdlOutput = ob_get_clean();
  542. $this->assertNotContains($scriptUri, $wsdlOutput);
  543. $this->assertContains("http://example.com/service.php", $wsdlOutput);
  544. }
  545. public function testSetNonStringNonZendUriUriThrowsException()
  546. {
  547. $server = new Zend_Soap_AutoDiscover();
  548. try {
  549. $server->setUri(array("bogus"));
  550. $this->fail();
  551. } catch(Zend_Soap_AutoDiscover_Exception $e) {
  552. }
  553. }
  554. /**
  555. * @group ZF-4117
  556. */
  557. public function testChangingWsdlUriAfterGenerationIsPossible()
  558. {
  559. $scriptUri = 'http://localhost/my_script.php';
  560. $server = new Zend_Soap_AutoDiscover(true);
  561. $server->setUri("http://example.com/service.php");
  562. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
  563. ob_start();
  564. $server->handle();
  565. $wsdlOutput = ob_get_clean();
  566. $this->assertNotContains($scriptUri, $wsdlOutput);
  567. $this->assertContains("http://example.com/service.php", $wsdlOutput);
  568. $server->setUri("http://example2.com/service2.php");
  569. ob_start();
  570. $server->handle();
  571. $wsdlOutput = ob_get_clean();
  572. $this->assertNotContains($scriptUri, $wsdlOutput);
  573. $this->assertNotContains("http://example.com/service.php", $wsdlOutput);
  574. $this->assertContains("http://example2.com/service2.php", $wsdlOutput);
  575. }
  576. /**
  577. * @group ZF-4688
  578. * @group ZF-4125
  579. *
  580. */
  581. public function testUsingClassWithMultipleMethodPrototypesProducesValidWsdl()
  582. {
  583. $scriptUri = 'http://localhost/my_script.php';
  584. $server = new Zend_Soap_AutoDiscover();
  585. $server->setClass('Zend_Soap_AutoDiscover_TestFixingMultiplePrototypes');
  586. ob_start();
  587. $server->handle();
  588. $wsdlOutput = ob_get_clean();
  589. $this->assertEquals(1, substr_count($wsdlOutput, '<message name="testFuncIn">'));
  590. $this->assertEquals(1, substr_count($wsdlOutput, '<message name="testFuncOut">'));
  591. }
  592. public function testUnusedFunctionsOfAutoDiscoverThrowException()
  593. {
  594. $server = new Zend_Soap_AutoDiscover();
  595. try {
  596. $server->setPersistence("bogus");
  597. $this->fail();
  598. } catch(Zend_Soap_AutoDiscover_Exception $e) {
  599. }
  600. try {
  601. $server->fault();
  602. $this->fail();
  603. } catch(Zend_Soap_AutoDiscover_Exception $e) {
  604. }
  605. try {
  606. $server->loadFunctions("bogus");
  607. $this->fail();
  608. } catch(Zend_Soap_AutoDiscover_Exception $e) {
  609. }
  610. }
  611. public function testGetFunctions()
  612. {
  613. $server = new Zend_Soap_AutoDiscover();
  614. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
  615. $server->setClass('Zend_Soap_AutoDiscover_Test');
  616. $functions = $server->getFunctions();
  617. $this->assertEquals(
  618. array('Zend_Soap_AutoDiscover_TestFunc', 'testFunc1', 'testFunc2', 'testFunc3', 'testFunc4'),
  619. $functions
  620. );
  621. }
  622. /**
  623. * @group ZF-4835
  624. */
  625. public function testUsingRequestUriWithoutParametersAsDefault()
  626. {
  627. // Apache
  628. $_SERVER = array('REQUEST_URI' => '/my_script.php?wsdl', 'HTTP_HOST' => 'localhost');
  629. $server = new Zend_Soap_AutoDiscover();
  630. $uri = $server->getUri()->getUri();
  631. $this->assertNotContains("?wsdl", $uri);
  632. $this->assertEquals("http://localhost/my_script.php", $uri);
  633. // Apache plus SSL
  634. $_SERVER = array('REQUEST_URI' => '/my_script.php?wsdl', 'HTTP_HOST' => 'localhost', 'HTTPS' => 'on');
  635. $server = new Zend_Soap_AutoDiscover();
  636. $uri = $server->getUri()->getUri();
  637. $this->assertNotContains("?wsdl", $uri);
  638. $this->assertEquals("https://localhost/my_script.php", $uri);
  639. // IIS 5 + PHP as FastCGI
  640. $_SERVER = array('ORIG_PATH_INFO' => '/my_script.php?wsdl', 'SERVER_NAME' => 'localhost');
  641. $server = new Zend_Soap_AutoDiscover();
  642. $uri = $server->getUri()->getUri();
  643. $this->assertNotContains("?wsdl", $uri);
  644. $this->assertEquals("http://localhost/my_script.php", $uri);
  645. // IIS
  646. $_SERVER = array('HTTP_X_REWRITE_URL' => '/my_script.php?wsdl', 'SERVER_NAME' => 'localhost');
  647. $server = new Zend_Soap_AutoDiscover();
  648. $uri = $server->getUri()->getUri();
  649. $this->assertNotContains("?wsdl", $uri);
  650. $this->assertEquals("http://localhost/my_script.php", $uri);
  651. }
  652. /**
  653. * @group ZF-4937
  654. */
  655. public function testComplexTypesThatAreUsedMultipleTimesAreRecoginzedOnce()
  656. {
  657. $server = new Zend_Soap_AutoDiscover('Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex');
  658. $server->setClass('Zend_Soap_AutoDiscoverTestClass2');
  659. ob_start();
  660. $server->handle();
  661. $wsdlOutput = ob_get_clean();
  662. $this->assertEquals(1,
  663. substr_count($wsdlOutput, 'wsdl:arrayType="tns:Zend_Soap_AutoDiscoverTestClass1[]"'),
  664. 'wsdl:arrayType definition of TestClass1 has to occour once.'
  665. );
  666. $this->assertEquals(1,
  667. substr_count($wsdlOutput, '<xsd:complexType name="Zend_Soap_AutoDiscoverTestClass1">'),
  668. 'Zend_Soap_AutoDiscoverTestClass1 has to be defined once.'
  669. );
  670. $this->assertEquals(1,
  671. substr_count($wsdlOutput, '<xsd:complexType name="ArrayOfZend_Soap_AutoDiscoverTestClass1">'),
  672. 'ArrayOfZend_Soap_AutoDiscoverTestClass1 should be defined once.'
  673. );
  674. $this->assertTrue(
  675. substr_count($wsdlOutput, '<part name="test" type="tns:Zend_Soap_AutoDiscoverTestClass1"/>') >= 1,
  676. 'Zend_Soap_AutoDiscoverTestClass1 appears once or more than once in the message parts section.'
  677. );
  678. }
  679. /**
  680. * @group ZF-5330
  681. */
  682. public function testDumpOrXmlOfAutoDiscover()
  683. {
  684. $server = new Zend_Soap_AutoDiscover();
  685. $server->addFunction('Zend_Soap_AutoDiscover_TestFunc');
  686. ob_start();
  687. $server->handle();
  688. $wsdlOutput = ob_get_clean();
  689. $this->assertEquals(
  690. $this->sanitizeWsdlXmlOutputForOsCompability($wsdlOutput),
  691. $this->sanitizeWsdlXmlOutputForOsCompability($server->toXml())
  692. );
  693. ob_start();
  694. $server->dump(false);
  695. $wsdlOutput = ob_get_clean();
  696. $this->assertEquals(
  697. $this->sanitizeWsdlXmlOutputForOsCompability($wsdlOutput),
  698. $this->sanitizeWsdlXmlOutputForOsCompability($server->toXml())
  699. );
  700. }
  701. /**
  702. * @group ZF-5330
  703. */
  704. public function testDumpOrXmlOnlyAfterGeneratedAutoDiscoverWsdl()
  705. {
  706. $server = new Zend_Soap_AutoDiscover();
  707. try {
  708. $server->dump(false);
  709. $this->fail();
  710. } catch(Exception $e) {
  711. $this->assertTrue($e instanceof Zend_Soap_AutoDiscover_Exception);
  712. }
  713. try {
  714. $server->toXml();
  715. $this->fail();
  716. } catch(Exception $e) {
  717. $this->assertTrue($e instanceof Zend_Soap_AutoDiscover_Exception);
  718. }
  719. }
  720. /**
  721. * @group ZF-5604
  722. */
  723. public function testReturnSameArrayOfObjectsResponseOnDifferentMethodsWhenArrayComplex()
  724. {
  725. $autodiscover = new Zend_Soap_AutoDiscover('Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex');
  726. $autodiscover->setClass('Zend_Soap_AutoDiscover_MyService');
  727. $wsdl = $autodiscover->toXml();
  728. $this->assertEquals(1, substr_count($wsdl, '<xsd:complexType name="ArrayOfZend_Soap_AutoDiscover_MyResponse">'));
  729. $this->assertEquals(0, substr_count($wsdl, 'tns:My_Response[]'));
  730. }
  731. /**
  732. * @group ZF-5430
  733. */
  734. public function testReturnSameArrayOfObjectsResponseOnDifferentMethodsWhenArraySequence()
  735. {
  736. $autodiscover = new Zend_Soap_AutoDiscover('Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence');
  737. $autodiscover->setClass('Zend_Soap_AutoDiscover_MyServiceSequence');
  738. $wsdl = $autodiscover->toXml();
  739. $this->assertEquals(1, substr_count($wsdl, '<xsd:complexType name="ArrayOfString">'));
  740. $this->assertEquals(1, substr_count($wsdl, '<xsd:complexType name="ArrayOfArrayOfString">'));
  741. $this->assertEquals(1, substr_count($wsdl, '<xsd:complexType name="ArrayOfArrayOfArrayOfString">'));
  742. $this->assertEquals(0, substr_count($wsdl, 'tns:string[]'));
  743. }
  744. /**
  745. * @group ZF-5736
  746. */
  747. public function testAmpersandInUrlIsCorrectlyEncoded()
  748. {
  749. $autodiscover = new Zend_Soap_AutoDiscover();
  750. $autodiscover->setUri("http://example.com/?a=b&amp;b=c");
  751. $autodiscover->setClass("Zend_Soap_AutoDiscover_Test");
  752. $wsdl = $autodiscover->toXml();
  753. $this->assertContains("http://example.com/?a=b&amp;b=c", $wsdl);
  754. }
  755. /**
  756. * @group ZF-6689
  757. */
  758. public function testNoReturnIsOneWayCallInSetClass()
  759. {
  760. $autodiscover = new Zend_Soap_AutoDiscover();
  761. $autodiscover->setClass('Zend_Soap_AutoDiscover_NoReturnType');
  762. $wsdl = $autodiscover->toXml();
  763. $this->assertContains(
  764. '<operation name="pushOneWay"><documentation>@param string $message</documentation><input message="tns:pushOneWayIn"/></operation>',
  765. $wsdl
  766. );
  767. }
  768. /**
  769. * @group ZF-6689
  770. */
  771. public function testNoReturnIsOneWayCallInAddFunction()
  772. {
  773. $autodiscover = new Zend_Soap_AutoDiscover();
  774. $autodiscover->addFunction('Zend_Soap_AutoDiscover_OneWay');
  775. $wsdl = $autodiscover->toXml();
  776. $this->assertContains(
  777. '<operation name="Zend_Soap_AutoDiscover_OneWay"><documentation>@param string $message</documentation><input message="tns:Zend_Soap_AutoDiscover_OneWayIn"/></operation>',
  778. $wsdl
  779. );
  780. }
  781. }