1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the ParentUserGroupLimitationTest 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\Values\User\Limitation; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\API\Repository\Values\User\Limitation\ParentUserGroupLimitation; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Test case for the {@link \eZ\Publish\API\Repository\Values\User\Limitation\ParentUserGroupLimitation} |
15
|
|
|
* class. |
16
|
|
|
* |
17
|
|
|
* @see eZ\Publish\API\Repository\Values\User\Limitation |
18
|
|
|
* @see eZ\Publish\API\Repository\Values\User\Limitation\ParentUserGroupLimitation |
19
|
|
|
* @group integration |
20
|
|
|
* @group limitation |
21
|
|
|
*/ |
22
|
|
|
class ParentUserGroupLimitationTest extends BaseLimitationTest |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Tests a ParentUserGroupLimitation. |
26
|
|
|
* |
27
|
|
|
* @see eZ\Publish\API\Repository\Values\User\Limitation\ParentUserGroupLimitation |
28
|
|
|
*/ |
29
|
|
|
public function testParentUserGroupLimitationAllow() |
30
|
|
|
{ |
31
|
|
|
$repository = $this->getRepository(); |
32
|
|
|
$userService = $repository->getUserService(); |
33
|
|
|
$permissionResolver = $repository->getPermissionResolver(); |
34
|
|
|
|
35
|
|
|
$parentUserGroupId = $this->generateId('location', 4); |
36
|
|
|
/* BEGIN: Use Case */ |
37
|
|
|
$user = $this->createUserVersion1(); |
38
|
|
|
$currentUser = $userService->loadUser( |
39
|
|
|
$permissionResolver->getCurrentUserReference()->getUserId() |
40
|
|
|
); |
41
|
|
|
|
42
|
|
|
$userGroupCreate = $userService->newUserGroupCreateStruct('eng-GB'); |
43
|
|
|
$userGroupCreate->setField('name', 'Shared wiki'); |
44
|
|
|
|
45
|
|
|
$userGroup = $userService->createUserGroup( |
46
|
|
|
$userGroupCreate, |
47
|
|
|
$userService->loadUserGroup( |
48
|
|
|
$parentUserGroupId |
49
|
|
|
) |
50
|
|
|
); |
51
|
|
|
|
52
|
|
|
// Assign system user and example user to same group |
53
|
|
|
$userService->assignUserToUserGroup($user, $userGroup); |
54
|
|
|
$userService->assignUserToUserGroup($currentUser, $userGroup); |
55
|
|
|
|
56
|
|
|
$roleService = $repository->getRoleService(); |
57
|
|
|
|
58
|
|
|
$policyCreate = $roleService->newPolicyCreateStruct('content', 'create'); |
59
|
|
|
$policyCreate->addLimitation( |
60
|
|
|
new ParentUserGroupLimitation( |
61
|
|
|
[ |
62
|
|
|
'limitationValues' => [true], |
63
|
|
|
] |
64
|
|
|
) |
65
|
|
|
); |
66
|
|
|
$role = $roleService->loadRoleByIdentifier('Editor'); |
67
|
|
|
$roleDraft = $roleService->createRoleDraft($role); |
68
|
|
|
$roleService->addPolicyByRoleDraft( |
69
|
|
|
$roleDraft, |
70
|
|
|
$policyCreate |
71
|
|
|
); |
72
|
|
|
$roleService->addPolicyByRoleDraft( |
73
|
|
|
$roleDraft, |
74
|
|
|
$roleService->newPolicyCreateStruct('content', 'read') |
75
|
|
|
); |
76
|
|
|
$roleService->publishRoleDraft($roleDraft); |
77
|
|
|
|
78
|
|
|
$roleService->assignRoleToUserGroup($role, $userGroup); |
79
|
|
|
|
80
|
|
|
$permissionResolver->setCurrentUserReference($user); |
81
|
|
|
|
82
|
|
|
$draft = $this->createWikiPageDraft(); |
83
|
|
|
/* END: Use Case */ |
84
|
|
|
|
85
|
|
|
$this->assertEquals( |
86
|
|
|
'An awesome wiki page', |
87
|
|
|
$draft->getFieldValue('title')->text |
88
|
|
|
); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Tests a ParentUserGroupLimitation. |
93
|
|
|
* |
94
|
|
|
* @see eZ\Publish\API\Repository\Values\User\Limitation\ParentUserGroupLimitation |
95
|
|
|
*/ |
96
|
|
View Code Duplication |
public function testParentUserGroupLimitationForbid() |
97
|
|
|
{ |
98
|
|
|
$this->expectException(\eZ\Publish\API\Repository\Exceptions\UnauthorizedException::class); |
99
|
|
|
|
100
|
|
|
$repository = $this->getRepository(); |
101
|
|
|
$userService = $repository->getUserService(); |
102
|
|
|
$permissionResolver = $repository->getPermissionResolver(); |
103
|
|
|
|
104
|
|
|
$parentUserGroupId = $this->generateId('location', 4); |
105
|
|
|
/* BEGIN: Use Case */ |
106
|
|
|
$user = $this->createUserVersion1(); |
107
|
|
|
|
108
|
|
|
$userGroupCreate = $userService->newUserGroupCreateStruct('eng-GB'); |
109
|
|
|
$userGroupCreate->setField('name', 'Shared wiki'); |
110
|
|
|
|
111
|
|
|
$userGroup = $userService->createUserGroup( |
112
|
|
|
$userGroupCreate, |
113
|
|
|
$userService->loadUserGroup( |
114
|
|
|
$parentUserGroupId |
115
|
|
|
) |
116
|
|
|
); |
117
|
|
|
|
118
|
|
|
// Assign only example user to new group |
119
|
|
|
$userService->assignUserToUserGroup($user, $userGroup); |
120
|
|
|
|
121
|
|
|
$roleService = $repository->getRoleService(); |
122
|
|
|
|
123
|
|
|
$policyCreate = $roleService->newPolicyCreateStruct('content', 'create'); |
124
|
|
|
$policyCreate->addLimitation( |
125
|
|
|
new ParentUserGroupLimitation( |
126
|
|
|
[ |
127
|
|
|
'limitationValues' => [true], |
128
|
|
|
] |
129
|
|
|
) |
130
|
|
|
); |
131
|
|
|
|
132
|
|
|
$role = $roleService->loadRoleByIdentifier('Editor'); |
133
|
|
|
$roleDraft = $roleService->createRoleDraft($role); |
134
|
|
|
$roleService->addPolicyByRoleDraft( |
135
|
|
|
$roleDraft, |
136
|
|
|
$policyCreate |
137
|
|
|
); |
138
|
|
|
$roleService->addPolicyByRoleDraft( |
139
|
|
|
$roleDraft, |
140
|
|
|
$roleService->newPolicyCreateStruct('content', 'read') |
141
|
|
|
); |
142
|
|
|
$roleService->publishRoleDraft($roleDraft); |
143
|
|
|
|
144
|
|
|
$roleService->assignRoleToUserGroup($role, $userGroup); |
145
|
|
|
|
146
|
|
|
$permissionResolver->setCurrentUserReference($user); |
147
|
|
|
|
148
|
|
|
$this->createWikiPageDraft(); |
149
|
|
|
/* END: Use Case */ |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|