WsdlTest.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  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_Wsdl */
  26. require_once 'Zend/Soap/Wsdl.php';
  27. /**
  28. * Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence
  29. */
  30. require_once 'Zend/Soap/Wsdl/Strategy/ArrayOfTypeSequence.php';
  31. /**
  32. * Test cases for Zend_Soap_Wsdl
  33. *
  34. * @category Zend
  35. * @package Zend_Soap
  36. * @subpackage UnitTests
  37. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  38. * @license http://framework.zend.com/license/new-bsd New BSD License
  39. * @group Zend_Soap
  40. * @group Zend_Soap_Wsdl
  41. */
  42. class Zend_Soap_WsdlTest extends PHPUnit_Framework_TestCase
  43. {
  44. protected function sanitizeWsdlXmlOutputForOsCompability($xmlstring)
  45. {
  46. $xmlstring = str_replace(array("\r", "\n"), "", $xmlstring);
  47. $xmlstring = preg_replace('/(>[\s]{1,}<)/', '', $xmlstring);
  48. return $xmlstring;
  49. }
  50. function testConstructor()
  51. {
  52. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php');
  53. $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()),
  54. '<?xml version="1.0"?>' .
  55. '<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" '
  56. . 'xmlns:tns="http://localhost/MyService.php" '
  57. . 'xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" '
  58. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  59. . 'xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" '
  60. . 'xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" '
  61. . 'name="MyService" targetNamespace="http://localhost/MyService.php"/>' );
  62. }
  63. function testSetUriChangesDomDocumentWsdlStructureTnsAndTargetNamespaceAttributes()
  64. {
  65. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php');
  66. $wsdl->setUri('http://localhost/MyNewService.php');
  67. $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()),
  68. '<?xml version="1.0"?>' .
  69. '<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" '
  70. . 'xmlns:tns="http://localhost/MyNewService.php" '
  71. . 'xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" '
  72. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  73. . 'xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" '
  74. . 'xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" '
  75. . 'name="MyService" targetNamespace="http://localhost/MyNewService.php"/>' );
  76. }
  77. function testAddMessage()
  78. {
  79. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php');
  80. $messageParts = array();
  81. $messageParts['parameter1'] = $wsdl->getType('int');
  82. $messageParts['parameter2'] = $wsdl->getType('string');
  83. $messageParts['parameter3'] = $wsdl->getType('mixed');
  84. $wsdl->addMessage('myMessage', $messageParts);
  85. $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()),
  86. '<?xml version="1.0"?>' .
  87. '<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" '
  88. . 'xmlns:tns="http://localhost/MyService.php" '
  89. . 'xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" '
  90. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  91. . 'xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" '
  92. . 'xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" '
  93. . 'name="MyService" targetNamespace="http://localhost/MyService.php">'
  94. . '<message name="myMessage">'
  95. . '<part name="parameter1" type="xsd:int"/>'
  96. . '<part name="parameter2" type="xsd:string"/>'
  97. . '<part name="parameter3" type="xsd:anyType"/>'
  98. . '</message>'
  99. . '</definitions>' );
  100. }
  101. function testAddPortType()
  102. {
  103. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php');
  104. $wsdl->addPortType('myPortType');
  105. $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()),
  106. '<?xml version="1.0"?>' .
  107. '<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" '
  108. . 'xmlns:tns="http://localhost/MyService.php" '
  109. . 'xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" '
  110. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  111. . 'xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" '
  112. . 'xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" '
  113. . 'name="MyService" targetNamespace="http://localhost/MyService.php">'
  114. . '<portType name="myPortType"/>'
  115. . '</definitions>' );
  116. }
  117. function testAddPortOperation()
  118. {
  119. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php');
  120. $portType = $wsdl->addPortType('myPortType');
  121. $wsdl->addPortOperation($portType, 'operation1');
  122. $wsdl->addPortOperation($portType, 'operation2', 'tns:operation2Request', 'tns:operation2Response');
  123. $wsdl->addPortOperation($portType, 'operation3', 'tns:operation3Request', 'tns:operation3Response', 'tns:operation3Fault');
  124. $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()),
  125. '<?xml version="1.0"?>' .
  126. '<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" '
  127. . 'xmlns:tns="http://localhost/MyService.php" '
  128. . 'xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" '
  129. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  130. . 'xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" '
  131. . 'xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" '
  132. . 'name="MyService" targetNamespace="http://localhost/MyService.php">'
  133. . '<portType name="myPortType">'
  134. . '<operation name="operation1"/>'
  135. . '<operation name="operation2">'
  136. . '<input message="tns:operation2Request"/>'
  137. . '<output message="tns:operation2Response"/>'
  138. . '</operation>'
  139. . '<operation name="operation3">'
  140. . '<input message="tns:operation3Request"/>'
  141. . '<output message="tns:operation3Response"/>'
  142. . '<fault message="tns:operation3Fault"/>'
  143. . '</operation>'
  144. . '</portType>'
  145. . '</definitions>' );
  146. }
  147. function testAddBinding()
  148. {
  149. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php');
  150. $wsdl->addPortType('myPortType');
  151. $wsdl->addBinding('MyServiceBinding', 'myPortType');
  152. $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()),
  153. '<?xml version="1.0"?>' .
  154. '<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" '
  155. . 'xmlns:tns="http://localhost/MyService.php" '
  156. . 'xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" '
  157. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  158. . 'xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" '
  159. . 'xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" '
  160. . 'name="MyService" targetNamespace="http://localhost/MyService.php">'
  161. . '<portType name="myPortType"/>'
  162. . '<binding name="MyServiceBinding" type="myPortType"/>'
  163. . '</definitions>' );
  164. }
  165. function testAddBindingOperation()
  166. {
  167. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php');
  168. $wsdl->addPortType('myPortType');
  169. $binding = $wsdl->addBinding('MyServiceBinding', 'myPortType');
  170. $wsdl->addBindingOperation($binding, 'operation1');
  171. $wsdl->addBindingOperation($binding,
  172. 'operation2',
  173. array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/"),
  174. array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/")
  175. );
  176. $wsdl->addBindingOperation($binding,
  177. 'operation3',
  178. array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/"),
  179. array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/"),
  180. array('name' => 'MyFault', 'use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/")
  181. );
  182. $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()),
  183. '<?xml version="1.0"?>' .
  184. '<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" '
  185. . 'xmlns:tns="http://localhost/MyService.php" '
  186. . 'xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" '
  187. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  188. . 'xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" '
  189. . 'xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" '
  190. . 'name="MyService" targetNamespace="http://localhost/MyService.php">'
  191. . '<portType name="myPortType"/>'
  192. . '<binding name="MyServiceBinding" type="myPortType">'
  193. . '<operation name="operation1"/>'
  194. . '<operation name="operation2">'
  195. . '<input>'
  196. . '<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>'
  197. . '</input>'
  198. . '<output>'
  199. . '<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>'
  200. . '</output>'
  201. . '</operation>'
  202. . '<operation name="operation3">'
  203. . '<input>'
  204. . '<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>'
  205. . '</input>'
  206. . '<output>'
  207. . '<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>'
  208. . '</output>'
  209. . '<fault name="MyFault">'
  210. . '<soap:fault name="MyFault" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>'
  211. . '</fault>'
  212. . '</operation>'
  213. . '</binding>'
  214. . '</definitions>' );
  215. }
  216. function testAddSoapBinding()
  217. {
  218. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php');
  219. $wsdl->addPortType('myPortType');
  220. $binding = $wsdl->addBinding('MyServiceBinding', 'myPortType');
  221. $wsdl->addSoapBinding($binding);
  222. $wsdl->addBindingOperation($binding, 'operation1');
  223. $wsdl->addBindingOperation($binding,
  224. 'operation2',
  225. array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/"),
  226. array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/")
  227. );
  228. $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()),
  229. '<?xml version="1.0"?>' .
  230. '<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" '
  231. . 'xmlns:tns="http://localhost/MyService.php" '
  232. . 'xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" '
  233. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  234. . 'xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" '
  235. . 'xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" '
  236. . 'name="MyService" targetNamespace="http://localhost/MyService.php">'
  237. . '<portType name="myPortType"/>'
  238. . '<binding name="MyServiceBinding" type="myPortType">'
  239. . '<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>'
  240. . '<operation name="operation1"/>'
  241. . '<operation name="operation2">'
  242. . '<input>'
  243. . '<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>'
  244. . '</input>'
  245. . '<output>'
  246. . '<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>'
  247. . '</output>'
  248. . '</operation>'
  249. . '</binding>'
  250. . '</definitions>' );
  251. $wsdl1 = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php');
  252. $wsdl1->addPortType('myPortType');
  253. $binding = $wsdl1->addBinding('MyServiceBinding', 'myPortType');
  254. $wsdl1->addSoapBinding($binding, 'rpc');
  255. $wsdl1->addBindingOperation($binding, 'operation1');
  256. $wsdl1->addBindingOperation($binding,
  257. 'operation2',
  258. array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/"),
  259. array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/")
  260. );
  261. $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl1->toXml()),
  262. '<?xml version="1.0"?>' .
  263. '<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" '
  264. . 'xmlns:tns="http://localhost/MyService.php" '
  265. . 'xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" '
  266. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  267. . 'xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" '
  268. . 'xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" '
  269. . 'name="MyService" targetNamespace="http://localhost/MyService.php">'
  270. . '<portType name="myPortType"/>'
  271. . '<binding name="MyServiceBinding" type="myPortType">'
  272. . '<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>'
  273. . '<operation name="operation1"/>'
  274. . '<operation name="operation2">'
  275. . '<input>'
  276. . '<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>'
  277. . '</input>'
  278. . '<output>'
  279. . '<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>'
  280. . '</output>'
  281. . '</operation>'
  282. . '</binding>'
  283. . '</definitions>' );
  284. }
  285. function testAddSoapOperation()
  286. {
  287. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php');
  288. $wsdl->addPortType('myPortType');
  289. $binding = $wsdl->addBinding('MyServiceBinding', 'myPortType');
  290. $wsdl->addSoapOperation($binding, 'http://localhost/MyService.php#myOperation');
  291. $wsdl->addBindingOperation($binding, 'operation1');
  292. $wsdl->addBindingOperation($binding,
  293. 'operation2',
  294. array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/"),
  295. array('use' => 'encoded', 'encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/")
  296. );
  297. $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()),
  298. '<?xml version="1.0"?>' .
  299. '<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" '
  300. . 'xmlns:tns="http://localhost/MyService.php" '
  301. . 'xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" '
  302. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  303. . 'xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" '
  304. . 'xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" '
  305. . 'name="MyService" targetNamespace="http://localhost/MyService.php">'
  306. . '<portType name="myPortType"/>'
  307. . '<binding name="MyServiceBinding" type="myPortType">'
  308. . '<soap:operation soapAction="http://localhost/MyService.php#myOperation"/>'
  309. . '<operation name="operation1"/>'
  310. . '<operation name="operation2">'
  311. . '<input>'
  312. . '<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>'
  313. . '</input>'
  314. . '<output>'
  315. . '<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>'
  316. . '</output>'
  317. . '</operation>'
  318. . '</binding>'
  319. . '</definitions>' );
  320. }
  321. function testAddService()
  322. {
  323. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php');
  324. $wsdl->addPortType('myPortType');
  325. $wsdl->addBinding('MyServiceBinding', 'myPortType');
  326. $wsdl->addService('Service1', 'myPortType', 'MyServiceBinding', 'http://localhost/MyService.php');
  327. $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()),
  328. '<?xml version="1.0"?>' .
  329. '<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" '
  330. . 'xmlns:tns="http://localhost/MyService.php" '
  331. . 'xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" '
  332. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  333. . 'xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" '
  334. . 'xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" '
  335. . 'name="MyService" targetNamespace="http://localhost/MyService.php">'
  336. . '<portType name="myPortType"/>'
  337. . '<binding name="MyServiceBinding" type="myPortType"/>'
  338. . '<service name="Service1">'
  339. . '<port name="myPortType" binding="MyServiceBinding">'
  340. . '<soap:address location="http://localhost/MyService.php"/>'
  341. . '</port>'
  342. . '</service>'
  343. . '</definitions>' );
  344. }
  345. function testAddDocumentation()
  346. {
  347. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php');
  348. $portType = $wsdl->addPortType('myPortType');
  349. $wsdl->addDocumentation($portType, 'This is a description for Port Type node.');
  350. $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()),
  351. '<?xml version="1.0"?>' .
  352. '<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" '
  353. . 'xmlns:tns="http://localhost/MyService.php" '
  354. . 'xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" '
  355. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  356. . 'xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" '
  357. . 'xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" '
  358. . 'name="MyService" targetNamespace="http://localhost/MyService.php">'
  359. . '<portType name="myPortType">'
  360. . '<documentation>This is a description for Port Type node.</documentation>'
  361. . '</portType>'
  362. . '</definitions>' );
  363. }
  364. public function testAddDocumentationToSetInsertsBefore()
  365. {
  366. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php');
  367. $messageParts = array();
  368. $messageParts['parameter1'] = $wsdl->getType('int');
  369. $messageParts['parameter2'] = $wsdl->getType('string');
  370. $messageParts['parameter3'] = $wsdl->getType('mixed');
  371. $message = $wsdl->addMessage('myMessage', $messageParts);
  372. $wsdl->addDocumentation($message, "foo");
  373. $this->assertEquals(
  374. '<?xml version="1.0"?>' .
  375. '<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" '
  376. . 'xmlns:tns="http://localhost/MyService.php" '
  377. . 'xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" '
  378. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  379. . 'xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" '
  380. . 'xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" '
  381. . 'name="MyService" targetNamespace="http://localhost/MyService.php">'
  382. . '<message name="myMessage">'
  383. . '<documentation>foo</documentation>'
  384. . '<part name="parameter1" type="xsd:int"/>'
  385. . '<part name="parameter2" type="xsd:string"/>'
  386. . '<part name="parameter3" type="xsd:anyType"/>'
  387. . '</message>'
  388. . '</definitions>',
  389. $this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml())
  390. );
  391. }
  392. function testToXml()
  393. {
  394. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php');
  395. $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()),
  396. '<?xml version="1.0"?>' .
  397. '<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" '
  398. . 'xmlns:tns="http://localhost/MyService.php" '
  399. . 'xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" '
  400. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  401. . 'xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" '
  402. . 'xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" '
  403. . 'name="MyService" targetNamespace="http://localhost/MyService.php"/>' );
  404. }
  405. function testToDomDocument()
  406. {
  407. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php');
  408. $dom = $wsdl->toDomDocument();
  409. $this->assertTrue($dom instanceOf DOMDocument);
  410. $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($dom->saveXML()),
  411. '<?xml version="1.0"?>' .
  412. '<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" '
  413. . 'xmlns:tns="http://localhost/MyService.php" '
  414. . 'xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" '
  415. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  416. . 'xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" '
  417. . 'xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" '
  418. . 'name="MyService" targetNamespace="http://localhost/MyService.php"/>' );
  419. }
  420. function testDump()
  421. {
  422. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php');
  423. ob_start();
  424. $wsdl->dump();
  425. $wsdlDump = ob_get_clean();
  426. $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdlDump),
  427. '<?xml version="1.0"?>' .
  428. '<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" '
  429. . 'xmlns:tns="http://localhost/MyService.php" '
  430. . 'xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" '
  431. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  432. . 'xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" '
  433. . 'xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" '
  434. . 'name="MyService" targetNamespace="http://localhost/MyService.php"/>' );
  435. $wsdl->dump(dirname(__FILE__) . '/_files/dumped.wsdl');
  436. $dumpedContent = file_get_contents(dirname(__FILE__) . '/_files/dumped.wsdl');
  437. $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($dumpedContent),
  438. '<?xml version="1.0"?>' .
  439. '<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" '
  440. . 'xmlns:tns="http://localhost/MyService.php" '
  441. . 'xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" '
  442. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  443. . 'xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" '
  444. . 'xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" '
  445. . 'name="MyService" targetNamespace="http://localhost/MyService.php"/>' );
  446. unlink(dirname(__FILE__) . '/_files/dumped.wsdl');
  447. }
  448. function testGetType()
  449. {
  450. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php', true);
  451. $this->assertEquals('xsd:string', $wsdl->getType('string'), 'xsd:string detection failed.');
  452. $this->assertEquals('xsd:string', $wsdl->getType('str'), 'xsd:string detection failed.');
  453. $this->assertEquals('xsd:int', $wsdl->getType('int'), 'xsd:int detection failed.');
  454. $this->assertEquals('xsd:int', $wsdl->getType('integer'), 'xsd:int detection failed.');
  455. $this->assertEquals('xsd:float', $wsdl->getType('float'), 'xsd:float detection failed.');
  456. $this->assertEquals('xsd:float', $wsdl->getType('double'), 'xsd:float detection failed.');
  457. $this->assertEquals('xsd:boolean', $wsdl->getType('boolean'), 'xsd:boolean detection failed.');
  458. $this->assertEquals('xsd:boolean', $wsdl->getType('bool'), 'xsd:boolean detection failed.');
  459. $this->assertEquals('soap-enc:Array', $wsdl->getType('array'), 'soap-enc:Array detection failed.');
  460. $this->assertEquals('xsd:struct', $wsdl->getType('object'), 'xsd:struct detection failed.');
  461. $this->assertEquals('xsd:anyType', $wsdl->getType('mixed'), 'xsd:anyType detection failed.');
  462. $this->assertEquals('', $wsdl->getType('void'), 'void detection failed.');
  463. }
  464. function testGetComplexTypeBasedOnStrategiesBackwardsCompabilityBoolean()
  465. {
  466. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php', true);
  467. $this->assertEquals('tns:Zend_Soap_Wsdl_Test', $wsdl->getType('Zend_Soap_Wsdl_Test'));
  468. $this->assertTrue($wsdl->getComplexTypeStrategy() instanceof Zend_Soap_Wsdl_Strategy_DefaultComplexType);
  469. $wsdl2 = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php', false);
  470. $this->assertEquals('xsd:anyType', $wsdl2->getType('Zend_Soap_Wsdl_Test'));
  471. $this->assertTrue($wsdl2->getComplexTypeStrategy() instanceof Zend_Soap_Wsdl_Strategy_AnyType);
  472. }
  473. function testGetComplexTypeBasedOnStrategiesStringNames()
  474. {
  475. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php', 'Zend_Soap_Wsdl_Strategy_DefaultComplexType');
  476. $this->assertEquals('tns:Zend_Soap_Wsdl_Test', $wsdl->getType('Zend_Soap_Wsdl_Test'));
  477. $this->assertTrue($wsdl->getComplexTypeStrategy() instanceof Zend_Soap_Wsdl_Strategy_DefaultComplexType);
  478. $wsdl2 = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php', 'Zend_Soap_Wsdl_Strategy_AnyType');
  479. $this->assertEquals('xsd:anyType', $wsdl2->getType('Zend_Soap_Wsdl_Test'));
  480. $this->assertTrue($wsdl2->getComplexTypeStrategy() instanceof Zend_Soap_Wsdl_Strategy_AnyType);
  481. }
  482. function testSettingUnknownStrategyThrowsException()
  483. {
  484. try {
  485. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php', 'Zend_Soap_Wsdl_Strategy_UnknownStrategyType');
  486. $this->fail();
  487. } catch(Zend_Soap_Wsdl_Exception $e) {
  488. }
  489. }
  490. function testSettingInvalidStrategyObjectThrowsException()
  491. {
  492. try {
  493. $strategy = new Zend_Soap_Wsdl_Test();
  494. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php', $strategy);
  495. $this->fail();
  496. } catch(Zend_Soap_Wsdl_Exception $e) {
  497. }
  498. }
  499. function testAddingSameComplexTypeMoreThanOnceIsIgnored()
  500. {
  501. try {
  502. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php');
  503. $wsdl->addType('Zend_Soap_Wsdl_Test');
  504. $wsdl->addType('Zend_Soap_Wsdl_Test');
  505. $types = $wsdl->getTypes();
  506. $this->assertEquals(1, count($types));
  507. $this->assertEquals(array("Zend_Soap_Wsdl_Test"), $types);
  508. } catch(Zend_Soap_Wsdl_Exception $e) {
  509. $this->fail();
  510. }
  511. }
  512. function testUsingSameComplexTypeTwiceLeadsToReuseOfDefinition()
  513. {
  514. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php');
  515. $wsdl->addComplexType('Zend_Soap_Wsdl_Test');
  516. $this->assertEquals(array('Zend_Soap_Wsdl_Test'), $wsdl->getTypes());
  517. $wsdl->addComplexType('Zend_Soap_Wsdl_Test');
  518. $this->assertEquals(array('Zend_Soap_Wsdl_Test'), $wsdl->getTypes());
  519. }
  520. function testAddComplexType()
  521. {
  522. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php');
  523. $wsdl->addComplexType('Zend_Soap_Wsdl_Test');
  524. $this->assertEquals($this->sanitizeWsdlXmlOutputForOsCompability($wsdl->toXml()),
  525. '<?xml version="1.0"?>' .
  526. '<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" '
  527. . 'xmlns:tns="http://localhost/MyService.php" '
  528. . 'xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" '
  529. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  530. . 'xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" '
  531. . 'xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" '
  532. . 'name="MyService" targetNamespace="http://localhost/MyService.php">'
  533. . '<types>'
  534. . '<xsd:schema targetNamespace="http://localhost/MyService.php">'
  535. . '<xsd:complexType name="Zend_Soap_Wsdl_Test">'
  536. . '<xsd:all>'
  537. . '<xsd:element name="var1" type="xsd:int" nillable="true"/>'
  538. . '<xsd:element name="var2" type="xsd:string" nillable="true"/>'
  539. . '</xsd:all>'
  540. . '</xsd:complexType>'
  541. . '</xsd:schema>'
  542. . '</types>'
  543. . '</definitions>' );
  544. }
  545. /**
  546. * @group ZF-3910
  547. */
  548. function testCaseOfDocBlockParamsDosNotMatterForSoapTypeDetectionZf3910()
  549. {
  550. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php');
  551. $this->assertEquals("xsd:string", $wsdl->getType("StrIng"));
  552. $this->assertEquals("xsd:string", $wsdl->getType("sTr"));
  553. $this->assertEquals("xsd:int", $wsdl->getType("iNt"));
  554. $this->assertEquals("xsd:int", $wsdl->getType("INTEGER"));
  555. $this->assertEquals("xsd:float", $wsdl->getType("FLOAT"));
  556. $this->assertEquals("xsd:float", $wsdl->getType("douBLE"));
  557. }
  558. /**
  559. * @group ZF-5430
  560. */
  561. public function testMultipleSequenceDefinitionsOfSameTypeWillBeRecognizedOnceBySequenceStrategy()
  562. {
  563. $wsdl = new Zend_Soap_Wsdl("MyService", "http://localhost/MyService.php");
  564. $wsdl->setComplexTypeStrategy(new Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence());
  565. $wsdl->addComplexType("string[]");
  566. $wsdl->addComplexType("int[]");
  567. $wsdl->addComplexType("string[]");
  568. $xml = $wsdl->toXml();
  569. $this->assertEquals(1, substr_count($xml, "ArrayOfString"), "ArrayOfString should appear only once.");
  570. $this->assertEquals(1, substr_count($xml, "ArrayOfInt"), "ArrayOfInt should appear only once.");
  571. }
  572. const URI_WITH_EXPANDED_AMP = "http://localhost/MyService.php?a=b&amp;b=c";
  573. const URI_WITHOUT_EXPANDED_AMP = "http://localhost/MyService.php?a=b&b=c";
  574. /**
  575. * @group ZF-5736
  576. */
  577. public function testHtmlAmpersandInUrlInConstructorIsEncodedCorrectly()
  578. {
  579. $wsdl = new Zend_Soap_Wsdl("MyService", self::URI_WITH_EXPANDED_AMP);
  580. $this->assertContains(self::URI_WITH_EXPANDED_AMP, $wsdl->toXML());
  581. }
  582. /**
  583. * @group ZF-5736
  584. */
  585. public function testHtmlAmpersandInUrlInSetUriIsEncodedCorrectly()
  586. {
  587. $wsdl = new Zend_Soap_Wsdl("MyService", "http://example.com");
  588. $wsdl->setUri(self::URI_WITH_EXPANDED_AMP);
  589. $this->assertContains(self::URI_WITH_EXPANDED_AMP, $wsdl->toXML());
  590. }
  591. }
  592. /**
  593. * Test Class
  594. */
  595. class Zend_Soap_Wsdl_Test {
  596. /**
  597. * @var integer
  598. */
  599. public $var1;
  600. /**
  601. * @var string
  602. */
  603. public $var2;
  604. }