AutoDiscoverTest.php 47 KB

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