1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File contains: eZ\Publish\Core\Repository\Tests\Service\Integration\LocationBase class. |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
namespace eZ\Publish\Core\Repository\Tests\Service\Integration; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\Core\Repository\Tests\Service\Integration\Base as BaseServiceTest; |
12
|
|
|
use eZ\Publish\Core\Repository\Values\Content\Location; |
13
|
|
|
use eZ\Publish\API\Repository\Values\Content\LocationCreateStruct; |
14
|
|
|
use eZ\Publish\API\Repository\Exceptions\PropertyNotFoundException as PropertyNotFound; |
15
|
|
|
use eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException; |
16
|
|
|
use eZ\Publish\API\Repository\Exceptions\NotFoundException; |
17
|
|
|
use eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct; |
18
|
|
|
use eZ\Publish\API\Repository\Tests\BaseTest as APIBaseTest; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Test case for Location Service. |
22
|
|
|
*/ |
23
|
|
|
abstract class LocationBase extends BaseServiceTest |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Test a new class and default values on properties. |
27
|
|
|
* |
28
|
|
|
* @covers \eZ\Publish\API\Repository\Values\Content\Location::__construct |
29
|
|
|
*/ |
30
|
|
View Code Duplication |
public function testNewClass() |
31
|
|
|
{ |
32
|
|
|
$location = new Location(); |
33
|
|
|
|
34
|
|
|
$this->assertPropertiesCorrect( |
35
|
|
|
array( |
36
|
|
|
'id' => null, |
37
|
|
|
'priority' => null, |
38
|
|
|
'hidden' => null, |
39
|
|
|
'invisible' => null, |
40
|
|
|
'remoteId' => null, |
41
|
|
|
'parentLocationId' => null, |
42
|
|
|
'pathString' => null, |
43
|
|
|
'path' => array(), |
44
|
|
|
'depth' => null, |
45
|
|
|
'sortField' => null, |
46
|
|
|
'sortOrder' => null, |
47
|
|
|
), |
48
|
|
|
$location |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Test retrieving missing property. |
54
|
|
|
* |
55
|
|
|
* @covers \eZ\Publish\API\Repository\Values\Content\Location::__get |
56
|
|
|
*/ |
57
|
|
|
public function testMissingProperty() |
58
|
|
|
{ |
59
|
|
|
try { |
60
|
|
|
$location = new Location(); |
61
|
|
|
$value = $location->notDefined; |
|
|
|
|
62
|
|
|
self::fail('Succeeded getting non existing property'); |
63
|
|
|
} catch (PropertyNotFound $e) { |
|
|
|
|
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Test setting read only property. |
69
|
|
|
* |
70
|
|
|
* @covers \eZ\Publish\API\Repository\Values\Content\Location::__set |
71
|
|
|
*/ |
72
|
|
|
public function testReadOnlyProperty() |
73
|
|
|
{ |
74
|
|
|
try { |
75
|
|
|
$location = new Location(); |
76
|
|
|
$location->id = 42; |
77
|
|
|
self::fail('Succeeded setting read only property'); |
78
|
|
|
} catch (PropertyReadOnlyException $e) { |
|
|
|
|
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Test if property exists. |
84
|
|
|
* |
85
|
|
|
* @covers \eZ\Publish\API\Repository\Values\Content\Location::__isset |
86
|
|
|
*/ |
87
|
|
|
public function testIsPropertySet() |
88
|
|
|
{ |
89
|
|
|
$location = new Location(); |
90
|
|
|
$value = isset($location->notDefined); |
91
|
|
|
self::assertEquals(false, $value); |
92
|
|
|
|
93
|
|
|
$value = isset($location->id); |
94
|
|
|
self::assertEquals(true, $value); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Test unsetting a property. |
99
|
|
|
* |
100
|
|
|
* @covers \eZ\Publish\API\Repository\Values\Content\Location::__unset |
101
|
|
|
*/ |
102
|
|
|
public function testUnsetProperty() |
103
|
|
|
{ |
104
|
|
|
$location = new Location(array('id' => 2)); |
105
|
|
|
try { |
106
|
|
|
unset($location->id); |
107
|
|
|
self::fail('Unsetting read-only property succeeded'); |
108
|
|
|
} catch (PropertyReadOnlyException $e) { |
|
|
|
|
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @param int $parentLocationId |
114
|
|
|
* |
115
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Content |
116
|
|
|
*/ |
117
|
|
View Code Duplication |
protected function createTestContentLocation($parentLocationId) |
118
|
|
|
{ |
119
|
|
|
$contentService = $this->repository->getContentService(); |
120
|
|
|
$contentTypeService = $this->repository->getContentTypeService(); |
121
|
|
|
// User Group content type |
122
|
|
|
$contentType = $contentTypeService->loadContentType(3); |
123
|
|
|
|
124
|
|
|
$contentCreate = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
125
|
|
|
$contentCreate->setField('name', 'dummy value'); |
126
|
|
|
$contentCreate->sectionId = 1; |
127
|
|
|
$contentCreate->ownerId = 14; |
128
|
|
|
$contentCreate->remoteId = md5(uniqid(get_class($this), true)); |
129
|
|
|
$contentCreate->alwaysAvailable = true; |
130
|
|
|
|
131
|
|
|
$locationCreates = array( |
132
|
|
|
new LocationCreateStruct( |
133
|
|
|
array( |
134
|
|
|
//priority = 0 |
135
|
|
|
//hidden = false |
136
|
|
|
'remoteId' => md5(uniqid(get_class($this), true)), |
137
|
|
|
//sortField = Location::SORT_FIELD_NAME |
138
|
|
|
//sortOrder = Location::SORT_ORDER_ASC |
139
|
|
|
'parentLocationId' => $parentLocationId, |
140
|
|
|
) |
141
|
|
|
), |
142
|
|
|
); |
143
|
|
|
|
144
|
|
|
return $contentService->publishVersion( |
145
|
|
|
$contentService->createContent( |
146
|
|
|
$contentCreate, |
147
|
|
|
$locationCreates |
148
|
|
|
)->versionInfo |
149
|
|
|
); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
154
|
|
|
* @param int $parentLocationId |
155
|
|
|
* |
156
|
|
|
* @return mixed |
157
|
|
|
*/ |
158
|
|
|
protected function addNewMainLocation($contentInfo, $parentLocationId) |
159
|
|
|
{ |
160
|
|
|
$locationService = $this->repository->getLocationService(); |
161
|
|
|
$contentService = $this->repository->getContentService(); |
162
|
|
|
|
163
|
|
|
$newLocation = $locationService->createLocation( |
164
|
|
|
$contentInfo, |
165
|
|
|
new LocationCreateStruct( |
166
|
|
|
array( |
167
|
|
|
'remoteId' => md5(uniqid(get_class($this), true)), |
168
|
|
|
'parentLocationId' => $parentLocationId, |
169
|
|
|
) |
170
|
|
|
) |
171
|
|
|
); |
172
|
|
|
$contentService->updateContentMetadata( |
173
|
|
|
$contentInfo, |
174
|
|
|
new ContentMetadataUpdateStruct(array('mainLocationId' => $newLocation->id)) |
175
|
|
|
); |
176
|
|
|
|
177
|
|
|
return $newLocation->id; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Test copying a subtree. |
182
|
|
|
* |
183
|
|
|
* @group current |
184
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::copySubtree |
185
|
|
|
*/ |
186
|
|
|
public function testCopySubtree() |
187
|
|
|
{ |
188
|
|
|
// Prepare test tree |
189
|
|
|
$outsideLocationId = $this->createTestContentLocation(5)->contentInfo->mainLocationId; |
190
|
|
|
$targetLocationId = $this->createTestContentLocation(5)->contentInfo->mainLocationId; |
191
|
|
|
$locationToCopyContent = $this->createTestContentLocation(5); |
192
|
|
|
|
193
|
|
|
$locationToCopyId = $locationToCopyContent->contentInfo->mainLocationId; |
194
|
|
|
|
195
|
|
|
$this->createTestContentLocation($locationToCopyId); |
196
|
|
|
$subLocationContent20 = $this->createTestContentLocation($locationToCopyId); |
197
|
|
|
$subLocationId20 = $subLocationContent20->contentInfo->mainLocationId; |
198
|
|
|
$subLocationContent21 = $this->createTestContentLocation($subLocationId20); |
199
|
|
|
|
200
|
|
|
// Add main locations outside subtree |
201
|
|
|
$this->addNewMainLocation($locationToCopyContent->contentInfo, $outsideLocationId); |
202
|
|
|
$this->addNewMainLocation($subLocationContent20->contentInfo, $outsideLocationId); |
203
|
|
|
|
204
|
|
|
// Add main locations inside subtree |
205
|
|
|
$lastLocationId = $this->addNewMainLocation($subLocationContent21->contentInfo, $locationToCopyId); |
206
|
|
|
|
207
|
|
|
/* BEGIN: Use Case */ |
208
|
|
|
$locationService = $this->repository->getLocationService(); |
209
|
|
|
$locationToCopy = $locationService->loadLocation($locationToCopyId); |
210
|
|
|
$targetLocation = $locationService->loadLocation($targetLocationId); |
211
|
|
|
|
212
|
|
|
$copiedSubtreeRootLocation = $locationService->copySubtree($locationToCopy, $targetLocation); |
213
|
|
|
/* END: Use Case */ |
214
|
|
|
|
215
|
|
|
self::assertEquals($lastLocationId + 1, $copiedSubtreeRootLocation->id); |
216
|
|
|
|
217
|
|
|
// Check structure |
218
|
|
|
$subtreeRootChildren = $locationService->loadLocationChildren($copiedSubtreeRootLocation); |
219
|
|
|
self::assertEquals(3, $subtreeRootChildren->totalCount); |
220
|
|
|
self::assertEquals(0, $locationService->getLocationChildCount($subtreeRootChildren->locations[0])); |
221
|
|
|
$subLocationChildren = $locationService->loadLocationChildren($subtreeRootChildren->locations[1]); |
222
|
|
|
self::assertEquals(1, $subLocationChildren->totalCount); |
223
|
|
|
self::assertEquals(0, $locationService->getLocationChildCount($subtreeRootChildren->locations[2])); |
224
|
|
|
self::assertEquals(0, $locationService->getLocationChildCount($subLocationChildren->locations[0])); |
225
|
|
|
|
226
|
|
|
// Check main locations |
227
|
|
|
self::assertEquals($copiedSubtreeRootLocation->contentInfo->mainLocationId, $copiedSubtreeRootLocation->id); |
228
|
|
|
self::assertEquals($subtreeRootChildren->locations[0]->contentInfo->mainLocationId, $subtreeRootChildren->locations[0]->id); |
229
|
|
|
self::assertEquals($subtreeRootChildren->locations[1]->contentInfo->mainLocationId, $subtreeRootChildren->locations[1]->id); |
230
|
|
|
self::assertEquals($subtreeRootChildren->locations[2]->contentInfo->mainLocationId, $subtreeRootChildren->locations[2]->id); |
231
|
|
|
self::assertEquals($subLocationChildren->locations[0]->contentInfo->mainLocationId, $subtreeRootChildren->locations[2]->id); |
232
|
|
|
|
233
|
|
|
self::assertInstanceOf('eZ\\Publish\\API\\Repository\\Values\\Content\\Location', $copiedSubtreeRootLocation); |
234
|
|
|
self::assertEquals($targetLocation->id, $copiedSubtreeRootLocation->parentLocationId); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* Test copying a subtree throwing InvalidArgumentException. |
239
|
|
|
* |
240
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
241
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::copySubtree |
242
|
|
|
*/ |
243
|
|
|
public function testCopySubtreeThrowsInvalidArgumentException() |
244
|
|
|
{ |
245
|
|
|
$locationService = $this->repository->getLocationService(); |
246
|
|
|
$locationToCopy = $locationService->loadLocation(5); |
247
|
|
|
$targetLocation = $locationService->loadLocation(44); |
248
|
|
|
|
249
|
|
|
$locationService->copySubtree($locationToCopy, $targetLocation); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* Test loading a location. |
254
|
|
|
* |
255
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::loadLocation |
256
|
|
|
*/ |
257
|
|
|
public function testLoadLocation() |
258
|
|
|
{ |
259
|
|
|
$locationService = $this->repository->getLocationService(); |
260
|
|
|
$loadedLocation = $locationService->loadLocation(5); |
261
|
|
|
|
262
|
|
|
self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', $loadedLocation); |
263
|
|
|
self::assertEquals(5, $loadedLocation->id); |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* Test loading a location throwing NotFoundException. |
268
|
|
|
* |
269
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
270
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::loadLocation |
271
|
|
|
*/ |
272
|
|
|
public function testLoadLocationThrowsNotFoundException() |
273
|
|
|
{ |
274
|
|
|
$locationService = $this->repository->getLocationService(); |
275
|
|
|
$locationService->loadLocation(APIBaseTest::DB_INT_MAX); |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* Test loading location by remote ID. |
280
|
|
|
* |
281
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::loadLocationByRemoteId |
282
|
|
|
*/ |
283
|
|
|
public function testLoadLocationByRemoteId() |
284
|
|
|
{ |
285
|
|
|
$location = $this->repository->getLocationService()->loadLocationByRemoteId('769380b7aa94541679167eab817ca893'); |
286
|
|
|
|
287
|
|
|
self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', $location); |
288
|
|
|
self::assertGreaterThan(0, $location->id); |
289
|
|
|
self::assertEquals('769380b7aa94541679167eab817ca893', $location->remoteId); |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
/** |
293
|
|
|
* Test loading location by remote ID. |
294
|
|
|
* |
295
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
296
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::loadLocationByRemoteId |
297
|
|
|
*/ |
298
|
|
|
public function testLoadLocationByRemoteIdThrowsNotFoundException() |
299
|
|
|
{ |
300
|
|
|
$this->repository->getLocationService()->loadLocationByRemoteId('not-existing'); |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
protected function createContentDraft() |
304
|
|
|
{ |
305
|
|
|
$contentTypeService = $this->repository->getContentTypeService(); |
306
|
|
|
$contentService = $this->repository->getContentService(); |
307
|
|
|
$locationService = $this->repository->getLocationService(); |
308
|
|
|
|
309
|
|
|
$contentCreateStruct = $contentService->newContentCreateStruct( |
310
|
|
|
$contentTypeService->loadContentType(3), |
311
|
|
|
'eng-GB' |
312
|
|
|
); |
313
|
|
|
$contentCreateStruct->sectionId = 1; |
314
|
|
|
$contentCreateStruct->ownerId = 14; |
315
|
|
|
|
316
|
|
|
$contentCreateStruct->setField('name', 'New group'); |
317
|
|
|
$contentCreateStruct->setField('description', 'New group description'); |
318
|
|
|
|
319
|
|
|
$locationCreateStruct = $locationService->newLocationCreateStruct(5); |
320
|
|
|
|
321
|
|
|
return $contentService->createContent($contentCreateStruct, array($locationCreateStruct)); |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
/** |
325
|
|
|
* Test loading locations for content. |
326
|
|
|
* |
327
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::newLocationCreateStruct |
328
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::createLocation |
329
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::loadLocations |
330
|
|
|
*/ |
331
|
|
|
public function testLoadLocations() |
332
|
|
|
{ |
333
|
|
|
$contentInfo = $this->repository->getContentService()->loadContentInfo(12); |
334
|
|
|
|
335
|
|
|
$locationService = $this->repository->getLocationService(); |
336
|
|
|
$locations = $locationService->loadLocations($contentInfo); |
337
|
|
|
|
338
|
|
|
self::assertInternalType('array', $locations); |
339
|
|
|
self::assertNotEmpty($locations); |
340
|
|
|
|
341
|
|
|
foreach ($locations as $location) { |
342
|
|
|
self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', $location); |
343
|
|
|
self::assertEquals($contentInfo->id, $location->getContentInfo()->id); |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
$locationsCount = count($locations); |
347
|
|
|
|
348
|
|
|
$locationCreateStruct = $locationService->newLocationCreateStruct(44); |
349
|
|
|
$locationService->createLocation($contentInfo, $locationCreateStruct); |
350
|
|
|
|
351
|
|
|
$locations = $locationService->loadLocations($contentInfo); |
352
|
|
|
|
353
|
|
|
self::assertInternalType('array', $locations); |
354
|
|
|
self::assertNotEmpty($locations); |
355
|
|
|
|
356
|
|
|
foreach ($locations as $location) { |
357
|
|
|
self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', $location); |
358
|
|
|
self::assertEquals($contentInfo->id, $location->getContentInfo()->id); |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
$newLocationsCount = count($locations); |
362
|
|
|
|
363
|
|
|
self::assertEquals($locationsCount + 1, $newLocationsCount); |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
/** |
367
|
|
|
* Test loading locations for content with root location specified. |
368
|
|
|
* |
369
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::loadLocations |
370
|
|
|
*/ |
371
|
|
|
public function testLoadLocationsWithRootLocation() |
372
|
|
|
{ |
373
|
|
|
$contentInfo = $this->repository->getContentService()->loadContentInfo(12); |
374
|
|
|
|
375
|
|
|
$locationService = $this->repository->getLocationService(); |
376
|
|
|
$parentLocation = $locationService->loadLocation(5); |
377
|
|
|
|
378
|
|
|
$locations = $locationService->loadLocations($contentInfo, $parentLocation); |
379
|
|
|
|
380
|
|
|
self::assertInternalType('array', $locations); |
381
|
|
|
self::assertNotEmpty($locations); |
382
|
|
|
|
383
|
|
|
foreach ($locations as $location) { |
384
|
|
|
self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', $location); |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
foreach ($locations as $location) { |
388
|
|
|
if (stripos($location->pathString, $parentLocation->pathString) === false) { |
389
|
|
|
self::fail('fetched locations outside root node'); |
390
|
|
|
} |
391
|
|
|
} |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
/** |
395
|
|
|
* Test loading locations for content throwing BadStateException. |
396
|
|
|
* |
397
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
398
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::loadLocations |
399
|
|
|
*/ |
400
|
|
|
public function testLoadLocationsThrowsBadStateException() |
401
|
|
|
{ |
402
|
|
|
$contentDraft = $this->createContentDraft(); |
403
|
|
|
|
404
|
|
|
$this->repository->getLocationService()->loadLocations( |
405
|
|
|
$contentDraft->getVersionInfo()->getContentInfo() |
406
|
|
|
); |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
/** |
410
|
|
|
* Test loading location children. |
411
|
|
|
* |
412
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::loadLocationChildren |
413
|
|
|
*/ |
414
|
|
|
public function testLoadLocationChildren() |
415
|
|
|
{ |
416
|
|
|
$locationService = $this->repository->getLocationService(); |
417
|
|
|
|
418
|
|
|
$rootLocation = $locationService->loadLocation(5); |
419
|
|
|
$childrenLocations = $locationService->loadLocationChildren($rootLocation); |
420
|
|
|
|
421
|
|
|
self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\LocationList', $childrenLocations); |
422
|
|
|
self::assertInternalType('array', $childrenLocations->locations); |
423
|
|
|
self::assertInternalType('int', $childrenLocations->totalCount); |
424
|
|
|
self::assertNotEmpty($childrenLocations->locations); |
425
|
|
|
|
426
|
|
|
foreach ($childrenLocations->locations as $childLocation) { |
427
|
|
|
self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', $childLocation); |
428
|
|
|
self::assertEquals($rootLocation->id, $childLocation->parentLocationId); |
429
|
|
|
} |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
/** |
433
|
|
|
* Test creating a location. |
434
|
|
|
* |
435
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::createLocation |
436
|
|
|
*/ |
437
|
|
|
public function testCreateLocation() |
438
|
|
|
{ |
439
|
|
|
$locationService = $this->repository->getLocationService(); |
440
|
|
|
$contentService = $this->repository->getContentService(); |
441
|
|
|
|
442
|
|
|
$parentLocation = $locationService->loadLocation(44); |
443
|
|
|
|
444
|
|
|
$locationCreateStruct = $locationService->newLocationCreateStruct($parentLocation->id); |
445
|
|
|
$locationCreateStruct->priority = 42; |
446
|
|
|
$locationCreateStruct->remoteId = 'new-remote-id'; |
447
|
|
|
$locationCreateStruct->hidden = true; |
448
|
|
|
$locationCreateStruct->sortField = Location::SORT_FIELD_DEPTH; |
449
|
|
|
$locationCreateStruct->sortOrder = Location::SORT_ORDER_DESC; |
450
|
|
|
|
451
|
|
|
$contentInfo = $contentService->loadContentInfo(12); |
452
|
|
|
|
453
|
|
|
$createdLocation = $locationService->createLocation( |
454
|
|
|
$contentInfo, |
455
|
|
|
$locationCreateStruct |
456
|
|
|
); |
457
|
|
|
|
458
|
|
|
self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', $createdLocation); |
459
|
|
|
self::assertGreaterThan(0, $createdLocation->id); |
460
|
|
|
$createdPath = $parentLocation->path; |
461
|
|
|
$createdPath[] = $createdLocation->id; |
462
|
|
|
|
463
|
|
|
$this->assertPropertiesCorrect( |
464
|
|
|
array( |
465
|
|
|
'priority' => $locationCreateStruct->priority, |
466
|
|
|
'hidden' => $locationCreateStruct->hidden, |
467
|
|
|
'invisible' => $locationCreateStruct->hidden, |
468
|
|
|
'remoteId' => $locationCreateStruct->remoteId, |
469
|
|
|
'parentLocationId' => $locationCreateStruct->parentLocationId, |
470
|
|
|
'pathString' => $parentLocation->pathString . $createdLocation->id . '/', |
471
|
|
|
'path' => $createdPath, |
472
|
|
|
'depth' => $parentLocation->depth + 1, |
473
|
|
|
'sortField' => $locationCreateStruct->sortField, |
474
|
|
|
'sortOrder' => $locationCreateStruct->sortOrder, |
475
|
|
|
), |
476
|
|
|
$createdLocation |
477
|
|
|
); |
478
|
|
|
|
479
|
|
|
self::assertEquals($contentInfo->id, $createdLocation->getContentInfo()->id); |
480
|
|
|
} |
481
|
|
|
|
482
|
|
|
/** |
483
|
|
|
* Test creating a location throwing InvalidArgumentException. |
484
|
|
|
* |
485
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
486
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::createLocation |
487
|
|
|
*/ |
488
|
|
View Code Duplication |
public function testCreateLocationThrowsInvalidArgumentExceptionLocationExistsBelowParent() |
489
|
|
|
{ |
490
|
|
|
$locationService = $this->repository->getLocationService(); |
491
|
|
|
$contentService = $this->repository->getContentService(); |
492
|
|
|
|
493
|
|
|
$locationCreateStruct = $locationService->newLocationCreateStruct(5); |
494
|
|
|
$contentInfo = $contentService->loadContentInfo(12); |
495
|
|
|
$locationService->createLocation($contentInfo, $locationCreateStruct); |
496
|
|
|
} |
497
|
|
|
|
498
|
|
|
/** |
499
|
|
|
* Test creating a location throwing InvalidArgumentException. |
500
|
|
|
* |
501
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
502
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::createLocation |
503
|
|
|
*/ |
504
|
|
View Code Duplication |
public function testCreateLocationThrowsInvalidArgumentExceptionExistingRemoteId() |
505
|
|
|
{ |
506
|
|
|
$locationService = $this->repository->getLocationService(); |
507
|
|
|
$contentService = $this->repository->getContentService(); |
508
|
|
|
|
509
|
|
|
$locationCreateStruct = $locationService->newLocationCreateStruct(2); |
510
|
|
|
$locationCreateStruct->remoteId = '769380b7aa94541679167eab817ca893'; |
511
|
|
|
$contentInfo = $contentService->loadContentInfo(4); |
512
|
|
|
$locationService->createLocation($contentInfo, $locationCreateStruct); |
513
|
|
|
} |
514
|
|
|
|
515
|
|
|
/** |
516
|
|
|
* Test creating a location throwing InvalidArgumentException. |
517
|
|
|
* |
518
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
519
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::createLocation |
520
|
|
|
*/ |
521
|
|
View Code Duplication |
public function testCreateLocationThrowsInvalidArgumentExceptionParentIsASubLocation() |
522
|
|
|
{ |
523
|
|
|
$locationService = $this->repository->getLocationService(); |
524
|
|
|
$contentService = $this->repository->getContentService(); |
525
|
|
|
|
526
|
|
|
$locationCreateStruct = $locationService->newLocationCreateStruct(44); |
527
|
|
|
$contentInfo = $contentService->loadContentInfo(4); |
528
|
|
|
$locationService->createLocation($contentInfo, $locationCreateStruct); |
529
|
|
|
} |
530
|
|
|
|
531
|
|
|
/** |
532
|
|
|
* Test updating location. |
533
|
|
|
* |
534
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::updateLocation |
535
|
|
|
*/ |
536
|
|
|
public function testUpdateLocation() |
537
|
|
|
{ |
538
|
|
|
$locationService = $this->repository->getLocationService(); |
539
|
|
|
|
540
|
|
|
$location = $locationService->loadLocation(5); |
541
|
|
|
$locationUpdateStruct = $locationService->newLocationUpdateStruct(); |
542
|
|
|
$locationUpdateStruct->priority = 42; |
543
|
|
|
$locationUpdateStruct->sortField = Location::SORT_FIELD_DEPTH; |
544
|
|
|
$locationUpdateStruct->sortOrder = Location::SORT_ORDER_DESC; |
545
|
|
|
$locationUpdateStruct->remoteId = 'NEW_REMOTE_ID'; |
546
|
|
|
|
547
|
|
|
$location = $locationService->updateLocation($location, $locationUpdateStruct); |
548
|
|
|
|
549
|
|
|
self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', $location); |
550
|
|
|
|
551
|
|
|
$this->assertPropertiesCorrect( |
552
|
|
|
array( |
553
|
|
|
'priority' => $locationUpdateStruct->priority, |
554
|
|
|
'sortField' => $locationUpdateStruct->sortField, |
555
|
|
|
'sortOrder' => $locationUpdateStruct->sortOrder, |
556
|
|
|
'remoteId' => $locationUpdateStruct->remoteId, |
557
|
|
|
), |
558
|
|
|
$location |
559
|
|
|
); |
560
|
|
|
} |
561
|
|
|
|
562
|
|
|
/** |
563
|
|
|
* Test updating location throwing InvalidArgumentException. |
564
|
|
|
* |
565
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
566
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::updateLocation |
567
|
|
|
*/ |
568
|
|
|
public function testUpdateLocationThrowsInvalidArgumentException() |
569
|
|
|
{ |
570
|
|
|
$locationService = $this->repository->getLocationService(); |
571
|
|
|
|
572
|
|
|
$location = $locationService->loadLocation(5); |
573
|
|
|
$locationUpdateStruct = $locationService->newLocationUpdateStruct(); |
574
|
|
|
$locationUpdateStruct->remoteId = '769380b7aa94541679167eab817ca893'; |
575
|
|
|
|
576
|
|
|
$locationService->updateLocation($location, $locationUpdateStruct); |
577
|
|
|
} |
578
|
|
|
|
579
|
|
|
/** |
580
|
|
|
* Test swapping location. |
581
|
|
|
* |
582
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::swapLocation |
583
|
|
|
*/ |
584
|
|
|
public function testSwapLocation() |
585
|
|
|
{ |
586
|
|
|
$locationService = $this->repository->getLocationService(); |
587
|
|
|
|
588
|
|
|
$location1 = $locationService->loadLocation(2); |
589
|
|
|
$location2 = $locationService->loadLocation(44); |
590
|
|
|
|
591
|
|
|
$contentId1 = $location1->getContentInfo()->id; |
592
|
|
|
$contentId2 = $location2->getContentInfo()->id; |
593
|
|
|
|
594
|
|
|
$locationService->swapLocation($location1, $location2); |
595
|
|
|
|
596
|
|
|
$location1 = $locationService->loadLocation(2); |
597
|
|
|
$location2 = $locationService->loadLocation(44); |
598
|
|
|
|
599
|
|
|
self::assertEquals($contentId1, $location2->getContentInfo()->id); |
600
|
|
|
self::assertEquals($contentId2, $location1->getContentInfo()->id); |
601
|
|
|
} |
602
|
|
|
|
603
|
|
|
/** |
604
|
|
|
* Test hiding & unhiding a location. |
605
|
|
|
* |
606
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::hideLocation |
607
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::unhideLocation |
608
|
|
|
*/ |
609
|
|
|
public function testHideUnhideLocation() |
610
|
|
|
{ |
611
|
|
|
$locationService = $this->repository->getLocationService(); |
612
|
|
|
|
613
|
|
|
$location = $locationService->loadLocation(5); |
614
|
|
|
$location = $locationService->hideLocation($location); |
615
|
|
|
self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', $location); |
616
|
|
|
self::assertEquals(true, $location->hidden); |
617
|
|
|
self::assertEquals(true, $location->invisible); |
618
|
|
|
|
619
|
|
|
$location = $locationService->unhideLocation($location); |
620
|
|
|
self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Location', $location); |
621
|
|
|
self::assertEquals(false, $location->hidden); |
622
|
|
|
self::assertEquals(false, $location->invisible); |
623
|
|
|
} |
624
|
|
|
|
625
|
|
|
/** |
626
|
|
|
* Test moving a subtree. |
627
|
|
|
* |
628
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::moveSubtree |
629
|
|
|
*/ |
630
|
|
|
public function testMoveSubtree() |
631
|
|
|
{ |
632
|
|
|
$locationService = $this->repository->getLocationService(); |
633
|
|
|
|
634
|
|
|
$locationToMove = $locationService->loadLocation(13); |
635
|
|
|
$newParent = $locationService->loadLocation(44); |
636
|
|
|
$locationService->moveSubtree($locationToMove, $newParent); |
637
|
|
|
|
638
|
|
|
$loadedLocation = $locationService->loadLocation($locationToMove->id); |
639
|
|
|
self::assertEquals($newParent->id, $loadedLocation->parentLocationId); |
640
|
|
|
} |
641
|
|
|
|
642
|
|
|
/** |
643
|
|
|
* Test deleting a location. |
644
|
|
|
* |
645
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::deleteLocation |
646
|
|
|
*/ |
647
|
|
|
public function testDeleteLocation() |
648
|
|
|
{ |
649
|
|
|
$locationService = $this->repository->getLocationService(); |
650
|
|
|
|
651
|
|
|
$location = $locationService->loadLocation(44); |
652
|
|
|
$locationService->deleteLocation($location); |
653
|
|
|
|
654
|
|
|
try { |
655
|
|
|
$locationService->loadLocation($location->id); |
656
|
|
|
self::fail('failed deleting a location'); |
657
|
|
|
} catch (NotFoundException $e) { |
658
|
|
|
// Do nothing |
659
|
|
|
} |
660
|
|
|
} |
661
|
|
|
|
662
|
|
|
/** |
663
|
|
|
* Test creating new LocationCreateStruct. |
664
|
|
|
* |
665
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::newLocationCreateStruct |
666
|
|
|
*/ |
667
|
|
|
public function testNewLocationCreateStruct() |
668
|
|
|
{ |
669
|
|
|
$locationService = $this->repository->getLocationService(); |
670
|
|
|
|
671
|
|
|
$locationCreateStruct = $locationService->newLocationCreateStruct(2); |
672
|
|
|
self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\LocationCreateStruct', $locationCreateStruct); |
673
|
|
|
|
674
|
|
|
$this->assertPropertiesCorrect( |
675
|
|
|
array( |
676
|
|
|
'priority' => 0, |
677
|
|
|
'hidden' => false, |
678
|
|
|
'remoteId' => null, |
679
|
|
|
'sortField' => Location::SORT_FIELD_NAME, |
680
|
|
|
'sortOrder' => Location::SORT_ORDER_ASC, |
681
|
|
|
'parentLocationId' => 2, |
682
|
|
|
), |
683
|
|
|
$locationCreateStruct |
684
|
|
|
); |
685
|
|
|
} |
686
|
|
|
|
687
|
|
|
/** |
688
|
|
|
* Test creating new LocationUpdateStruct. |
689
|
|
|
* |
690
|
|
|
* @covers \eZ\Publish\API\Repository\LocationService::newLocationUpdateStruct |
691
|
|
|
*/ |
692
|
|
|
public function testNewLocationUpdateStruct() |
693
|
|
|
{ |
694
|
|
|
$locationService = $this->repository->getLocationService(); |
695
|
|
|
|
696
|
|
|
$locationUpdateStruct = $locationService->newLocationUpdateStruct(); |
697
|
|
|
self::assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\LocationUpdateStruct', $locationUpdateStruct); |
698
|
|
|
|
699
|
|
|
$this->assertPropertiesCorrect( |
700
|
|
|
array( |
701
|
|
|
'priority' => null, |
702
|
|
|
'remoteId' => null, |
703
|
|
|
'sortField' => null, |
704
|
|
|
'sortOrder' => null, |
705
|
|
|
), |
706
|
|
|
$locationUpdateStruct |
707
|
|
|
); |
708
|
|
|
} |
709
|
|
|
} |
710
|
|
|
|
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.