1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the LocationServiceTest 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\API\Repository\Tests; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\API\Repository\Exceptions\BadStateException; |
12
|
|
|
use eZ\Publish\API\Repository\Values\Content\Content; |
13
|
|
|
use eZ\Publish\API\Repository\Values\Content\Location; |
14
|
|
|
use eZ\Publish\API\Repository\Values\Content\LocationCreateStruct; |
15
|
|
|
use eZ\Publish\API\Repository\Values\Content\LocationList; |
16
|
|
|
use eZ\Publish\API\Repository\Values\Content\ContentInfo; |
17
|
|
|
use eZ\Publish\API\Repository\Exceptions\NotFoundException; |
18
|
|
|
use Exception; |
19
|
|
|
use eZ\Publish\API\Repository\Values\Content\LocationUpdateStruct; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Test case for operations in the LocationService using in memory storage. |
23
|
|
|
* |
24
|
|
|
* @see eZ\Publish\API\Repository\LocationService |
25
|
|
|
* @group location |
26
|
|
|
*/ |
27
|
|
|
class LocationServiceTest extends BaseTest |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* Test for the newLocationCreateStruct() method. |
31
|
|
|
* |
32
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct |
33
|
|
|
* |
34
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::newLocationCreateStruct() |
35
|
|
|
*/ |
36
|
|
View Code Duplication |
public function testNewLocationCreateStruct() |
37
|
|
|
{ |
38
|
|
|
$repository = $this->getRepository(); |
39
|
|
|
|
40
|
|
|
$parentLocationId = $this->generateId('location', 1); |
41
|
|
|
/* BEGIN: Use Case */ |
42
|
|
|
// $parentLocationId is the ID of an existing location |
43
|
|
|
$locationService = $repository->getLocationService(); |
44
|
|
|
|
45
|
|
|
$locationCreate = $locationService->newLocationCreateStruct( |
46
|
|
|
$parentLocationId |
47
|
|
|
); |
48
|
|
|
/* END: Use Case */ |
49
|
|
|
|
50
|
|
|
$this->assertInstanceOf( |
51
|
|
|
'\\eZ\\Publish\\API\\Repository\\Values\\Content\\LocationCreateStruct', |
52
|
|
|
$locationCreate |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
return $locationCreate; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Test for the newLocationCreateStruct() method. |
60
|
|
|
* |
61
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $locationCreate |
62
|
|
|
* |
63
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::newLocationCreateStruct() |
64
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testNewLocationCreateStruct |
65
|
|
|
*/ |
66
|
|
|
public function testNewLocationCreateStructValues(LocationCreateStruct $locationCreate) |
67
|
|
|
{ |
68
|
|
|
$this->assertPropertiesCorrect( |
69
|
|
|
array( |
70
|
|
|
'priority' => 0, |
71
|
|
|
'hidden' => false, |
72
|
|
|
// remoteId should be initialized with a default value |
73
|
|
|
//'remoteId' => null, |
74
|
|
|
'sortField' => Location::SORT_FIELD_NAME, |
75
|
|
|
'sortOrder' => Location::SORT_ORDER_ASC, |
76
|
|
|
'parentLocationId' => $this->generateId('location', 1), |
77
|
|
|
), |
78
|
|
|
$locationCreate |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Test for the createLocation() method. |
84
|
|
|
* |
85
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::createLocation() |
86
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testNewLocationCreateStruct |
87
|
|
|
*/ |
88
|
|
|
public function testCreateLocation() |
89
|
|
|
{ |
90
|
|
|
$repository = $this->getRepository(); |
91
|
|
|
|
92
|
|
|
$contentId = $this->generateId('object', 41); |
93
|
|
|
$parentLocationId = $this->generateId('location', 5); |
94
|
|
|
/* BEGIN: Use Case */ |
95
|
|
|
// $contentId is the ID of an existing content object |
96
|
|
|
// $parentLocationId is the ID of an existing location |
97
|
|
|
$contentService = $repository->getContentService(); |
98
|
|
|
$locationService = $repository->getLocationService(); |
99
|
|
|
|
100
|
|
|
// ContentInfo for "How to use eZ Publish" |
101
|
|
|
$contentInfo = $contentService->loadContentInfo($contentId); |
102
|
|
|
|
103
|
|
|
$locationCreate = $locationService->newLocationCreateStruct($parentLocationId); |
104
|
|
|
$locationCreate->priority = 23; |
105
|
|
|
$locationCreate->hidden = true; |
106
|
|
|
$locationCreate->remoteId = 'sindelfingen'; |
107
|
|
|
$locationCreate->sortField = Location::SORT_FIELD_NODE_ID; |
108
|
|
|
$locationCreate->sortOrder = Location::SORT_ORDER_DESC; |
109
|
|
|
|
110
|
|
|
$location = $locationService->createLocation( |
111
|
|
|
$contentInfo, |
112
|
|
|
$locationCreate |
113
|
|
|
); |
114
|
|
|
/* END: Use Case */ |
115
|
|
|
|
116
|
|
|
$this->assertInstanceOf( |
117
|
|
|
'\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', |
118
|
|
|
$location |
119
|
|
|
); |
120
|
|
|
|
121
|
|
|
return array( |
122
|
|
|
'locationCreate' => $locationCreate, |
123
|
|
|
'createdLocation' => $location, |
124
|
|
|
'contentInfo' => $contentInfo, |
125
|
|
|
'parentLocation' => $locationService->loadLocation($this->generateId('location', 5)), |
126
|
|
|
); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Test for the createLocation() method. |
131
|
|
|
* |
132
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::createLocation() |
133
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCreateLocation |
134
|
|
|
*/ |
135
|
|
|
public function testCreateLocationStructValues(array $data) |
136
|
|
|
{ |
137
|
|
|
$locationCreate = $data['locationCreate']; |
138
|
|
|
$createdLocation = $data['createdLocation']; |
139
|
|
|
$contentInfo = $data['contentInfo']; |
140
|
|
|
|
141
|
|
|
$this->assertPropertiesCorrect( |
142
|
|
|
array( |
143
|
|
|
'priority' => $locationCreate->priority, |
144
|
|
|
'hidden' => $locationCreate->hidden, |
145
|
|
|
'invisible' => $locationCreate->hidden, |
146
|
|
|
'remoteId' => $locationCreate->remoteId, |
147
|
|
|
'contentInfo' => $contentInfo, |
148
|
|
|
'parentLocationId' => $locationCreate->parentLocationId, |
149
|
|
|
'pathString' => '/1/5/' . $this->parseId('location', $createdLocation->id) . '/', |
150
|
|
|
'depth' => 2, |
151
|
|
|
'sortField' => $locationCreate->sortField, |
152
|
|
|
'sortOrder' => $locationCreate->sortOrder, |
153
|
|
|
), |
154
|
|
|
$createdLocation |
155
|
|
|
); |
156
|
|
|
|
157
|
|
|
$this->assertNotNull($createdLocation->id); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Test for the createLocation() method. |
162
|
|
|
* |
163
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::createLocation() |
164
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testNewLocationCreateStruct |
165
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
166
|
|
|
*/ |
167
|
|
View Code Duplication |
public function testCreateLocationThrowsInvalidArgumentExceptionContentAlreadyBelowParent() |
168
|
|
|
{ |
169
|
|
|
$repository = $this->getRepository(); |
170
|
|
|
|
171
|
|
|
$contentId = $this->generateId('object', 11); |
172
|
|
|
$parentLocationId = $this->generateId('location', 5); |
173
|
|
|
/* BEGIN: Use Case */ |
174
|
|
|
// $contentId is the ID of an existing content object |
175
|
|
|
// $parentLocationId is the ID of an existing location which already |
176
|
|
|
// has the content assigned to one of its descendant locations |
177
|
|
|
$contentService = $repository->getContentService(); |
178
|
|
|
$locationService = $repository->getLocationService(); |
179
|
|
|
|
180
|
|
|
// ContentInfo for "How to use eZ Publish" |
181
|
|
|
$contentInfo = $contentService->loadContentInfo($contentId); |
182
|
|
|
|
183
|
|
|
$locationCreate = $locationService->newLocationCreateStruct($parentLocationId); |
184
|
|
|
|
185
|
|
|
// Throws exception, since content is already located at "/1/2/107/110/" |
186
|
|
|
$locationService->createLocation( |
187
|
|
|
$contentInfo, |
188
|
|
|
$locationCreate |
189
|
|
|
); |
190
|
|
|
/* END: Use Case */ |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* Test for the createLocation() method. |
195
|
|
|
* |
196
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::createLocation() |
197
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testNewLocationCreateStruct |
198
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
199
|
|
|
*/ |
200
|
|
View Code Duplication |
public function testCreateLocationThrowsInvalidArgumentExceptionParentIsSubLocationOfContent() |
201
|
|
|
{ |
202
|
|
|
$repository = $this->getRepository(); |
203
|
|
|
|
204
|
|
|
$contentId = $this->generateId('object', 4); |
205
|
|
|
$parentLocationId = $this->generateId('location', 12); |
206
|
|
|
/* BEGIN: Use Case */ |
207
|
|
|
// $contentId is the ID of an existing content object |
208
|
|
|
// $parentLocationId is the ID of an existing location which is below a |
209
|
|
|
// location that is assigned to the content |
210
|
|
|
$contentService = $repository->getContentService(); |
211
|
|
|
$locationService = $repository->getLocationService(); |
212
|
|
|
|
213
|
|
|
// ContentInfo for "How to use eZ Publish" |
214
|
|
|
$contentInfo = $contentService->loadContentInfo($contentId); |
215
|
|
|
|
216
|
|
|
$locationCreate = $locationService->newLocationCreateStruct($parentLocationId); |
217
|
|
|
|
218
|
|
|
// Throws exception, since content is already located at "/1/2/" |
219
|
|
|
$locationService->createLocation( |
220
|
|
|
$contentInfo, |
221
|
|
|
$locationCreate |
222
|
|
|
); |
223
|
|
|
/* END: Use Case */ |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* Test for the createLocation() method. |
228
|
|
|
* |
229
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::createLocation() |
230
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testNewLocationCreateStruct |
231
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
232
|
|
|
*/ |
233
|
|
View Code Duplication |
public function testCreateLocationThrowsInvalidArgumentExceptionRemoteIdExists() |
234
|
|
|
{ |
235
|
|
|
$repository = $this->getRepository(); |
236
|
|
|
|
237
|
|
|
$contentId = $this->generateId('object', 41); |
238
|
|
|
$parentLocationId = $this->generateId('location', 5); |
239
|
|
|
/* BEGIN: Use Case */ |
240
|
|
|
// $contentId is the ID of an existing content object |
241
|
|
|
$contentService = $repository->getContentService(); |
242
|
|
|
$locationService = $repository->getLocationService(); |
243
|
|
|
|
244
|
|
|
// ContentInfo for "How to use eZ Publish" |
245
|
|
|
$contentInfo = $contentService->loadContentInfo($contentId); |
246
|
|
|
|
247
|
|
|
$locationCreate = $locationService->newLocationCreateStruct($parentLocationId); |
248
|
|
|
// This remote ID already exists |
249
|
|
|
$locationCreate->remoteId = 'f3e90596361e31d496d4026eb624c983'; |
250
|
|
|
|
251
|
|
|
// Throws exception, since remote ID is already in use |
252
|
|
|
$locationService->createLocation( |
253
|
|
|
$contentInfo, |
254
|
|
|
$locationCreate |
255
|
|
|
); |
256
|
|
|
/* END: Use Case */ |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* Test for the createLocation() method. |
261
|
|
|
* |
262
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::createLocation() |
263
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testNewLocationCreateStruct |
264
|
|
|
* @dataProvider dataProviderForOutOfRangeLocationPriority |
265
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
266
|
|
|
*/ |
267
|
|
View Code Duplication |
public function testCreateLocationThrowsInvalidArgumentExceptionPriorityIsOutOfRange($priority) |
268
|
|
|
{ |
269
|
|
|
$repository = $this->getRepository(); |
270
|
|
|
|
271
|
|
|
$contentId = $this->generateId('object', 41); |
272
|
|
|
$parentLocationId = $this->generateId('location', 5); |
273
|
|
|
/* BEGIN: Use Case */ |
274
|
|
|
// $contentId is the ID of an existing content object |
275
|
|
|
// $parentLocationId is the ID of an existing location |
276
|
|
|
$contentService = $repository->getContentService(); |
277
|
|
|
$locationService = $repository->getLocationService(); |
278
|
|
|
|
279
|
|
|
// ContentInfo for "How to use eZ Publish" |
280
|
|
|
$contentInfo = $contentService->loadContentInfo($contentId); |
281
|
|
|
|
282
|
|
|
$locationCreate = $locationService->newLocationCreateStruct($parentLocationId); |
283
|
|
|
$locationCreate->priority = $priority; |
284
|
|
|
$locationCreate->hidden = true; |
285
|
|
|
$locationCreate->remoteId = 'sindelfingen'; |
286
|
|
|
$locationCreate->sortField = Location::SORT_FIELD_NODE_ID; |
287
|
|
|
$locationCreate->sortOrder = Location::SORT_ORDER_DESC; |
288
|
|
|
|
289
|
|
|
// Throws exception, since priority is out of range |
290
|
|
|
$locationService->createLocation( |
291
|
|
|
$contentInfo, |
292
|
|
|
$locationCreate |
293
|
|
|
); |
294
|
|
|
/* END: Use Case */ |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
public function dataProviderForOutOfRangeLocationPriority() |
298
|
|
|
{ |
299
|
|
|
return [[-2147483649], [2147483648]]; |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
/** |
303
|
|
|
* Test for the createLocation() method. |
304
|
|
|
* |
305
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::createLocation() |
306
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCreateLocation |
307
|
|
|
*/ |
308
|
|
|
public function testCreateLocationInTransactionWithRollback() |
309
|
|
|
{ |
310
|
|
|
$repository = $this->getRepository(); |
311
|
|
|
|
312
|
|
|
$contentId = $this->generateId('object', 41); |
313
|
|
|
$parentLocationId = $this->generateId('location', 5); |
314
|
|
|
/* BEGIN: Use Case */ |
315
|
|
|
// $contentId is the ID of an existing content object |
316
|
|
|
// $parentLocationId is the ID of an existing location |
317
|
|
|
$contentService = $repository->getContentService(); |
318
|
|
|
$locationService = $repository->getLocationService(); |
319
|
|
|
|
320
|
|
|
$repository->beginTransaction(); |
321
|
|
|
|
322
|
|
|
try { |
323
|
|
|
// ContentInfo for "How to use eZ Publish" |
324
|
|
|
$contentInfo = $contentService->loadContentInfo($contentId); |
325
|
|
|
|
326
|
|
|
$locationCreate = $locationService->newLocationCreateStruct($parentLocationId); |
327
|
|
|
$locationCreate->remoteId = 'sindelfingen'; |
328
|
|
|
|
329
|
|
|
$createdLocationId = $locationService->createLocation( |
330
|
|
|
$contentInfo, |
331
|
|
|
$locationCreate |
332
|
|
|
)->id; |
333
|
|
|
} catch (Exception $e) { |
334
|
|
|
// Cleanup hanging transaction on error |
335
|
|
|
$repository->rollback(); |
336
|
|
|
throw $e; |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
$repository->rollback(); |
340
|
|
|
|
341
|
|
|
try { |
342
|
|
|
// Throws exception since creation of location was rolled back |
343
|
|
|
$location = $locationService->loadLocation($createdLocationId); |
|
|
|
|
344
|
|
|
} catch (NotFoundException $e) { |
345
|
|
|
return; |
346
|
|
|
} |
347
|
|
|
/* END: Use Case */ |
348
|
|
|
|
349
|
|
|
$this->fail('Objects still exists after rollback.'); |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
/** |
353
|
|
|
* Test for the loadLocation() method. |
354
|
|
|
* |
355
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Location |
356
|
|
|
* |
357
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::loadLocation |
358
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCreateLocation |
359
|
|
|
*/ |
360
|
|
|
public function testLoadLocation() |
361
|
|
|
{ |
362
|
|
|
$repository = $this->getRepository(); |
363
|
|
|
|
364
|
|
|
$locationId = $this->generateId('location', 5); |
365
|
|
|
/* BEGIN: Use Case */ |
366
|
|
|
// $locationId is the ID of an existing location |
367
|
|
|
$locationService = $repository->getLocationService(); |
368
|
|
|
|
369
|
|
|
$location = $locationService->loadLocation($locationId); |
370
|
|
|
/* END: Use Case */ |
371
|
|
|
|
372
|
|
|
$this->assertInstanceOf( |
373
|
|
|
Location::class, |
374
|
|
|
$location |
375
|
|
|
); |
376
|
|
|
self::assertEquals(5, $location->id); |
377
|
|
|
|
378
|
|
|
return $location; |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
/** |
382
|
|
|
* Test for the loadLocation() method. |
383
|
|
|
* |
384
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::loadLocation() |
385
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
386
|
|
|
*/ |
387
|
|
|
public function testLoadLocationRootStructValues() |
388
|
|
|
{ |
389
|
|
|
$repository = $this->getRepository(); |
390
|
|
|
$locationService = $repository->getLocationService(); |
391
|
|
|
$location = $locationService->loadLocation($this->generateId('location', 1)); |
392
|
|
|
|
393
|
|
|
$legacyDateTime = new \DateTime(); |
394
|
|
|
$legacyDateTime->setTimestamp(1030968000); |
395
|
|
|
|
396
|
|
|
// $location |
397
|
|
|
$this->assertPropertiesCorrect( |
398
|
|
|
array( |
399
|
|
|
'id' => $this->generateId('location', 1), |
400
|
|
|
'status' => 1, |
401
|
|
|
'priority' => 0, |
402
|
|
|
'hidden' => false, |
403
|
|
|
'invisible' => false, |
404
|
|
|
'remoteId' => '629709ba256fe317c3ddcee35453a96a', |
405
|
|
|
'parentLocationId' => $this->generateId('location', 1), |
406
|
|
|
'pathString' => '/1/', |
407
|
|
|
'depth' => 0, |
408
|
|
|
'sortField' => 1, |
409
|
|
|
'sortOrder' => 1, |
410
|
|
|
), |
411
|
|
|
$location |
412
|
|
|
); |
413
|
|
|
|
414
|
|
|
// $location->contentInfo |
415
|
|
|
$this->assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\ContentInfo', $location->contentInfo); |
416
|
|
|
$this->assertPropertiesCorrect( |
417
|
|
|
array( |
418
|
|
|
'id' => $this->generateId('content', 0), |
419
|
|
|
'name' => 'Top Level Nodes', |
420
|
|
|
'sectionId' => 1, |
421
|
|
|
'mainLocationId' => 1, |
422
|
|
|
'contentTypeId' => 1, |
423
|
|
|
'currentVersionNo' => 1, |
424
|
|
|
'published' => 1, |
425
|
|
|
'ownerId' => 14, |
426
|
|
|
'modificationDate' => $legacyDateTime, |
427
|
|
|
'publishedDate' => $legacyDateTime, |
428
|
|
|
'alwaysAvailable' => 1, |
429
|
|
|
'remoteId' => null, |
430
|
|
|
'mainLanguageCode' => 'eng-GB', |
431
|
|
|
), |
432
|
|
|
$location->contentInfo |
433
|
|
|
); |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
/** |
437
|
|
|
* Test for the loadLocation() method. |
438
|
|
|
* |
439
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Location $location |
440
|
|
|
* |
441
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::loadLocation() |
442
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
443
|
|
|
*/ |
444
|
|
|
public function testLoadLocationStructValues(Location $location) |
445
|
|
|
{ |
446
|
|
|
$this->assertPropertiesCorrect( |
447
|
|
|
array( |
448
|
|
|
'id' => $this->generateId('location', 5), |
449
|
|
|
'priority' => 0, |
450
|
|
|
'hidden' => false, |
451
|
|
|
'invisible' => false, |
452
|
|
|
'remoteId' => '3f6d92f8044aed134f32153517850f5a', |
453
|
|
|
'parentLocationId' => $this->generateId('location', 1), |
454
|
|
|
'pathString' => '/1/5/', |
455
|
|
|
'depth' => 1, |
456
|
|
|
'sortField' => 1, |
457
|
|
|
'sortOrder' => 1, |
458
|
|
|
), |
459
|
|
|
$location |
460
|
|
|
); |
461
|
|
|
|
462
|
|
|
$this->assertInstanceOf( |
463
|
|
|
'\\eZ\\Publish\\API\\Repository\\Values\\Content\\ContentInfo', |
464
|
|
|
$location->contentInfo |
465
|
|
|
); |
466
|
|
|
$this->assertEquals($this->generateId('object', 4), $location->contentInfo->id); |
467
|
|
|
} |
468
|
|
|
|
469
|
|
|
/** |
470
|
|
|
* Test for the loadLocation() method. |
471
|
|
|
* |
472
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::loadLocation() |
473
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCreateLocation |
474
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
475
|
|
|
*/ |
476
|
|
|
public function testLoadLocationThrowsNotFoundException() |
477
|
|
|
{ |
478
|
|
|
$repository = $this->getRepository(); |
479
|
|
|
|
480
|
|
|
$nonExistentLocationId = $this->generateId('location', 2342); |
481
|
|
|
/* BEGIN: Use Case */ |
482
|
|
|
$locationService = $repository->getLocationService(); |
483
|
|
|
|
484
|
|
|
// Throws exception, if Location with $nonExistentLocationId does not |
485
|
|
|
// exist |
486
|
|
|
$location = $locationService->loadLocation($nonExistentLocationId); |
|
|
|
|
487
|
|
|
/* END: Use Case */ |
488
|
|
|
} |
489
|
|
|
|
490
|
|
|
/** |
491
|
|
|
* Test for the loadLocationByRemoteId() method. |
492
|
|
|
* |
493
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::loadLocationByRemoteId() |
494
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
495
|
|
|
*/ |
496
|
|
View Code Duplication |
public function testLoadLocationByRemoteId() |
497
|
|
|
{ |
498
|
|
|
$repository = $this->getRepository(); |
499
|
|
|
|
500
|
|
|
/* BEGIN: Use Case */ |
501
|
|
|
$locationService = $repository->getLocationService(); |
502
|
|
|
|
503
|
|
|
$location = $locationService->loadLocationByRemoteId( |
504
|
|
|
'3f6d92f8044aed134f32153517850f5a' |
505
|
|
|
); |
506
|
|
|
/* END: Use Case */ |
507
|
|
|
|
508
|
|
|
$this->assertEquals( |
509
|
|
|
$locationService->loadLocation($this->generateId('location', 5)), |
510
|
|
|
$location |
511
|
|
|
); |
512
|
|
|
} |
513
|
|
|
|
514
|
|
|
/** |
515
|
|
|
* Test for the loadLocationByRemoteId() method. |
516
|
|
|
* |
517
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::loadLocationByRemoteId() |
518
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
519
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
520
|
|
|
*/ |
521
|
|
|
public function testLoadLocationByRemoteIdThrowsNotFoundException() |
522
|
|
|
{ |
523
|
|
|
$repository = $this->getRepository(); |
524
|
|
|
|
525
|
|
|
/* BEGIN: Use Case */ |
526
|
|
|
$locationService = $repository->getLocationService(); |
527
|
|
|
|
528
|
|
|
// Throws exception, since Location with remote ID does not exist |
529
|
|
|
$location = $locationService->loadLocationByRemoteId( |
|
|
|
|
530
|
|
|
'not-exists' |
531
|
|
|
); |
532
|
|
|
/* END: Use Case */ |
533
|
|
|
} |
534
|
|
|
|
535
|
|
|
/** |
536
|
|
|
* Test for the loadLocations() method. |
537
|
|
|
* |
538
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::loadLocations() |
539
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCreateLocation |
540
|
|
|
*/ |
541
|
|
|
public function testLoadLocations() |
542
|
|
|
{ |
543
|
|
|
$repository = $this->getRepository(); |
544
|
|
|
|
545
|
|
|
$contentId = $this->generateId('object', 4); |
546
|
|
|
/* BEGIN: Use Case */ |
547
|
|
|
// $contentId contains the ID of an existing content object |
548
|
|
|
$contentService = $repository->getContentService(); |
549
|
|
|
$locationService = $repository->getLocationService(); |
550
|
|
|
|
551
|
|
|
$contentInfo = $contentService->loadContentInfo($contentId); |
552
|
|
|
|
553
|
|
|
$locations = $locationService->loadLocations($contentInfo); |
554
|
|
|
/* END: Use Case */ |
555
|
|
|
|
556
|
|
|
$this->assertInternalType('array', $locations); |
557
|
|
|
self::assertNotEmpty($locations); |
558
|
|
|
|
559
|
|
|
foreach ($locations as $location) { |
560
|
|
|
self::assertInstanceOf(Location::class, $location); |
561
|
|
|
self::assertEquals($contentInfo->id, $location->getContentInfo()->id); |
562
|
|
|
} |
563
|
|
|
|
564
|
|
|
return $locations; |
565
|
|
|
} |
566
|
|
|
|
567
|
|
|
/** |
568
|
|
|
* Test for the loadLocations() method. |
569
|
|
|
* |
570
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::loadLocations() |
571
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocations |
572
|
|
|
*/ |
573
|
|
|
public function testLoadLocationsContent(array $locations) |
574
|
|
|
{ |
575
|
|
|
$repository = $this->getRepository(); |
576
|
|
|
$locationService = $repository->getLocationService(); |
|
|
|
|
577
|
|
|
|
578
|
|
|
$this->assertEquals(1, count($locations)); |
579
|
|
|
foreach ($locations as $loadedLocation) { |
580
|
|
|
$this->assertInstanceOf( |
581
|
|
|
'\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', |
582
|
|
|
$loadedLocation |
583
|
|
|
); |
584
|
|
|
} |
585
|
|
|
|
586
|
|
|
usort( |
587
|
|
|
$locations, |
588
|
|
|
function ($a, $b) { |
589
|
|
|
strcmp($a->id, $b->id); |
590
|
|
|
} |
591
|
|
|
); |
592
|
|
|
|
593
|
|
|
$this->assertEquals( |
594
|
|
|
array($this->generateId('location', 5)), |
595
|
|
|
array_map( |
596
|
|
|
function (Location $location) { |
597
|
|
|
return $location->id; |
598
|
|
|
}, |
599
|
|
|
$locations |
600
|
|
|
) |
601
|
|
|
); |
602
|
|
|
} |
603
|
|
|
|
604
|
|
|
/** |
605
|
|
|
* Test for the loadLocations() method. |
606
|
|
|
* |
607
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Location[] |
608
|
|
|
* |
609
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::loadLocations($contentInfo, $rootLocation) |
610
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocations |
611
|
|
|
*/ |
612
|
|
|
public function testLoadLocationsLimitedSubtree() |
613
|
|
|
{ |
614
|
|
|
$repository = $this->getRepository(); |
615
|
|
|
|
616
|
|
|
$originalLocationId = $this->generateId('location', 54); |
617
|
|
|
$originalParentLocationId = $this->generateId('location', 48); |
618
|
|
|
$newParentLocationId = $this->generateId('location', 43); |
619
|
|
|
/* BEGIN: Use Case */ |
620
|
|
|
// $originalLocationId is the ID of an existing location |
621
|
|
|
// $originalParentLocationId is the ID of the parent location of |
622
|
|
|
// $originalLocationId |
623
|
|
|
// $newParentLocationId is the ID of an existing location outside the tree |
624
|
|
|
// of $originalLocationId and $originalParentLocationId |
625
|
|
|
$locationService = $repository->getLocationService(); |
626
|
|
|
|
627
|
|
|
// Location at "/1/48/54" |
628
|
|
|
$originalLocation = $locationService->loadLocation($originalLocationId); |
629
|
|
|
|
630
|
|
|
// Create location under "/1/43/" |
631
|
|
|
$locationCreate = $locationService->newLocationCreateStruct($newParentLocationId); |
632
|
|
|
$locationService->createLocation( |
633
|
|
|
$originalLocation->contentInfo, |
634
|
|
|
$locationCreate |
635
|
|
|
); |
636
|
|
|
|
637
|
|
|
$findRootLocation = $locationService->loadLocation($originalParentLocationId); |
638
|
|
|
|
639
|
|
|
// Returns an array with only $originalLocation |
640
|
|
|
$locations = $locationService->loadLocations( |
641
|
|
|
$originalLocation->contentInfo, |
642
|
|
|
$findRootLocation |
643
|
|
|
); |
644
|
|
|
/* END: Use Case */ |
645
|
|
|
|
646
|
|
|
$this->assertInternalType('array', $locations); |
647
|
|
|
|
648
|
|
|
return $locations; |
649
|
|
|
} |
650
|
|
|
|
651
|
|
|
/** |
652
|
|
|
* Test for the loadLocations() method. |
653
|
|
|
* |
654
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Location[] $locations |
655
|
|
|
* |
656
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::loadLocations() |
657
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationsLimitedSubtree |
658
|
|
|
*/ |
659
|
|
|
public function testLoadLocationsLimitedSubtreeContent(array $locations) |
660
|
|
|
{ |
661
|
|
|
$this->assertEquals(1, count($locations)); |
662
|
|
|
|
663
|
|
|
$this->assertEquals( |
664
|
|
|
$this->generateId('location', 54), |
665
|
|
|
reset($locations)->id |
666
|
|
|
); |
667
|
|
|
} |
668
|
|
|
|
669
|
|
|
/** |
670
|
|
|
* Test for the loadLocations() method. |
671
|
|
|
* |
672
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::loadLocations() |
673
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocations |
674
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
675
|
|
|
*/ |
676
|
|
View Code Duplication |
public function testLoadLocationsThrowsBadStateException() |
677
|
|
|
{ |
678
|
|
|
$repository = $this->getRepository(); |
679
|
|
|
|
680
|
|
|
/* BEGIN: Use Case */ |
681
|
|
|
$contentTypeService = $repository->getContentTypeService(); |
682
|
|
|
$contentService = $repository->getContentService(); |
683
|
|
|
$locationService = $repository->getLocationService(); |
684
|
|
|
|
685
|
|
|
// Create new content, which is not published |
686
|
|
|
$folderType = $contentTypeService->loadContentTypeByIdentifier('folder'); |
687
|
|
|
$contentCreate = $contentService->newContentCreateStruct($folderType, 'eng-US'); |
688
|
|
|
$contentCreate->setField('name', 'New Folder'); |
689
|
|
|
$content = $contentService->createContent($contentCreate); |
690
|
|
|
|
691
|
|
|
// Throws Exception, since $content has no published version, yet |
692
|
|
|
$locationService->loadLocations( |
693
|
|
|
$content->contentInfo |
694
|
|
|
); |
695
|
|
|
/* END: Use Case */ |
696
|
|
|
} |
697
|
|
|
|
698
|
|
|
/** |
699
|
|
|
* Test for the loadLocations() method. |
700
|
|
|
* |
701
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::loadLocations($contentInfo, $rootLocation) |
702
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocations |
703
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
704
|
|
|
*/ |
705
|
|
|
public function testLoadLocationsThrowsBadStateExceptionLimitedSubtree() |
706
|
|
|
{ |
707
|
|
|
$repository = $this->getRepository(); |
708
|
|
|
|
709
|
|
|
$someLocationId = $this->generateId('location', 2); |
710
|
|
|
/* BEGIN: Use Case */ |
711
|
|
|
// $someLocationId is the ID of an existing location |
712
|
|
|
$contentTypeService = $repository->getContentTypeService(); |
713
|
|
|
$contentService = $repository->getContentService(); |
714
|
|
|
$locationService = $repository->getLocationService(); |
715
|
|
|
|
716
|
|
|
// Create new content, which is not published |
717
|
|
|
$folderType = $contentTypeService->loadContentTypeByIdentifier('folder'); |
718
|
|
|
$contentCreate = $contentService->newContentCreateStruct($folderType, 'eng-US'); |
719
|
|
|
$contentCreate->setField('name', 'New Folder'); |
720
|
|
|
$content = $contentService->createContent($contentCreate); |
721
|
|
|
|
722
|
|
|
$findRootLocation = $locationService->loadLocation($someLocationId); |
723
|
|
|
|
724
|
|
|
// Throws Exception, since $content has no published version, yet |
725
|
|
|
$locationService->loadLocations( |
726
|
|
|
$content->contentInfo, |
727
|
|
|
$findRootLocation |
728
|
|
|
); |
729
|
|
|
/* END: Use Case */ |
730
|
|
|
} |
731
|
|
|
|
732
|
|
|
/** |
733
|
|
|
* Test for the loadLocationChildren() method. |
734
|
|
|
* |
735
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::loadLocationChildren |
736
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
737
|
|
|
*/ |
738
|
|
|
public function testLoadLocationChildren() |
739
|
|
|
{ |
740
|
|
|
$repository = $this->getRepository(); |
741
|
|
|
|
742
|
|
|
$locationId = $this->generateId('location', 5); |
743
|
|
|
/* BEGIN: Use Case */ |
744
|
|
|
// $locationId is the ID of an existing location |
745
|
|
|
$locationService = $repository->getLocationService(); |
746
|
|
|
|
747
|
|
|
$location = $locationService->loadLocation($locationId); |
748
|
|
|
|
749
|
|
|
$childLocations = $locationService->loadLocationChildren($location); |
750
|
|
|
/* END: Use Case */ |
751
|
|
|
|
752
|
|
|
$this->assertInstanceOf(LocationList::class, $childLocations); |
753
|
|
|
$this->assertInternalType('array', $childLocations->locations); |
754
|
|
|
$this->assertNotEmpty($childLocations->locations); |
755
|
|
|
$this->assertInternalType('int', $childLocations->totalCount); |
756
|
|
|
|
757
|
|
|
foreach ($childLocations->locations as $childLocation) { |
758
|
|
|
$this->assertInstanceOf(Location::class, $childLocation); |
759
|
|
|
$this->assertEquals($location->id, $childLocation->parentLocationId); |
760
|
|
|
} |
761
|
|
|
|
762
|
|
|
return $childLocations; |
763
|
|
|
} |
764
|
|
|
|
765
|
|
|
/** |
766
|
|
|
* Test loading parent Locations for draft Content. |
767
|
|
|
* |
768
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::loadParentLocationsForDraftContent |
769
|
|
|
*/ |
770
|
|
|
public function testLoadParentLocationsForDraftContent() |
771
|
|
|
{ |
772
|
|
|
$repository = $this->getRepository(); |
773
|
|
|
$locationService = $repository->getLocationService(); |
774
|
|
|
$contentService = $repository->getContentService(); |
775
|
|
|
$contentTypeService = $repository->getContentTypeService(); |
776
|
|
|
|
777
|
|
|
// prepare locations |
778
|
|
|
$locationCreateStructs = [ |
779
|
|
|
$locationService->newLocationCreateStruct(2), |
780
|
|
|
$locationService->newLocationCreateStruct(5), |
781
|
|
|
]; |
782
|
|
|
|
783
|
|
|
// Create new content |
784
|
|
|
$folderType = $contentTypeService->loadContentTypeByIdentifier('folder'); |
785
|
|
|
$contentCreate = $contentService->newContentCreateStruct($folderType, 'eng-US'); |
786
|
|
|
$contentCreate->setField('name', 'New Folder'); |
787
|
|
|
$contentDraft = $contentService->createContent($contentCreate, $locationCreateStructs); |
788
|
|
|
|
789
|
|
|
// Test loading parent Locations |
790
|
|
|
$locations = $locationService->loadParentLocationsForDraftContent($contentDraft->versionInfo); |
791
|
|
|
|
792
|
|
|
self::assertCount(2, $locations); |
793
|
|
|
foreach ($locations as $location) { |
794
|
|
|
// test it is one of the given parent locations |
795
|
|
|
self::assertTrue($location->id === 2 || $location->id === 5); |
796
|
|
|
} |
797
|
|
|
|
798
|
|
|
return $contentDraft; |
799
|
|
|
} |
800
|
|
|
|
801
|
|
|
/** |
802
|
|
|
* Test that trying to load parent Locations throws Exception if Content is not a draft. |
803
|
|
|
* |
804
|
|
|
* @depends testLoadParentLocationsForDraftContent |
805
|
|
|
* |
806
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Content $contentDraft |
807
|
|
|
*/ |
808
|
|
|
public function testLoadParentLocationsForDraftContentThrowsBadStateException(Content $contentDraft) |
809
|
|
|
{ |
810
|
|
|
$this->expectException(BadStateException::class); |
811
|
|
|
$this->expectExceptionMessageRegExp('/has been already published/'); |
812
|
|
|
|
813
|
|
|
$repository = $this->getRepository(false); |
814
|
|
|
$locationService = $repository->getLocationService(); |
815
|
|
|
$contentService = $repository->getContentService(); |
816
|
|
|
|
817
|
|
|
$content = $contentService->publishVersion($contentDraft->versionInfo); |
818
|
|
|
|
819
|
|
|
$locationService->loadParentLocationsForDraftContent($content->versionInfo); |
820
|
|
|
} |
821
|
|
|
|
822
|
|
|
/** |
823
|
|
|
* Test for the getLocationChildCount() method. |
824
|
|
|
* |
825
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::getLocationChildCount() |
826
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
827
|
|
|
*/ |
828
|
|
|
public function testGetLocationChildCount() |
829
|
|
|
{ |
830
|
|
|
// $locationId is the ID of an existing location |
831
|
|
|
$locationService = $this->getRepository()->getLocationService(); |
832
|
|
|
|
833
|
|
|
$this->assertSame( |
834
|
|
|
5, |
835
|
|
|
$locationService->getLocationChildCount( |
836
|
|
|
$locationService->loadLocation($this->generateId('location', 5)) |
837
|
|
|
) |
838
|
|
|
); |
839
|
|
|
} |
840
|
|
|
|
841
|
|
|
/** |
842
|
|
|
* Test for the loadLocationChildren() method. |
843
|
|
|
* |
844
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::loadLocationChildren() |
845
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren |
846
|
|
|
*/ |
847
|
|
|
public function testLoadLocationChildrenData(LocationList $locations) |
848
|
|
|
{ |
849
|
|
|
$this->assertEquals(5, count($locations->locations)); |
850
|
|
|
$this->assertEquals(5, $locations->totalCount); |
851
|
|
|
|
852
|
|
|
foreach ($locations->locations as $location) { |
853
|
|
|
$this->assertInstanceOf( |
854
|
|
|
'\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', |
855
|
|
|
$location |
856
|
|
|
); |
857
|
|
|
} |
858
|
|
|
|
859
|
|
|
$this->assertEquals( |
860
|
|
|
array( |
861
|
|
|
$this->generateId('location', 12), |
862
|
|
|
$this->generateId('location', 13), |
863
|
|
|
$this->generateId('location', 14), |
864
|
|
|
$this->generateId('location', 44), |
865
|
|
|
$this->generateId('location', 61), |
866
|
|
|
), |
867
|
|
|
array_map( |
868
|
|
|
function (Location $location) { |
869
|
|
|
return $location->id; |
870
|
|
|
}, |
871
|
|
|
$locations->locations |
872
|
|
|
) |
873
|
|
|
); |
874
|
|
|
} |
875
|
|
|
|
876
|
|
|
/** |
877
|
|
|
* Test for the loadLocationChildren() method. |
878
|
|
|
* |
879
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Location[] |
880
|
|
|
* |
881
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::loadLocationChildren($location, $offset) |
882
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren |
883
|
|
|
*/ |
884
|
|
View Code Duplication |
public function testLoadLocationChildrenWithOffset() |
885
|
|
|
{ |
886
|
|
|
$repository = $this->getRepository(); |
887
|
|
|
|
888
|
|
|
$locationId = $this->generateId('location', 5); |
889
|
|
|
/* BEGIN: Use Case */ |
890
|
|
|
// $locationId is the ID of an existing location |
891
|
|
|
$locationService = $repository->getLocationService(); |
892
|
|
|
|
893
|
|
|
$location = $locationService->loadLocation($locationId); |
894
|
|
|
|
895
|
|
|
$childLocations = $locationService->loadLocationChildren($location, 2); |
896
|
|
|
/* END: Use Case */ |
897
|
|
|
|
898
|
|
|
$this->assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\LocationList', $childLocations); |
899
|
|
|
$this->assertInternalType('array', $childLocations->locations); |
900
|
|
|
$this->assertInternalType('int', $childLocations->totalCount); |
901
|
|
|
|
902
|
|
|
return $childLocations; |
903
|
|
|
} |
904
|
|
|
|
905
|
|
|
/** |
906
|
|
|
* Test for the loadLocationChildren() method. |
907
|
|
|
* |
908
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\LocationList $locations |
909
|
|
|
* |
910
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::loadLocationChildren($location, $offset) |
911
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildrenWithOffset |
912
|
|
|
*/ |
913
|
|
View Code Duplication |
public function testLoadLocationChildrenDataWithOffset(LocationList $locations) |
914
|
|
|
{ |
915
|
|
|
$this->assertEquals(3, count($locations->locations)); |
916
|
|
|
$this->assertEquals(5, $locations->totalCount); |
917
|
|
|
|
918
|
|
|
foreach ($locations->locations as $location) { |
919
|
|
|
$this->assertInstanceOf( |
920
|
|
|
'\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', |
921
|
|
|
$location |
922
|
|
|
); |
923
|
|
|
} |
924
|
|
|
|
925
|
|
|
$this->assertEquals( |
926
|
|
|
array( |
927
|
|
|
$this->generateId('location', 14), |
928
|
|
|
$this->generateId('location', 44), |
929
|
|
|
$this->generateId('location', 61), |
930
|
|
|
), |
931
|
|
|
array_map( |
932
|
|
|
function (Location $location) { |
933
|
|
|
return $location->id; |
934
|
|
|
}, |
935
|
|
|
$locations->locations |
936
|
|
|
) |
937
|
|
|
); |
938
|
|
|
} |
939
|
|
|
|
940
|
|
|
/** |
941
|
|
|
* Test for the loadLocationChildren() method. |
942
|
|
|
* |
943
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Location[] |
944
|
|
|
* |
945
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::loadLocationChildren($location, $offset, $limit) |
946
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren |
947
|
|
|
*/ |
948
|
|
View Code Duplication |
public function testLoadLocationChildrenWithOffsetAndLimit() |
949
|
|
|
{ |
950
|
|
|
$repository = $this->getRepository(); |
951
|
|
|
|
952
|
|
|
$locationId = $this->generateId('location', 5); |
953
|
|
|
/* BEGIN: Use Case */ |
954
|
|
|
// $locationId is the ID of an existing location |
955
|
|
|
$locationService = $repository->getLocationService(); |
956
|
|
|
|
957
|
|
|
$location = $locationService->loadLocation($locationId); |
958
|
|
|
|
959
|
|
|
$childLocations = $locationService->loadLocationChildren($location, 2, 2); |
960
|
|
|
/* END: Use Case */ |
961
|
|
|
|
962
|
|
|
$this->assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\LocationList', $childLocations); |
963
|
|
|
$this->assertInternalType('array', $childLocations->locations); |
964
|
|
|
$this->assertInternalType('int', $childLocations->totalCount); |
965
|
|
|
|
966
|
|
|
return $childLocations; |
967
|
|
|
} |
968
|
|
|
|
969
|
|
|
/** |
970
|
|
|
* Test for the loadLocationChildren() method. |
971
|
|
|
* |
972
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Location[] $locations |
973
|
|
|
* |
974
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::loadLocationChildren($location, $offset, $limit) |
975
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildrenWithOffsetAndLimit |
976
|
|
|
*/ |
977
|
|
View Code Duplication |
public function testLoadLocationChildrenDataWithOffsetAndLimit(LocationList $locations) |
978
|
|
|
{ |
979
|
|
|
$this->assertEquals(2, count($locations->locations)); |
980
|
|
|
$this->assertEquals(5, $locations->totalCount); |
981
|
|
|
|
982
|
|
|
foreach ($locations->locations as $location) { |
983
|
|
|
$this->assertInstanceOf( |
984
|
|
|
'\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', |
985
|
|
|
$location |
986
|
|
|
); |
987
|
|
|
} |
988
|
|
|
|
989
|
|
|
$this->assertEquals( |
990
|
|
|
array( |
991
|
|
|
$this->generateId('location', 14), |
992
|
|
|
$this->generateId('location', 44), |
993
|
|
|
), |
994
|
|
|
array_map( |
995
|
|
|
function (Location $location) { |
996
|
|
|
return $location->id; |
997
|
|
|
}, |
998
|
|
|
$locations->locations |
999
|
|
|
) |
1000
|
|
|
); |
1001
|
|
|
} |
1002
|
|
|
|
1003
|
|
|
/** |
1004
|
|
|
* Test for the newLocationUpdateStruct() method. |
1005
|
|
|
* |
1006
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::newLocationUpdateStruct |
1007
|
|
|
*/ |
1008
|
|
View Code Duplication |
public function testNewLocationUpdateStruct() |
1009
|
|
|
{ |
1010
|
|
|
$repository = $this->getRepository(); |
1011
|
|
|
|
1012
|
|
|
/* BEGIN: Use Case */ |
1013
|
|
|
$locationService = $repository->getLocationService(); |
1014
|
|
|
|
1015
|
|
|
$updateStruct = $locationService->newLocationUpdateStruct(); |
1016
|
|
|
/* END: Use Case */ |
1017
|
|
|
|
1018
|
|
|
$this->assertInstanceOf( |
1019
|
|
|
LocationUpdateStruct::class, |
1020
|
|
|
$updateStruct |
1021
|
|
|
); |
1022
|
|
|
|
1023
|
|
|
$this->assertPropertiesCorrect( |
1024
|
|
|
[ |
1025
|
|
|
'priority' => null, |
1026
|
|
|
'remoteId' => null, |
1027
|
|
|
'sortField' => null, |
1028
|
|
|
'sortOrder' => null, |
1029
|
|
|
], |
1030
|
|
|
$updateStruct |
1031
|
|
|
); |
1032
|
|
|
} |
1033
|
|
|
|
1034
|
|
|
/** |
1035
|
|
|
* Test for the updateLocation() method. |
1036
|
|
|
* |
1037
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::updateLocation() |
1038
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
1039
|
|
|
*/ |
1040
|
|
|
public function testUpdateLocation() |
1041
|
|
|
{ |
1042
|
|
|
$repository = $this->getRepository(); |
1043
|
|
|
|
1044
|
|
|
$originalLocationId = $this->generateId('location', 5); |
1045
|
|
|
/* BEGIN: Use Case */ |
1046
|
|
|
// $originalLocationId is the ID of an existing location |
1047
|
|
|
$locationService = $repository->getLocationService(); |
1048
|
|
|
|
1049
|
|
|
$originalLocation = $locationService->loadLocation($originalLocationId); |
1050
|
|
|
|
1051
|
|
|
$updateStruct = $locationService->newLocationUpdateStruct(); |
1052
|
|
|
$updateStruct->priority = 3; |
1053
|
|
|
$updateStruct->remoteId = 'c7adcbf1e96bc29bca28c2d809d0c7ef69272651'; |
1054
|
|
|
$updateStruct->sortField = Location::SORT_FIELD_PRIORITY; |
1055
|
|
|
$updateStruct->sortOrder = Location::SORT_ORDER_DESC; |
1056
|
|
|
|
1057
|
|
|
$updatedLocation = $locationService->updateLocation($originalLocation, $updateStruct); |
1058
|
|
|
/* END: Use Case */ |
1059
|
|
|
|
1060
|
|
|
$this->assertInstanceOf( |
1061
|
|
|
'\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', |
1062
|
|
|
$updatedLocation |
1063
|
|
|
); |
1064
|
|
|
|
1065
|
|
|
return array( |
1066
|
|
|
'originalLocation' => $originalLocation, |
1067
|
|
|
'updateStruct' => $updateStruct, |
1068
|
|
|
'updatedLocation' => $updatedLocation, |
1069
|
|
|
); |
1070
|
|
|
} |
1071
|
|
|
|
1072
|
|
|
/** |
1073
|
|
|
* Test for the updateLocation() method. |
1074
|
|
|
* |
1075
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::updateLocation() |
1076
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testUpdateLocation |
1077
|
|
|
*/ |
1078
|
|
|
public function testUpdateLocationStructValues(array $data) |
1079
|
|
|
{ |
1080
|
|
|
$originalLocation = $data['originalLocation']; |
1081
|
|
|
$updateStruct = $data['updateStruct']; |
1082
|
|
|
$updatedLocation = $data['updatedLocation']; |
1083
|
|
|
|
1084
|
|
|
$this->assertPropertiesCorrect( |
1085
|
|
|
array( |
1086
|
|
|
'id' => $originalLocation->id, |
1087
|
|
|
'priority' => $updateStruct->priority, |
1088
|
|
|
'hidden' => $originalLocation->hidden, |
1089
|
|
|
'invisible' => $originalLocation->invisible, |
1090
|
|
|
'remoteId' => $updateStruct->remoteId, |
1091
|
|
|
'contentInfo' => $originalLocation->contentInfo, |
1092
|
|
|
'parentLocationId' => $originalLocation->parentLocationId, |
1093
|
|
|
'pathString' => $originalLocation->pathString, |
1094
|
|
|
'depth' => $originalLocation->depth, |
1095
|
|
|
'sortField' => $updateStruct->sortField, |
1096
|
|
|
'sortOrder' => $updateStruct->sortOrder, |
1097
|
|
|
), |
1098
|
|
|
$updatedLocation |
1099
|
|
|
); |
1100
|
|
|
} |
1101
|
|
|
|
1102
|
|
|
/** |
1103
|
|
|
* Test for the updateLocation() method. |
1104
|
|
|
* |
1105
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::updateLocation() |
1106
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
1107
|
|
|
*/ |
1108
|
|
|
public function testUpdateLocationWithSameRemoteId() |
1109
|
|
|
{ |
1110
|
|
|
$repository = $this->getRepository(); |
1111
|
|
|
|
1112
|
|
|
$locationId = $this->generateId('location', 5); |
1113
|
|
|
/* BEGIN: Use Case */ |
1114
|
|
|
// $locationId and remote ID is the IDs of the same, existing location |
1115
|
|
|
$locationService = $repository->getLocationService(); |
1116
|
|
|
|
1117
|
|
|
$originalLocation = $locationService->loadLocation($locationId); |
1118
|
|
|
|
1119
|
|
|
$updateStruct = $locationService->newLocationUpdateStruct(); |
1120
|
|
|
|
1121
|
|
|
// Remote ID of an existing location with the same locationId |
1122
|
|
|
$updateStruct->remoteId = $originalLocation->remoteId; |
1123
|
|
|
|
1124
|
|
|
// Sets one of the properties to be able to confirm location gets updated, here: priority |
1125
|
|
|
$updateStruct->priority = 2; |
1126
|
|
|
|
1127
|
|
|
$location = $locationService->updateLocation($originalLocation, $updateStruct); |
1128
|
|
|
|
1129
|
|
|
// Checks that the location was updated |
1130
|
|
|
$this->assertEquals(2, $location->priority); |
1131
|
|
|
|
1132
|
|
|
// Checks that remoteId remains the same |
1133
|
|
|
$this->assertEquals($originalLocation->remoteId, $location->remoteId); |
1134
|
|
|
/* END: Use Case */ |
1135
|
|
|
} |
1136
|
|
|
|
1137
|
|
|
/** |
1138
|
|
|
* Test for the updateLocation() method. |
1139
|
|
|
* |
1140
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::updateLocation() |
1141
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
1142
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
1143
|
|
|
*/ |
1144
|
|
View Code Duplication |
public function testUpdateLocationThrowsInvalidArgumentException() |
1145
|
|
|
{ |
1146
|
|
|
$repository = $this->getRepository(); |
1147
|
|
|
|
1148
|
|
|
$locationId = $this->generateId('location', 5); |
1149
|
|
|
/* BEGIN: Use Case */ |
1150
|
|
|
// $locationId and remoteId is the IDs of an existing, but not the same, location |
1151
|
|
|
$locationService = $repository->getLocationService(); |
1152
|
|
|
|
1153
|
|
|
$originalLocation = $locationService->loadLocation($locationId); |
1154
|
|
|
|
1155
|
|
|
$updateStruct = $locationService->newLocationUpdateStruct(); |
1156
|
|
|
|
1157
|
|
|
// Remote ID of an existing location with a different locationId |
1158
|
|
|
$updateStruct->remoteId = 'f3e90596361e31d496d4026eb624c983'; |
1159
|
|
|
|
1160
|
|
|
// Throws exception, since remote ID is already taken |
1161
|
|
|
$locationService->updateLocation($originalLocation, $updateStruct); |
1162
|
|
|
/* END: Use Case */ |
1163
|
|
|
} |
1164
|
|
|
|
1165
|
|
|
/** |
1166
|
|
|
* Test for the updateLocation() method. |
1167
|
|
|
* |
1168
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::updateLocation() |
1169
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
1170
|
|
|
* @dataProvider dataProviderForOutOfRangeLocationPriority |
1171
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
1172
|
|
|
*/ |
1173
|
|
|
public function testUpdateLocationThrowsInvalidArgumentExceptionPriorityIsOutOfRange($priority) |
1174
|
|
|
{ |
1175
|
|
|
$repository = $this->getRepository(); |
1176
|
|
|
|
1177
|
|
|
$locationId = $this->generateId('location', 5); |
1178
|
|
|
/* BEGIN: Use Case */ |
1179
|
|
|
// $locationId and remoteId is the IDs of an existing, but not the same, location |
1180
|
|
|
$locationService = $repository->getLocationService(); |
1181
|
|
|
|
1182
|
|
|
$originalLocation = $locationService->loadLocation($locationId); |
1183
|
|
|
|
1184
|
|
|
$updateStruct = $locationService->newLocationUpdateStruct(); |
1185
|
|
|
|
1186
|
|
|
// Priority value is out of range |
1187
|
|
|
$updateStruct->priority = $priority; |
1188
|
|
|
|
1189
|
|
|
// Throws exception, since remote ID is already taken |
1190
|
|
|
$locationService->updateLocation($originalLocation, $updateStruct); |
1191
|
|
|
/* END: Use Case */ |
1192
|
|
|
} |
1193
|
|
|
|
1194
|
|
|
/** |
1195
|
|
|
* Test for the updateLocation() method. |
1196
|
|
|
* Ref EZP-23302: Update Location fails if no change is performed with the update. |
1197
|
|
|
* |
1198
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::updateLocation() |
1199
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
1200
|
|
|
*/ |
1201
|
|
|
public function testUpdateLocationTwice() |
1202
|
|
|
{ |
1203
|
|
|
$repository = $this->getRepository(); |
1204
|
|
|
|
1205
|
|
|
$locationId = $this->generateId('location', 5); |
1206
|
|
|
/* BEGIN: Use Case */ |
1207
|
|
|
$locationService = $repository->getLocationService(); |
1208
|
|
|
$repository->setCurrentUser($repository->getUserService()->loadUser(14)); |
|
|
|
|
1209
|
|
|
|
1210
|
|
|
$originalLocation = $locationService->loadLocation($locationId); |
1211
|
|
|
|
1212
|
|
|
$updateStruct = $locationService->newLocationUpdateStruct(); |
1213
|
|
|
$updateStruct->priority = 42; |
1214
|
|
|
|
1215
|
|
|
$updatedLocation = $locationService->updateLocation($originalLocation, $updateStruct); |
1216
|
|
|
|
1217
|
|
|
// Repeated update with the same, unchanged struct |
1218
|
|
|
$secondUpdatedLocation = $locationService->updateLocation($updatedLocation, $updateStruct); |
1219
|
|
|
/* END: Use Case */ |
1220
|
|
|
|
1221
|
|
|
$this->assertEquals($updatedLocation->priority, 42); |
1222
|
|
|
$this->assertEquals($secondUpdatedLocation->priority, 42); |
1223
|
|
|
} |
1224
|
|
|
|
1225
|
|
|
/** |
1226
|
|
|
* Test for the swapLocation() method. |
1227
|
|
|
* |
1228
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::swapLocation() |
1229
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
1230
|
|
|
*/ |
1231
|
|
|
public function testSwapLocation() |
1232
|
|
|
{ |
1233
|
|
|
$repository = $this->getRepository(); |
1234
|
|
|
$locationService = $repository->getLocationService(); |
1235
|
|
|
|
1236
|
|
|
$mediaLocationId = $this->generateId('location', 43); |
1237
|
|
|
$demoDesignLocationId = $this->generateId('location', 56); |
1238
|
|
|
|
1239
|
|
|
$mediaContentInfo = $locationService->loadLocation($mediaLocationId)->getContentInfo(); |
1240
|
|
|
$demoDesignContentInfo = $locationService->loadLocation($demoDesignLocationId)->getContentInfo(); |
1241
|
|
|
|
1242
|
|
|
/* BEGIN: Use Case */ |
1243
|
|
|
// $mediaLocationId is the ID of the "Media" page location in |
1244
|
|
|
// an eZ Publish demo installation |
1245
|
|
|
|
1246
|
|
|
// $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ |
1247
|
|
|
// Publish demo installation |
1248
|
|
|
|
1249
|
|
|
// Load the location service |
1250
|
|
|
$locationService = $repository->getLocationService(); |
1251
|
|
|
|
1252
|
|
|
$mediaLocation = $locationService->loadLocation($mediaLocationId); |
1253
|
|
|
$demoDesignLocation = $locationService->loadLocation($demoDesignLocationId); |
1254
|
|
|
|
1255
|
|
|
// Swaps the content referred to by the locations |
1256
|
|
|
$locationService->swapLocation($mediaLocation, $demoDesignLocation); |
1257
|
|
|
/* END: Use Case */ |
1258
|
|
|
|
1259
|
|
|
// Reload Locations, IDs swapped |
1260
|
|
|
$demoDesignLocation = $locationService->loadLocation($mediaLocationId); |
1261
|
|
|
$mediaLocation = $locationService->loadLocation($demoDesignLocationId); |
1262
|
|
|
|
1263
|
|
|
// Assert Location's Content is updated |
1264
|
|
|
$this->assertEquals( |
1265
|
|
|
$mediaContentInfo->id, |
1266
|
|
|
$mediaLocation->getContentInfo()->id |
1267
|
|
|
); |
1268
|
|
|
$this->assertEquals( |
1269
|
|
|
$demoDesignContentInfo->id, |
1270
|
|
|
$demoDesignLocation->getContentInfo()->id |
1271
|
|
|
); |
1272
|
|
|
|
1273
|
|
|
// Assert URL aliases are updated |
1274
|
|
|
$this->assertEquals( |
1275
|
|
|
$mediaLocation->id, |
1276
|
|
|
$repository->getURLAliasService()->lookup('/Design/Media')->destination |
1277
|
|
|
); |
1278
|
|
|
$this->assertEquals( |
1279
|
|
|
$demoDesignLocation->id, |
1280
|
|
|
$repository->getURLAliasService()->lookup('/eZ-Publish-Demo-Design-without-demo-content')->destination |
1281
|
|
|
); |
1282
|
|
|
} |
1283
|
|
|
|
1284
|
|
|
/** |
1285
|
|
|
* Test swapping Main Location of a Content with another one updates Content item Main Location. |
1286
|
|
|
* |
1287
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::swapLocation |
1288
|
|
|
*/ |
1289
|
|
|
public function testSwapLocationUpdatesMainLocation() |
1290
|
|
|
{ |
1291
|
|
|
$repository = $this->getRepository(); |
1292
|
|
|
$locationService = $repository->getLocationService(); |
1293
|
|
|
$contentService = $repository->getContentService(); |
1294
|
|
|
|
1295
|
|
|
$mainLocationParentId = 60; |
1296
|
|
|
$secondaryLocationId = 43; |
1297
|
|
|
|
1298
|
|
|
$publishedContent = $this->publishContentWithParentLocation( |
1299
|
|
|
'Content for Swap Location Test', $mainLocationParentId |
1300
|
|
|
); |
1301
|
|
|
|
1302
|
|
|
// sanity check |
1303
|
|
|
$mainLocation = $locationService->loadLocation($publishedContent->contentInfo->mainLocationId); |
1304
|
|
|
self::assertEquals($mainLocationParentId, $mainLocation->parentLocationId); |
1305
|
|
|
|
1306
|
|
|
// load another pre-existing location |
1307
|
|
|
$secondaryLocation = $locationService->loadLocation($secondaryLocationId); |
1308
|
|
|
|
1309
|
|
|
// swap the Main Location with a secondary one |
1310
|
|
|
$locationService->swapLocation($mainLocation, $secondaryLocation); |
1311
|
|
|
|
1312
|
|
|
// check if Main Location has been updated |
1313
|
|
|
$mainLocation = $locationService->loadLocation($secondaryLocation->id); |
1314
|
|
|
self::assertEquals($publishedContent->contentInfo->id, $mainLocation->contentInfo->id); |
1315
|
|
|
self::assertEquals($mainLocation->id, $mainLocation->contentInfo->mainLocationId); |
1316
|
|
|
|
1317
|
|
|
$reloadedContent = $contentService->loadContentByContentInfo($publishedContent->contentInfo); |
1318
|
|
|
self::assertEquals($mainLocation->id, $reloadedContent->contentInfo->mainLocationId); |
1319
|
|
|
} |
1320
|
|
|
|
1321
|
|
|
/** |
1322
|
|
|
* Test if location swap affects related bookmarks. |
1323
|
|
|
* |
1324
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::swapLocation |
1325
|
|
|
*/ |
1326
|
|
|
public function testBookmarksAreSwappedAfterSwapLocation() |
1327
|
|
|
{ |
1328
|
|
|
$repository = $this->getRepository(); |
1329
|
|
|
|
1330
|
|
|
$mediaLocationId = $this->generateId('location', 43); |
1331
|
|
|
$demoDesignLocationId = $this->generateId('location', 56); |
1332
|
|
|
|
1333
|
|
|
/* BEGIN: Use Case */ |
1334
|
|
|
$locationService = $repository->getLocationService(); |
1335
|
|
|
$bookmarkService = $repository->getBookmarkService(); |
1336
|
|
|
|
1337
|
|
|
$mediaLocation = $locationService->loadLocation($mediaLocationId); |
1338
|
|
|
$demoDesignLocation = $locationService->loadLocation($demoDesignLocationId); |
1339
|
|
|
|
1340
|
|
|
// Bookmark locations |
1341
|
|
|
$bookmarkService->createBookmark($mediaLocation); |
1342
|
|
|
$bookmarkService->createBookmark($demoDesignLocation); |
1343
|
|
|
|
1344
|
|
|
$beforeSwap = $bookmarkService->loadBookmarks(); |
1345
|
|
|
|
1346
|
|
|
// Swaps the content referred to by the locations |
1347
|
|
|
$locationService->swapLocation($mediaLocation, $demoDesignLocation); |
1348
|
|
|
|
1349
|
|
|
$afterSwap = $bookmarkService->loadBookmarks(); |
1350
|
|
|
/* END: Use Case */ |
1351
|
|
|
|
1352
|
|
|
$this->assertEquals($beforeSwap->items[0]->id, $afterSwap->items[1]->id); |
1353
|
|
|
$this->assertEquals($beforeSwap->items[1]->id, $afterSwap->items[0]->id); |
1354
|
|
|
} |
1355
|
|
|
|
1356
|
|
|
/** |
1357
|
|
|
* Test for the hideLocation() method. |
1358
|
|
|
* |
1359
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::hideLocation() |
1360
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
1361
|
|
|
*/ |
1362
|
|
|
public function testHideLocation() |
1363
|
|
|
{ |
1364
|
|
|
$repository = $this->getRepository(); |
1365
|
|
|
|
1366
|
|
|
$locationId = $this->generateId('location', 5); |
1367
|
|
|
/* BEGIN: Use Case */ |
1368
|
|
|
// $locationId is the ID of an existing location |
1369
|
|
|
$locationService = $repository->getLocationService(); |
1370
|
|
|
|
1371
|
|
|
$visibleLocation = $locationService->loadLocation($locationId); |
1372
|
|
|
|
1373
|
|
|
$hiddenLocation = $locationService->hideLocation($visibleLocation); |
1374
|
|
|
/* END: Use Case */ |
1375
|
|
|
|
1376
|
|
|
$this->assertInstanceOf( |
1377
|
|
|
'\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', |
1378
|
|
|
$hiddenLocation |
1379
|
|
|
); |
1380
|
|
|
|
1381
|
|
|
$this->assertTrue( |
1382
|
|
|
$hiddenLocation->hidden, |
1383
|
|
|
sprintf( |
1384
|
|
|
'Location with ID "%s" not hidden.', |
1385
|
|
|
$hiddenLocation->id |
1386
|
|
|
) |
1387
|
|
|
); |
1388
|
|
|
|
1389
|
|
|
$this->refreshSearch($repository); |
1390
|
|
|
|
1391
|
|
|
foreach ($locationService->loadLocationChildren($hiddenLocation)->locations as $child) { |
1392
|
|
|
$this->assertSubtreeProperties( |
1393
|
|
|
array('invisible' => true), |
1394
|
|
|
$child |
1395
|
|
|
); |
1396
|
|
|
} |
1397
|
|
|
} |
1398
|
|
|
|
1399
|
|
|
/** |
1400
|
|
|
* Assert that $expectedValues are set in the subtree starting at $location. |
1401
|
|
|
* |
1402
|
|
|
* @param array $expectedValues |
1403
|
|
|
* @param Location $location |
1404
|
|
|
*/ |
1405
|
|
|
protected function assertSubtreeProperties(array $expectedValues, Location $location, $stopId = null) |
1406
|
|
|
{ |
1407
|
|
|
$repository = $this->getRepository(); |
1408
|
|
|
$locationService = $repository->getLocationService(); |
1409
|
|
|
|
1410
|
|
|
if ($location->id === $stopId) { |
1411
|
|
|
return; |
1412
|
|
|
} |
1413
|
|
|
|
1414
|
|
|
foreach ($expectedValues as $propertyName => $propertyValue) { |
1415
|
|
|
$this->assertEquals( |
1416
|
|
|
$propertyValue, |
1417
|
|
|
$location->$propertyName |
1418
|
|
|
); |
1419
|
|
|
|
1420
|
|
|
foreach ($locationService->loadLocationChildren($location)->locations as $child) { |
1421
|
|
|
$this->assertSubtreeProperties($expectedValues, $child); |
1422
|
|
|
} |
1423
|
|
|
} |
1424
|
|
|
} |
1425
|
|
|
|
1426
|
|
|
/** |
1427
|
|
|
* Test for the unhideLocation() method. |
1428
|
|
|
* |
1429
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::unhideLocation() |
1430
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testHideLocation |
1431
|
|
|
*/ |
1432
|
|
|
public function testUnhideLocation() |
1433
|
|
|
{ |
1434
|
|
|
$repository = $this->getRepository(); |
1435
|
|
|
|
1436
|
|
|
$locationId = $this->generateId('location', 5); |
1437
|
|
|
/* BEGIN: Use Case */ |
1438
|
|
|
// $locationId is the ID of an existing location |
1439
|
|
|
$locationService = $repository->getLocationService(); |
1440
|
|
|
|
1441
|
|
|
$visibleLocation = $locationService->loadLocation($locationId); |
1442
|
|
|
$hiddenLocation = $locationService->hideLocation($visibleLocation); |
1443
|
|
|
|
1444
|
|
|
$unHiddenLocation = $locationService->unhideLocation($hiddenLocation); |
1445
|
|
|
/* END: Use Case */ |
1446
|
|
|
|
1447
|
|
|
$this->assertInstanceOf( |
1448
|
|
|
'\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', |
1449
|
|
|
$unHiddenLocation |
1450
|
|
|
); |
1451
|
|
|
|
1452
|
|
|
$this->assertFalse( |
1453
|
|
|
$unHiddenLocation->hidden, |
1454
|
|
|
sprintf( |
1455
|
|
|
'Location with ID "%s" not unhidden.', |
1456
|
|
|
$unHiddenLocation->id |
1457
|
|
|
) |
1458
|
|
|
); |
1459
|
|
|
|
1460
|
|
|
$this->refreshSearch($repository); |
1461
|
|
|
|
1462
|
|
|
foreach ($locationService->loadLocationChildren($unHiddenLocation)->locations as $child) { |
1463
|
|
|
$this->assertSubtreeProperties( |
1464
|
|
|
array('invisible' => false), |
1465
|
|
|
$child |
1466
|
|
|
); |
1467
|
|
|
} |
1468
|
|
|
} |
1469
|
|
|
|
1470
|
|
|
/** |
1471
|
|
|
* Test for the unhideLocation() method. |
1472
|
|
|
* |
1473
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::unhideLocation() |
1474
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testUnhideLocation |
1475
|
|
|
*/ |
1476
|
|
|
public function testUnhideLocationNotUnhidesHiddenSubtree() |
1477
|
|
|
{ |
1478
|
|
|
$repository = $this->getRepository(); |
1479
|
|
|
|
1480
|
|
|
$higherLocationId = $this->generateId('location', 5); |
1481
|
|
|
$lowerLocationId = $this->generateId('location', 13); |
1482
|
|
|
/* BEGIN: Use Case */ |
1483
|
|
|
// $higherLocationId is the ID of a location |
1484
|
|
|
// $lowerLocationId is the ID of a location below $higherLocationId |
1485
|
|
|
$locationService = $repository->getLocationService(); |
1486
|
|
|
|
1487
|
|
|
$higherLocation = $locationService->loadLocation($higherLocationId); |
1488
|
|
|
$hiddenHigherLocation = $locationService->hideLocation($higherLocation); |
1489
|
|
|
|
1490
|
|
|
$lowerLocation = $locationService->loadLocation($lowerLocationId); |
1491
|
|
|
$hiddenLowerLocation = $locationService->hideLocation($lowerLocation); |
|
|
|
|
1492
|
|
|
|
1493
|
|
|
$unHiddenHigherLocation = $locationService->unhideLocation($hiddenHigherLocation); |
1494
|
|
|
/* END: Use Case */ |
1495
|
|
|
|
1496
|
|
|
$this->assertInstanceOf( |
1497
|
|
|
'\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', |
1498
|
|
|
$unHiddenHigherLocation |
1499
|
|
|
); |
1500
|
|
|
|
1501
|
|
|
$this->assertFalse( |
1502
|
|
|
$unHiddenHigherLocation->hidden, |
1503
|
|
|
sprintf( |
1504
|
|
|
'Location with ID "%s" not unhidden.', |
1505
|
|
|
$unHiddenHigherLocation->id |
1506
|
|
|
) |
1507
|
|
|
); |
1508
|
|
|
|
1509
|
|
|
$this->refreshSearch($repository); |
1510
|
|
|
|
1511
|
|
|
foreach ($locationService->loadLocationChildren($unHiddenHigherLocation)->locations as $child) { |
1512
|
|
|
$this->assertSubtreeProperties( |
1513
|
|
|
array('invisible' => false), |
1514
|
|
|
$child, |
1515
|
|
|
$this->generateId('location', 13) |
1516
|
|
|
); |
1517
|
|
|
} |
1518
|
|
|
|
1519
|
|
|
$stillHiddenLocation = $locationService->loadLocation($this->generateId('location', 13)); |
1520
|
|
|
$this->assertTrue( |
1521
|
|
|
$stillHiddenLocation->hidden, |
1522
|
|
|
sprintf( |
1523
|
|
|
'Hidden sub-location with ID %s accidentally unhidden.', |
1524
|
|
|
$stillHiddenLocation->id |
1525
|
|
|
) |
1526
|
|
|
); |
1527
|
|
|
foreach ($locationService->loadLocationChildren($stillHiddenLocation)->locations as $child) { |
1528
|
|
|
$this->assertSubtreeProperties( |
1529
|
|
|
array('invisible' => true), |
1530
|
|
|
$child |
1531
|
|
|
); |
1532
|
|
|
} |
1533
|
|
|
} |
1534
|
|
|
|
1535
|
|
|
/** |
1536
|
|
|
* Test for the deleteLocation() method. |
1537
|
|
|
* |
1538
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::deleteLocation() |
1539
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
1540
|
|
|
*/ |
1541
|
|
|
public function testDeleteLocation() |
1542
|
|
|
{ |
1543
|
|
|
$repository = $this->getRepository(); |
1544
|
|
|
|
1545
|
|
|
$mediaLocationId = $this->generateId('location', 43); |
1546
|
|
|
/* BEGIN: Use Case */ |
1547
|
|
|
// $mediaLocationId is the ID of the location of the |
1548
|
|
|
// "Media" location in an eZ Publish demo installation |
1549
|
|
|
$locationService = $repository->getLocationService(); |
1550
|
|
|
|
1551
|
|
|
$location = $locationService->loadLocation($mediaLocationId); |
1552
|
|
|
|
1553
|
|
|
$locationService->deleteLocation($location); |
1554
|
|
|
/* END: Use Case */ |
1555
|
|
|
|
1556
|
|
|
try { |
1557
|
|
|
$locationService->loadLocation($mediaLocationId); |
1558
|
|
|
$this->fail("Location $mediaLocationId not deleted."); |
1559
|
|
|
} catch (NotFoundException $e) { |
|
|
|
|
1560
|
|
|
} |
1561
|
|
|
|
1562
|
|
|
// The following IDs are IDs of child locations of $mediaLocationId location |
1563
|
|
|
// ( Media/Images, Media/Files, Media/Multimedia respectively ) |
1564
|
|
|
foreach (array(51, 52, 53) as $childLocationId) { |
1565
|
|
|
try { |
1566
|
|
|
$locationService->loadLocation($this->generateId('location', $childLocationId)); |
1567
|
|
|
$this->fail("Location $childLocationId not deleted."); |
1568
|
|
|
} catch (NotFoundException $e) { |
|
|
|
|
1569
|
|
|
} |
1570
|
|
|
} |
1571
|
|
|
|
1572
|
|
|
// The following IDs are IDs of content below $mediaLocationId location |
1573
|
|
|
// ( Media/Images, Media/Files, Media/Multimedia respectively ) |
1574
|
|
|
$contentService = $this->getRepository()->getContentService(); |
1575
|
|
|
foreach (array(49, 50, 51) as $childContentId) { |
1576
|
|
|
try { |
1577
|
|
|
$contentService->loadContentInfo($this->generateId('object', $childContentId)); |
1578
|
|
|
$this->fail("Content $childContentId not deleted."); |
1579
|
|
|
} catch (NotFoundException $e) { |
|
|
|
|
1580
|
|
|
} |
1581
|
|
|
} |
1582
|
|
|
} |
1583
|
|
|
|
1584
|
|
|
/** |
1585
|
|
|
* Test for the deleteLocation() method. |
1586
|
|
|
* |
1587
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::deleteLocation() |
1588
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testDeleteLocation |
1589
|
|
|
*/ |
1590
|
|
|
public function testDeleteLocationDecrementsChildCountOnParent() |
1591
|
|
|
{ |
1592
|
|
|
$repository = $this->getRepository(); |
1593
|
|
|
|
1594
|
|
|
$mediaLocationId = $this->generateId('location', 43); |
1595
|
|
|
/* BEGIN: Use Case */ |
1596
|
|
|
// $mediaLocationId is the ID of the location of the |
1597
|
|
|
// "Media" location in an eZ Publish demo installation |
1598
|
|
|
|
1599
|
|
|
$locationService = $repository->getLocationService(); |
1600
|
|
|
|
1601
|
|
|
// Load the current the user group location |
1602
|
|
|
$location = $locationService->loadLocation($mediaLocationId); |
1603
|
|
|
|
1604
|
|
|
// Load the parent location |
1605
|
|
|
$parentLocation = $locationService->loadLocation( |
1606
|
|
|
$location->parentLocationId |
1607
|
|
|
); |
1608
|
|
|
|
1609
|
|
|
// Get child count |
1610
|
|
|
$childCountBefore = $locationService->getLocationChildCount($parentLocation); |
1611
|
|
|
|
1612
|
|
|
// Delete the user group location |
1613
|
|
|
$locationService->deleteLocation($location); |
1614
|
|
|
|
1615
|
|
|
$this->refreshSearch($repository); |
1616
|
|
|
|
1617
|
|
|
// Reload parent location |
1618
|
|
|
$parentLocation = $locationService->loadLocation( |
1619
|
|
|
$location->parentLocationId |
1620
|
|
|
); |
1621
|
|
|
|
1622
|
|
|
// This will be $childCountBefore - 1 |
1623
|
|
|
$childCountAfter = $locationService->getLocationChildCount($parentLocation); |
1624
|
|
|
/* END: Use Case */ |
1625
|
|
|
|
1626
|
|
|
$this->assertEquals($childCountBefore - 1, $childCountAfter); |
1627
|
|
|
} |
1628
|
|
|
|
1629
|
|
|
/** |
1630
|
|
|
* Test for the deleteLocation() method. |
1631
|
|
|
* |
1632
|
|
|
* Related issue: EZP-21904 |
1633
|
|
|
* |
1634
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::deleteLocation() |
1635
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
1636
|
|
|
*/ |
1637
|
|
|
public function testDeleteContentObjectLastLocation() |
1638
|
|
|
{ |
1639
|
|
|
$repository = $this->getRepository(); |
1640
|
|
|
|
1641
|
|
|
/* BEGIN: Use case */ |
1642
|
|
|
$contentService = $repository->getContentService(); |
1643
|
|
|
$locationService = $repository->getLocationService(); |
1644
|
|
|
$contentTypeService = $repository->getContentTypeService(); |
1645
|
|
|
$urlAliasService = $repository->getURLAliasService(); |
1646
|
|
|
|
1647
|
|
|
// prepare Content object |
1648
|
|
|
$createStruct = $contentService->newContentCreateStruct( |
1649
|
|
|
$contentTypeService->loadContentTypeByIdentifier('folder'), |
1650
|
|
|
'eng-GB' |
1651
|
|
|
); |
1652
|
|
|
$createStruct->setField('name', 'Test folder'); |
1653
|
|
|
|
1654
|
|
|
// creata Content object |
1655
|
|
|
$content = $contentService->publishVersion( |
1656
|
|
|
$contentService->createContent( |
1657
|
|
|
$createStruct, |
1658
|
|
|
array($locationService->newLocationCreateStruct(2)) |
1659
|
|
|
)->versionInfo |
1660
|
|
|
); |
1661
|
|
|
|
1662
|
|
|
// delete location |
1663
|
|
|
$locationService->deleteLocation( |
1664
|
|
|
$locationService->loadLocation( |
1665
|
|
|
$urlAliasService->lookup('/Test-folder')->destination |
1666
|
|
|
) |
1667
|
|
|
); |
1668
|
|
|
|
1669
|
|
|
// this should throw a not found exception |
1670
|
|
|
$contentService->loadContent($content->versionInfo->contentInfo->id); |
1671
|
|
|
/* END: Use case*/ |
1672
|
|
|
} |
1673
|
|
|
|
1674
|
|
|
/** |
1675
|
|
|
* Test for the deleteLocation() method. |
1676
|
|
|
* |
1677
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::deleteLocation() |
1678
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testDeleteLocation |
1679
|
|
|
*/ |
1680
|
|
|
public function testDeleteLocationDeletesRelatedBookmarks() |
1681
|
|
|
{ |
1682
|
|
|
$repository = $this->getRepository(); |
1683
|
|
|
|
1684
|
|
|
$parentLocationId = $this->generateId('location', 43); |
1685
|
|
|
$childLocationId = $this->generateId('location', 53); |
1686
|
|
|
|
1687
|
|
|
/* BEGIN: Use Case */ |
1688
|
|
|
$locationService = $repository->getLocationService(); |
1689
|
|
|
$bookmarkService = $repository->getBookmarkService(); |
1690
|
|
|
|
1691
|
|
|
// Load location |
1692
|
|
|
$childLocation = $locationService->loadLocation($childLocationId); |
1693
|
|
|
// Add location to bookmarks |
1694
|
|
|
$bookmarkService->createBookmark($childLocation); |
1695
|
|
|
// Load parent location |
1696
|
|
|
$parentLocation = $locationService->loadLocation($parentLocationId); |
1697
|
|
|
// Delete parent location |
1698
|
|
|
$locationService->deleteLocation($parentLocation); |
1699
|
|
|
/* END: Use Case */ |
1700
|
|
|
|
1701
|
|
|
// Location isn't bookmarked anymore |
1702
|
|
|
foreach ($bookmarkService->loadBookmarks(0, 9999) as $bookmarkedLocation) { |
1703
|
|
|
$this->assertNotEquals($childLocation->id, $bookmarkedLocation->id); |
1704
|
|
|
} |
1705
|
|
|
} |
1706
|
|
|
|
1707
|
|
|
/** |
1708
|
|
|
* Test for the copySubtree() method. |
1709
|
|
|
* |
1710
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::copySubtree() |
1711
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
1712
|
|
|
*/ |
1713
|
|
|
public function testCopySubtree() |
1714
|
|
|
{ |
1715
|
|
|
$repository = $this->getRepository(); |
1716
|
|
|
|
1717
|
|
|
$mediaLocationId = $this->generateId('location', 43); |
1718
|
|
|
$demoDesignLocationId = $this->generateId('location', 56); |
1719
|
|
|
/* BEGIN: Use Case */ |
1720
|
|
|
// $mediaLocationId is the ID of the "Media" page location in |
1721
|
|
|
// an eZ Publish demo installation |
1722
|
|
|
|
1723
|
|
|
// $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ |
1724
|
|
|
// Publish demo installation |
1725
|
|
|
|
1726
|
|
|
// Load the location service |
1727
|
|
|
$locationService = $repository->getLocationService(); |
1728
|
|
|
|
1729
|
|
|
// Load location to copy |
1730
|
|
|
$locationToCopy = $locationService->loadLocation($mediaLocationId); |
1731
|
|
|
|
1732
|
|
|
// Load new parent location |
1733
|
|
|
$newParentLocation = $locationService->loadLocation($demoDesignLocationId); |
1734
|
|
|
|
1735
|
|
|
// Copy location "Media" to "Demo Design" |
1736
|
|
|
$copiedLocation = $locationService->copySubtree( |
1737
|
|
|
$locationToCopy, |
1738
|
|
|
$newParentLocation |
1739
|
|
|
); |
1740
|
|
|
/* END: Use Case */ |
1741
|
|
|
|
1742
|
|
|
$this->assertInstanceOf( |
1743
|
|
|
'\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', |
1744
|
|
|
$copiedLocation |
1745
|
|
|
); |
1746
|
|
|
|
1747
|
|
|
$this->assertPropertiesCorrect( |
1748
|
|
|
array( |
1749
|
|
|
'depth' => $newParentLocation->depth + 1, |
1750
|
|
|
'parentLocationId' => $newParentLocation->id, |
1751
|
|
|
'pathString' => "{$newParentLocation->pathString}" . $this->parseId('location', $copiedLocation->id) . '/', |
1752
|
|
|
), |
1753
|
|
|
$copiedLocation |
1754
|
|
|
); |
1755
|
|
|
|
1756
|
|
|
$this->assertDefaultContentStates($copiedLocation->contentInfo); |
1757
|
|
|
} |
1758
|
|
|
|
1759
|
|
|
/** |
1760
|
|
|
* Test for the copySubtree() method. |
1761
|
|
|
* |
1762
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::copySubtree() |
1763
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
1764
|
|
|
*/ |
1765
|
|
|
public function testCopySubtreeWithAliases() |
1766
|
|
|
{ |
1767
|
|
|
$repository = $this->getRepository(); |
1768
|
|
|
$urlAliasService = $repository->getURLAliasService(); |
1769
|
|
|
|
1770
|
|
|
// $mediaLocationId is the ID of the "Media" page location in |
1771
|
|
|
// an eZ Publish demo installation |
1772
|
|
|
|
1773
|
|
|
// $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ |
1774
|
|
|
// Publish demo installation |
1775
|
|
|
$mediaLocationId = $this->generateId('location', 43); |
1776
|
|
|
$demoDesignLocationId = $this->generateId('location', 56); |
1777
|
|
|
|
1778
|
|
|
$locationService = $repository->getLocationService(); |
1779
|
|
|
$locationToCopy = $locationService->loadLocation($mediaLocationId); |
1780
|
|
|
$newParentLocation = $locationService->loadLocation($demoDesignLocationId); |
1781
|
|
|
|
1782
|
|
|
$expectedSubItemAliases = [ |
1783
|
|
|
'/Design/Plain-site/Media/Multimedia', |
1784
|
|
|
'/Design/Plain-site/Media/Images', |
1785
|
|
|
'/Design/Plain-site/Media/Files', |
1786
|
|
|
]; |
1787
|
|
|
|
1788
|
|
|
$this->assertAliasesBeforeCopy($urlAliasService, $expectedSubItemAliases); |
1789
|
|
|
|
1790
|
|
|
// Copy location "Media" to "Design" |
1791
|
|
|
$locationService->copySubtree( |
1792
|
|
|
$locationToCopy, |
1793
|
|
|
$newParentLocation |
1794
|
|
|
); |
1795
|
|
|
|
1796
|
|
|
$this->assertGeneratedAliases($urlAliasService, $expectedSubItemAliases); |
1797
|
|
|
} |
1798
|
|
|
|
1799
|
|
|
/** |
1800
|
|
|
* Asserts that given Content has default ContentStates. |
1801
|
|
|
* |
1802
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
1803
|
|
|
*/ |
1804
|
|
View Code Duplication |
private function assertDefaultContentStates(ContentInfo $contentInfo) |
1805
|
|
|
{ |
1806
|
|
|
$repository = $this->getRepository(); |
1807
|
|
|
$objectStateService = $repository->getObjectStateService(); |
1808
|
|
|
|
1809
|
|
|
$objectStateGroups = $objectStateService->loadObjectStateGroups(); |
1810
|
|
|
|
1811
|
|
|
foreach ($objectStateGroups as $objectStateGroup) { |
1812
|
|
|
$contentState = $objectStateService->getContentState($contentInfo, $objectStateGroup); |
1813
|
|
|
foreach ($objectStateService->loadObjectStates($objectStateGroup) as $objectState) { |
1814
|
|
|
// Only check the first object state which is the default one. |
1815
|
|
|
$this->assertEquals( |
1816
|
|
|
$objectState, |
1817
|
|
|
$contentState |
1818
|
|
|
); |
1819
|
|
|
break; |
1820
|
|
|
} |
1821
|
|
|
} |
1822
|
|
|
} |
1823
|
|
|
|
1824
|
|
|
/** |
1825
|
|
|
* Test for the copySubtree() method. |
1826
|
|
|
* |
1827
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::copySubtree() |
1828
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCopySubtree |
1829
|
|
|
*/ |
1830
|
|
|
public function testCopySubtreeUpdatesSubtreeProperties() |
1831
|
|
|
{ |
1832
|
|
|
$repository = $this->getRepository(); |
1833
|
|
|
$locationService = $repository->getLocationService(); |
1834
|
|
|
|
1835
|
|
|
$locationToCopy = $locationService->loadLocation($this->generateId('location', 43)); |
1836
|
|
|
|
1837
|
|
|
// Load Subtree properties before copy |
1838
|
|
|
$expected = $this->loadSubtreeProperties($locationToCopy); |
1839
|
|
|
|
1840
|
|
|
$mediaLocationId = $this->generateId('location', 43); |
1841
|
|
|
$demoDesignLocationId = $this->generateId('location', 56); |
1842
|
|
|
/* BEGIN: Use Case */ |
1843
|
|
|
// $mediaLocationId is the ID of the "Media" page location in |
1844
|
|
|
// an eZ Publish demo installation |
1845
|
|
|
|
1846
|
|
|
// $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ |
1847
|
|
|
// Publish demo installation |
1848
|
|
|
|
1849
|
|
|
// Load the location service |
1850
|
|
|
$locationService = $repository->getLocationService(); |
1851
|
|
|
|
1852
|
|
|
// Load location to copy |
1853
|
|
|
$locationToCopy = $locationService->loadLocation($mediaLocationId); |
1854
|
|
|
|
1855
|
|
|
// Load new parent location |
1856
|
|
|
$newParentLocation = $locationService->loadLocation($demoDesignLocationId); |
1857
|
|
|
|
1858
|
|
|
// Copy location "Media" to "Demo Design" |
1859
|
|
|
$copiedLocation = $locationService->copySubtree( |
1860
|
|
|
$locationToCopy, |
1861
|
|
|
$newParentLocation |
1862
|
|
|
); |
1863
|
|
|
/* END: Use Case */ |
1864
|
|
|
|
1865
|
|
|
$beforeIds = array(); |
1866
|
|
|
foreach ($expected as $properties) { |
1867
|
|
|
$beforeIds[] = $properties['id']; |
1868
|
|
|
} |
1869
|
|
|
|
1870
|
|
|
$this->refreshSearch($repository); |
1871
|
|
|
|
1872
|
|
|
// Load Subtree properties after copy |
1873
|
|
|
$actual = $this->loadSubtreeProperties($copiedLocation); |
1874
|
|
|
|
1875
|
|
|
$this->assertEquals(count($expected), count($actual)); |
1876
|
|
|
|
1877
|
|
|
foreach ($actual as $properties) { |
1878
|
|
|
$this->assertNotContains($properties['id'], $beforeIds); |
1879
|
|
|
$this->assertStringStartsWith( |
1880
|
|
|
"{$newParentLocation->pathString}" . $this->parseId('location', $copiedLocation->id) . '/', |
1881
|
|
|
$properties['pathString'] |
1882
|
|
|
); |
1883
|
|
|
$this->assertStringEndsWith( |
1884
|
|
|
'/' . $this->parseId('location', $properties['id']) . '/', |
1885
|
|
|
$properties['pathString'] |
1886
|
|
|
); |
1887
|
|
|
} |
1888
|
|
|
} |
1889
|
|
|
|
1890
|
|
|
/** |
1891
|
|
|
* Test for the copySubtree() method. |
1892
|
|
|
* |
1893
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::copySubtree() |
1894
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCopySubtree |
1895
|
|
|
*/ |
1896
|
|
|
public function testCopySubtreeIncrementsChildCountOfNewParent() |
1897
|
|
|
{ |
1898
|
|
|
$repository = $this->getRepository(); |
1899
|
|
|
$locationService = $repository->getLocationService(); |
1900
|
|
|
|
1901
|
|
|
$childCountBefore = $locationService->getLocationChildCount($locationService->loadLocation(56)); |
1902
|
|
|
|
1903
|
|
|
$mediaLocationId = $this->generateId('location', 43); |
1904
|
|
|
$demoDesignLocationId = $this->generateId('location', 56); |
1905
|
|
|
/* BEGIN: Use Case */ |
1906
|
|
|
// $mediaLocationId is the ID of the "Media" page location in |
1907
|
|
|
// an eZ Publish demo installation |
1908
|
|
|
|
1909
|
|
|
// $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ |
1910
|
|
|
// Publish demo installation |
1911
|
|
|
|
1912
|
|
|
// Load the location service |
1913
|
|
|
$locationService = $repository->getLocationService(); |
1914
|
|
|
|
1915
|
|
|
// Load location to copy |
1916
|
|
|
$locationToCopy = $locationService->loadLocation($mediaLocationId); |
1917
|
|
|
|
1918
|
|
|
// Load new parent location |
1919
|
|
|
$newParentLocation = $locationService->loadLocation($demoDesignLocationId); |
1920
|
|
|
|
1921
|
|
|
// Copy location "Media" to "Demo Design" |
1922
|
|
|
$copiedLocation = $locationService->copySubtree( |
|
|
|
|
1923
|
|
|
$locationToCopy, |
1924
|
|
|
$newParentLocation |
1925
|
|
|
); |
1926
|
|
|
/* END: Use Case */ |
1927
|
|
|
|
1928
|
|
|
$this->refreshSearch($repository); |
1929
|
|
|
|
1930
|
|
|
$childCountAfter = $locationService->getLocationChildCount($locationService->loadLocation($demoDesignLocationId)); |
1931
|
|
|
|
1932
|
|
|
$this->assertEquals($childCountBefore + 1, $childCountAfter); |
1933
|
|
|
} |
1934
|
|
|
|
1935
|
|
|
/** |
1936
|
|
|
* Test for the copySubtree() method. |
1937
|
|
|
* |
1938
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::copySubtree() |
1939
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
1940
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCopySubtree |
1941
|
|
|
*/ |
1942
|
|
View Code Duplication |
public function testCopySubtreeThrowsInvalidArgumentException() |
1943
|
|
|
{ |
1944
|
|
|
$repository = $this->getRepository(); |
1945
|
|
|
|
1946
|
|
|
$communityLocationId = $this->generateId('location', 5); |
1947
|
|
|
/* BEGIN: Use Case */ |
1948
|
|
|
// $communityLocationId is the ID of the "Community" page location in |
1949
|
|
|
// an eZ Publish demo installation |
1950
|
|
|
|
1951
|
|
|
// Load the location service |
1952
|
|
|
$locationService = $repository->getLocationService(); |
1953
|
|
|
|
1954
|
|
|
// Load location to copy |
1955
|
|
|
$locationToCopy = $locationService->loadLocation($communityLocationId); |
1956
|
|
|
|
1957
|
|
|
// Use a child as new parent |
1958
|
|
|
$childLocations = $locationService->loadLocationChildren($locationToCopy)->locations; |
1959
|
|
|
$newParentLocation = end($childLocations); |
1960
|
|
|
|
1961
|
|
|
// This call will fail with an "InvalidArgumentException", because the |
1962
|
|
|
// new parent is a child location of the subtree to copy. |
1963
|
|
|
$locationService->copySubtree( |
1964
|
|
|
$locationToCopy, |
1965
|
|
|
$newParentLocation |
|
|
|
|
1966
|
|
|
); |
1967
|
|
|
/* END: Use Case */ |
1968
|
|
|
} |
1969
|
|
|
|
1970
|
|
|
/** |
1971
|
|
|
* Test for the moveSubtree() method. |
1972
|
|
|
* |
1973
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::moveSubtree() |
1974
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
1975
|
|
|
*/ |
1976
|
|
|
public function testMoveSubtree() |
1977
|
|
|
{ |
1978
|
|
|
$repository = $this->getRepository(); |
1979
|
|
|
|
1980
|
|
|
$mediaLocationId = $this->generateId('location', 43); |
1981
|
|
|
$demoDesignLocationId = $this->generateId('location', 56); |
1982
|
|
|
/* BEGIN: Use Case */ |
1983
|
|
|
// $mediaLocationId is the ID of the "Media" page location in |
1984
|
|
|
// an eZ Publish demo installation |
1985
|
|
|
|
1986
|
|
|
// $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ |
1987
|
|
|
// Publish demo installation |
1988
|
|
|
|
1989
|
|
|
// Load the location service |
1990
|
|
|
$locationService = $repository->getLocationService(); |
1991
|
|
|
|
1992
|
|
|
// Load location to move |
1993
|
|
|
$locationToMove = $locationService->loadLocation($mediaLocationId); |
1994
|
|
|
|
1995
|
|
|
// Load new parent location |
1996
|
|
|
$newParentLocation = $locationService->loadLocation($demoDesignLocationId); |
1997
|
|
|
|
1998
|
|
|
// Move location from "Home" to "Demo Design" |
1999
|
|
|
$locationService->moveSubtree( |
2000
|
|
|
$locationToMove, |
2001
|
|
|
$newParentLocation |
2002
|
|
|
); |
2003
|
|
|
|
2004
|
|
|
// Load moved location |
2005
|
|
|
$movedLocation = $locationService->loadLocation($mediaLocationId); |
2006
|
|
|
/* END: Use Case */ |
2007
|
|
|
|
2008
|
|
|
$this->assertPropertiesCorrect( |
2009
|
|
|
array( |
2010
|
|
|
'hidden' => false, |
2011
|
|
|
'invisible' => false, |
2012
|
|
|
'depth' => $newParentLocation->depth + 1, |
2013
|
|
|
'parentLocationId' => $newParentLocation->id, |
2014
|
|
|
'pathString' => "{$newParentLocation->pathString}" . $this->parseId('location', $movedLocation->id) . '/', |
2015
|
|
|
), |
2016
|
|
|
$movedLocation |
2017
|
|
|
); |
2018
|
|
|
} |
2019
|
|
|
|
2020
|
|
|
/** |
2021
|
|
|
* Test for the moveSubtree() method. |
2022
|
|
|
* |
2023
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::moveSubtree() |
2024
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree |
2025
|
|
|
*/ |
2026
|
|
|
public function testMoveSubtreeHidden() |
2027
|
|
|
{ |
2028
|
|
|
$repository = $this->getRepository(); |
2029
|
|
|
|
2030
|
|
|
$mediaLocationId = $this->generateId('location', 43); |
2031
|
|
|
$demoDesignLocationId = $this->generateId('location', 56); |
2032
|
|
|
/* BEGIN: Use Case */ |
2033
|
|
|
// $mediaLocationId is the ID of the "Media" page location in |
2034
|
|
|
// an eZ Publish demo installation |
2035
|
|
|
|
2036
|
|
|
// $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ |
2037
|
|
|
// Publish demo installation |
2038
|
|
|
|
2039
|
|
|
// Load the location service |
2040
|
|
|
$locationService = $repository->getLocationService(); |
2041
|
|
|
|
2042
|
|
|
// Load location to move |
2043
|
|
|
$locationToMove = $locationService->loadLocation($mediaLocationId); |
2044
|
|
|
|
2045
|
|
|
// Load new parent location |
2046
|
|
|
$newParentLocation = $locationService->loadLocation($demoDesignLocationId); |
2047
|
|
|
|
2048
|
|
|
// Hide the target location before we move |
2049
|
|
|
$newParentLocation = $locationService->hideLocation($newParentLocation); |
2050
|
|
|
|
2051
|
|
|
// Move location from "Home" to "Demo Design" |
2052
|
|
|
$locationService->moveSubtree( |
2053
|
|
|
$locationToMove, |
2054
|
|
|
$newParentLocation |
2055
|
|
|
); |
2056
|
|
|
|
2057
|
|
|
// Load moved location |
2058
|
|
|
$movedLocation = $locationService->loadLocation($mediaLocationId); |
2059
|
|
|
/* END: Use Case */ |
2060
|
|
|
|
2061
|
|
|
$this->assertPropertiesCorrect( |
2062
|
|
|
array( |
2063
|
|
|
'hidden' => false, |
2064
|
|
|
'invisible' => true, |
2065
|
|
|
'depth' => $newParentLocation->depth + 1, |
2066
|
|
|
'parentLocationId' => $newParentLocation->id, |
2067
|
|
|
'pathString' => "{$newParentLocation->pathString}" . $this->parseId('location', $movedLocation->id) . '/', |
2068
|
|
|
), |
2069
|
|
|
$movedLocation |
2070
|
|
|
); |
2071
|
|
|
} |
2072
|
|
|
|
2073
|
|
|
/** |
2074
|
|
|
* Test for the moveSubtree() method. |
2075
|
|
|
* |
2076
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::moveSubtree() |
2077
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree |
2078
|
|
|
*/ |
2079
|
|
|
public function testMoveSubtreeUpdatesSubtreeProperties() |
2080
|
|
|
{ |
2081
|
|
|
$repository = $this->getRepository(); |
2082
|
|
|
$locationService = $repository->getLocationService(); |
2083
|
|
|
|
2084
|
|
|
$locationToMove = $locationService->loadLocation($this->generateId('location', 43)); |
2085
|
|
|
$newParentLocation = $locationService->loadLocation($this->generateId('location', 56)); |
2086
|
|
|
|
2087
|
|
|
// Load Subtree properties before move |
2088
|
|
|
$expected = $this->loadSubtreeProperties($locationToMove); |
2089
|
|
|
foreach ($expected as $id => $properties) { |
2090
|
|
|
$expected[$id]['depth'] = $properties['depth'] + 2; |
2091
|
|
|
$expected[$id]['pathString'] = str_replace( |
2092
|
|
|
$locationToMove->pathString, |
2093
|
|
|
"{$newParentLocation->pathString}" . $this->parseId('location', $locationToMove->id) . '/', |
2094
|
|
|
$properties['pathString'] |
2095
|
|
|
); |
2096
|
|
|
} |
2097
|
|
|
|
2098
|
|
|
$mediaLocationId = $this->generateId('location', 43); |
2099
|
|
|
$demoDesignLocationId = $this->generateId('location', 56); |
2100
|
|
|
/* BEGIN: Use Case */ |
2101
|
|
|
// $mediaLocationId is the ID of the "Media" page location in |
2102
|
|
|
// an eZ Publish demo installation |
2103
|
|
|
|
2104
|
|
|
// $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ |
2105
|
|
|
// Publish demo installation |
2106
|
|
|
|
2107
|
|
|
// Load the location service |
2108
|
|
|
$locationService = $repository->getLocationService(); |
2109
|
|
|
|
2110
|
|
|
// Load location to move |
2111
|
|
|
$locationToMove = $locationService->loadLocation($mediaLocationId); |
2112
|
|
|
|
2113
|
|
|
// Load new parent location |
2114
|
|
|
$newParentLocation = $locationService->loadLocation($demoDesignLocationId); |
2115
|
|
|
|
2116
|
|
|
// Move location from "Home" to "Demo Design" |
2117
|
|
|
$locationService->moveSubtree( |
2118
|
|
|
$locationToMove, |
2119
|
|
|
$newParentLocation |
2120
|
|
|
); |
2121
|
|
|
|
2122
|
|
|
// Load moved location |
2123
|
|
|
$movedLocation = $locationService->loadLocation($mediaLocationId); |
2124
|
|
|
/* END: Use Case */ |
2125
|
|
|
|
2126
|
|
|
$this->refreshSearch($repository); |
2127
|
|
|
|
2128
|
|
|
// Load Subtree properties after move |
2129
|
|
|
$actual = $this->loadSubtreeProperties($movedLocation); |
2130
|
|
|
|
2131
|
|
|
$this->assertEquals($expected, $actual); |
2132
|
|
|
} |
2133
|
|
|
|
2134
|
|
|
/** |
2135
|
|
|
* Test for the moveSubtree() method. |
2136
|
|
|
* |
2137
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::moveSubtree() |
2138
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtreeUpdatesSubtreeProperties |
2139
|
|
|
*/ |
2140
|
|
|
public function testMoveSubtreeUpdatesSubtreePropertiesHidden() |
2141
|
|
|
{ |
2142
|
|
|
$repository = $this->getRepository(); |
2143
|
|
|
$locationService = $repository->getLocationService(); |
2144
|
|
|
|
2145
|
|
|
$locationToMove = $locationService->loadLocation($this->generateId('location', 43)); |
2146
|
|
|
$newParentLocation = $locationService->loadLocation($this->generateId('location', 56)); |
2147
|
|
|
|
2148
|
|
|
// Hide the target location before we move |
2149
|
|
|
$newParentLocation = $locationService->hideLocation($newParentLocation); |
2150
|
|
|
|
2151
|
|
|
// Load Subtree properties before move |
2152
|
|
|
$expected = $this->loadSubtreeProperties($locationToMove); |
2153
|
|
|
foreach ($expected as $id => $properties) { |
2154
|
|
|
$expected[$id]['invisible'] = true; |
2155
|
|
|
$expected[$id]['depth'] = $properties['depth'] + 2; |
2156
|
|
|
$expected[$id]['pathString'] = str_replace( |
2157
|
|
|
$locationToMove->pathString, |
2158
|
|
|
"{$newParentLocation->pathString}" . $this->parseId('location', $locationToMove->id) . '/', |
2159
|
|
|
$properties['pathString'] |
2160
|
|
|
); |
2161
|
|
|
} |
2162
|
|
|
|
2163
|
|
|
$mediaLocationId = $this->generateId('location', 43); |
2164
|
|
|
$demoDesignLocationId = $this->generateId('location', 56); |
2165
|
|
|
/* BEGIN: Use Case */ |
2166
|
|
|
// $mediaLocationId is the ID of the "Media" page location in |
2167
|
|
|
// an eZ Publish demo installation |
2168
|
|
|
|
2169
|
|
|
// $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ |
2170
|
|
|
// Publish demo installation |
2171
|
|
|
|
2172
|
|
|
// Load the location service |
2173
|
|
|
$locationService = $repository->getLocationService(); |
2174
|
|
|
|
2175
|
|
|
// Load location to move |
2176
|
|
|
$locationToMove = $locationService->loadLocation($mediaLocationId); |
2177
|
|
|
|
2178
|
|
|
// Load new parent location |
2179
|
|
|
$newParentLocation = $locationService->loadLocation($demoDesignLocationId); |
2180
|
|
|
|
2181
|
|
|
// Move location from "Home" to "Demo Design" |
2182
|
|
|
$locationService->moveSubtree( |
2183
|
|
|
$locationToMove, |
2184
|
|
|
$newParentLocation |
2185
|
|
|
); |
2186
|
|
|
|
2187
|
|
|
// Load moved location |
2188
|
|
|
$movedLocation = $locationService->loadLocation($mediaLocationId); |
2189
|
|
|
/* END: Use Case */ |
2190
|
|
|
|
2191
|
|
|
$this->refreshSearch($repository); |
2192
|
|
|
|
2193
|
|
|
// Load Subtree properties after move |
2194
|
|
|
$actual = $this->loadSubtreeProperties($movedLocation); |
2195
|
|
|
|
2196
|
|
|
$this->assertEquals($expected, $actual); |
2197
|
|
|
} |
2198
|
|
|
|
2199
|
|
|
/** |
2200
|
|
|
* Test for the moveSubtree() method. |
2201
|
|
|
* |
2202
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::moveSubtree() |
2203
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree |
2204
|
|
|
*/ |
2205
|
|
View Code Duplication |
public function testMoveSubtreeIncrementsChildCountOfNewParent() |
2206
|
|
|
{ |
2207
|
|
|
$repository = $this->getRepository(); |
2208
|
|
|
$locationService = $repository->getLocationService(); |
2209
|
|
|
|
2210
|
|
|
$newParentLocation = $locationService->loadLocation($this->generateId('location', 56)); |
2211
|
|
|
|
2212
|
|
|
// Load expected properties before move |
2213
|
|
|
$expected = $this->loadLocationProperties($newParentLocation); |
2214
|
|
|
$childCountBefore = $locationService->getLocationChildCount($newParentLocation); |
2215
|
|
|
|
2216
|
|
|
$mediaLocationId = $this->generateId('location', 43); |
2217
|
|
|
$demoDesignLocationId = $this->generateId('location', 56); |
2218
|
|
|
/* BEGIN: Use Case */ |
2219
|
|
|
// $mediaLocationId is the ID of the "Media" page location in |
2220
|
|
|
// an eZ Publish demo installation |
2221
|
|
|
|
2222
|
|
|
// $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ |
2223
|
|
|
// Publish demo installation |
2224
|
|
|
|
2225
|
|
|
// Load the location service |
2226
|
|
|
$locationService = $repository->getLocationService(); |
2227
|
|
|
|
2228
|
|
|
// Load location to move |
2229
|
|
|
$locationToMove = $locationService->loadLocation($mediaLocationId); |
2230
|
|
|
|
2231
|
|
|
// Load new parent location |
2232
|
|
|
$newParentLocation = $locationService->loadLocation($demoDesignLocationId); |
2233
|
|
|
|
2234
|
|
|
// Move location from "Home" to "Demo Design" |
2235
|
|
|
$locationService->moveSubtree( |
2236
|
|
|
$locationToMove, |
2237
|
|
|
$newParentLocation |
2238
|
|
|
); |
2239
|
|
|
|
2240
|
|
|
// Load moved location |
2241
|
|
|
$movedLocation = $locationService->loadLocation($mediaLocationId); |
|
|
|
|
2242
|
|
|
|
2243
|
|
|
// Reload new parent location |
2244
|
|
|
$newParentLocation = $locationService->loadLocation($demoDesignLocationId); |
2245
|
|
|
/* END: Use Case */ |
2246
|
|
|
|
2247
|
|
|
$this->refreshSearch($repository); |
2248
|
|
|
|
2249
|
|
|
// Load Subtree properties after move |
2250
|
|
|
$actual = $this->loadLocationProperties($newParentLocation); |
2251
|
|
|
$childCountAfter = $locationService->getLocationChildCount($newParentLocation); |
2252
|
|
|
|
2253
|
|
|
$this->assertEquals($expected, $actual); |
2254
|
|
|
$this->assertEquals($childCountBefore + 1, $childCountAfter); |
2255
|
|
|
} |
2256
|
|
|
|
2257
|
|
|
/** |
2258
|
|
|
* Test for the moveSubtree() method. |
2259
|
|
|
* |
2260
|
|
|
* @see \eZ\Publish\API\Repository\LocationService::moveSubtree() |
2261
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree |
2262
|
|
|
*/ |
2263
|
|
View Code Duplication |
public function testMoveSubtreeDecrementsChildCountOfOldParent() |
2264
|
|
|
{ |
2265
|
|
|
$repository = $this->getRepository(); |
2266
|
|
|
$locationService = $repository->getLocationService(); |
2267
|
|
|
|
2268
|
|
|
$oldParentLocation = $locationService->loadLocation($this->generateId('location', 1)); |
2269
|
|
|
|
2270
|
|
|
// Load expected properties before move |
2271
|
|
|
$expected = $this->loadLocationProperties($oldParentLocation); |
2272
|
|
|
$childCountBefore = $locationService->getLocationChildCount($oldParentLocation); |
2273
|
|
|
|
2274
|
|
|
$mediaLocationId = $this->generateId('location', 43); |
2275
|
|
|
$demoDesignLocationId = $this->generateId('location', 56); |
2276
|
|
|
/* BEGIN: Use Case */ |
2277
|
|
|
// $mediaLocationId is the ID of the "Media" page location in |
2278
|
|
|
// an eZ Publish demo installation |
2279
|
|
|
|
2280
|
|
|
// $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ |
2281
|
|
|
// Publish demo installation |
2282
|
|
|
|
2283
|
|
|
// Load the location service |
2284
|
|
|
$locationService = $repository->getLocationService(); |
2285
|
|
|
|
2286
|
|
|
// Load location to move |
2287
|
|
|
$locationToMove = $locationService->loadLocation($mediaLocationId); |
2288
|
|
|
|
2289
|
|
|
// Get the location id of the old parent |
2290
|
|
|
$oldParentLocationId = $locationToMove->parentLocationId; |
2291
|
|
|
|
2292
|
|
|
// Load new parent location |
2293
|
|
|
$newParentLocation = $locationService->loadLocation($demoDesignLocationId); |
2294
|
|
|
|
2295
|
|
|
// Move location from "Home" to "Demo Design" |
2296
|
|
|
$locationService->moveSubtree( |
2297
|
|
|
$locationToMove, |
2298
|
|
|
$newParentLocation |
2299
|
|
|
); |
2300
|
|
|
|
2301
|
|
|
// Reload old parent location |
2302
|
|
|
$oldParentLocation = $locationService->loadLocation($oldParentLocationId); |
2303
|
|
|
/* END: Use Case */ |
2304
|
|
|
|
2305
|
|
|
$this->refreshSearch($repository); |
2306
|
|
|
|
2307
|
|
|
// Load Subtree properties after move |
2308
|
|
|
$actual = $this->loadLocationProperties($oldParentLocation); |
2309
|
|
|
$childCountAfter = $locationService->getLocationChildCount($oldParentLocation); |
2310
|
|
|
|
2311
|
|
|
$this->assertEquals($expected, $actual); |
2312
|
|
|
$this->assertEquals($childCountBefore - 1, $childCountAfter); |
2313
|
|
|
} |
2314
|
|
|
|
2315
|
|
|
/** |
2316
|
|
|
* Test for the moveSubtree() method. |
2317
|
|
|
* |
2318
|
|
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree |
2319
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
2320
|
|
|
*/ |
2321
|
|
View Code Duplication |
public function testMoveSubtreeThrowsInvalidArgumentException() |
2322
|
|
|
{ |
2323
|
|
|
$repository = $this->getRepository(); |
2324
|
|
|
$mediaLocationId = $this->generateId('location', 43); |
2325
|
|
|
$multimediaLocationId = $this->generateId('location', 53); |
2326
|
|
|
|
2327
|
|
|
/* BEGIN: Use Case */ |
2328
|
|
|
// $mediaLocationId is the ID of the "Media" page location in |
2329
|
|
|
// an eZ Publish demo installation |
2330
|
|
|
|
2331
|
|
|
// $multimediaLocationId is the ID of the "Multimedia" page location in an eZ |
2332
|
|
|
// Publish demo installation |
2333
|
|
|
|
2334
|
|
|
// Load the location service |
2335
|
|
|
$locationService = $repository->getLocationService(); |
2336
|
|
|
|
2337
|
|
|
// Load location to move |
2338
|
|
|
$locationToMove = $locationService->loadLocation($mediaLocationId); |
2339
|
|
|
|
2340
|
|
|
// Load new parent location |
2341
|
|
|
$newParentLocation = $locationService->loadLocation($multimediaLocationId); |
2342
|
|
|
|
2343
|
|
|
// Throws an exception because new parent location is placed below location to move |
2344
|
|
|
$locationService->moveSubtree( |
2345
|
|
|
$locationToMove, |
2346
|
|
|
$newParentLocation |
2347
|
|
|
); |
2348
|
|
|
/* END: Use Case */ |
2349
|
|
|
} |
2350
|
|
|
|
2351
|
|
|
/** |
2352
|
|
|
* Loads properties from all locations in the $location's subtree. |
2353
|
|
|
* |
2354
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Location $location |
2355
|
|
|
* @param array $properties |
2356
|
|
|
* |
2357
|
|
|
* @return array |
2358
|
|
|
*/ |
2359
|
|
|
private function loadSubtreeProperties(Location $location, array $properties = array()) |
2360
|
|
|
{ |
2361
|
|
|
$locationService = $this->getRepository()->getLocationService(); |
2362
|
|
|
|
2363
|
|
|
foreach ($locationService->loadLocationChildren($location)->locations as $childLocation) { |
2364
|
|
|
$properties[] = $this->loadLocationProperties($childLocation); |
2365
|
|
|
|
2366
|
|
|
$properties = $this->loadSubtreeProperties($childLocation, $properties); |
2367
|
|
|
} |
2368
|
|
|
|
2369
|
|
|
return $properties; |
2370
|
|
|
} |
2371
|
|
|
|
2372
|
|
|
/** |
2373
|
|
|
* Loads assertable properties from the given location. |
2374
|
|
|
* |
2375
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\Location $location |
2376
|
|
|
* @param mixed[] $overwrite |
2377
|
|
|
* |
2378
|
|
|
* @return array |
2379
|
|
|
*/ |
2380
|
|
|
private function loadLocationProperties(Location $location, array $overwrite = array()) |
2381
|
|
|
{ |
2382
|
|
|
return array_merge( |
2383
|
|
|
array( |
2384
|
|
|
'id' => $location->id, |
2385
|
|
|
'depth' => $location->depth, |
2386
|
|
|
'parentLocationId' => $location->parentLocationId, |
2387
|
|
|
'pathString' => $location->pathString, |
2388
|
|
|
'remoteId' => $location->remoteId, |
2389
|
|
|
'hidden' => $location->hidden, |
2390
|
|
|
'invisible' => $location->invisible, |
2391
|
|
|
'priority' => $location->priority, |
2392
|
|
|
'sortField' => $location->sortField, |
2393
|
|
|
'sortOrder' => $location->sortOrder, |
2394
|
|
|
), |
2395
|
|
|
$overwrite |
2396
|
|
|
); |
2397
|
|
|
} |
2398
|
|
|
|
2399
|
|
|
/** |
2400
|
|
|
* Assert generated aliases to expected alias return. |
2401
|
|
|
* |
2402
|
|
|
* @param \eZ\Publish\API\Repository\URLAliasService $urlAliasService |
2403
|
|
|
* @param array $expectedAliases |
2404
|
|
|
*/ |
2405
|
|
|
protected function assertGeneratedAliases($urlAliasService, array $expectedAliases) |
2406
|
|
|
{ |
2407
|
|
|
foreach ($expectedAliases as $expectedAlias) { |
2408
|
|
|
$urlAlias = $urlAliasService->lookup($expectedAlias); |
2409
|
|
|
$this->assertPropertiesCorrect(['type' => 0], $urlAlias); |
2410
|
|
|
} |
2411
|
|
|
} |
2412
|
|
|
|
2413
|
|
|
/** |
2414
|
|
|
* @param \eZ\Publish\API\Repository\URLAliasService $urlAliasService |
2415
|
|
|
* @param array $expectedSubItemAliases |
2416
|
|
|
*/ |
2417
|
|
|
private function assertAliasesBeforeCopy($urlAliasService, array $expectedSubItemAliases) |
2418
|
|
|
{ |
2419
|
|
|
foreach ($expectedSubItemAliases as $aliasUrl) { |
2420
|
|
|
try { |
2421
|
|
|
$urlAliasService->lookup($aliasUrl); |
2422
|
|
|
$this->fail('We didn\'t expect to find alias, but it was found'); |
2423
|
|
|
} catch (\Exception $e) { |
2424
|
|
|
$this->assertTrue(true); // OK - alias was not found |
2425
|
|
|
} |
2426
|
|
|
} |
2427
|
|
|
} |
2428
|
|
|
|
2429
|
|
|
/** |
2430
|
|
|
* Create and publish Content with the given parent Location. |
2431
|
|
|
* |
2432
|
|
|
* @param string $contentName |
2433
|
|
|
* @param int $parentLocationId |
2434
|
|
|
* |
2435
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Content published Content |
2436
|
|
|
*/ |
2437
|
|
View Code Duplication |
private function publishContentWithParentLocation($contentName, $parentLocationId) |
2438
|
|
|
{ |
2439
|
|
|
$repository = $this->getRepository(false); |
2440
|
|
|
$locationService = $repository->getLocationService(); |
2441
|
|
|
|
2442
|
|
|
$contentService = $repository->getContentService(); |
2443
|
|
|
$contentTypeService = $repository->getContentTypeService(); |
2444
|
|
|
|
2445
|
|
|
$contentCreateStruct = $contentService->newContentCreateStruct( |
2446
|
|
|
$contentTypeService->loadContentTypeByIdentifier('folder'), |
2447
|
|
|
'eng-US' |
2448
|
|
|
); |
2449
|
|
|
$contentCreateStruct->setField('name', $contentName); |
2450
|
|
|
$contentDraft = $contentService->createContent( |
2451
|
|
|
$contentCreateStruct, |
2452
|
|
|
[ |
2453
|
|
|
$locationService->newLocationCreateStruct($parentLocationId), |
2454
|
|
|
] |
2455
|
|
|
); |
2456
|
|
|
|
2457
|
|
|
return $contentService->publishVersion($contentDraft->versionInfo); |
2458
|
|
|
} |
2459
|
|
|
} |
2460
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.