PageRenderTime 56ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/ZendFramework-1.11.12/tests/Zend/Soap/AutoDiscoverTest.php

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