PageRenderTime 47ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/Zend/Soap/WsdlTest.php

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