Completed
Push — master ( b18ea5...87a68d )
by André
133:56 queued 114:49
created

testLoadLocationsNoAccess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 22
rs 9.2
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
use eZ\Publish\API\Repository\Values\User\Limitation\SubtreeLimitation;
14
15
/**
16
 * Test case for operations in the LocationService using in memory storage.
17
 *
18
 * @see eZ\Publish\API\Repository\LocationService
19
 * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser
20
 * @group integration
21
 * @group authorization
22
 */
23
class LocationServiceAuthorizationTest extends BaseTest
24
{
25
    /**
26
     * Test for the createLocation() method.
27
     *
28
     * @see \eZ\Publish\API\Repository\LocationService::createLocation()
29
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
30
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCreateLocation
31
     */
32 View Code Duplication
    public function testCreateLocationThrowsUnauthorizedException()
33
    {
34
        $repository = $this->getRepository();
35
36
        $editorsGroupId = $this->generateId('group', 13);
37
38
        /* BEGIN: Use Case */
39
        $contentService = $repository->getContentService();
40
        $locationService = $repository->getLocationService();
41
42
        $user = $this->createUserVersion1();
43
44
        // ContentInfo for "Editors" user group
45
        $contentInfo = $contentService->loadContentInfo($editorsGroupId);
46
47
        // Set current user to newly created user
48
        $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...
49
50
        $locationCreate = $locationService->newLocationCreateStruct(1);
51
        $locationCreate->priority = 23;
52
        $locationCreate->hidden = true;
53
        $locationCreate->remoteId = 'sindelfingen';
54
        $locationCreate->sortField = Location::SORT_FIELD_NODE_ID;
55
        $locationCreate->sortOrder = Location::SORT_ORDER_DESC;
56
57
        // This call will fail with an "UnauthorizedException"
58
        $locationService->createLocation(
59
            $contentInfo,
60
            $locationCreate
61
        );
62
        /* END: Use Case */
63
    }
64
65
    /**
66
     * Test for the createLocation() method. Tests a case when user doesn't have content/manage_locations policy for the new location ID.
67
     *
68
     * @see \eZ\Publish\API\Repository\LocationService::createLocation()
69
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
70
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCreateLocation
71
     */
72
    public function testCreateLocationThrowsUnauthorizedExceptionDueToLackOfContentManageLocationsPolicy()
73
    {
74
        $repository = $this->getRepository();
75
76
        $mediaDirectoryLocationId = $this->generateId('location', '43');
77
78
        /* BEGIN: Use Case */
79
        $locationService = $repository->getLocationService();
80
        // Location for "Media" directory
81
        $contentLocation = $locationService->loadLocation($mediaDirectoryLocationId);
82
83
        // Create the new "Dummy" user group
84
        $userService = $repository->getUserService();
85
        $userGroupCreateStruct = $userService->newUserGroupCreateStruct('eng-GB');
86
        $userGroupCreateStruct->setField('name', 'Dummy');
87
        $dummyUserGroup = $userService->createUserGroup($userGroupCreateStruct, $userService->loadUserGroup(4));
88
89
        // Create the new "Dummy" role with content/* policy limited by Subtree to "Media" folder
90
        $roleService = $repository->getRoleService();
91
        $role = $this->createRoleWithPolicies('Dummy', [
92
            [
93
                'module' => 'content',
94
                'function' => 'read',
95
                'limitations' => [],
96
            ],
97
            [
98
                'module' => 'content',
99
                'function' => 'manage_locations',
100
                'limitations' => [new SubtreeLimitation(['limitationValues' => [$contentLocation->pathString]])],
101
            ],
102
        ]);
103
104
        $user = $this->createUser('johndoe', 'John', 'Doe', $dummyUserGroup);
105
        $roleService->assignRoleToUser($role, $user);
106
        // Set current user to newly created user
107
        $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...
108
109
        $locationCreateStruct = $locationService->newLocationCreateStruct('2');
110
        $locationCreateStruct->priority = 12;
111
        $locationCreateStruct->hidden = false;
112
        $locationCreateStruct->sortField = Location::SORT_FIELD_NODE_ID;
113
        $locationCreateStruct->sortOrder = Location::SORT_ORDER_DESC;
114
115
        // This call will fail with an "UnauthorizedException"
116
        $locationService->createLocation(
117
            $contentLocation->contentInfo,
118
            $locationCreateStruct
119
        );
120
        /* END: Use Case */
121
    }
122
123
    /**
124
     * Test for the loadLocation() method.
125
     *
126
     * @see \eZ\Publish\API\Repository\LocationService::loadLocation()
127
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
128
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
129
     */
130 View Code Duplication
    public function testLoadLocationThrowsUnauthorizedException()
131
    {
132
        $repository = $this->getRepository();
133
134
        $editorsGroupId = $this->generateId('group', 13);
135
136
        /* BEGIN: Use Case */
137
        $locationService = $repository->getLocationService();
138
139
        $user = $this->createUserVersion1();
140
141
        // Set current user to newly created user
142
        $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...
143
144
        // This call will fail with an "UnauthorizedException"
145
        $locationService->loadLocation($editorsGroupId);
146
        /* END: Use Case */
147
    }
148
149
    /**
150
     * Test for the loadLocationByRemoteId() method.
151
     *
152
     * @see \eZ\Publish\API\Repository\LocationService::loadLocationByRemoteId()
153
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
154
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationByRemoteId
155
     */
156
    public function testLoadLocationByRemoteIdThrowsUnauthorizedException()
157
    {
158
        $repository = $this->getRepository();
159
160
        /* BEGIN: Use Case */
161
        // remoteId of the "Editors" location in an eZ Publish demo installation
162
        $editorsRemoteId = 'f7dda2854fc68f7c8455d9cb14bd04a9';
163
164
        $locationService = $repository->getLocationService();
165
166
        $user = $this->createUserVersion1();
167
168
        // Set current user to newly created user
169
        $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...
170
171
        // This call will fail with an "UnauthorizedException"
172
        $locationService->loadLocationByRemoteId($editorsRemoteId);
173
        /* END: Use Case */
174
    }
175
176
    /**
177
     * Test for the loadLocations() method.
178
     *
179
     * @see \eZ\Publish\API\Repository\LocationService::loadLocations()
180
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocations
181
     */
182
    public function testLoadLocationsNoAccess()
183
    {
184
        $repository = $this->getRepository();
185
        $locationService = $repository->getLocationService();
186
187
        $editorsGroupId = $this->generateId('group', 13);
188
        $editorGroupContentInfo = $repository->getContentService()->loadContentInfo($editorsGroupId);
189
190
        // this should return one location for admin
191
        $locations = $locationService->loadLocations($editorGroupContentInfo);
192
        $this->assertCount(1, $locations);
193
        $this->assertInstanceOf(Location::class, $locations[0]);
194
195
        $user = $this->createUserVersion1();
196
197
        // Set current user to newly created user
198
        $repository->getPermissionResolver()->setCurrentUserReference($user);
199
200
        // This should return empty array given current user does not have read access
201
        $locations = $locationService->loadLocations($editorGroupContentInfo);
202
        $this->assertEmpty($locations);
203
    }
204
205
    /**
206
     * Test for the updateLocation() method.
207
     *
208
     * @see \eZ\Publish\API\Repository\LocationService::updateLocation()
209
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
210
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testUpdateLocation
211
     */
212
    public function testUpdateLocationThrowsUnauthorizedException()
213
    {
214
        $repository = $this->getRepository();
215
216
        $editorsGroupId = $this->generateId('group', 13);
217
218
        /* BEGIN: Use Case */
219
        $user = $this->createUserVersion1();
220
221
        $locationService = $repository->getLocationService();
222
223
        $originalLocation = $locationService->loadLocation($editorsGroupId);
224
225
        $locationUpdateStruct = $locationService->newLocationUpdateStruct();
226
        $locationUpdateStruct->priority = 3;
227
        $locationUpdateStruct->remoteId = 'c7adcbf1e96bc29bca28c2d809d0c7ef69272651';
228
        $locationUpdateStruct->sortField = Location::SORT_FIELD_PRIORITY;
229
        $locationUpdateStruct->sortOrder = Location::SORT_ORDER_DESC;
230
231
        // Set current user to newly created user
232
        $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...
233
234
        // This call will fail with an "UnauthorizedException"
235
        $locationService->updateLocation(
236
            $originalLocation,
237
            $locationUpdateStruct
238
        );
239
        /* END: Use Case */
240
    }
241
242
    /**
243
     * Test for the swapLocation() method.
244
     *
245
     * @see \eZ\Publish\API\Repository\LocationService::swapLocation()
246
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
247
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testSwapLocation
248
     */
249
    public function testSwapLocationThrowsUnauthorizedException()
250
    {
251
        $repository = $this->getRepository();
252
253
        $mediaLocationId = $this->generateId('location', 43);
254
        $demoDesignLocationId = $this->generateId('location', 56);
255
        /* BEGIN: Use Case */
256
        // $mediaLocationId is the ID of the "Media" Location in
257
        // an eZ Publish demo installation
258
259
        // $demoDesignLocationId is the ID of the "Demo Design" Location in an eZ
260
        // Publish demo installation
261
262
        // Load the location service
263
        $locationService = $repository->getLocationService();
264
265
        $mediaLocation = $locationService->loadLocation($mediaLocationId);
266
        $demoDesignLocation = $locationService->loadLocation($demoDesignLocationId);
267
268
        // Swaps the content referred to by the locations
269
        $locationService->swapLocation($mediaLocation, $demoDesignLocation);
270
271
        $user = $this->createMediaUserVersion1();
272
273
        // Set media editor as current user
274
        $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...
275
276
        // This call will fail with an "UnauthorizedException"
277
        $locationService->swapLocation($mediaLocation, $demoDesignLocation);
278
        /* END: Use Case */
279
    }
280
281
    /**
282
     * Test for the hideLocation() method.
283
     *
284
     * @see \eZ\Publish\API\Repository\LocationService::hideLocation()
285
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
286
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testHideLocation
287
     */
288 View Code Duplication
    public function testHideLocationThrowsUnauthorizedException()
289
    {
290
        $repository = $this->getRepository();
291
292
        $editorsGroupId = $this->generateId('group', 13);
293
294
        /* BEGIN: Use Case */
295
        $user = $this->createUserVersion1();
296
297
        $locationService = $repository->getLocationService();
298
299
        $visibleLocation = $locationService->loadLocation($editorsGroupId);
300
301
        // Set current user to newly created user
302
        $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...
303
304
        // This call will fail with an "UnauthorizedException"
305
        $locationService->hideLocation($visibleLocation);
306
        /* END: Use Case */
307
    }
308
309
    /**
310
     * Test for the unhideLocation() method.
311
     *
312
     * @see \eZ\Publish\API\Repository\LocationService::unhideLocation()
313
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
314
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testUnhideLocation
315
     */
316 View Code Duplication
    public function testUnhideLocationThrowsUnauthorizedException()
317
    {
318
        $repository = $this->getRepository();
319
320
        $editorsGroupId = $this->generateId('group', 13);
321
322
        /* BEGIN: Use Case */
323
        $user = $this->createUserVersion1();
324
325
        $locationService = $repository->getLocationService();
326
327
        $visibleLocation = $locationService->loadLocation($editorsGroupId);
328
329
        // Hide location
330
        $hiddenLocation = $locationService->hideLocation($visibleLocation);
331
332
        // Set current user to newly created user
333
        $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...
334
335
        // This call will fail with an "UnauthorizedException"
336
        $locationService->unhideLocation($hiddenLocation);
337
        /* END: Use Case */
338
    }
339
340
    /**
341
     * Test for the deleteLocation() method.
342
     *
343
     * @see \eZ\Publish\API\Repository\LocationService::deleteLocation()
344
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
345
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testDeleteLocation
346
     */
347 View Code Duplication
    public function testDeleteLocationThrowsUnauthorizedException()
348
    {
349
        $repository = $this->getRepository();
350
351
        $editorsGroupId = $this->generateId('group', 13);
352
353
        /* BEGIN: Use Case */
354
        $user = $this->createUserVersion1();
355
356
        $locationService = $repository->getLocationService();
357
358
        $location = $locationService->loadLocation($editorsGroupId);
359
360
        // Set current user to newly created user
361
        $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...
362
363
        // This call will fail with an "UnauthorizedException"
364
        $locationService->deleteLocation($location);
365
        /* END: Use Case */
366
    }
367
368
    /**
369
     * Test for the deleteLocation() method.
370
     *
371
     * @see \eZ\Publish\API\Repository\LocationService::deleteLocation()
372
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
373
     * @expectedExceptionMessage User does not have access to 'remove' 'content'
374
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testDeleteLocation
375
     */
376
    public function testDeleteLocationWithSubtreeThrowsUnauthorizedException()
377
    {
378
        $repository = $this->getRepository();
379
380
        $parentLocationId = $this->generateId('location', 43);
381
        $administratorUserId = $this->generateId('user', 14);
382
383
        /* BEGIN: Use Case */
384
        $user = $this->createUserVersion1();
385
386
        $roleService = $repository->getRoleService();
387
388
        $role = $roleService->loadRoleByIdentifier('Editor');
389
390
        $removePolicy = null;
391
        foreach ($role->getPolicies() as $policy) {
392
            if ('content' != $policy->module || 'remove' != $policy->function) {
393
                continue;
394
            }
395
            $removePolicy = $policy;
396
            break;
397
        }
398
399
        if (null === $removePolicy) {
400
            throw new \ErrorException('No content:remove policy found.');
401
        }
402
403
        // Update content/remove policy to only allow removal of the user's own content
404
        $policyUpdate = $roleService->newPolicyUpdateStruct();
405
        $policyUpdate->addLimitation(
406
            new OwnerLimitation(
407
                array('limitationValues' => array(1))
408
            )
409
        );
410
        $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...
411
412
        // Set current user to newly created user
413
        $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...
414
415
        $locationService = $repository->getLocationService();
416
        $contentService = $repository->getContentService();
417
        $contentTypeService = $repository->getContentTypeService();
418
        $userService = $repository->getUserService();
419
420
        // Create and publish Content with Location under $parentLocationId
421
        $contentType = $contentTypeService->loadContentTypeByIdentifier('folder');
422
423
        $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-US');
424
        $contentCreateStruct->setField('name', 'My awesome possibly deletable folder');
425
        $contentCreateStruct->alwaysAvailable = true;
426
427
        $locationCreateStruct = $locationService->newLocationCreateStruct($parentLocationId);
428
429
        $contentDraft = $contentService->createContent($contentCreateStruct, array($locationCreateStruct));
430
        $content = $contentService->publishVersion($contentDraft->versionInfo);
431
432
        // New user will be able to delete this Location at this point
433
        $firstLocation = $locationService->loadLocation($content->contentInfo->mainLocationId);
434
435
        // Set current user to administrator user
436
        $administratorUser = $userService->loadUser($administratorUserId);
437
        $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...
438
439
        // Under newly created Location create Content with administrator user
440
        // After this created user will not be able to delete $firstLocation
441
        $locationCreateStruct = $locationService->newLocationCreateStruct($firstLocation->id);
442
        $contentDraft = $contentService->createContent($contentCreateStruct, array($locationCreateStruct));
443
        $content = $contentService->publishVersion($contentDraft->versionInfo);
444
        $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...
445
446
        // Set current user to newly created user again, and try to delete $firstLocation
447
        $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...
448
449
        $this->refreshSearch($repository);
450
451
        // This call will fail with an "UnauthorizedException" because user does not have
452
        // permission to delete $secondLocation which is in the subtree of the $firstLocation
453
        $locationService->deleteLocation($firstLocation);
454
        /* END: Use Case */
455
    }
456
457
    /**
458
     * Test for the copySubtree() method.
459
     *
460
     * @see \eZ\Publish\API\Repository\LocationService::copySubtree()
461
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
462
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCopySubtree
463
     */
464
    public function testCopySubtreeThrowsUnauthorizedException()
465
    {
466
        $repository = $this->getRepository();
467
468
        $mediaLocationId = $this->generateId('location', 43);
469
        $demoDesignLocationId = $this->generateId('location', 56);
470
        /* BEGIN: Use Case */
471
        $user = $this->createMediaUserVersion1();
472
473
        // $mediaLocationId is the ID of the "Media" Location in
474
        // an eZ Publish demo installation
475
476
        // $demoDesignLocationId is the ID of the "Demo Design" Location in an eZ
477
        // Publish demo installation
478
479
        // Load the location service
480
        $locationService = $repository->getLocationService();
481
482
        // Load location to copy
483
        $locationToCopy = $locationService->loadLocation($mediaLocationId);
484
485
        // Load new parent location
486
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
487
488
        // Set media editor as current user
489
        $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...
490
491
        // This call will fail with an "UnauthorizedException"
492
        $locationService->copySubtree(
493
            $locationToCopy,
494
            $newParentLocation
495
        );
496
        /* END: Use Case */
497
    }
498
499
    /**
500
     * Test for the moveSubtree() method.
501
     *
502
     * @see \eZ\Publish\API\Repository\LocationService::moveSubtree()
503
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
504
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
505
     */
506
    public function testMoveSubtreeThrowsUnauthorizedException()
507
    {
508
        $repository = $this->getRepository();
509
510
        $mediaLocationId = $this->generateId('location', 43);
511
        $demoDesignLocationId = $this->generateId('location', 56);
512
        /* BEGIN: Use Case */
513
        $user = $this->createMediaUserVersion1();
514
515
        // $mediaLocationId is the ID of the "Media" page location in
516
        // an eZ Publish demo installation
517
518
        // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ
519
        // Publish demo installation
520
521
        // Load the location service
522
        $locationService = $repository->getLocationService();
523
524
        // Load location to move
525
        $locationToMove = $locationService->loadLocation($mediaLocationId);
526
527
        // Load new parent location
528
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
529
530
        // Set media editor as current user
531
        $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...
532
533
        // This call will fail with an "UnauthorizedException"
534
        $locationService->moveSubtree(
535
            $locationToMove,
536
            $newParentLocation
537
        );
538
        /* END: Use Case */
539
    }
540
}
541