AutoDiscoverTest.php 39 KB

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