Completed
Push — ezp-27608 ( 370429...58ef42 )
by André
13:52
created

testSwapLocationThrowsUnauthorizedException()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 31
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 0
loc 31
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File containing the LocationServiceAuthorizationTest 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\Values\Content\Location;
12
use eZ\Publish\API\Repository\Values\User\Limitation\OwnerLimitation;
13
14
/**
15
 * Test case for operations in the LocationService using in memory storage.
16
 *
17
 * @see eZ\Publish\API\Repository\LocationService
18
 * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser
19
 * @group integration
20
 * @group authorization
21
 */
22
class LocationServiceAuthorizationTest extends BaseTest
23
{
24
    /**
25
     * Test for the createLocation() method.
26
     *
27
     * @see \eZ\Publish\API\Repository\LocationService::createLocation()
28
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
29
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCreateLocation
30
     */
31
    public function testCreateLocationThrowsUnauthorizedException()
32
    {
33
        $repository = $this->getRepository();
34
35
        $editorsGroupId = $this->generateId('group', 13);
36
37
        /* BEGIN: Use Case */
38
        $contentService = $repository->getContentService();
39
        $locationService = $repository->getLocationService();
40
41
        $user = $this->createUserVersion1();
42
43
        // ContentInfo for "Editors" user group
44
        $contentInfo = $contentService->loadContentInfo($editorsGroupId);
45
46
        // Set current user to newly created user
47
        $repository->setCurrentUser($user);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::setCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::setCurrentUserReference() instead. Sets the current user to the given $user.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
48
49
        $locationCreate = $locationService->newLocationCreateStruct(1);
50
        $locationCreate->priority = 23;
51
        $locationCreate->hidden = true;
52
        $locationCreate->remoteId = 'sindelfingen';
53
        $locationCreate->sortField = Location::SORT_FIELD_NODE_ID;
54
        $locationCreate->sortOrder = Location::SORT_ORDER_DESC;
55
56
        // This call will fail with an "UnauthorizedException"
57
        $locationService->createLocation(
58
            $contentInfo,
59
            $locationCreate
60
        );
61
        /* END: Use Case */
62
    }
63
64
    /**
65
     * Test for the loadLocation() method.
66
     *
67
     * @see \eZ\Publish\API\Repository\LocationService::loadLocation()
68
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
69
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
70
     */
71
    public function testLoadLocationThrowsUnauthorizedException()
72
    {
73
        $repository = $this->getRepository();
74
75
        $editorsGroupId = $this->generateId('group', 13);
76
77
        /* BEGIN: Use Case */
78
        $locationService = $repository->getLocationService();
79
80
        $user = $this->createUserVersion1();
81
82
        // Set current user to newly created user
83
        $repository->setCurrentUser($user);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::setCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::setCurrentUserReference() instead. Sets the current user to the given $user.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
84
85
        // This call will fail with an "UnauthorizedException"
86
        $locationService->loadLocation($editorsGroupId);
87
        /* END: Use Case */
88
    }
89
90
    /**
91
     * Test for the loadLocationByRemoteId() method.
92
     *
93
     * @see \eZ\Publish\API\Repository\LocationService::loadLocationByRemoteId()
94
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
95
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationByRemoteId
96
     */
97
    public function testLoadLocationByRemoteIdThrowsUnauthorizedException()
98
    {
99
        $repository = $this->getRepository();
100
101
        /* BEGIN: Use Case */
102
        // remoteId of the "Editors" location in an eZ Publish demo installation
103
        $editorsRemoteId = 'f7dda2854fc68f7c8455d9cb14bd04a9';
104
105
        $locationService = $repository->getLocationService();
106
107
        $user = $this->createUserVersion1();
108
109
        // Set current user to newly created user
110
        $repository->setCurrentUser($user);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::setCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::setCurrentUserReference() instead. Sets the current user to the given $user.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
111
112
        // This call will fail with an "UnauthorizedException"
113
        $locationService->loadLocationByRemoteId($editorsRemoteId);
114
        /* END: Use Case */
115
    }
116
117
118
    /**
119
     * Test for the loadLocations() method.
120
     *
121
     * @see \eZ\Publish\API\Repository\LocationService::loadLocations()
122
     * @depends \eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocations
123
     */
124
    public function testLoadLocationsNoAccess()
125
    {
126
        $repository = $this->getRepository();
127
        $locationService = $repository->getLocationService();
128
129
        $editorsGroupId = $this->generateId('group', 13);
130
        $editorGroupContentInfo = $repository->getContentService()->loadContentInfo($editorsGroupId);
131
132
        // this should return one location for admin
133
        $locations = $locationService->loadLocations($editorGroupContentInfo);
134
        $this->assertCount(1, $locations);
135
        $this->assertInstanceOf(Location::class, $locations[0]);
136
137
        $user = $this->createUserVersion1();
138
139
        // Set current user to newly created user
140
        $repository->setCurrentUser($user);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::setCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::setCurrentUserReference() instead. Sets the current user to the given $user.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
141
142
        // This should return empty array given current user does not have read access
143
        $locations = $locationService->loadLocations($editorGroupContentInfo);
144
        $this->assertEmpty($locations);
145
    }
146
147
    /**
148
     * Test for the updateLocation() method.
149
     *
150
     * @see \eZ\Publish\API\Repository\LocationService::updateLocation()
151
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
152
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testUpdateLocation
153
     */
154
    public function testUpdateLocationThrowsUnauthorizedException()
155
    {
156
        $repository = $this->getRepository();
157
158
        $editorsGroupId = $this->generateId('group', 13);
159
160
        /* BEGIN: Use Case */
161
        $user = $this->createUserVersion1();
162
163
        $locationService = $repository->getLocationService();
164
165
        $originalLocation = $locationService->loadLocation($editorsGroupId);
166
167
        $locationUpdateStruct = $locationService->newLocationUpdateStruct();
168
        $locationUpdateStruct->priority = 3;
169
        $locationUpdateStruct->remoteId = 'c7adcbf1e96bc29bca28c2d809d0c7ef69272651';
170
        $locationUpdateStruct->sortField = Location::SORT_FIELD_PRIORITY;
171
        $locationUpdateStruct->sortOrder = Location::SORT_ORDER_DESC;
172
173
        // Set current user to newly created user
174
        $repository->setCurrentUser($user);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::setCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::setCurrentUserReference() instead. Sets the current user to the given $user.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
175
176
        // This call will fail with an "UnauthorizedException"
177
        $locationService->updateLocation(
178
            $originalLocation,
179
            $locationUpdateStruct
180
        );
181
        /* END: Use Case */
182
    }
183
184
    /**
185
     * Test for the swapLocation() method.
186
     *
187
     * @see \eZ\Publish\API\Repository\LocationService::swapLocation()
188
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
189
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testSwapLocation
190
     */
191
    public function testSwapLocationThrowsUnauthorizedException()
192
    {
193
        $repository = $this->getRepository();
194
195
        $mediaLocationId = $this->generateId('location', 43);
196
        $demoDesignLocationId = $this->generateId('location', 56);
197
        /* BEGIN: Use Case */
198
        // $mediaLocationId is the ID of the "Media" Location in
199
        // an eZ Publish demo installation
200
201
        // $demoDesignLocationId is the ID of the "Demo Design" Location in an eZ
202
        // Publish demo installation
203
204
        // Load the location service
205
        $locationService = $repository->getLocationService();
206
207
        $mediaLocation = $locationService->loadLocation($mediaLocationId);
208
        $demoDesignLocation = $locationService->loadLocation($demoDesignLocationId);
209
210
        // Swaps the content referred to by the locations
211
        $locationService->swapLocation($mediaLocation, $demoDesignLocation);
212
213
        $user = $this->createMediaUserVersion1();
214
215
        // Set media editor as current user
216
        $repository->setCurrentUser($user);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::setCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::setCurrentUserReference() instead. Sets the current user to the given $user.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
217
218
        // This call will fail with an "UnauthorizedException"
219
        $locationService->swapLocation($mediaLocation, $demoDesignLocation);
220
        /* END: Use Case */
221
    }
222
223
    /**
224
     * Test for the hideLocation() method.
225
     *
226
     * @see \eZ\Publish\API\Repository\LocationService::hideLocation()
227
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
228
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testHideLocation
229
     */
230 View Code Duplication
    public function testHideLocationThrowsUnauthorizedException()
231
    {
232
        $repository = $this->getRepository();
233
234
        $editorsGroupId = $this->generateId('group', 13);
235
236
        /* BEGIN: Use Case */
237
        $user = $this->createUserVersion1();
238
239
        $locationService = $repository->getLocationService();
240
241
        $visibleLocation = $locationService->loadLocation($editorsGroupId);
242
243
        // Set current user to newly created user
244
        $repository->setCurrentUser($user);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::setCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::setCurrentUserReference() instead. Sets the current user to the given $user.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
245
246
        // This call will fail with an "UnauthorizedException"
247
        $locationService->hideLocation($visibleLocation);
248
        /* END: Use Case */
249
    }
250
251
    /**
252
     * Test for the unhideLocation() method.
253
     *
254
     * @see \eZ\Publish\API\Repository\LocationService::unhideLocation()
255
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
256
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testUnhideLocation
257
     */
258
    public function testUnhideLocationThrowsUnauthorizedException()
259
    {
260
        $repository = $this->getRepository();
261
262
        $editorsGroupId = $this->generateId('group', 13);
263
264
        /* BEGIN: Use Case */
265
        $user = $this->createUserVersion1();
266
267
        $locationService = $repository->getLocationService();
268
269
        $visibleLocation = $locationService->loadLocation($editorsGroupId);
270
271
        // Hide location
272
        $hiddenLocation = $locationService->hideLocation($visibleLocation);
273
274
        // Set current user to newly created user
275
        $repository->setCurrentUser($user);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::setCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::setCurrentUserReference() instead. Sets the current user to the given $user.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
276
277
        // This call will fail with an "UnauthorizedException"
278
        $locationService->unhideLocation($hiddenLocation);
279
        /* END: Use Case */
280
    }
281
282
    /**
283
     * Test for the deleteLocation() method.
284
     *
285
     * @see \eZ\Publish\API\Repository\LocationService::deleteLocation()
286
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
287
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testDeleteLocation
288
     */
289 View Code Duplication
    public function testDeleteLocationThrowsUnauthorizedException()
290
    {
291
        $repository = $this->getRepository();
292
293
        $editorsGroupId = $this->generateId('group', 13);
294
295
        /* BEGIN: Use Case */
296
        $user = $this->createUserVersion1();
297
298
        $locationService = $repository->getLocationService();
299
300
        $location = $locationService->loadLocation($editorsGroupId);
301
302
        // Set current user to newly created user
303
        $repository->setCurrentUser($user);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::setCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::setCurrentUserReference() instead. Sets the current user to the given $user.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
304
305
        // This call will fail with an "UnauthorizedException"
306
        $locationService->deleteLocation($location);
307
        /* END: Use Case */
308
    }
309
310
    /**
311
     * Test for the deleteLocation() method.
312
     *
313
     * @see \eZ\Publish\API\Repository\LocationService::deleteLocation()
314
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
315
     * @expectedExceptionMessage User does not have access to 'remove' 'content'
316
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testDeleteLocation
317
     */
318
    public function testDeleteLocationWithSubtreeThrowsUnauthorizedException()
319
    {
320
        $repository = $this->getRepository();
321
322
        $parentLocationId = $this->generateId('location', 43);
323
        $administratorUserId = $this->generateId('user', 14);
324
325
        /* BEGIN: Use Case */
326
        $user = $this->createUserVersion1();
327
328
        $roleService = $repository->getRoleService();
329
330
        $role = $roleService->loadRoleByIdentifier('Editor');
331
332
        $removePolicy = null;
333
        foreach ($role->getPolicies() as $policy) {
334
            if ('content' != $policy->module || 'remove' != $policy->function) {
335
                continue;
336
            }
337
            $removePolicy = $policy;
338
            break;
339
        }
340
341
        if (null === $removePolicy) {
342
            throw new \ErrorException('No content:remove policy found.');
343
        }
344
345
        // Update content/remove policy to only allow removal of the user's own content
346
        $policyUpdate = $roleService->newPolicyUpdateStruct();
347
        $policyUpdate->addLimitation(
348
            new OwnerLimitation(
349
                array('limitationValues' => array(1))
350
            )
351
        );
352
        $roleService->updatePolicy($removePolicy, $policyUpdate);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...Service::updatePolicy() has been deprecated with message: since 6.0, use {@link updatePolicyByRoleDraft()} instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
353
354
        // Set current user to newly created user
355
        $repository->setCurrentUser($user);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::setCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::setCurrentUserReference() instead. Sets the current user to the given $user.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
356
357
        $locationService = $repository->getLocationService();
358
        $contentService = $repository->getContentService();
359
        $contentTypeService = $repository->getContentTypeService();
360
        $userService = $repository->getUserService();
361
362
        // Create and publish Content with Location under $parentLocationId
363
        $contentType = $contentTypeService->loadContentTypeByIdentifier('folder');
364
365
        $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-US');
366
        $contentCreateStruct->setField('name', 'My awesome possibly deletable folder');
367
        $contentCreateStruct->alwaysAvailable = true;
368
369
        $locationCreateStruct = $locationService->newLocationCreateStruct($parentLocationId);
370
371
        $contentDraft = $contentService->createContent($contentCreateStruct, array($locationCreateStruct));
372
        $content = $contentService->publishVersion($contentDraft->versionInfo);
373
374
        // New user will be able to delete this Location at this point
375
        $firstLocation = $locationService->loadLocation($content->contentInfo->mainLocationId);
376
377
        // Set current user to administrator user
378
        $administratorUser = $userService->loadUser($administratorUserId);
379
        $repository->setCurrentUser($administratorUser);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::setCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::setCurrentUserReference() instead. Sets the current user to the given $user.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
380
381
        // Under newly created Location create Content with administrator user
382
        // After this created user will not be able to delete $firstLocation
383
        $locationCreateStruct = $locationService->newLocationCreateStruct($firstLocation->id);
384
        $contentDraft = $contentService->createContent($contentCreateStruct, array($locationCreateStruct));
385
        $content = $contentService->publishVersion($contentDraft->versionInfo);
386
        $secondLocation = $locationService->loadLocation($content->contentInfo->mainLocationId);
0 ignored issues
show
Unused Code introduced by
$secondLocation is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
387
388
        // Set current user to newly created user again, and try to delete $firstLocation
389
        $repository->setCurrentUser($user);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::setCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::setCurrentUserReference() instead. Sets the current user to the given $user.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
390
391
        $this->refreshSearch($repository);
392
393
        // This call will fail with an "UnauthorizedException" because user does not have
394
        // permission to delete $secondLocation which is in the subtree of the $firstLocation
395
        $locationService->deleteLocation($firstLocation);
396
        /* END: Use Case */
397
    }
398
399
    /**
400
     * Test for the copySubtree() method.
401
     *
402
     * @see \eZ\Publish\API\Repository\LocationService::copySubtree()
403
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
404
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCopySubtree
405
     */
406
    public function testCopySubtreeThrowsUnauthorizedException()
407
    {
408
        $repository = $this->getRepository();
409
410
        $mediaLocationId = $this->generateId('location', 43);
411
        $demoDesignLocationId = $this->generateId('location', 56);
412
        /* BEGIN: Use Case */
413
        $user = $this->createMediaUserVersion1();
414
415
        // $mediaLocationId is the ID of the "Media" Location in
416
        // an eZ Publish demo installation
417
418
        // $demoDesignLocationId is the ID of the "Demo Design" Location in an eZ
419
        // Publish demo installation
420
421
        // Load the location service
422
        $locationService = $repository->getLocationService();
423
424
        // Load location to copy
425
        $locationToCopy = $locationService->loadLocation($mediaLocationId);
426
427
        // Load new parent location
428
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
429
430
        // Set media editor as current user
431
        $repository->setCurrentUser($user);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::setCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::setCurrentUserReference() instead. Sets the current user to the given $user.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
432
433
        // This call will fail with an "UnauthorizedException"
434
        $locationService->copySubtree(
435
            $locationToCopy,
436
            $newParentLocation
437
        );
438
        /* END: Use Case */
439
    }
440
441
    /**
442
     * Test for the moveSubtree() method.
443
     *
444
     * @see \eZ\Publish\API\Repository\LocationService::moveSubtree()
445
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
446
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
447
     */
448
    public function testMoveSubtreeThrowsUnauthorizedException()
449
    {
450
        $repository = $this->getRepository();
451
452
        $mediaLocationId = $this->generateId('location', 43);
453
        $demoDesignLocationId = $this->generateId('location', 56);
454
        /* BEGIN: Use Case */
455
        $user = $this->createMediaUserVersion1();
456
457
        // $mediaLocationId is the ID of the "Media" page location in
458
        // an eZ Publish demo installation
459
460
        // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ
461
        // Publish demo installation
462
463
        // Load the location service
464
        $locationService = $repository->getLocationService();
465
466
        // Load location to move
467
        $locationToMove = $locationService->loadLocation($mediaLocationId);
468
469
        // Load new parent location
470
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
471
472
        // Set media editor as current user
473
        $repository->setCurrentUser($user);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::setCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::setCurrentUserReference() instead. Sets the current user to the given $user.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
474
475
        // This call will fail with an "UnauthorizedException"
476
        $locationService->moveSubtree(
477
            $locationToMove,
478
            $newParentLocation
479
        );
480
        /* END: Use Case */
481
    }
482
}
483