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
|
|
|
namespace eZ\Publish\Core\REST\Server\Tests\Output\ValueObjectVisitor; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\Core\REST\Common\Tests\Output\ValueObjectVisitorBaseTest; |
12
|
|
|
use eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor; |
13
|
|
|
use eZ\Publish\Core\REST\Server\Values\RestContent; |
14
|
|
|
use eZ\Publish\Core\REST\Server\Values\RestLocation; |
15
|
|
|
use eZ\Publish\Core\Repository\Values\Content\Location; |
16
|
|
|
use eZ\Publish\API\Repository\Values\Content\ContentInfo; |
17
|
|
|
|
18
|
|
|
class RestLocationTest extends ValueObjectVisitorBaseTest |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Test the Location visitor. |
22
|
|
|
* |
23
|
|
|
* @return string |
24
|
|
|
*/ |
25
|
|
|
public function testVisit() |
26
|
|
|
{ |
27
|
|
|
$visitor = $this->getVisitor(); |
28
|
|
|
$generator = $this->getGenerator(); |
29
|
|
|
|
30
|
|
|
$generator->startDocument(null); |
31
|
|
|
|
32
|
|
|
$location = new RestLocation( |
33
|
|
|
new Location( |
34
|
|
|
[ |
35
|
|
|
'id' => 42, |
36
|
|
|
'priority' => 0, |
37
|
|
|
'hidden' => false, |
38
|
|
|
'invisible' => true, |
39
|
|
|
'explicitlyHidden' => true, |
40
|
|
|
'remoteId' => 'remote-id', |
41
|
|
|
'parentLocationId' => 21, |
42
|
|
|
'pathString' => '/1/2/21/42/', |
43
|
|
|
'depth' => 3, |
44
|
|
|
'sortField' => Location::SORT_FIELD_PATH, |
45
|
|
|
'sortOrder' => Location::SORT_ORDER_ASC, |
46
|
|
|
'contentInfo' => new ContentInfo( |
47
|
|
|
[ |
48
|
|
|
'id' => 42, |
49
|
|
|
'contentTypeId' => 4, |
50
|
|
|
'name' => 'A Node, long lost', |
51
|
|
|
] |
52
|
|
|
), |
53
|
|
|
] |
54
|
|
|
), |
55
|
|
|
// Dummy value for ChildCount |
56
|
|
|
0 |
57
|
|
|
); |
58
|
|
|
|
59
|
|
|
$this->addRouteExpectation( |
60
|
|
|
'ezpublish_rest_loadLocation', |
61
|
|
|
['locationPath' => '1/2/21/42'], |
62
|
|
|
'/content/locations/1/2/21/42' |
63
|
|
|
); |
64
|
|
|
$this->addRouteExpectation( |
65
|
|
|
'ezpublish_rest_loadLocation', |
66
|
|
|
['locationPath' => '1/2/21'], |
67
|
|
|
'/content/locations/1/2/21' |
68
|
|
|
); |
69
|
|
|
$this->addRouteExpectation( |
70
|
|
|
'ezpublish_rest_loadLocationChildren', |
71
|
|
|
['locationPath' => '1/2/21/42'], |
72
|
|
|
'/content/locations/1/2/21/42/children' |
73
|
|
|
); |
74
|
|
|
$this->addRouteExpectation( |
75
|
|
|
'ezpublish_rest_loadContent', |
76
|
|
|
['contentId' => $location->location->contentId], |
77
|
|
|
"/content/objects/{$location->location->contentId}" |
78
|
|
|
); |
79
|
|
|
$this->addRouteExpectation( |
80
|
|
|
'ezpublish_rest_listLocationURLAliases', |
81
|
|
|
['locationPath' => '1/2/21/42'], |
82
|
|
|
'/content/objects/1/2/21/42/urlaliases' |
83
|
|
|
); |
84
|
|
|
|
85
|
|
|
// Expected twice, second one here for ContentInfo |
86
|
|
|
$this->addRouteExpectation( |
87
|
|
|
'ezpublish_rest_loadContent', |
88
|
|
|
['contentId' => $location->location->contentId], |
89
|
|
|
"/content/objects/{$location->location->contentId}" |
90
|
|
|
); |
91
|
|
|
|
92
|
|
|
$this->getVisitorMock()->expects($this->once()) |
93
|
|
|
->method('visitValueObject') |
94
|
|
|
->with($this->isInstanceOf(RestContent::class)); |
95
|
|
|
|
96
|
|
|
$visitor->visit( |
97
|
|
|
$this->getVisitorMock(), |
|
|
|
|
98
|
|
|
$generator, |
99
|
|
|
$location |
100
|
|
|
); |
101
|
|
|
|
102
|
|
|
$result = $generator->endDocument(null); |
103
|
|
|
|
104
|
|
|
$this->assertNotNull($result); |
105
|
|
|
|
106
|
|
|
return $result; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Test if result contains Location element. |
111
|
|
|
* |
112
|
|
|
* @param string $result |
113
|
|
|
* |
114
|
|
|
* @depends testVisit |
115
|
|
|
*/ |
116
|
|
|
public function testResultContainsLocationElement($result) |
117
|
|
|
{ |
118
|
|
|
$this->assertXMLTag( |
119
|
|
|
[ |
120
|
|
|
'tag' => 'Location', |
121
|
|
|
], |
122
|
|
|
$result, |
123
|
|
|
'Invalid <Location> element.', |
124
|
|
|
false |
125
|
|
|
); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Test if result contains Location element attributes. |
130
|
|
|
* |
131
|
|
|
* @param string $result |
132
|
|
|
* |
133
|
|
|
* @depends testVisit |
134
|
|
|
*/ |
135
|
|
|
public function testResultContainsLocationAttributes($result) |
136
|
|
|
{ |
137
|
|
|
$this->assertXMLTag( |
138
|
|
|
[ |
139
|
|
|
'tag' => 'Location', |
140
|
|
|
'attributes' => [ |
141
|
|
|
'media-type' => 'application/vnd.ez.api.Location+xml', |
142
|
|
|
'href' => '/content/locations/1/2/21/42', |
143
|
|
|
], |
144
|
|
|
], |
145
|
|
|
$result, |
146
|
|
|
'Invalid <Location> attributes.', |
147
|
|
|
false |
148
|
|
|
); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Test if result contains ContentInfo element. |
153
|
|
|
* |
154
|
|
|
* @param string $result |
155
|
|
|
* |
156
|
|
|
* @depends testVisit |
157
|
|
|
*/ |
158
|
|
|
public function testResultContainsContentInfoElement($result) |
159
|
|
|
{ |
160
|
|
|
$this->assertXMLTag( |
161
|
|
|
[ |
162
|
|
|
'tag' => 'ContentInfo', |
163
|
|
|
], |
164
|
|
|
$result, |
165
|
|
|
'Invalid <ContentInfo> element.', |
166
|
|
|
false |
167
|
|
|
); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Test if result contains Location element attributes. |
172
|
|
|
* |
173
|
|
|
* @param string $result |
174
|
|
|
* |
175
|
|
|
* @depends testVisit |
176
|
|
|
*/ |
177
|
|
|
public function testResultContainsContentInfoAttributes($result) |
178
|
|
|
{ |
179
|
|
|
$this->assertXMLTag( |
180
|
|
|
[ |
181
|
|
|
'tag' => 'ContentInfo', |
182
|
|
|
'attributes' => [ |
183
|
|
|
'media-type' => 'application/vnd.ez.api.ContentInfo+xml', |
184
|
|
|
'href' => '/content/objects/42', |
185
|
|
|
], |
186
|
|
|
], |
187
|
|
|
$result, |
188
|
|
|
'Invalid <ContentInfo> attributes.', |
189
|
|
|
false |
190
|
|
|
); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* Test if result contains id value element. |
195
|
|
|
* |
196
|
|
|
* @param string $result |
197
|
|
|
* |
198
|
|
|
* @depends testVisit |
199
|
|
|
*/ |
200
|
|
|
public function testResultContainsIdValueElement($result) |
201
|
|
|
{ |
202
|
|
|
$this->assertXMLTag( |
203
|
|
|
[ |
204
|
|
|
'tag' => 'id', |
205
|
|
|
'content' => '42', |
206
|
|
|
], |
207
|
|
|
$result, |
208
|
|
|
'Invalid or non-existing <Location> id value element.', |
209
|
|
|
false |
210
|
|
|
); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Test if result contains priority value element. |
215
|
|
|
* |
216
|
|
|
* @param string $result |
217
|
|
|
* |
218
|
|
|
* @depends testVisit |
219
|
|
|
*/ |
220
|
|
|
public function testResultContainsPriorityValueElement($result) |
221
|
|
|
{ |
222
|
|
|
$this->assertXMLTag( |
223
|
|
|
[ |
224
|
|
|
'tag' => 'priority', |
225
|
|
|
'content' => '0', |
226
|
|
|
], |
227
|
|
|
$result, |
228
|
|
|
'Invalid or non-existing <Location> priority value element.', |
229
|
|
|
false |
230
|
|
|
); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* Test if result contains hidden value element. |
235
|
|
|
* |
236
|
|
|
* @param string $result |
237
|
|
|
* |
238
|
|
|
* @depends testVisit |
239
|
|
|
*/ |
240
|
|
|
public function testResultContainsHiddenValueElement($result) |
241
|
|
|
{ |
242
|
|
|
$this->assertXMLTag( |
243
|
|
|
[ |
244
|
|
|
'tag' => 'hidden', |
245
|
|
|
'content' => 'false', |
246
|
|
|
], |
247
|
|
|
$result, |
248
|
|
|
'Invalid or non-existing <Location> hidden value element.', |
249
|
|
|
false |
250
|
|
|
); |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* Test if result contains invisible value element. |
255
|
|
|
* |
256
|
|
|
* @param string $result |
257
|
|
|
* |
258
|
|
|
* @depends testVisit |
259
|
|
|
*/ |
260
|
|
|
public function testResultContainsInvisibleValueElement($result) |
261
|
|
|
{ |
262
|
|
|
$this->assertXMLTag( |
263
|
|
|
[ |
264
|
|
|
'tag' => 'invisible', |
265
|
|
|
'content' => 'true', |
266
|
|
|
], |
267
|
|
|
$result, |
268
|
|
|
'Invalid or non-existing <Location> invisible value element.', |
269
|
|
|
false |
270
|
|
|
); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* Test if result contains explicitlyHidden value element. |
275
|
|
|
* |
276
|
|
|
* @param string $result |
277
|
|
|
* |
278
|
|
|
* @depends testVisit |
279
|
|
|
*/ |
280
|
|
|
public function testResultContainsExplicitlyHiddenValueElement($result) |
281
|
|
|
{ |
282
|
|
|
$this->assertXMLTag( |
283
|
|
|
[ |
284
|
|
|
'tag' => 'explicitlyHidden', |
285
|
|
|
'content' => 'true', |
286
|
|
|
], |
287
|
|
|
$result, |
288
|
|
|
'Invalid or non-existing <Location> explicitlyHidden value element.' |
289
|
|
|
); |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
/** |
293
|
|
|
* Test if result contains remoteId value element. |
294
|
|
|
* |
295
|
|
|
* @param string $result |
296
|
|
|
* |
297
|
|
|
* @depends testVisit |
298
|
|
|
*/ |
299
|
|
|
public function testResultContainsRemoteIdValueElement($result) |
300
|
|
|
{ |
301
|
|
|
$this->assertXMLTag( |
302
|
|
|
[ |
303
|
|
|
'tag' => 'remoteId', |
304
|
|
|
'content' => 'remote-id', |
305
|
|
|
], |
306
|
|
|
$result, |
307
|
|
|
'Invalid or non-existing <Location> remoteId value element.', |
308
|
|
|
false |
309
|
|
|
); |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
/** |
313
|
|
|
* Test if result contains Children element. |
314
|
|
|
* |
315
|
|
|
* @param string $result |
316
|
|
|
* |
317
|
|
|
* @depends testVisit |
318
|
|
|
*/ |
319
|
|
|
public function testResultContainsChildrenElement($result) |
320
|
|
|
{ |
321
|
|
|
$this->assertXMLTag( |
322
|
|
|
[ |
323
|
|
|
'tag' => 'Children', |
324
|
|
|
], |
325
|
|
|
$result, |
326
|
|
|
'Invalid <Children> element.', |
327
|
|
|
false |
328
|
|
|
); |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* Test if result contains Children element attributes. |
333
|
|
|
* |
334
|
|
|
* @param string $result |
335
|
|
|
* |
336
|
|
|
* @depends testVisit |
337
|
|
|
*/ |
338
|
|
|
public function testResultContainsChildrenAttributes($result) |
339
|
|
|
{ |
340
|
|
|
$this->assertXMLTag( |
341
|
|
|
[ |
342
|
|
|
'tag' => 'Children', |
343
|
|
|
'attributes' => [ |
344
|
|
|
'media-type' => 'application/vnd.ez.api.LocationList+xml', |
345
|
|
|
'href' => '/content/locations/1/2/21/42/children', |
346
|
|
|
], |
347
|
|
|
], |
348
|
|
|
$result, |
349
|
|
|
'Invalid <Children> attributes.', |
350
|
|
|
false |
351
|
|
|
); |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* Test if result contains ParentLocation element. |
356
|
|
|
* |
357
|
|
|
* @param string $result |
358
|
|
|
* |
359
|
|
|
* @depends testVisit |
360
|
|
|
*/ |
361
|
|
|
public function testResultContainsParentLocationElement($result) |
362
|
|
|
{ |
363
|
|
|
$this->assertXMLTag( |
364
|
|
|
[ |
365
|
|
|
'tag' => 'ParentLocation', |
366
|
|
|
], |
367
|
|
|
$result, |
368
|
|
|
'Invalid <ParentLocation> element.', |
369
|
|
|
false |
370
|
|
|
); |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
/** |
374
|
|
|
* Test if result contains ParentLocation element attributes. |
375
|
|
|
* |
376
|
|
|
* @param string $result |
377
|
|
|
* |
378
|
|
|
* @depends testVisit |
379
|
|
|
*/ |
380
|
|
|
public function testResultContainsParentLocationAttributes($result) |
381
|
|
|
{ |
382
|
|
|
$this->assertXMLTag( |
383
|
|
|
[ |
384
|
|
|
'tag' => 'ParentLocation', |
385
|
|
|
'attributes' => [ |
386
|
|
|
'media-type' => 'application/vnd.ez.api.Location+xml', |
387
|
|
|
'href' => '/content/locations/1/2/21', |
388
|
|
|
], |
389
|
|
|
], |
390
|
|
|
$result, |
391
|
|
|
'Invalid <ParentLocation> attributes.', |
392
|
|
|
false |
393
|
|
|
); |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
/** |
397
|
|
|
* Test if result contains Content element. |
398
|
|
|
* |
399
|
|
|
* @param string $result |
400
|
|
|
* |
401
|
|
|
* @depends testVisit |
402
|
|
|
*/ |
403
|
|
|
public function testResultContainsContentElement($result) |
404
|
|
|
{ |
405
|
|
|
$this->assertXMLTag( |
406
|
|
|
[ |
407
|
|
|
'tag' => 'Content', |
408
|
|
|
], |
409
|
|
|
$result, |
410
|
|
|
'Invalid <Content> element.', |
411
|
|
|
false |
412
|
|
|
); |
413
|
|
|
} |
414
|
|
|
|
415
|
|
|
/** |
416
|
|
|
* Test if result contains Content element attributes. |
417
|
|
|
* |
418
|
|
|
* @param string $result |
419
|
|
|
* |
420
|
|
|
* @depends testVisit |
421
|
|
|
*/ |
422
|
|
|
public function testResultContainsContentAttributes($result) |
423
|
|
|
{ |
424
|
|
|
$this->assertXMLTag( |
425
|
|
|
[ |
426
|
|
|
'tag' => 'Content', |
427
|
|
|
'attributes' => [ |
428
|
|
|
'media-type' => 'application/vnd.ez.api.Content+xml', |
429
|
|
|
'href' => '/content/objects/42', |
430
|
|
|
], |
431
|
|
|
], |
432
|
|
|
$result, |
433
|
|
|
'Invalid <Content> attributes.', |
434
|
|
|
false |
435
|
|
|
); |
436
|
|
|
} |
437
|
|
|
|
438
|
|
|
/** |
439
|
|
|
* Test if result contains pathString value element. |
440
|
|
|
* |
441
|
|
|
* @param string $result |
442
|
|
|
* |
443
|
|
|
* @depends testVisit |
444
|
|
|
*/ |
445
|
|
|
public function testResultContainsPathStringValueElement($result) |
446
|
|
|
{ |
447
|
|
|
$this->assertXMLTag( |
448
|
|
|
[ |
449
|
|
|
'tag' => 'pathString', |
450
|
|
|
'content' => '/1/2/21/42/', |
451
|
|
|
], |
452
|
|
|
$result, |
453
|
|
|
'Invalid or non-existing <Location> pathString value element.', |
454
|
|
|
false |
455
|
|
|
); |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
/** |
459
|
|
|
* Test if result contains depth value element. |
460
|
|
|
* |
461
|
|
|
* @param string $result |
462
|
|
|
* |
463
|
|
|
* @depends testVisit |
464
|
|
|
*/ |
465
|
|
|
public function testResultContainsDepthValueElement($result) |
466
|
|
|
{ |
467
|
|
|
$this->assertXMLTag( |
468
|
|
|
[ |
469
|
|
|
'tag' => 'depth', |
470
|
|
|
'content' => '3', |
471
|
|
|
], |
472
|
|
|
$result, |
473
|
|
|
'Invalid or non-existing <Location> depth value element.', |
474
|
|
|
false |
475
|
|
|
); |
476
|
|
|
} |
477
|
|
|
|
478
|
|
|
/** |
479
|
|
|
* Test if result contains sortField value element. |
480
|
|
|
* |
481
|
|
|
* @param string $result |
482
|
|
|
* |
483
|
|
|
* @depends testVisit |
484
|
|
|
*/ |
485
|
|
|
public function testResultContainsSortFieldValueElement($result) |
486
|
|
|
{ |
487
|
|
|
$this->assertXMLTag( |
488
|
|
|
[ |
489
|
|
|
'tag' => 'sortField', |
490
|
|
|
'content' => 'PATH', |
491
|
|
|
], |
492
|
|
|
$result, |
493
|
|
|
'Invalid or non-existing <Location> sortField value element.', |
494
|
|
|
false |
495
|
|
|
); |
496
|
|
|
} |
497
|
|
|
|
498
|
|
|
/** |
499
|
|
|
* Test if result contains sortOrder value element. |
500
|
|
|
* |
501
|
|
|
* @param string $result |
502
|
|
|
* |
503
|
|
|
* @depends testVisit |
504
|
|
|
*/ |
505
|
|
|
public function testResultContainsSortOrderValueElement($result) |
506
|
|
|
{ |
507
|
|
|
$this->assertXMLTag( |
508
|
|
|
[ |
509
|
|
|
'tag' => 'sortOrder', |
510
|
|
|
'content' => 'ASC', |
511
|
|
|
], |
512
|
|
|
$result, |
513
|
|
|
'Invalid or non-existing <Location> sortOrder value element.', |
514
|
|
|
false |
515
|
|
|
); |
516
|
|
|
} |
517
|
|
|
|
518
|
|
|
/** |
519
|
|
|
* Test if result contains childCount value element. |
520
|
|
|
* |
521
|
|
|
* @param string $result |
522
|
|
|
* |
523
|
|
|
* @depends testVisit |
524
|
|
|
*/ |
525
|
|
|
public function testResultContainsChildCountValueElement($result) |
526
|
|
|
{ |
527
|
|
|
$this->assertXMLTag( |
528
|
|
|
[ |
529
|
|
|
'tag' => 'childCount', |
530
|
|
|
'content' => '0', |
531
|
|
|
], |
532
|
|
|
$result, |
533
|
|
|
'Invalid or non-existing <Location> childCount value element.', |
534
|
|
|
false |
535
|
|
|
); |
536
|
|
|
} |
537
|
|
|
|
538
|
|
|
/** |
539
|
|
|
* Test if result contains Content element. |
540
|
|
|
* |
541
|
|
|
* @param string $result |
542
|
|
|
* |
543
|
|
|
* @depends testVisit |
544
|
|
|
*/ |
545
|
|
|
public function testResultContainsUrlAliasesTag($result) |
546
|
|
|
{ |
547
|
|
|
$this->assertXMLTag( |
548
|
|
|
[ |
549
|
|
|
'tag' => 'UrlAliases', |
550
|
|
|
], |
551
|
|
|
$result, |
552
|
|
|
'Invalid <UrlAliases> element.', |
553
|
|
|
false |
554
|
|
|
); |
555
|
|
|
} |
556
|
|
|
|
557
|
|
|
/** |
558
|
|
|
* Test if result contains Content element attributes. |
559
|
|
|
* |
560
|
|
|
* @param string $result |
561
|
|
|
* |
562
|
|
|
* @depends testVisit |
563
|
|
|
*/ |
564
|
|
|
public function testResultContainsUrlAliasesTagAttributes($result) |
565
|
|
|
{ |
566
|
|
|
$this->assertXMLTag( |
567
|
|
|
[ |
568
|
|
|
'tag' => 'UrlAliases', |
569
|
|
|
'attributes' => [ |
570
|
|
|
'media-type' => 'application/vnd.ez.api.UrlAliasRefList+xml', |
571
|
|
|
'href' => '/content/objects/1/2/21/42/urlaliases', |
572
|
|
|
], |
573
|
|
|
], |
574
|
|
|
$result, |
575
|
|
|
'Invalid <UrlAliases> attributes.', |
576
|
|
|
false |
577
|
|
|
); |
578
|
|
|
} |
579
|
|
|
|
580
|
|
|
/** |
581
|
|
|
* Get the Location visitor. |
582
|
|
|
* |
583
|
|
|
* @return \eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\RestLocation |
584
|
|
|
*/ |
585
|
|
|
protected function internalGetVisitor() |
586
|
|
|
{ |
587
|
|
|
return new ValueObjectVisitor\RestLocation(); |
588
|
|
|
} |
589
|
|
|
} |
590
|
|
|
|
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.