1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the TrashServiceAuthorizationTest 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
|
|
|
/** |
12
|
|
|
* Test case for operations in the TrashService using in memory storage. |
13
|
|
|
* |
14
|
|
|
* @see eZ\Publish\API\Repository\TrashService |
15
|
|
|
* @group integration |
16
|
|
|
* @group authorization |
17
|
|
|
*/ |
18
|
|
|
class TrashServiceAuthorizationTest extends BaseTrashServiceTest |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Test for the loadTrashItem() method. |
22
|
|
|
* |
23
|
|
|
* @see \eZ\Publish\API\Repository\TrashService::loadTrashItem() |
24
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
25
|
|
|
* @depends eZ\Publish\API\Repository\Tests\TrashServiceTest::testLoadTrashItem |
26
|
|
|
* @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testLoadAnonymousUser |
27
|
|
|
*/ |
28
|
|
|
public function testLoadTrashItemThrowsUnauthorizedException() |
29
|
|
|
{ |
30
|
|
|
$repository = $this->getRepository(); |
31
|
|
|
$trashService = $repository->getTrashService(); |
32
|
|
|
|
33
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
34
|
|
|
/* BEGIN: Use Case */ |
35
|
|
|
// $anonymousUserId is the ID of the "Anonymous" user |
36
|
|
|
$trashItem = $this->createTrashItem(); |
37
|
|
|
|
38
|
|
|
// Load user service |
39
|
|
|
$userService = $repository->getUserService(); |
40
|
|
|
|
41
|
|
|
// Set "Anonymous" as current user |
42
|
|
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
|
|
|
43
|
|
|
|
44
|
|
|
// This call will fail with an "UnauthorizedException" |
45
|
|
|
$trashService->loadTrashItem($trashItem->id); |
46
|
|
|
/* END: Use Case */ |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Test for the trash() method without proper permissions. |
51
|
|
|
* |
52
|
|
|
* @covers \eZ\Publish\API\Repository\TrashService::trash |
53
|
|
|
* |
54
|
|
|
* @expectedException \eZ\Publish\Core\Base\Exceptions\UnauthorizedException |
55
|
|
|
* @expectedExceptionMessage User does not have access to 'remove' 'content' |
56
|
|
|
*/ |
57
|
|
|
public function testTrashThrowsUnauthorizedException() |
58
|
|
|
{ |
59
|
|
|
$repository = $this->getRepository(); |
60
|
|
|
$trashService = $repository->getTrashService(); |
61
|
|
|
$locationService = $repository->getLocationService(); |
62
|
|
|
|
63
|
|
|
// Load "Media" page location to be trashed |
64
|
|
|
$mediaLocation = $locationService->loadLocationByRemoteId( |
65
|
|
|
'75c715a51699d2d309a924eca6a95145' |
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
// switch user context before testing TrashService::trash method |
69
|
|
|
$repository->getPermissionResolver()->setCurrentUserReference( |
70
|
|
|
$this->createUserWithPolicies('trash_test_user', []) |
71
|
|
|
); |
72
|
|
|
$trashService->trash($mediaLocation); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Test for the trash() method with proper minimal permission set. |
77
|
|
|
* |
78
|
|
|
* @depends testTrashThrowsUnauthorizedException |
79
|
|
|
* |
80
|
|
|
* @covers \eZ\Publish\API\Repository\TrashService::trash |
81
|
|
|
*/ |
82
|
|
|
public function testTrashRequiresContentRemovePolicy() |
83
|
|
|
{ |
84
|
|
|
$repository = $this->getRepository(); |
85
|
|
|
$trashService = $repository->getTrashService(); |
86
|
|
|
$locationService = $repository->getLocationService(); |
87
|
|
|
|
88
|
|
|
// Load "Media" page location to be trashed |
89
|
|
|
$mediaLocation = $locationService->loadLocationByRemoteId( |
90
|
|
|
'75c715a51699d2d309a924eca6a95145' |
91
|
|
|
); |
92
|
|
|
|
93
|
|
|
$repository->getPermissionResolver()->setCurrentUserReference( |
94
|
|
|
$this->createUserWithPolicies( |
95
|
|
|
'trash_test_user', |
96
|
|
|
[ |
97
|
|
|
['module' => 'content', 'function' => 'remove'], |
98
|
|
|
] |
99
|
|
|
) |
100
|
|
|
); |
101
|
|
|
$trashService->trash($mediaLocation); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Test for the recover() method. |
106
|
|
|
* |
107
|
|
|
* @see \eZ\Publish\API\Repository\TrashService::recover() |
108
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
109
|
|
|
* @depends eZ\Publish\API\Repository\Tests\TrashServiceTest::testRecover |
110
|
|
|
* @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testLoadAnonymousUser |
111
|
|
|
*/ |
112
|
|
|
public function testRecoverThrowsUnauthorizedException() |
113
|
|
|
{ |
114
|
|
|
$repository = $this->getRepository(); |
115
|
|
|
$trashService = $repository->getTrashService(); |
116
|
|
|
|
117
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
118
|
|
|
/* BEGIN: Use Case */ |
119
|
|
|
// $anonymousUserId is the ID of the "Anonymous" user |
120
|
|
|
$trashItem = $this->createTrashItem(); |
121
|
|
|
|
122
|
|
|
// Load user service |
123
|
|
|
$userService = $repository->getUserService(); |
124
|
|
|
|
125
|
|
|
// Set "Anonymous" as current user |
126
|
|
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
|
|
|
127
|
|
|
|
128
|
|
|
// This call will fail with an "UnauthorizedException" |
129
|
|
|
$trashService->recover($trashItem); |
|
|
|
|
130
|
|
|
/* END: Use Case */ |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Test for the recover() method. |
135
|
|
|
* |
136
|
|
|
* @see \eZ\Publish\API\Repository\TrashService::recover($trashItem, $newParentLocation) |
137
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
138
|
|
|
* @depends eZ\Publish\API\Repository\Tests\TrashServiceTest::testRecover |
139
|
|
|
* @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testLoadAnonymousUser |
140
|
|
|
*/ |
141
|
|
|
public function testRecoverThrowsUnauthorizedExceptionWithNewParentLocationParameter() |
142
|
|
|
{ |
143
|
|
|
$repository = $this->getRepository(); |
144
|
|
|
$trashService = $repository->getTrashService(); |
145
|
|
|
$locationService = $repository->getLocationService(); |
146
|
|
|
|
147
|
|
|
$homeLocationId = $this->generateId('location', 2); |
148
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
149
|
|
|
/* BEGIN: Use Case */ |
150
|
|
|
// $anonymousUserId is the ID of the "Anonymous" user |
151
|
|
|
// $homeLocationId is the ID of the "Home" location in an eZ Publish |
152
|
|
|
// demo installation |
153
|
|
|
|
154
|
|
|
$trashItem = $this->createTrashItem(); |
155
|
|
|
|
156
|
|
|
// Get the new parent location |
157
|
|
|
$newParentLocation = $locationService->loadLocation($homeLocationId); |
158
|
|
|
|
159
|
|
|
// Load user service |
160
|
|
|
$userService = $repository->getUserService(); |
161
|
|
|
|
162
|
|
|
// Set "Anonymous" as current user |
163
|
|
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
|
|
|
164
|
|
|
|
165
|
|
|
// This call will fail with an "UnauthorizedException" |
166
|
|
|
$trashService->recover($trashItem, $newParentLocation); |
|
|
|
|
167
|
|
|
/* END: Use Case */ |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Test for the emptyTrash() method. |
172
|
|
|
* |
173
|
|
|
* @see \eZ\Publish\API\Repository\TrashService::emptyTrash() |
174
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
175
|
|
|
* @depends eZ\Publish\API\Repository\Tests\TrashServiceTest::testEmptyTrash |
176
|
|
|
* @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testLoadAnonymousUser |
177
|
|
|
*/ |
178
|
|
|
public function testEmptyTrashThrowsUnauthorizedException() |
179
|
|
|
{ |
180
|
|
|
$repository = $this->getRepository(); |
181
|
|
|
$trashService = $repository->getTrashService(); |
182
|
|
|
|
183
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
184
|
|
|
/* BEGIN: Use Case */ |
185
|
|
|
// $anonymousUserId is the ID of the "Anonymous" user |
186
|
|
|
$this->createTrashItem(); |
187
|
|
|
|
188
|
|
|
// Load user service |
189
|
|
|
$userService = $repository->getUserService(); |
190
|
|
|
|
191
|
|
|
// Set "Anonymous" as current user |
192
|
|
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
|
|
|
193
|
|
|
|
194
|
|
|
// This call will fail with an "UnauthorizedException" |
195
|
|
|
$trashService->emptyTrash(); |
196
|
|
|
/* END: Use Case */ |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* Test for the deleteTrashItem() method. |
201
|
|
|
* |
202
|
|
|
* @see \eZ\Publish\API\Repository\TrashService::deleteTrashItem() |
203
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
204
|
|
|
* @depends eZ\Publish\API\Repository\Tests\TrashServiceTest::testDeleteTrashItem |
205
|
|
|
* @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testLoadAnonymousUser |
206
|
|
|
*/ |
207
|
|
|
public function testDeleteTrashItemThrowsUnauthorizedException() |
208
|
|
|
{ |
209
|
|
|
$repository = $this->getRepository(); |
210
|
|
|
$trashService = $repository->getTrashService(); |
211
|
|
|
|
212
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
213
|
|
|
/* BEGIN: Use Case */ |
214
|
|
|
// $anonymousUserId is the ID of the "Anonymous" user |
215
|
|
|
$trashItem = $this->createTrashItem(); |
216
|
|
|
|
217
|
|
|
// Load user service |
218
|
|
|
$userService = $repository->getUserService(); |
219
|
|
|
|
220
|
|
|
// Set "Anonymous" as current user |
221
|
|
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
|
|
|
222
|
|
|
|
223
|
|
|
// This call will fail with an "UnauthorizedException" |
224
|
|
|
$trashService->deleteTrashItem($trashItem); |
|
|
|
|
225
|
|
|
/* END: Use Case */ |
226
|
|
|
} |
227
|
|
|
} |
228
|
|
|
|
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.