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