1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (C) 2013-2016 |
4
|
|
|
* Piotr Olaszewski <[email protected]> |
5
|
|
|
* |
6
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
7
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
8
|
|
|
* in the Software without restriction, including without limitation the rights |
9
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
10
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
11
|
|
|
* furnished to do so, subject to the following conditions: |
12
|
|
|
* |
13
|
|
|
* The above copyright notice and this permission notice shall be included in |
14
|
|
|
* all copies or substantial portions of the Software. |
15
|
|
|
* |
16
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
19
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
20
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
21
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
22
|
|
|
* SOFTWARE. |
23
|
|
|
*/ |
24
|
|
|
namespace Tests\WSDL\XML\XMLStyle; |
25
|
|
|
|
26
|
|
|
use DOMDocument; |
27
|
|
|
use Ouzo\Tests\Assert; |
28
|
|
|
use PHPUnit_Framework_TestCase; |
29
|
|
|
use WSDL\Builder\Parameter; |
30
|
|
|
use WSDL\Parser\Node; |
31
|
|
|
use WSDL\XML\XMLStyle\XMLRpcStyle; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* XMLRpcStyleTest |
35
|
|
|
* |
36
|
|
|
* @author Piotr Olaszewski <[email protected]> |
37
|
|
|
*/ |
38
|
|
|
class XMLRpcStyleTest extends PHPUnit_Framework_TestCase |
39
|
|
|
{ |
40
|
|
|
/** |
41
|
|
|
* @var DOMDocument |
42
|
|
|
*/ |
43
|
|
|
private $DOMDocument; |
44
|
|
|
/** |
45
|
|
|
* @var XMLRpcStyle |
46
|
|
|
*/ |
47
|
|
|
private $XMLRpcStyle; |
48
|
|
|
|
49
|
|
|
protected function setUp() |
50
|
|
|
{ |
51
|
|
|
parent::setUp(); |
52
|
|
|
$this->DOMDocument = new DOMDocument(); |
53
|
|
|
$this->XMLRpcStyle = new XMLRpcStyle(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @test |
58
|
|
|
*/ |
59
|
|
|
public function shouldGenerateDOMElementForBinding() |
60
|
|
|
{ |
61
|
|
|
//when |
62
|
|
|
$DOMElement = $this->XMLRpcStyle->generateBinding($this->DOMDocument, 'soap'); |
63
|
|
|
|
64
|
|
|
//then |
65
|
|
|
$this->assertEquals('soap:binding', $DOMElement->tagName); |
66
|
|
|
$this->assertEquals('rpc', $DOMElement->getAttribute('style')); |
67
|
|
|
$this->assertEquals('http://schemas.xmlsoap.org/soap/http', $DOMElement->getAttribute('transport')); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @test |
72
|
|
|
*/ |
73
|
|
|
public function shouldGenerateDOMElementsForMessage() |
74
|
|
|
{ |
75
|
|
|
//given |
76
|
|
|
$nodes = [ |
77
|
|
|
new Node('int', '$age', false), |
78
|
|
|
new Node('object', '$user', false, [new Node('string', '$name', false)]), |
79
|
|
|
new Node('string', '$numbers', true) |
80
|
|
|
]; |
81
|
|
|
|
82
|
|
|
//when |
83
|
|
|
$DOMElements = $this->XMLRpcStyle->generateMessagePart($this->DOMDocument, $nodes); |
84
|
|
|
|
85
|
|
|
//then |
86
|
|
|
Assert::thatArray($DOMElements)->extracting('tagName')->containsExactly('part', 'part', 'part'); |
87
|
|
|
|
88
|
|
|
$this->assertEquals('age', $DOMElements[0]->getAttribute('name')); |
89
|
|
|
$this->assertEquals('xsd:int', $DOMElements[0]->getAttribute('type')); |
90
|
|
|
|
91
|
|
|
$this->assertEquals('user', $DOMElements[1]->getAttribute('name')); |
92
|
|
|
$this->assertEquals('ns:User', $DOMElements[1]->getAttribute('element')); |
93
|
|
|
|
94
|
|
|
$this->assertEquals('numbers', $DOMElements[2]->getAttribute('name')); |
95
|
|
|
$this->assertEquals('ns:ArrayOfNumbers', $DOMElements[2]->getAttribute('type')); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @test |
100
|
|
|
*/ |
101
|
|
|
public function shouldGenerateDOMElementsForTypesObject() |
102
|
|
|
{ |
103
|
|
|
//given |
104
|
|
|
$parameters = [ |
105
|
|
|
new Parameter(new Node('object', '$user', false, [new Node('string', '$name', false)]), false) |
106
|
|
|
]; |
107
|
|
|
|
108
|
|
|
//when |
109
|
|
|
$DOMElements = $this->XMLRpcStyle->generateTypes($this->DOMDocument, $parameters, 'soap'); |
110
|
|
|
|
111
|
|
|
//then |
112
|
|
|
Assert::thatArray($DOMElements) |
113
|
|
|
->extracting('tagName') |
114
|
|
|
->containsExactly('xsd:element', 'xsd:complexType'); |
115
|
|
|
|
116
|
|
|
//<xsd:element name="User" nillable="true" type="ns:User"/> |
117
|
|
|
$this->assertEquals('User', $DOMElements[0]->getAttribute('name')); |
118
|
|
|
$this->assertEquals('true', $DOMElements[0]->getAttribute('nillable')); |
119
|
|
|
$this->assertEquals('ns:User', $DOMElements[0]->getAttribute('type')); |
120
|
|
|
|
121
|
|
|
//<xsd:complexType name="User"> |
122
|
|
|
// <xsd:sequence> |
123
|
|
|
// <xsd:element name="name" type="xsd:string"/> |
124
|
|
|
// </xsd:sequence> |
125
|
|
|
//</xsd:complexType> |
126
|
|
|
$this->assertEquals('User', $DOMElements[1]->getAttribute('name')); |
127
|
|
|
$this->assertEquals('xsd:sequence', $DOMElements[1]->firstChild->tagName); |
|
|
|
|
128
|
|
|
$DOMElements1Nodes = $DOMElements[1]->firstChild->childNodes; |
129
|
|
|
Assert::thatArray(iterator_to_array($DOMElements1Nodes)) |
130
|
|
|
->extracting('tagName') |
131
|
|
|
->containsExactly('xsd:element'); |
132
|
|
|
$this->assertEquals('name', $DOMElements1Nodes[0]->getAttribute('name')); |
133
|
|
|
$this->assertEquals('xsd:string', $DOMElements1Nodes[0]->getAttribute('type')); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @test |
138
|
|
|
*/ |
139
|
|
|
public function shouldGenerateDOMElementsForTypesArrayOdSimpleType() |
140
|
|
|
{ |
141
|
|
|
//given |
142
|
|
|
$parameters = [ |
143
|
|
|
new Parameter(new Node('string', '$numbers', true), true) |
144
|
|
|
]; |
145
|
|
|
|
146
|
|
|
//when |
147
|
|
|
$DOMElements = $this->XMLRpcStyle->generateTypes($this->DOMDocument, $parameters, 'soap'); |
148
|
|
|
|
149
|
|
|
//then |
150
|
|
|
Assert::thatArray($DOMElements) |
151
|
|
|
->extracting('tagName') |
152
|
|
|
->containsExactly('xsd:complexType'); |
153
|
|
|
|
154
|
|
|
//<xsd:complexType name="ArrayOfNumbers"> |
155
|
|
|
// <xsd:complexContent> |
156
|
|
|
// <xsd:restriction base="soapenc:Array"> |
157
|
|
|
// <xsd:attribute ref="soapenc:arrayType" soap:arrayType="xsd:string[]"/> |
158
|
|
|
// </xsd:restriction> |
159
|
|
|
// </xsd:complexContent> |
160
|
|
|
//</xsd:complexType> |
161
|
|
|
$this->assertEquals('ArrayOfNumbers', $DOMElements[0]->getAttribute('name')); |
162
|
|
|
$this->assertEquals('xsd:complexContent', $DOMElements[0]->firstChild->tagName); |
|
|
|
|
163
|
|
|
$this->assertEquals('xsd:restriction', $DOMElements[0]->firstChild->firstChild->tagName); |
164
|
|
|
$this->assertEquals('soapenc:Array', $DOMElements[0]->firstChild->firstChild->getAttribute('base')); |
165
|
|
|
$this->assertEquals('xsd:attribute', $DOMElements[0]->firstChild->firstChild->firstChild->tagName); |
166
|
|
|
$this->assertEquals('soapenc:arrayType', $DOMElements[0]->firstChild->firstChild->firstChild->getAttribute('ref')); |
167
|
|
|
$this->assertEquals('xsd:string[]', $DOMElements[0]->firstChild->firstChild->firstChild->getAttribute('soap:arrayType')); |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
|
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.