WsdlTest.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  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 sanatizeWsdlXmlOutputForOsCompability($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->sanatizeWsdlXmlOutputForOsCompability($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->sanatizeWsdlXmlOutputForOsCompability($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->sanatizeWsdlXmlOutputForOsCompability($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->sanatizeWsdlXmlOutputForOsCompability($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->sanatizeWsdlXmlOutputForOsCompability($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->sanatizeWsdlXmlOutputForOsCompability($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->sanatizeWsdlXmlOutputForOsCompability($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->sanatizeWsdlXmlOutputForOsCompability($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->sanatizeWsdlXmlOutputForOsCompability($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->sanatizeWsdlXmlOutputForOsCompability($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->sanatizeWsdlXmlOutputForOsCompability($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->sanatizeWsdlXmlOutputForOsCompability($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. function testToXml()
  344. {
  345. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php');
  346. $this->assertEquals($this->sanatizeWsdlXmlOutputForOsCompability($wsdl->toXml()),
  347. '<?xml version="1.0"?>' .
  348. '<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" '
  349. . 'xmlns:tns="http://localhost/MyService.php" '
  350. . 'xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" '
  351. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  352. . 'xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" '
  353. . 'xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" '
  354. . 'name="MyService" targetNamespace="http://localhost/MyService.php"/>' );
  355. }
  356. function testToDomDocument()
  357. {
  358. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php');
  359. $dom = $wsdl->toDomDocument();
  360. $this->assertTrue($dom instanceOf DOMDocument);
  361. $this->assertEquals($this->sanatizeWsdlXmlOutputForOsCompability($dom->saveXML()),
  362. '<?xml version="1.0"?>' .
  363. '<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" '
  364. . 'xmlns:tns="http://localhost/MyService.php" '
  365. . 'xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" '
  366. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  367. . 'xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" '
  368. . 'xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" '
  369. . 'name="MyService" targetNamespace="http://localhost/MyService.php"/>' );
  370. }
  371. function testDump()
  372. {
  373. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php');
  374. ob_start();
  375. $wsdl->dump();
  376. $wsdlDump = ob_get_contents();
  377. ob_end_clean();
  378. $this->assertEquals($this->sanatizeWsdlXmlOutputForOsCompability($wsdlDump),
  379. '<?xml version="1.0"?>' .
  380. '<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" '
  381. . 'xmlns:tns="http://localhost/MyService.php" '
  382. . 'xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" '
  383. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  384. . 'xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" '
  385. . 'xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" '
  386. . 'name="MyService" targetNamespace="http://localhost/MyService.php"/>' );
  387. $wsdl->dump(dirname(__FILE__) . '/_files/dumped.wsdl');
  388. $dumpedContent = file_get_contents(dirname(__FILE__) . '/_files/dumped.wsdl');
  389. $this->assertEquals($this->sanatizeWsdlXmlOutputForOsCompability($dumpedContent),
  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. unlink(dirname(__FILE__) . '/_files/dumped.wsdl');
  399. }
  400. function testGetType()
  401. {
  402. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php', true);
  403. $this->assertEquals('xsd:string', $wsdl->getType('string'), 'xsd:string detection failed.');
  404. $this->assertEquals('xsd:string', $wsdl->getType('str'), 'xsd:string detection failed.');
  405. $this->assertEquals('xsd:int', $wsdl->getType('int'), 'xsd:int detection failed.');
  406. $this->assertEquals('xsd:int', $wsdl->getType('integer'), 'xsd:int detection failed.');
  407. $this->assertEquals('xsd:float', $wsdl->getType('float'), 'xsd:float detection failed.');
  408. $this->assertEquals('xsd:float', $wsdl->getType('double'), 'xsd:float detection failed.');
  409. $this->assertEquals('xsd:boolean', $wsdl->getType('boolean'), 'xsd:boolean detection failed.');
  410. $this->assertEquals('xsd:boolean', $wsdl->getType('bool'), 'xsd:boolean detection failed.');
  411. $this->assertEquals('soap-enc:Array', $wsdl->getType('array'), 'soap-enc:Array detection failed.');
  412. $this->assertEquals('xsd:struct', $wsdl->getType('object'), 'xsd:struct detection failed.');
  413. $this->assertEquals('xsd:anyType', $wsdl->getType('mixed'), 'xsd:anyType detection failed.');
  414. $this->assertEquals('', $wsdl->getType('void'), 'void detection failed.');
  415. }
  416. function testGetComplexTypeBasedOnStrategiesBackwardsCompabilityBoolean()
  417. {
  418. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php', true);
  419. $this->assertEquals('tns:Zend_Soap_Wsdl_Test', $wsdl->getType('Zend_Soap_Wsdl_Test'));
  420. $this->assertTrue($wsdl->getComplexTypeStrategy() instanceof Zend_Soap_Wsdl_Strategy_DefaultComplexType);
  421. $wsdl2 = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php', false);
  422. $this->assertEquals('xsd:anyType', $wsdl2->getType('Zend_Soap_Wsdl_Test'));
  423. $this->assertTrue($wsdl2->getComplexTypeStrategy() instanceof Zend_Soap_Wsdl_Strategy_AnyType);
  424. }
  425. function testGetComplexTypeBasedOnStrategiesStringNames()
  426. {
  427. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php', 'Zend_Soap_Wsdl_Strategy_DefaultComplexType');
  428. $this->assertEquals('tns:Zend_Soap_Wsdl_Test', $wsdl->getType('Zend_Soap_Wsdl_Test'));
  429. $this->assertTrue($wsdl->getComplexTypeStrategy() instanceof Zend_Soap_Wsdl_Strategy_DefaultComplexType);
  430. $wsdl2 = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php', 'Zend_Soap_Wsdl_Strategy_AnyType');
  431. $this->assertEquals('xsd:anyType', $wsdl2->getType('Zend_Soap_Wsdl_Test'));
  432. $this->assertTrue($wsdl2->getComplexTypeStrategy() instanceof Zend_Soap_Wsdl_Strategy_AnyType);
  433. }
  434. function testSettingUnknownStrategyThrowsException()
  435. {
  436. try {
  437. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php', 'Zend_Soap_Wsdl_Strategy_UnknownStrategyType');
  438. $this->fail();
  439. } catch(Zend_Soap_Wsdl_Exception $e) {
  440. }
  441. }
  442. function testSettingInvalidStrategyObjectThrowsException()
  443. {
  444. try {
  445. $strategy = new Zend_Soap_Wsdl_Test();
  446. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php', $strategy);
  447. $this->fail();
  448. } catch(Zend_Soap_Wsdl_Exception $e) {
  449. }
  450. }
  451. function testAddingSameComplexTypeMoreThanOnceIsIgnored()
  452. {
  453. try {
  454. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php');
  455. $wsdl->addType('Zend_Soap_Wsdl_Test');
  456. $wsdl->addType('Zend_Soap_Wsdl_Test');
  457. $types = $wsdl->getTypes();
  458. $this->assertEquals(1, count($types));
  459. $this->assertEquals(array("Zend_Soap_Wsdl_Test"), $types);
  460. } catch(Zend_Soap_Wsdl_Exception $e) {
  461. $this->fail();
  462. }
  463. }
  464. function testUsingSameComplexTypeTwiceLeadsToReuseOfDefinition()
  465. {
  466. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php');
  467. $wsdl->addComplexType('Zend_Soap_Wsdl_Test');
  468. $this->assertEquals(array('Zend_Soap_Wsdl_Test'), $wsdl->getTypes());
  469. $wsdl->addComplexType('Zend_Soap_Wsdl_Test');
  470. $this->assertEquals(array('Zend_Soap_Wsdl_Test'), $wsdl->getTypes());
  471. }
  472. function testAddComplexType()
  473. {
  474. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php');
  475. $wsdl->addComplexType('Zend_Soap_Wsdl_Test');
  476. $this->assertEquals($this->sanatizeWsdlXmlOutputForOsCompability($wsdl->toXml()),
  477. '<?xml version="1.0"?>' .
  478. '<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" '
  479. . 'xmlns:tns="http://localhost/MyService.php" '
  480. . 'xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" '
  481. . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
  482. . 'xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" '
  483. . 'xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" '
  484. . 'name="MyService" targetNamespace="http://localhost/MyService.php">'
  485. . '<types>'
  486. . '<xsd:schema targetNamespace="http://localhost/MyService.php">'
  487. . '<xsd:complexType name="Zend_Soap_Wsdl_Test">'
  488. . '<xsd:all>'
  489. . '<xsd:element name="var1" type="xsd:int"/>'
  490. . '<xsd:element name="var2" type="xsd:string"/>'
  491. . '</xsd:all>'
  492. . '</xsd:complexType>'
  493. . '</xsd:schema>'
  494. . '</types>'
  495. . '</definitions>' );
  496. }
  497. /**
  498. * @group ZF-3910
  499. */
  500. function testCaseOfDocBlockParamsDosNotMatterForSoapTypeDetectionZf3910()
  501. {
  502. $wsdl = new Zend_Soap_Wsdl('MyService', 'http://localhost/MyService.php');
  503. $this->assertEquals("xsd:string", $wsdl->getType("StrIng"));
  504. $this->assertEquals("xsd:string", $wsdl->getType("sTr"));
  505. $this->assertEquals("xsd:int", $wsdl->getType("iNt"));
  506. $this->assertEquals("xsd:int", $wsdl->getType("INTEGER"));
  507. $this->assertEquals("xsd:float", $wsdl->getType("FLOAT"));
  508. $this->assertEquals("xsd:float", $wsdl->getType("douBLE"));
  509. }
  510. /**
  511. * @group ZF-5430
  512. */
  513. public function testMultipleSequenceDefinitionsOfSameTypeWillBeRecognizedOnceBySequenceStrategy()
  514. {
  515. $wsdl = new Zend_Soap_Wsdl("MyService", "http://localhost/MyService.php");
  516. $wsdl->setComplexTypeStrategy(new Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence());
  517. $wsdl->addComplexType("string[]");
  518. $wsdl->addComplexType("int[]");
  519. $wsdl->addComplexType("string[]");
  520. $xml = $wsdl->toXml();
  521. $this->assertEquals(1, substr_count($xml, "ArrayOfString"), "ArrayOfString should appear only once.");
  522. $this->assertEquals(1, substr_count($xml, "ArrayOfInt"), "ArrayOfInt should appear only once.");
  523. }
  524. const URI_WITH_EXPANDED_AMP = "http://localhost/MyService.php?a=b&amp;b=c";
  525. const URI_WITHOUT_EXPANDED_AMP = "http://localhost/MyService.php?a=b&b=c";
  526. /**
  527. * @group ZF-5736
  528. */
  529. public function testHtmlAmpersandInUrlInConstructorIsEncodedCorrectly()
  530. {
  531. $wsdl = new Zend_Soap_Wsdl("MyService", self::URI_WITH_EXPANDED_AMP);
  532. $this->assertContains(self::URI_WITH_EXPANDED_AMP, $wsdl->toXML());
  533. }
  534. /**
  535. * @group ZF-5736
  536. */
  537. public function testHtmlAmpersandInUrlInSetUriIsEncodedCorrectly()
  538. {
  539. $wsdl = new Zend_Soap_Wsdl("MyService", "http://example.com");
  540. $wsdl->setUri(self::URI_WITH_EXPANDED_AMP);
  541. $this->assertContains(self::URI_WITH_EXPANDED_AMP, $wsdl->toXML());
  542. }
  543. }
  544. /**
  545. * Test Class
  546. */
  547. class Zend_Soap_Wsdl_Test {
  548. /**
  549. * @var integer
  550. */
  551. public $var1;
  552. /**
  553. * @var string
  554. */
  555. public $var2;
  556. }