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

/tests/Zend/Soap/WsdlTest.php

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