1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing a test class. |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
8
|
|
|
* |
9
|
|
|
* @version //autogentag// |
10
|
|
|
*/ |
11
|
|
|
namespace eZ\Publish\Core\REST\Server\Tests\Output\ValueObjectVisitor; |
12
|
|
|
|
13
|
|
|
use eZ\Publish\Core\REST\Common\Tests\Output\ValueObjectVisitorBaseTest; |
14
|
|
|
use eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor; |
15
|
|
|
use eZ\Publish\Core\Repository\Values\ObjectState; |
16
|
|
|
|
17
|
|
|
class ObjectStateGroupTest extends ValueObjectVisitorBaseTest |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Test the ObjectStateGroup visitor. |
21
|
|
|
* |
22
|
|
|
* @return string |
23
|
|
|
*/ |
24
|
|
|
public function testVisit() |
25
|
|
|
{ |
26
|
|
|
$visitor = $this->getVisitor(); |
27
|
|
|
$generator = $this->getGenerator(); |
28
|
|
|
|
29
|
|
|
$generator->startDocument(null); |
30
|
|
|
|
31
|
|
|
$objectStateGroup = new ObjectState\ObjectStateGroup( |
32
|
|
|
array( |
33
|
|
|
'id' => 42, |
34
|
|
|
'identifier' => 'test-group', |
35
|
|
|
'defaultLanguageCode' => 'eng-GB', |
36
|
|
|
'languageCodes' => array('eng-GB', 'eng-US'), |
37
|
|
|
'names' => array( |
38
|
|
|
'eng-GB' => 'Group name EN', |
39
|
|
|
'eng-US' => 'Group name EN US', |
40
|
|
|
), |
41
|
|
|
'descriptions' => array( |
42
|
|
|
'eng-GB' => 'Group description EN', |
43
|
|
|
'eng-US' => 'Group description EN US', |
44
|
|
|
), |
45
|
|
|
) |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
$this->addRouteExpectation( |
49
|
|
|
'ezpublish_rest_loadObjectStateGroup', |
50
|
|
|
array('objectStateGroupId' => $objectStateGroup->id), |
51
|
|
|
"/content/objectstategroups/$objectStateGroup->id" |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
$this->addRouteExpectation( |
55
|
|
|
'ezpublish_rest_loadObjectStates', |
56
|
|
|
array('objectStateGroupId' => $objectStateGroup->id), |
57
|
|
|
"/content/objectstategroups/$objectStateGroup->id/objectstates" |
58
|
|
|
); |
59
|
|
|
|
60
|
|
|
$visitor->visit( |
61
|
|
|
$this->getVisitorMock(), |
|
|
|
|
62
|
|
|
$generator, |
63
|
|
|
$objectStateGroup |
64
|
|
|
); |
65
|
|
|
|
66
|
|
|
$result = $generator->endDocument(null); |
67
|
|
|
|
68
|
|
|
$this->assertNotNull($result); |
69
|
|
|
|
70
|
|
|
return $result; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Test if result contains ObjectStateGroup element. |
75
|
|
|
* |
76
|
|
|
* @param string $result |
77
|
|
|
* |
78
|
|
|
* @depends testVisit |
79
|
|
|
*/ |
80
|
|
|
public function testResultContainsObjectStateGroupElement($result) |
81
|
|
|
{ |
82
|
|
|
$this->assertXMLTag( |
83
|
|
|
array( |
84
|
|
|
'tag' => 'ObjectStateGroup', |
85
|
|
|
'children' => array( |
86
|
|
|
'count' => 7, |
87
|
|
|
), |
88
|
|
|
), |
89
|
|
|
$result, |
90
|
|
|
'Invalid <ObjectStateGroup> element.', |
91
|
|
|
false |
92
|
|
|
); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Test if result contains ObjectStateGroup element attributes. |
97
|
|
|
* |
98
|
|
|
* @param string $result |
99
|
|
|
* |
100
|
|
|
* @depends testVisit |
101
|
|
|
*/ |
102
|
|
|
public function testResultContainsObjectStateGroupAttributes($result) |
103
|
|
|
{ |
104
|
|
|
$this->assertXMLTag( |
105
|
|
|
array( |
106
|
|
|
'tag' => 'ObjectStateGroup', |
107
|
|
|
'attributes' => array( |
108
|
|
|
'media-type' => 'application/vnd.ez.api.ObjectStateGroup+xml', |
109
|
|
|
'href' => '/content/objectstategroups/42', |
110
|
|
|
), |
111
|
|
|
), |
112
|
|
|
$result, |
113
|
|
|
'Invalid <ObjectStateGroup> attributes.', |
114
|
|
|
false |
115
|
|
|
); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Test if result contains id value element. |
120
|
|
|
* |
121
|
|
|
* @param string $result |
122
|
|
|
* |
123
|
|
|
* @depends testVisit |
124
|
|
|
*/ |
125
|
|
|
public function testResultContainsIdValueElement($result) |
126
|
|
|
{ |
127
|
|
|
$this->assertXMLTag( |
128
|
|
|
array( |
129
|
|
|
'tag' => 'id', |
130
|
|
|
'content' => '42', |
131
|
|
|
), |
132
|
|
|
$result, |
133
|
|
|
'Invalid or non-existing <ObjectStateGroup> id value element.', |
134
|
|
|
false |
135
|
|
|
); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Test if result contains identifier value element. |
140
|
|
|
* |
141
|
|
|
* @param string $result |
142
|
|
|
* |
143
|
|
|
* @depends testVisit |
144
|
|
|
*/ |
145
|
|
|
public function testResultContainsIdentifierValueElement($result) |
146
|
|
|
{ |
147
|
|
|
$this->assertXMLTag( |
148
|
|
|
array( |
149
|
|
|
'tag' => 'identifier', |
150
|
|
|
'content' => 'test-group', |
151
|
|
|
), |
152
|
|
|
$result, |
153
|
|
|
'Invalid or non-existing <ObjectStateGroup> identifier value element.', |
154
|
|
|
false |
155
|
|
|
); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Test if result contains defaultLanguageCode value element. |
160
|
|
|
* |
161
|
|
|
* @param string $result |
162
|
|
|
* |
163
|
|
|
* @depends testVisit |
164
|
|
|
*/ |
165
|
|
|
public function testResultContainsDefaultLanguageCodeValueElement($result) |
166
|
|
|
{ |
167
|
|
|
$this->assertXMLTag( |
168
|
|
|
array( |
169
|
|
|
'tag' => 'defaultLanguageCode', |
170
|
|
|
'content' => 'eng-GB', |
171
|
|
|
), |
172
|
|
|
$result, |
173
|
|
|
'Invalid or non-existing <ObjectStateGroup> defaultLanguageCode value element.', |
174
|
|
|
false |
175
|
|
|
); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Test if result contains languageCodes value element. |
180
|
|
|
* |
181
|
|
|
* @param string $result |
182
|
|
|
* |
183
|
|
|
* @depends testVisit |
184
|
|
|
*/ |
185
|
|
|
public function testResultContainsLanguageCodesValueElement($result) |
186
|
|
|
{ |
187
|
|
|
$this->assertXMLTag( |
188
|
|
|
array( |
189
|
|
|
'tag' => 'languageCodes', |
190
|
|
|
'content' => 'eng-GB,eng-US', |
191
|
|
|
), |
192
|
|
|
$result, |
193
|
|
|
'Invalid or non-existing <ObjectStateGroup> languageCodes value element.', |
194
|
|
|
false |
195
|
|
|
); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Test if result contains names element. |
200
|
|
|
* |
201
|
|
|
* @param string $result |
202
|
|
|
* |
203
|
|
|
* @depends testVisit |
204
|
|
|
*/ |
205
|
|
|
public function testResultContainsNamesElement($result) |
206
|
|
|
{ |
207
|
|
|
$this->assertXMLTag( |
208
|
|
|
array( |
209
|
|
|
'tag' => 'names', |
210
|
|
|
'children' => array( |
211
|
|
|
'count' => 2, |
212
|
|
|
), |
213
|
|
|
), |
214
|
|
|
$result, |
215
|
|
|
'Invalid <names> element.', |
216
|
|
|
false |
217
|
|
|
); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* Test if result contains descriptions element. |
222
|
|
|
* |
223
|
|
|
* @param string $result |
224
|
|
|
* |
225
|
|
|
* @depends testVisit |
226
|
|
|
*/ |
227
|
|
|
public function testResultContainsDescriptionsElement($result) |
228
|
|
|
{ |
229
|
|
|
$this->assertXMLTag( |
230
|
|
|
array( |
231
|
|
|
'tag' => 'descriptions', |
232
|
|
|
'children' => array( |
233
|
|
|
'count' => 2, |
234
|
|
|
), |
235
|
|
|
), |
236
|
|
|
$result, |
237
|
|
|
'Invalid <descriptions> element.', |
238
|
|
|
false |
239
|
|
|
); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* Get the ObjectStateGroup visitor. |
244
|
|
|
* |
245
|
|
|
* @return \eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\ObjectStateGroup |
246
|
|
|
*/ |
247
|
|
|
protected function internalGetVisitor() |
248
|
|
|
{ |
249
|
|
|
return new ValueObjectVisitor\ObjectStateGroup(); |
250
|
|
|
} |
251
|
|
|
} |
252
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.