WsdlTest.php 35 KB

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