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
|
|
|
|
34
|
|
|
$parentUserGroupId = $this->generateId('location', 4); |
35
|
|
|
/* BEGIN: Use Case */ |
36
|
|
|
$user = $this->createUserVersion1(); |
37
|
|
|
|
38
|
|
|
$userGroupCreate = $userService->newUserGroupCreateStruct('eng-GB'); |
39
|
|
|
$userGroupCreate->setField('name', 'Shared wiki'); |
40
|
|
|
|
41
|
|
|
$userGroup = $userService->createUserGroup( |
42
|
|
|
$userGroupCreate, |
43
|
|
|
$userService->loadUserGroup( |
44
|
|
|
$parentUserGroupId |
45
|
|
|
) |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
// Assign system user and example user to same group |
49
|
|
|
$userService->assignUserToUserGroup($user, $userGroup); |
50
|
|
|
$userService->assignUserToUserGroup($repository->getCurrentUser(), $userGroup); |
|
|
|
|
51
|
|
|
|
52
|
|
|
$roleService = $repository->getRoleService(); |
53
|
|
|
|
54
|
|
|
$policyCreate = $roleService->newPolicyCreateStruct('content', 'create'); |
55
|
|
|
$policyCreate->addLimitation( |
56
|
|
|
new ParentUserGroupLimitation( |
57
|
|
|
[ |
58
|
|
|
'limitationValues' => [true], |
59
|
|
|
] |
60
|
|
|
) |
61
|
|
|
); |
62
|
|
|
|
63
|
|
|
$role = $roleService->addPolicy( |
|
|
|
|
64
|
|
|
$roleService->loadRoleByIdentifier('Editor'), |
65
|
|
|
$policyCreate |
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
$role = $roleService->addPolicy( |
|
|
|
|
69
|
|
|
$role, |
70
|
|
|
$roleService->newPolicyCreateStruct('content', 'read') |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
$roleService->assignRoleToUserGroup($role, $userGroup); |
74
|
|
|
|
75
|
|
|
$repository->setCurrentUser($user); |
|
|
|
|
76
|
|
|
|
77
|
|
|
$draft = $this->createWikiPageDraft(); |
78
|
|
|
/* END: Use Case */ |
79
|
|
|
|
80
|
|
|
$this->assertEquals( |
81
|
|
|
'An awesome wiki page', |
82
|
|
|
$draft->getFieldValue('title')->text |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Tests a ParentUserGroupLimitation. |
88
|
|
|
* |
89
|
|
|
* @see eZ\Publish\API\Repository\Values\User\Limitation\ParentUserGroupLimitation |
90
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
91
|
|
|
*/ |
92
|
|
View Code Duplication |
public function testParentUserGroupLimitationForbid() |
93
|
|
|
{ |
94
|
|
|
$repository = $this->getRepository(); |
95
|
|
|
$userService = $repository->getUserService(); |
96
|
|
|
|
97
|
|
|
$parentUserGroupId = $this->generateId('location', 4); |
98
|
|
|
/* BEGIN: Use Case */ |
99
|
|
|
$user = $this->createUserVersion1(); |
100
|
|
|
|
101
|
|
|
$userGroupCreate = $userService->newUserGroupCreateStruct('eng-GB'); |
102
|
|
|
$userGroupCreate->setField('name', 'Shared wiki'); |
103
|
|
|
|
104
|
|
|
$userGroup = $userService->createUserGroup( |
105
|
|
|
$userGroupCreate, |
106
|
|
|
$userService->loadUserGroup( |
107
|
|
|
$parentUserGroupId |
108
|
|
|
) |
109
|
|
|
); |
110
|
|
|
|
111
|
|
|
// Assign only example user to new group |
112
|
|
|
$userService->assignUserToUserGroup($user, $userGroup); |
113
|
|
|
|
114
|
|
|
$roleService = $repository->getRoleService(); |
115
|
|
|
|
116
|
|
|
$policyCreate = $roleService->newPolicyCreateStruct('content', 'create'); |
117
|
|
|
$policyCreate->addLimitation( |
118
|
|
|
new ParentUserGroupLimitation( |
119
|
|
|
[ |
120
|
|
|
'limitationValues' => [true], |
121
|
|
|
] |
122
|
|
|
) |
123
|
|
|
); |
124
|
|
|
|
125
|
|
|
$role = $roleService->addPolicy( |
|
|
|
|
126
|
|
|
$roleService->loadRoleByIdentifier('Editor'), |
127
|
|
|
$policyCreate |
128
|
|
|
); |
129
|
|
|
|
130
|
|
|
$role = $roleService->addPolicy( |
|
|
|
|
131
|
|
|
$role, |
132
|
|
|
$roleService->newPolicyCreateStruct('content', 'read') |
133
|
|
|
); |
134
|
|
|
|
135
|
|
|
$roleService->assignRoleToUserGroup($role, $userGroup); |
136
|
|
|
|
137
|
|
|
$repository->setCurrentUser($user); |
|
|
|
|
138
|
|
|
|
139
|
|
|
$this->createWikiPageDraft(); |
140
|
|
|
/* END: Use Case */ |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
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.