|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* File containing the ContentServiceAuthorizationTest 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\Exceptions\UnauthorizedException; |
|
12
|
|
|
use eZ\Publish\API\Repository\Repository; |
|
13
|
|
|
use eZ\Publish\API\Repository\Values\Content\ContentInfo; |
|
14
|
|
|
use eZ\Publish\API\Repository\Values\Content\Location; |
|
15
|
|
|
use eZ\Publish\API\Repository\Values\User\Limitation\LocationLimitation; |
|
16
|
|
|
use eZ\Publish\API\Repository\Values\User\Limitation\SubtreeLimitation; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Test case for operations in the ContentServiceAuthorization using in memory storage. |
|
20
|
|
|
* |
|
21
|
|
|
* @see eZ\Publish\API\Repository\ContentService |
|
22
|
|
|
* @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testLoadAnonymousUser |
|
23
|
|
|
* @group integration |
|
24
|
|
|
* @group authorization |
|
25
|
|
|
*/ |
|
26
|
|
|
class ContentServiceAuthorizationTest extends BaseContentServiceTest |
|
27
|
|
|
{ |
|
28
|
|
|
/** @var \eZ\Publish\API\Repository\Values\User\User */ |
|
29
|
|
|
private $administratorUser; |
|
30
|
|
|
|
|
31
|
|
|
/** @var \eZ\Publish\API\Repository\Values\User\User */ |
|
32
|
|
|
private $anonymousUser; |
|
33
|
|
|
|
|
34
|
|
|
/** @var \eZ\Publish\API\Repository\Repository */ |
|
35
|
|
|
private $repository; |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
/** @var \eZ\Publish\API\Repository\PermissionResolver */ |
|
38
|
|
|
private $permissionResolver; |
|
39
|
|
|
|
|
40
|
|
|
/** @var \eZ\Publish\API\Repository\UserService */ |
|
41
|
|
|
private $userService; |
|
42
|
|
|
|
|
43
|
|
|
/** @var \eZ\Publish\API\Repository\ContentService */ |
|
44
|
|
|
private $contentService; |
|
45
|
|
|
|
|
46
|
|
|
public function setUp(): void |
|
47
|
|
|
{ |
|
48
|
|
|
parent::setUp(); |
|
49
|
|
|
|
|
50
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
|
51
|
|
|
$administratorUserId = $this->generateId('user', 14); |
|
52
|
|
|
|
|
53
|
|
|
$this->repository = $this->getRepository(); |
|
54
|
|
|
$this->permissionResolver = $this->repository->getPermissionResolver(); |
|
55
|
|
|
$this->userService = $this->repository->getUserService(); |
|
56
|
|
|
$this->contentService = $this->repository->getContentService(); |
|
57
|
|
|
|
|
58
|
|
|
$this->administratorUser = $this->userService->loadUser($administratorUserId); |
|
59
|
|
|
$this->anonymousUser = $this->userService->loadUser($anonymousUserId); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Test for the createContent() method. |
|
64
|
|
|
* |
|
65
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContent() |
|
66
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
|
67
|
|
|
*/ |
|
68
|
|
|
public function testCreateContentThrowsUnauthorizedException() |
|
69
|
|
|
{ |
|
70
|
|
|
if ($this->isVersion4()) { |
|
71
|
|
|
$this->markTestSkipped('This test requires eZ Publish 5'); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
$this->permissionResolver->setCurrentUserReference($this->anonymousUser); |
|
75
|
|
|
|
|
76
|
|
|
$contentTypeService = $this->getRepository()->getContentTypeService(); |
|
77
|
|
|
|
|
78
|
|
|
$contentType = $contentTypeService->loadContentTypeByIdentifier('forum'); |
|
79
|
|
|
|
|
80
|
|
|
$contentCreate = $this->contentService->newContentCreateStruct($contentType, 'eng-US'); |
|
81
|
|
|
$contentCreate->setField('name', 'Awesome Sindelfingen forum'); |
|
82
|
|
|
|
|
83
|
|
|
$contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; |
|
84
|
|
|
$contentCreate->alwaysAvailable = true; |
|
85
|
|
|
|
|
86
|
|
|
$this->expectException(UnauthorizedException::class); |
|
87
|
|
|
$this->expectExceptionMessageRegExp('/\'create\' \'content\'/'); |
|
88
|
|
|
|
|
89
|
|
|
$this->contentService->createContent($contentCreate); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Test for the createContent() method. |
|
94
|
|
|
* |
|
95
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContent($contentCreateStruct, $locationCreateStructs) |
|
96
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
|
97
|
|
|
*/ |
|
98
|
|
|
public function testCreateContentThrowsUnauthorizedExceptionWithSecondParameter() |
|
99
|
|
|
{ |
|
100
|
|
|
$this->permissionResolver->setCurrentUserReference($this->anonymousUser); |
|
101
|
|
|
|
|
102
|
|
|
$this->expectException(UnauthorizedException::class); |
|
103
|
|
|
$this->expectExceptionMessageRegExp('/\'create\' \'content\'/'); |
|
104
|
|
|
|
|
105
|
|
|
$this->createContentDraftVersion1(); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Test for the loadContentInfo() method. |
|
110
|
|
|
* |
|
111
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentInfo() |
|
112
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
|
113
|
|
|
*/ |
|
114
|
|
View Code Duplication |
public function testLoadContentInfoThrowsUnauthorizedException() |
|
115
|
|
|
{ |
|
116
|
|
|
$contentId = $this->generateId('object', 10); |
|
117
|
|
|
$this->setRestrictedEditorUser(); |
|
118
|
|
|
|
|
119
|
|
|
$this->expectException(UnauthorizedException::class); |
|
120
|
|
|
$this->expectExceptionMessageRegExp('/\'read\' \'content\'/'); |
|
121
|
|
|
|
|
122
|
|
|
// $contentId contains a content object ID not accessible for anonymous |
|
123
|
|
|
$this->contentService->loadContentInfo($contentId); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Test for the sudo() method. |
|
128
|
|
|
* |
|
129
|
|
|
* @see \eZ\Publish\API\Repository\Repository::sudo() |
|
130
|
|
|
* @depends testLoadContentInfoThrowsUnauthorizedException |
|
131
|
|
|
*/ |
|
132
|
|
|
public function testSudo() |
|
133
|
|
|
{ |
|
134
|
|
|
$repository = $this->getRepository(); |
|
135
|
|
|
$contentId = $this->generateId('object', 10); |
|
136
|
|
|
$this->setRestrictedEditorUser(); |
|
137
|
|
|
|
|
138
|
|
|
$contentInfo = $repository->sudo(function (Repository $repository) use ($contentId) { |
|
139
|
|
|
return $repository->getContentService()->loadContentInfo($contentId); |
|
140
|
|
|
}); |
|
141
|
|
|
|
|
142
|
|
|
$this->assertInstanceOf( |
|
143
|
|
|
ContentInfo::class, |
|
144
|
|
|
$contentInfo |
|
145
|
|
|
); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* Test for the loadContentInfoList() method. |
|
150
|
|
|
* |
|
151
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentInfoList() |
|
152
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfoList |
|
153
|
|
|
*/ |
|
154
|
|
|
public function testLoadContentInfoListSkipsUnauthorizedItems() |
|
155
|
|
|
{ |
|
156
|
|
|
$contentId = $this->generateId('object', 10); |
|
157
|
|
|
$this->setRestrictedEditorUser(); |
|
158
|
|
|
|
|
159
|
|
|
$this->assertCount(0, $this->contentService->loadContentInfoList([$contentId])); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* Test for the loadContentInfoByRemoteId() method. |
|
164
|
|
|
* |
|
165
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentInfoByRemoteId() |
|
166
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfoByRemoteId |
|
167
|
|
|
*/ |
|
168
|
|
View Code Duplication |
public function testLoadContentInfoByRemoteIdThrowsUnauthorizedException() |
|
169
|
|
|
{ |
|
170
|
|
|
$anonymousRemoteId = 'faaeb9be3bd98ed09f606fc16d144eca'; |
|
171
|
|
|
|
|
172
|
|
|
$this->setRestrictedEditorUser(); |
|
173
|
|
|
|
|
174
|
|
|
$this->expectException(UnauthorizedException::class); |
|
175
|
|
|
$this->expectExceptionMessageRegExp('/\'read\' \'content\'/'); |
|
176
|
|
|
|
|
177
|
|
|
$this->contentService->loadContentInfoByRemoteId($anonymousRemoteId); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* Test for the loadVersionInfo() method. |
|
182
|
|
|
* |
|
183
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadVersionInfo() |
|
184
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo |
|
185
|
|
|
*/ |
|
186
|
|
|
public function testLoadVersionInfoThrowsUnauthorizedException() |
|
187
|
|
|
{ |
|
188
|
|
|
$contentInfo = $this->getContentInfoForAnonymousUser(); |
|
189
|
|
|
|
|
190
|
|
|
$this->setRestrictedEditorUser(); |
|
191
|
|
|
|
|
192
|
|
|
$this->expectException(UnauthorizedException::class); |
|
193
|
|
|
$this->expectExceptionMessageRegExp('/\'read\' \'content\'/'); |
|
194
|
|
|
|
|
195
|
|
|
$this->contentService->loadVersionInfo($contentInfo); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* Test for the loadVersionInfo() method. |
|
200
|
|
|
* |
|
201
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadVersionInfo($contentInfo, $versionNo) |
|
202
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoWithSecondParameter |
|
203
|
|
|
*/ |
|
204
|
|
|
public function testLoadVersionInfoThrowsUnauthorizedExceptionWithSecondParameter() |
|
205
|
|
|
{ |
|
206
|
|
|
$contentInfo = $this->getContentInfoForAnonymousUser(); |
|
207
|
|
|
|
|
208
|
|
|
$this->setRestrictedEditorUser(); |
|
209
|
|
|
|
|
210
|
|
|
$this->expectException(UnauthorizedException::class); |
|
211
|
|
|
$this->expectExceptionMessageRegExp('/\'read\' \'content\'/'); |
|
212
|
|
|
|
|
213
|
|
|
$this->contentService->loadVersionInfo($contentInfo, 2); |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* Test for the loadVersionInfoById() method. |
|
218
|
|
|
* |
|
219
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadVersionInfoById() |
|
220
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoById |
|
221
|
|
|
*/ |
|
222
|
|
View Code Duplication |
public function testLoadVersionInfoByIdThrowsUnauthorizedException() |
|
223
|
|
|
{ |
|
224
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
|
225
|
|
|
$this->setRestrictedEditorUser(); |
|
226
|
|
|
|
|
227
|
|
|
$this->expectException(UnauthorizedException::class); |
|
228
|
|
|
$this->expectExceptionMessageRegExp('/\'read\' \'content\'/'); |
|
229
|
|
|
|
|
230
|
|
|
$this->contentService->loadVersionInfoById($anonymousUserId); |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
/** |
|
234
|
|
|
* Test for the loadVersionInfoById() method. |
|
235
|
|
|
* |
|
236
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadVersionInfoById($contentId, $versionNo) |
|
237
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoByIdWithSecondParameter |
|
238
|
|
|
*/ |
|
239
|
|
View Code Duplication |
public function testLoadVersionInfoByIdThrowsUnauthorizedExceptionWithSecondParameter() |
|
240
|
|
|
{ |
|
241
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
|
242
|
|
|
$this->setRestrictedEditorUser(); |
|
243
|
|
|
|
|
244
|
|
|
$this->expectException(UnauthorizedException::class); |
|
245
|
|
|
$this->expectExceptionMessageRegExp('/\'read\' \'content\'/'); |
|
246
|
|
|
|
|
247
|
|
|
$this->contentService->loadVersionInfoById($anonymousUserId, 2); |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
/** |
|
251
|
|
|
* Test for the loadVersionInfoById() method. |
|
252
|
|
|
* |
|
253
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadVersionInfoById($contentId, $versionNo) |
|
254
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoById |
|
255
|
|
|
*/ |
|
256
|
|
|
public function testLoadVersionInfoByIdThrowsUnauthorizedExceptionForFirstDraft() |
|
257
|
|
|
{ |
|
258
|
|
|
$contentDraft = $this->createContentDraftVersion1(); |
|
259
|
|
|
|
|
260
|
|
|
$this->permissionResolver->setCurrentUserReference($this->anonymousUser); |
|
261
|
|
|
|
|
262
|
|
|
$this->expectException(UnauthorizedException::class); |
|
263
|
|
|
// content versionread policy is needed because it is a draft |
|
264
|
|
|
$this->expectExceptionMessageRegExp('/\'versionread\' \'content\'/'); |
|
265
|
|
|
|
|
266
|
|
|
$this->contentService->loadVersionInfoById( |
|
267
|
|
|
$contentDraft->id, |
|
268
|
|
|
$contentDraft->contentInfo->currentVersionNo |
|
269
|
|
|
); |
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
|
|
/** |
|
273
|
|
|
* Test for the loadContentByContentInfo() method. |
|
274
|
|
|
* |
|
275
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentByContentInfo() |
|
276
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByContentInfo |
|
277
|
|
|
*/ |
|
278
|
|
|
public function testLoadContentByContentInfoThrowsUnauthorizedException() |
|
279
|
|
|
{ |
|
280
|
|
|
$contentInfo = $this->getContentInfoForAnonymousUser(); |
|
281
|
|
|
|
|
282
|
|
|
$this->setRestrictedEditorUser(); |
|
283
|
|
|
|
|
284
|
|
|
$this->expectException(UnauthorizedException::class); |
|
285
|
|
|
$this->expectExceptionMessageRegExp('/\'read\' \'content\'/'); |
|
286
|
|
|
|
|
287
|
|
|
$this->contentService->loadContentByContentInfo($contentInfo); |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
|
|
/** |
|
291
|
|
|
* Test for the loadContentByContentInfo() method. |
|
292
|
|
|
* |
|
293
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentByContentInfo($contentInfo, $languages) |
|
294
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByContentInfoWithLanguageParameters |
|
295
|
|
|
*/ |
|
296
|
|
View Code Duplication |
public function testLoadContentByContentInfoThrowsUnauthorizedExceptionWithSecondParameter() |
|
297
|
|
|
{ |
|
298
|
|
|
$contentInfo = $this->getContentInfoForAnonymousUser(); |
|
299
|
|
|
|
|
300
|
|
|
$this->setRestrictedEditorUser(); |
|
301
|
|
|
|
|
302
|
|
|
$this->expectException(UnauthorizedException::class); |
|
303
|
|
|
$this->expectExceptionMessageRegExp('/\'read\' \'content\'/'); |
|
304
|
|
|
|
|
305
|
|
|
$this->contentService->loadContentByContentInfo($contentInfo, ['eng-US']); |
|
306
|
|
|
} |
|
307
|
|
|
|
|
308
|
|
|
/** |
|
309
|
|
|
* Test for the loadContentByContentInfo() method. |
|
310
|
|
|
* |
|
311
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentByContentInfo($contentInfo, $languages, $versionNo) |
|
312
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByContentInfoWithVersionNumberParameter |
|
313
|
|
|
*/ |
|
314
|
|
View Code Duplication |
public function testLoadContentByContentInfoThrowsUnauthorizedExceptionWithThirdParameter() |
|
315
|
|
|
{ |
|
316
|
|
|
$contentInfo = $this->getContentInfoForAnonymousUser(); |
|
317
|
|
|
|
|
318
|
|
|
$this->setRestrictedEditorUser(); |
|
319
|
|
|
|
|
320
|
|
|
$this->expectException(UnauthorizedException::class); |
|
321
|
|
|
$this->expectExceptionMessageRegExp('/\'read\' \'content\'/'); |
|
322
|
|
|
|
|
323
|
|
|
$this->contentService->loadContentByContentInfo($contentInfo, ['eng-US'], 2); |
|
324
|
|
|
} |
|
325
|
|
|
|
|
326
|
|
|
/** |
|
327
|
|
|
* Test for the loadContentByVersionInfo() method. |
|
328
|
|
|
* |
|
329
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentByVersionInfo() |
|
330
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByVersionInfo |
|
331
|
|
|
*/ |
|
332
|
|
View Code Duplication |
public function testLoadContentByVersionInfoThrowsUnauthorizedException() |
|
333
|
|
|
{ |
|
334
|
|
|
$contentInfo = $this->getContentInfoForAnonymousUser(); |
|
335
|
|
|
|
|
336
|
|
|
$versionInfo = $this->contentService->loadVersionInfo($contentInfo); |
|
337
|
|
|
|
|
338
|
|
|
$this->setRestrictedEditorUser(); |
|
339
|
|
|
|
|
340
|
|
|
$this->expectException(UnauthorizedException::class); |
|
341
|
|
|
$this->expectExceptionMessageRegExp('/\'read\' \'content\'/'); |
|
342
|
|
|
|
|
343
|
|
|
$this->contentService->loadContentByVersionInfo($versionInfo); |
|
344
|
|
|
} |
|
345
|
|
|
|
|
346
|
|
|
/** |
|
347
|
|
|
* Test for the loadContentByVersionInfo() method. |
|
348
|
|
|
* |
|
349
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentByVersionInfo($versionInfo, $languages) |
|
350
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByVersionInfoWithSecondParameter |
|
351
|
|
|
*/ |
|
352
|
|
View Code Duplication |
public function testLoadContentByVersionInfoThrowsUnauthorizedExceptionWithSecondParameter() |
|
353
|
|
|
{ |
|
354
|
|
|
$contentInfo = $this->getContentInfoForAnonymousUser(); |
|
355
|
|
|
|
|
356
|
|
|
$versionInfo = $this->contentService->loadVersionInfo($contentInfo); |
|
357
|
|
|
|
|
358
|
|
|
$this->setRestrictedEditorUser(); |
|
359
|
|
|
|
|
360
|
|
|
$this->expectException(UnauthorizedException::class); |
|
361
|
|
|
$this->expectExceptionMessageRegExp('/\'read\' \'content\'/'); |
|
362
|
|
|
|
|
363
|
|
|
$this->contentService->loadContentByVersionInfo($versionInfo, ['eng-US']); |
|
364
|
|
|
} |
|
365
|
|
|
|
|
366
|
|
|
/** |
|
367
|
|
|
* Test for the loadContent() method. |
|
368
|
|
|
* |
|
369
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContent() |
|
370
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
|
371
|
|
|
*/ |
|
372
|
|
View Code Duplication |
public function testLoadContentThrowsUnauthorizedException() |
|
373
|
|
|
{ |
|
374
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
|
375
|
|
|
$this->setRestrictedEditorUser(); |
|
376
|
|
|
|
|
377
|
|
|
$this->expectException(UnauthorizedException::class); |
|
378
|
|
|
$this->expectExceptionMessageRegExp('/\'read\' \'content\'/'); |
|
379
|
|
|
|
|
380
|
|
|
$this->contentService->loadContent($anonymousUserId); |
|
381
|
|
|
} |
|
382
|
|
|
|
|
383
|
|
|
/** |
|
384
|
|
|
* Test for the loadContent() method. |
|
385
|
|
|
* |
|
386
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContent($contentId, $languages) |
|
387
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentWithSecondParameter |
|
388
|
|
|
*/ |
|
389
|
|
View Code Duplication |
public function testLoadContentThrowsUnauthorizedExceptionWithSecondParameter() |
|
390
|
|
|
{ |
|
391
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
|
392
|
|
|
$this->setRestrictedEditorUser(); |
|
393
|
|
|
|
|
394
|
|
|
$this->expectException(UnauthorizedException::class); |
|
395
|
|
|
$this->expectExceptionMessageRegExp('/\'read\' \'content\'/'); |
|
396
|
|
|
|
|
397
|
|
|
$this->contentService->loadContent($anonymousUserId, ['eng-US']); |
|
398
|
|
|
} |
|
399
|
|
|
|
|
400
|
|
|
/** |
|
401
|
|
|
* Test for the loadContent() method. |
|
402
|
|
|
* |
|
403
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContent($contentId, $languages, $versionNo) |
|
404
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentWithThirdParameter |
|
405
|
|
|
*/ |
|
406
|
|
View Code Duplication |
public function testLoadContentThrowsUnauthorizedExceptionWithThirdParameter() |
|
407
|
|
|
{ |
|
408
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
|
409
|
|
|
$this->setRestrictedEditorUser(); |
|
410
|
|
|
|
|
411
|
|
|
$this->expectException(UnauthorizedException::class); |
|
412
|
|
|
$this->expectExceptionMessageRegExp('/\'read\' \'content\'/'); |
|
413
|
|
|
|
|
414
|
|
|
$this->contentService->loadContent($anonymousUserId, ['eng-US'], 2); |
|
415
|
|
|
} |
|
416
|
|
|
|
|
417
|
|
|
/** |
|
418
|
|
|
* Test for the loadContent() method on a draft. |
|
419
|
|
|
* |
|
420
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContent() |
|
421
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
|
422
|
|
|
*/ |
|
423
|
|
|
public function testLoadContentThrowsUnauthorizedExceptionOnDrafts() |
|
424
|
|
|
{ |
|
425
|
|
|
$editorUser = $this->createUserVersion1(); |
|
426
|
|
|
|
|
427
|
|
|
$this->permissionResolver->setCurrentUserReference($editorUser); |
|
428
|
|
|
|
|
429
|
|
|
// Create draft with this user |
|
430
|
|
|
$draft = $this->createContentDraftVersion1(2, 'folder'); |
|
431
|
|
|
|
|
432
|
|
|
$this->permissionResolver->setCurrentUserReference($this->anonymousUser); |
|
433
|
|
|
|
|
434
|
|
|
// Try to load the draft with anonymous user to make sure access won't be allowed by throwing an exception |
|
435
|
|
|
$this->expectException(UnauthorizedException::class); |
|
436
|
|
|
// content versionread policy is needed because it is a draft |
|
437
|
|
|
$this->expectExceptionMessageRegExp('/\'versionread\' \'content\'/'); |
|
438
|
|
|
|
|
439
|
|
|
$this->contentService->loadContent($draft->id); |
|
440
|
|
|
} |
|
441
|
|
|
|
|
442
|
|
|
/** |
|
443
|
|
|
* Test for the ContentService::loadContent() method on an archive. |
|
444
|
|
|
* |
|
445
|
|
|
* This test the version permission on loading archived versions |
|
446
|
|
|
* |
|
447
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContent() |
|
448
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
|
449
|
|
|
*/ |
|
450
|
|
|
public function testLoadContentThrowsUnauthorizedExceptionsOnArchives() |
|
451
|
|
|
{ |
|
452
|
|
|
$contentTypeService = $this->getRepository()->getContentTypeService(); |
|
453
|
|
|
|
|
454
|
|
|
// set admin as current user |
|
455
|
|
|
$this->permissionResolver->setCurrentUserReference($this->administratorUser); |
|
456
|
|
|
|
|
457
|
|
|
// create folder |
|
458
|
|
|
$newStruct = $this->contentService->newContentCreateStruct( |
|
459
|
|
|
$contentTypeService->loadContentTypeByIdentifier('folder'), |
|
460
|
|
|
'eng-US' |
|
461
|
|
|
); |
|
462
|
|
|
$newStruct->setField('name', 'Test Folder'); |
|
463
|
|
|
$draft = $this->contentService->createContent( |
|
464
|
|
|
$newStruct, |
|
465
|
|
|
[$this->repository->getLocationService()->newLocationCreateStruct(2)] |
|
466
|
|
|
); |
|
467
|
|
|
$object = $this->contentService->publishVersion($draft->versionInfo); |
|
468
|
|
|
|
|
469
|
|
|
// update folder to make an archived version |
|
470
|
|
|
$updateStruct = $this->contentService->newContentUpdateStruct(); |
|
471
|
|
|
$updateStruct->setField('name', 'Test Folder Updated'); |
|
472
|
|
|
$draftUpdated = $this->contentService->updateContent( |
|
473
|
|
|
$this->contentService->createContentDraft($object->contentInfo)->versionInfo, |
|
474
|
|
|
$updateStruct |
|
475
|
|
|
); |
|
476
|
|
|
$objectUpdated = $this->contentService->publishVersion($draftUpdated->versionInfo); |
|
477
|
|
|
|
|
478
|
|
|
// set an anonymous as current user |
|
479
|
|
|
$this->permissionResolver->setCurrentUserReference($this->anonymousUser); |
|
480
|
|
|
|
|
481
|
|
|
$this->expectException(UnauthorizedException::class); |
|
482
|
|
|
// content versionread policy is needed because it is a draft |
|
483
|
|
|
$this->expectExceptionMessageRegExp('/\'versionread\' \'content\'/'); |
|
484
|
|
|
|
|
485
|
|
|
$this->contentService->loadContent($objectUpdated->id, null, 1); |
|
486
|
|
|
} |
|
487
|
|
|
|
|
488
|
|
|
/** |
|
489
|
|
|
* Test for the loadContentByRemoteId() method. |
|
490
|
|
|
* |
|
491
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentByRemoteId() |
|
492
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByRemoteId |
|
493
|
|
|
*/ |
|
494
|
|
View Code Duplication |
public function testLoadContentByRemoteIdThrowsUnauthorizedException() |
|
495
|
|
|
{ |
|
496
|
|
|
$anonymousRemoteId = 'faaeb9be3bd98ed09f606fc16d144eca'; |
|
497
|
|
|
|
|
498
|
|
|
$this->setRestrictedEditorUser(); |
|
499
|
|
|
|
|
500
|
|
|
$this->expectException(UnauthorizedException::class); |
|
501
|
|
|
$this->expectExceptionMessageRegExp('/\'read\' \'content\'/'); |
|
502
|
|
|
|
|
503
|
|
|
$this->contentService->loadContentByRemoteId($anonymousRemoteId); |
|
504
|
|
|
} |
|
505
|
|
|
|
|
506
|
|
|
/** |
|
507
|
|
|
* Test for the loadContentByRemoteId() method. |
|
508
|
|
|
* |
|
509
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentByRemoteId($remoteId, $languages) |
|
510
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByRemoteIdWithSecondParameter |
|
511
|
|
|
*/ |
|
512
|
|
View Code Duplication |
public function testLoadContentByRemoteIdThrowsUnauthorizedExceptionWithSecondParameter() |
|
513
|
|
|
{ |
|
514
|
|
|
$anonymousRemoteId = 'faaeb9be3bd98ed09f606fc16d144eca'; |
|
515
|
|
|
|
|
516
|
|
|
$this->setRestrictedEditorUser(); |
|
517
|
|
|
|
|
518
|
|
|
$this->expectException(UnauthorizedException::class); |
|
519
|
|
|
$this->expectExceptionMessageRegExp('/\'read\' \'content\'/'); |
|
520
|
|
|
|
|
521
|
|
|
$this->contentService->loadContentByRemoteId($anonymousRemoteId, ['eng-US']); |
|
522
|
|
|
} |
|
523
|
|
|
|
|
524
|
|
|
/** |
|
525
|
|
|
* Test for the loadContentByRemoteId() method. |
|
526
|
|
|
* |
|
527
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentByRemoteId($remoteId, $languages, $versionNo) |
|
528
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByRemoteIdWithThirdParameter |
|
529
|
|
|
*/ |
|
530
|
|
View Code Duplication |
public function testLoadContentByRemoteIdThrowsUnauthorizedExceptionWithThirdParameter() |
|
531
|
|
|
{ |
|
532
|
|
|
$anonymousRemoteId = 'faaeb9be3bd98ed09f606fc16d144eca'; |
|
533
|
|
|
|
|
534
|
|
|
$this->setRestrictedEditorUser(); |
|
535
|
|
|
|
|
536
|
|
|
$this->expectException(UnauthorizedException::class); |
|
537
|
|
|
$this->expectExceptionMessageRegExp('/\'read\' \'content\'/'); |
|
538
|
|
|
|
|
539
|
|
|
$this->contentService->loadContentByRemoteId($anonymousRemoteId, ['eng-US'], 2); |
|
540
|
|
|
} |
|
541
|
|
|
|
|
542
|
|
|
/** |
|
543
|
|
|
* Test for the updateContentMetadata() method. |
|
544
|
|
|
* |
|
545
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::updateContentMetadata() |
|
546
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata |
|
547
|
|
|
*/ |
|
548
|
|
|
public function testUpdateContentMetadataThrowsUnauthorizedException() |
|
549
|
|
|
{ |
|
550
|
|
|
$content = $this->createContentVersion1(); |
|
551
|
|
|
|
|
552
|
|
|
$contentInfo = $content->contentInfo; |
|
553
|
|
|
|
|
554
|
|
|
$this->permissionResolver->setCurrentUserReference($this->anonymousUser); |
|
555
|
|
|
|
|
556
|
|
|
$metadataUpdate = $this->contentService->newContentMetadataUpdateStruct(); |
|
557
|
|
|
|
|
558
|
|
|
$metadataUpdate->remoteId = 'aaaabbbbccccddddeeeeffff11112222'; |
|
559
|
|
|
$metadataUpdate->mainLanguageCode = 'eng-US'; |
|
560
|
|
|
$metadataUpdate->alwaysAvailable = false; |
|
561
|
|
|
$metadataUpdate->publishedDate = $this->createDateTime(); |
|
562
|
|
|
$metadataUpdate->modificationDate = $this->createDateTime(); |
|
563
|
|
|
|
|
564
|
|
|
$this->expectException(UnauthorizedException::class); |
|
565
|
|
|
$this->expectExceptionMessageRegExp('/\'edit\' \'content\'/'); |
|
566
|
|
|
|
|
567
|
|
|
$this->contentService->updateContentMetadata( |
|
568
|
|
|
$contentInfo, |
|
569
|
|
|
$metadataUpdate |
|
570
|
|
|
); |
|
571
|
|
|
} |
|
572
|
|
|
|
|
573
|
|
|
/** |
|
574
|
|
|
* Test for the deleteContent() method. |
|
575
|
|
|
* |
|
576
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::deleteContent() |
|
577
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteContent |
|
578
|
|
|
*/ |
|
579
|
|
View Code Duplication |
public function testDeleteContentThrowsUnauthorizedException() |
|
580
|
|
|
{ |
|
581
|
|
|
$contentVersion2 = $this->createContentVersion2(); |
|
582
|
|
|
|
|
583
|
|
|
$contentInfo = $contentVersion2->contentInfo; |
|
584
|
|
|
|
|
585
|
|
|
$this->permissionResolver->setCurrentUserReference($this->anonymousUser); |
|
586
|
|
|
|
|
587
|
|
|
$this->expectException(UnauthorizedException::class); |
|
588
|
|
|
$this->expectExceptionMessageRegExp('/\'remove\' \'content\'/'); |
|
589
|
|
|
|
|
590
|
|
|
$this->contentService->deleteContent($contentInfo); |
|
591
|
|
|
} |
|
592
|
|
|
|
|
593
|
|
|
/** |
|
594
|
|
|
* Test for the createContentDraft() method. |
|
595
|
|
|
* |
|
596
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
|
597
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
|
598
|
|
|
*/ |
|
599
|
|
View Code Duplication |
public function testCreateContentDraftThrowsUnauthorizedException() |
|
600
|
|
|
{ |
|
601
|
|
|
$content = $this->createContentVersion1(); |
|
602
|
|
|
|
|
603
|
|
|
$contentInfo = $content->contentInfo; |
|
604
|
|
|
|
|
605
|
|
|
$this->permissionResolver->setCurrentUserReference($this->anonymousUser); |
|
606
|
|
|
|
|
607
|
|
|
$this->expectException(UnauthorizedException::class); |
|
608
|
|
|
$this->expectExceptionMessageRegExp('/\'edit\' \'content\'/'); |
|
609
|
|
|
|
|
610
|
|
|
$this->contentService->createContentDraft($contentInfo); |
|
611
|
|
|
} |
|
612
|
|
|
|
|
613
|
|
|
/** |
|
614
|
|
|
* Test for the createContentDraft() method. |
|
615
|
|
|
* |
|
616
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContentDraft($contentInfo, $versionInfo) |
|
617
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraftWithSecondParameter |
|
618
|
|
|
*/ |
|
619
|
|
|
public function testCreateContentDraftThrowsUnauthorizedExceptionWithSecondParameter() |
|
620
|
|
|
{ |
|
621
|
|
|
$content = $this->createContentVersion1(); |
|
622
|
|
|
|
|
623
|
|
|
$contentInfo = $content->contentInfo; |
|
624
|
|
|
$versionInfo = $content->getVersionInfo(); |
|
625
|
|
|
|
|
626
|
|
|
$this->permissionResolver->setCurrentUserReference($this->anonymousUser); |
|
627
|
|
|
|
|
628
|
|
|
$this->expectException(UnauthorizedException::class); |
|
629
|
|
|
$this->expectExceptionMessageRegExp('/\'edit\' \'content\'/'); |
|
630
|
|
|
|
|
631
|
|
|
$this->contentService->createContentDraft($contentInfo, $versionInfo); |
|
632
|
|
|
} |
|
633
|
|
|
|
|
634
|
|
|
/** |
|
635
|
|
|
* Test for the loadContentDrafts() method. |
|
636
|
|
|
* |
|
637
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentDrafts() |
|
638
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentDrafts |
|
639
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentDrafts |
|
640
|
|
|
*/ |
|
641
|
|
|
public function testLoadContentDraftsThrowsUnauthorizedException() |
|
642
|
|
|
{ |
|
643
|
|
|
$this->permissionResolver->setCurrentUserReference($this->anonymousUser); |
|
644
|
|
|
|
|
645
|
|
|
$this->expectException(UnauthorizedException::class); |
|
646
|
|
|
$this->expectExceptionMessageRegExp('/\'versionread\' \'content\'/'); |
|
647
|
|
|
|
|
648
|
|
|
$this->contentService->loadContentDrafts(); |
|
649
|
|
|
} |
|
650
|
|
|
|
|
651
|
|
|
/** |
|
652
|
|
|
* Test for the loadContentDrafts() method. |
|
653
|
|
|
* |
|
654
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentDrafts($user) |
|
655
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentDrafts |
|
656
|
|
|
*/ |
|
657
|
|
|
public function testLoadContentDraftsThrowsUnauthorizedExceptionWithUser() |
|
658
|
|
|
{ |
|
659
|
|
|
$this->permissionResolver->setCurrentUserReference($this->anonymousUser); |
|
660
|
|
|
|
|
661
|
|
|
$this->expectException(UnauthorizedException::class); |
|
662
|
|
|
$this->expectExceptionMessageRegExp('/\'versionread\' \'content\'/'); |
|
663
|
|
|
|
|
664
|
|
|
$this->contentService->loadContentDrafts($this->administratorUser); |
|
665
|
|
|
} |
|
666
|
|
|
|
|
667
|
|
|
/** |
|
668
|
|
|
* Test for the updateContent() method. |
|
669
|
|
|
* |
|
670
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::updateContent() |
|
671
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
|
672
|
|
|
*/ |
|
673
|
|
|
public function testUpdateContentThrowsUnauthorizedException() |
|
674
|
|
|
{ |
|
675
|
|
|
$draftVersion2 = $this->createContentDraftVersion2(); |
|
676
|
|
|
|
|
677
|
|
|
$versionInfo = $draftVersion2->getVersionInfo(); |
|
678
|
|
|
|
|
679
|
|
|
$this->permissionResolver->setCurrentUserReference($this->anonymousUser); |
|
680
|
|
|
|
|
681
|
|
|
// Create an update struct and modify some fields |
|
682
|
|
|
$contentUpdate = $this->contentService->newContentUpdateStruct(); |
|
683
|
|
|
$contentUpdate->setField('name', 'An awesome² story about ezp.'); |
|
684
|
|
|
$contentUpdate->setField('name', 'An awesome²³ story about ezp.', 'eng-GB'); |
|
685
|
|
|
|
|
686
|
|
|
$contentUpdate->initialLanguageCode = 'eng-US'; |
|
687
|
|
|
|
|
688
|
|
|
$this->expectException(UnauthorizedException::class); |
|
689
|
|
|
/* TODO - the `content/edit` policy should be probably needed */ |
|
690
|
|
|
$this->expectExceptionMessageRegExp('/\'versionread\' \'content\'/'); |
|
691
|
|
|
|
|
692
|
|
|
$this->contentService->updateContent($versionInfo, $contentUpdate); |
|
693
|
|
|
} |
|
694
|
|
|
|
|
695
|
|
|
/** |
|
696
|
|
|
* Test for the publishVersion() method. |
|
697
|
|
|
* |
|
698
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
|
699
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
|
700
|
|
|
*/ |
|
701
|
|
View Code Duplication |
public function testPublishVersionThrowsUnauthorizedException() |
|
702
|
|
|
{ |
|
703
|
|
|
$draft = $this->createContentDraftVersion1(); |
|
704
|
|
|
|
|
705
|
|
|
$this->permissionResolver->setCurrentUserReference($this->anonymousUser); |
|
706
|
|
|
|
|
707
|
|
|
$this->expectException(UnauthorizedException::class); |
|
708
|
|
|
$this->expectExceptionMessageRegExp('/\'publish\' \'content\'/'); |
|
709
|
|
|
|
|
710
|
|
|
$this->contentService->publishVersion($draft->getVersionInfo()); |
|
711
|
|
|
} |
|
712
|
|
|
|
|
713
|
|
|
/** |
|
714
|
|
|
* Test for the deleteVersion() method. |
|
715
|
|
|
* |
|
716
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::deleteVersion() |
|
717
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteVersion |
|
718
|
|
|
*/ |
|
719
|
|
View Code Duplication |
public function testDeleteVersionThrowsUnauthorizedException() |
|
720
|
|
|
{ |
|
721
|
|
|
$draft = $this->createContentDraftVersion1(); |
|
722
|
|
|
|
|
723
|
|
|
$this->permissionResolver->setCurrentUserReference($this->anonymousUser); |
|
724
|
|
|
|
|
725
|
|
|
$this->expectException(UnauthorizedException::class); |
|
726
|
|
|
$this->expectExceptionMessageRegExp('/\'versionremove\' \'content\'/'); |
|
727
|
|
|
|
|
728
|
|
|
$this->contentService->deleteVersion($draft->getVersionInfo()); |
|
729
|
|
|
} |
|
730
|
|
|
|
|
731
|
|
|
/** |
|
732
|
|
|
* Test for the loadVersions() method. |
|
733
|
|
|
* |
|
734
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadVersions() |
|
735
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersions |
|
736
|
|
|
*/ |
|
737
|
|
View Code Duplication |
public function testLoadVersionsThrowsUnauthorizedException() |
|
738
|
|
|
{ |
|
739
|
|
|
$contentVersion2 = $this->createContentVersion2(); |
|
740
|
|
|
|
|
741
|
|
|
$contentInfo = $contentVersion2->contentInfo; |
|
742
|
|
|
|
|
743
|
|
|
$this->permissionResolver->setCurrentUserReference($this->anonymousUser); |
|
744
|
|
|
|
|
745
|
|
|
$this->expectException(UnauthorizedException::class); |
|
746
|
|
|
$this->expectExceptionMessageRegExp('/\'versionread\' \'content\'/'); |
|
747
|
|
|
|
|
748
|
|
|
$this->contentService->loadVersions($contentInfo); |
|
749
|
|
|
} |
|
750
|
|
|
|
|
751
|
|
|
/** |
|
752
|
|
|
* Test for the copyContent() method. |
|
753
|
|
|
* |
|
754
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::copyContent() |
|
755
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCopyContent |
|
756
|
|
|
*/ |
|
757
|
|
|
public function testCopyContentThrowsUnauthorizedException() |
|
758
|
|
|
{ |
|
759
|
|
|
$parentLocationId = $this->generateId('location', 52); |
|
760
|
|
|
|
|
761
|
|
|
$locationService = $this->repository->getLocationService(); |
|
762
|
|
|
|
|
763
|
|
|
$contentVersion2 = $this->createMultipleLanguageContentVersion2(); |
|
764
|
|
|
|
|
765
|
|
|
$contentInfo = $contentVersion2->contentInfo; |
|
766
|
|
|
|
|
767
|
|
|
$this->permissionResolver->setCurrentUserReference($this->anonymousUser); |
|
768
|
|
|
|
|
769
|
|
|
// Configure new target location |
|
770
|
|
|
$targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId); |
|
771
|
|
|
|
|
772
|
|
|
$targetLocationCreate->priority = 42; |
|
773
|
|
|
$targetLocationCreate->hidden = true; |
|
774
|
|
|
$targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789'; |
|
775
|
|
|
$targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID; |
|
776
|
|
|
$targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC; |
|
777
|
|
|
|
|
778
|
|
|
$this->expectException(UnauthorizedException::class); |
|
779
|
|
|
$this->expectExceptionMessageRegExp('/\'read\' \'content\'/'); |
|
780
|
|
|
|
|
781
|
|
|
$this->contentService->copyContent( |
|
782
|
|
|
$contentInfo, |
|
783
|
|
|
$targetLocationCreate |
|
784
|
|
|
); |
|
785
|
|
|
} |
|
786
|
|
|
|
|
787
|
|
|
/** |
|
788
|
|
|
* Test for the copyContent() method. |
|
789
|
|
|
* |
|
790
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::copyContent($contentInfo, $destinationLocationCreateStruct, $versionInfo) |
|
791
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCopyContentWithGivenVersion |
|
792
|
|
|
*/ |
|
793
|
|
|
public function testCopyContentThrowsUnauthorizedExceptionWithGivenVersion() |
|
794
|
|
|
{ |
|
795
|
|
|
$parentLocationId = $this->generateId('location', 52); |
|
796
|
|
|
|
|
797
|
|
|
$contentVersion2 = $this->createContentVersion2(); |
|
798
|
|
|
|
|
799
|
|
|
$this->permissionResolver->setCurrentUserReference($this->anonymousUser); |
|
800
|
|
|
|
|
801
|
|
|
// Configure new target location |
|
802
|
|
|
$targetLocationCreate = $this->repository->getLocationService()->newLocationCreateStruct($parentLocationId); |
|
803
|
|
|
|
|
804
|
|
|
$targetLocationCreate->priority = 42; |
|
805
|
|
|
$targetLocationCreate->hidden = true; |
|
806
|
|
|
$targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789'; |
|
807
|
|
|
$targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID; |
|
808
|
|
|
$targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC; |
|
809
|
|
|
|
|
810
|
|
|
$this->expectException(UnauthorizedException::class); |
|
811
|
|
|
$this->expectExceptionMessageRegExp('/\'versionread\' \'content\'/'); |
|
812
|
|
|
|
|
813
|
|
|
$this->contentService->copyContent( |
|
814
|
|
|
$contentVersion2->contentInfo, |
|
815
|
|
|
$targetLocationCreate, |
|
816
|
|
|
$this->contentService->loadVersionInfo($contentVersion2->contentInfo, 1) |
|
817
|
|
|
); |
|
818
|
|
|
} |
|
819
|
|
|
|
|
820
|
|
|
/** |
|
821
|
|
|
* Test for the loadRelations() method. |
|
822
|
|
|
* |
|
823
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadRelations() |
|
824
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadRelations |
|
825
|
|
|
*/ |
|
826
|
|
View Code Duplication |
public function testLoadRelationsThrowsUnauthorizedException() |
|
827
|
|
|
{ |
|
828
|
|
|
$mediaEditor = $this->createMediaUserVersion1(); |
|
829
|
|
|
|
|
830
|
|
|
$setupRemoteId = '241d538ce310074e602f29f49e44e938'; |
|
831
|
|
|
|
|
832
|
|
|
$versionInfo = $this->contentService->loadVersionInfo( |
|
833
|
|
|
$this->contentService->loadContentInfoByRemoteId( |
|
834
|
|
|
$setupRemoteId |
|
835
|
|
|
) |
|
836
|
|
|
); |
|
837
|
|
|
|
|
838
|
|
|
$this->permissionResolver->setCurrentUserReference($mediaEditor); |
|
839
|
|
|
|
|
840
|
|
|
$this->expectException(UnauthorizedException::class); |
|
841
|
|
|
$this->expectExceptionMessageRegExp('/\'read\' \'content\'/'); |
|
842
|
|
|
|
|
843
|
|
|
$this->contentService->loadRelations($versionInfo); |
|
844
|
|
|
} |
|
845
|
|
|
|
|
846
|
|
|
/** |
|
847
|
|
|
* Test for the loadRelations() method. |
|
848
|
|
|
* |
|
849
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadRelations() |
|
850
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadRelations |
|
851
|
|
|
*/ |
|
852
|
|
View Code Duplication |
public function testLoadRelationsForDraftVersionThrowsUnauthorizedException() |
|
853
|
|
|
{ |
|
854
|
|
|
$draft = $this->createContentDraftVersion1(); |
|
855
|
|
|
|
|
856
|
|
|
$this->permissionResolver->setCurrentUserReference($this->anonymousUser); |
|
857
|
|
|
|
|
858
|
|
|
$this->expectException(UnauthorizedException::class); |
|
859
|
|
|
$this->expectExceptionMessageRegExp('/\'versionread\' \'content\'/'); |
|
860
|
|
|
|
|
861
|
|
|
$this->contentService->loadRelations($draft->versionInfo); |
|
862
|
|
|
} |
|
863
|
|
|
|
|
864
|
|
|
/** |
|
865
|
|
|
* Test for the loadReverseRelations() method. |
|
866
|
|
|
* |
|
867
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadReverseRelations() |
|
868
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadReverseRelations |
|
869
|
|
|
*/ |
|
870
|
|
|
public function testLoadReverseRelationsThrowsUnauthorizedException() |
|
871
|
|
|
{ |
|
872
|
|
|
$mediaEditor = $this->createMediaUserVersion1(); |
|
873
|
|
|
|
|
874
|
|
|
$mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262'; |
|
875
|
|
|
|
|
876
|
|
|
$contentInfo = $this->contentService->loadContentInfoByRemoteId($mediaRemoteId); |
|
877
|
|
|
|
|
878
|
|
|
$this->permissionResolver->setCurrentUserReference($mediaEditor); |
|
879
|
|
|
|
|
880
|
|
|
$this->expectException(UnauthorizedException::class); |
|
881
|
|
|
$this->expectExceptionMessageRegExp('/\'reverserelatedlist\' \'content\'/'); |
|
882
|
|
|
|
|
883
|
|
|
$this->contentService->loadReverseRelations($contentInfo); |
|
884
|
|
|
} |
|
885
|
|
|
|
|
886
|
|
|
/** |
|
887
|
|
|
* Test for the addRelation() method. |
|
888
|
|
|
* |
|
889
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::addRelation() |
|
890
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation |
|
891
|
|
|
*/ |
|
892
|
|
View Code Duplication |
public function testAddRelationThrowsUnauthorizedException() |
|
893
|
|
|
{ |
|
894
|
|
|
$mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262'; |
|
895
|
|
|
|
|
896
|
|
|
$draft = $this->createContentDraftVersion1(); |
|
897
|
|
|
|
|
898
|
|
|
$versionInfo = $draft->getVersionInfo(); |
|
899
|
|
|
|
|
900
|
|
|
$media = $this->contentService->loadContentInfoByRemoteId($mediaRemoteId); |
|
901
|
|
|
|
|
902
|
|
|
$this->permissionResolver->setCurrentUserReference($this->anonymousUser); |
|
903
|
|
|
|
|
904
|
|
|
$this->expectException(UnauthorizedException::class); |
|
905
|
|
|
$this->expectExceptionMessageRegExp('/\'versionread\' \'content\'/'); |
|
906
|
|
|
|
|
907
|
|
|
$this->contentService->addRelation( |
|
908
|
|
|
$versionInfo, |
|
909
|
|
|
$media |
|
910
|
|
|
); |
|
911
|
|
|
} |
|
912
|
|
|
|
|
913
|
|
|
/** |
|
914
|
|
|
* Test for the deleteRelation() method. |
|
915
|
|
|
* |
|
916
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::deleteRelation() |
|
917
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteRelation |
|
918
|
|
|
*/ |
|
919
|
|
|
public function testDeleteRelationThrowsUnauthorizedException() |
|
920
|
|
|
{ |
|
921
|
|
|
$mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262'; |
|
922
|
|
|
$demoDesignRemoteId = '8b8b22fe3c6061ed500fbd2b377b885f'; |
|
923
|
|
|
|
|
924
|
|
|
$draft = $this->createContentDraftVersion1(); |
|
925
|
|
|
|
|
926
|
|
|
$versionInfo = $draft->getVersionInfo(); |
|
927
|
|
|
|
|
928
|
|
|
$media = $this->contentService->loadContentInfoByRemoteId($mediaRemoteId); |
|
929
|
|
|
$demoDesign = $this->contentService->loadContentInfoByRemoteId($demoDesignRemoteId); |
|
930
|
|
|
|
|
931
|
|
|
// Establish some relations |
|
932
|
|
|
$this->contentService->addRelation($draft->getVersionInfo(), $media); |
|
933
|
|
|
$this->contentService->addRelation($draft->getVersionInfo(), $demoDesign); |
|
934
|
|
|
|
|
935
|
|
|
$this->permissionResolver->setCurrentUserReference($this->anonymousUser); |
|
936
|
|
|
|
|
937
|
|
|
$this->expectException(UnauthorizedException::class); |
|
938
|
|
|
$this->expectExceptionMessageRegExp('/\'versionread\' \'content\'/'); |
|
939
|
|
|
|
|
940
|
|
|
$this->contentService->deleteRelation($versionInfo, $media); |
|
941
|
|
|
} |
|
942
|
|
|
|
|
943
|
|
|
/** |
|
944
|
|
|
* Creates a pseudo editor with a limitation to objects in the "Media/Images" |
|
945
|
|
|
* subtree. |
|
946
|
|
|
* |
|
947
|
|
|
* @return \eZ\Publish\API\Repository\Values\User\User |
|
948
|
|
|
*/ |
|
949
|
|
|
private function createAnonymousWithEditorRole() |
|
950
|
|
|
{ |
|
951
|
|
|
$roleService = $this->repository->getRoleService(); |
|
952
|
|
|
|
|
953
|
|
|
$user = $this->anonymousUser; |
|
954
|
|
|
$role = $roleService->loadRoleByIdentifier('Editor'); |
|
955
|
|
|
|
|
956
|
|
|
// Assign "Editor" role with limitation to "Media/Images" |
|
957
|
|
|
$roleService->assignRoleToUser( |
|
958
|
|
|
$role, |
|
959
|
|
|
$user, |
|
960
|
|
|
new \eZ\Publish\API\Repository\Values\User\Limitation\SubtreeLimitation( |
|
961
|
|
|
[ |
|
962
|
|
|
'limitationValues' => ['/1/43/51/'], |
|
963
|
|
|
] |
|
964
|
|
|
) |
|
965
|
|
|
); |
|
966
|
|
|
/* END: Use Case */ |
|
967
|
|
|
|
|
968
|
|
|
return $this->userService->loadUser($user->id); |
|
969
|
|
|
} |
|
970
|
|
|
|
|
971
|
|
|
/** |
|
972
|
|
|
* Test that for an user that doesn't have access (read permissions) to an |
|
973
|
|
|
* related object, executing loadRelations() would not throw any exception, |
|
974
|
|
|
* only that the non-readable related object(s) won't be loaded. |
|
975
|
|
|
* |
|
976
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadRelations() |
|
977
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation |
|
978
|
|
|
*/ |
|
979
|
|
|
public function testLoadRelationsWithUnauthorizedRelations() |
|
980
|
|
|
{ |
|
981
|
|
|
$mainLanguage = 'eng-GB'; |
|
982
|
|
|
|
|
983
|
|
|
$contentTypeService = $this->repository->getContentTypeService(); |
|
984
|
|
|
$locationService = $this->repository->getLocationService(); |
|
985
|
|
|
$sectionService = $this->repository->getSectionService(); |
|
986
|
|
|
|
|
987
|
|
|
// set the current user as admin to create the environment to test |
|
988
|
|
|
$this->permissionResolver->setCurrentUserReference($this->administratorUser); |
|
989
|
|
|
|
|
990
|
|
|
// create section |
|
991
|
|
|
// since anonymous users have their read permissions to specific sections |
|
992
|
|
|
// the created section will be non-readable to them |
|
993
|
|
|
$sectionCreate = $sectionService->newSectionCreateStruct(); |
|
994
|
|
|
$sectionCreate->identifier = 'private'; |
|
995
|
|
|
$sectionCreate->name = 'Private Section'; |
|
996
|
|
|
$section = $sectionService->createSection($sectionCreate); |
|
997
|
|
|
|
|
998
|
|
|
// create objects for testing |
|
999
|
|
|
// here we will create 4 objects which 2 will be readable by an anonymous |
|
1000
|
|
|
// user, and the other 2 wont these last 2 will go to a private section |
|
1001
|
|
|
// where anonymous can't read, just like: |
|
1002
|
|
|
// readable object 1 -> /Main Folder |
|
1003
|
|
|
// readable object 2 -> /Main Folder/Available Folder |
|
1004
|
|
|
// non-readable object 1 -> /Restricted Folder |
|
1005
|
|
|
// non-readable object 2 -> /Restricted Folder/Unavailable Folder |
|
1006
|
|
|
// |
|
1007
|
|
|
// here is created - readable object 1 -> /Main Folder |
|
1008
|
|
|
$mainFolder = $this->createFolder([$mainLanguage => 'Main Folder'], 2); |
|
1009
|
|
|
|
|
1010
|
|
|
// here is created readable object 2 -> /Main Folder/Available Folder |
|
1011
|
|
|
$availableFolder = $this->createFolder( |
|
1012
|
|
|
[$mainLanguage => 'Avaliable Folder'], |
|
1013
|
|
|
$mainFolder->contentInfo->mainLocationId |
|
1014
|
|
|
); |
|
1015
|
|
|
|
|
1016
|
|
|
// here is created the non-readable object 1 -> /Restricted Folder |
|
1017
|
|
|
$restrictedFolderCreate = $this->contentService->newContentCreateStruct( |
|
1018
|
|
|
$contentTypeService->loadContentTypeByIdentifier('folder'), |
|
1019
|
|
|
$mainLanguage |
|
1020
|
|
|
); |
|
1021
|
|
|
$restrictedFolderCreate->setField('name', 'Restricted Folder'); |
|
1022
|
|
|
$restrictedFolderCreate->sectionId = $section->id; |
|
1023
|
|
|
$restrictedFolder = $this->contentService->publishVersion( |
|
1024
|
|
|
$this->contentService->createContent( |
|
1025
|
|
|
$restrictedFolderCreate, |
|
1026
|
|
|
[$locationService->newLocationCreateStruct(2)] |
|
1027
|
|
|
)->versionInfo |
|
1028
|
|
|
); |
|
1029
|
|
|
|
|
1030
|
|
|
// here is created non-readable object 2 -> /Restricted Folder/Unavailable Folder |
|
1031
|
|
|
$unavailableFolder = $this->createFolder( |
|
1032
|
|
|
[$mainLanguage => 'Unavailable Folder'], |
|
1033
|
|
|
$restrictedFolder->contentInfo->mainLocationId |
|
1034
|
|
|
); |
|
1035
|
|
|
|
|
1036
|
|
|
// this will be our test object, which will have all the relations (as source) |
|
1037
|
|
|
// and it is readable by the anonymous user |
|
1038
|
|
|
$testFolderCreate = $this->contentService->newContentCreateStruct( |
|
1039
|
|
|
$contentTypeService->loadContentTypeByIdentifier('folder'), |
|
1040
|
|
|
$mainLanguage |
|
1041
|
|
|
); |
|
1042
|
|
|
$testFolderCreate->setField('name', 'Test Folder'); |
|
1043
|
|
|
$testFolderDraft = $this->contentService->createContent( |
|
1044
|
|
|
$testFolderCreate, |
|
1045
|
|
|
[$locationService->newLocationCreateStruct(2)] |
|
1046
|
|
|
)->versionInfo; |
|
1047
|
|
|
|
|
1048
|
|
|
// add relations to test folder (as source) |
|
1049
|
|
|
// the first 2 will be read by the user |
|
1050
|
|
|
// and the other 2 wont |
|
1051
|
|
|
// |
|
1052
|
|
|
// create relation from Test Folder to Main Folder |
|
1053
|
|
|
$mainRelation = $this->contentService->addRelation( |
|
1054
|
|
|
$testFolderDraft, |
|
1055
|
|
|
$mainFolder->getVersionInfo()->getContentInfo() |
|
1056
|
|
|
); |
|
1057
|
|
|
// create relation from Test Folder to Available Folder |
|
1058
|
|
|
$availableRelation = $this->contentService->addRelation( |
|
1059
|
|
|
$testFolderDraft, |
|
1060
|
|
|
$availableFolder->getVersionInfo()->getContentInfo() |
|
1061
|
|
|
); |
|
1062
|
|
|
// create relation from Test Folder to Restricted Folder |
|
1063
|
|
|
$this->contentService->addRelation( |
|
1064
|
|
|
$testFolderDraft, |
|
1065
|
|
|
$restrictedFolder->getVersionInfo()->getContentInfo() |
|
1066
|
|
|
); |
|
1067
|
|
|
//create relation from Test Folder to Unavailable Folder |
|
1068
|
|
|
$this->contentService->addRelation( |
|
1069
|
|
|
$testFolderDraft, |
|
1070
|
|
|
$unavailableFolder->getVersionInfo()->getContentInfo() |
|
1071
|
|
|
); |
|
1072
|
|
|
|
|
1073
|
|
|
// publish Test Folder |
|
1074
|
|
|
$testFolder = $this->contentService->publishVersion($testFolderDraft); |
|
1075
|
|
|
|
|
1076
|
|
|
// set the current user to be an anonymous user since we want to test that |
|
1077
|
|
|
// if the user doesn't have access to an related object that object wont |
|
1078
|
|
|
// be loaded and no exception will be thrown |
|
1079
|
|
|
$this->permissionResolver->setCurrentUserReference($this->anonymousUser); |
|
1080
|
|
|
|
|
1081
|
|
|
// finaly load relations ( verify no exception is thrown ) |
|
1082
|
|
|
$actualRelations = $this->contentService->loadRelations($testFolder->getVersionInfo()); |
|
1083
|
|
|
|
|
1084
|
|
|
// assert results |
|
1085
|
|
|
// verify that the only expected relations are from the 2 readable objects |
|
1086
|
|
|
// Main Folder and Available Folder |
|
1087
|
|
|
$expectedRelations = [ |
|
1088
|
|
|
$mainRelation->destinationContentInfo->id => $mainRelation, |
|
1089
|
|
|
$availableRelation->destinationContentInfo->id => $availableRelation, |
|
1090
|
|
|
]; |
|
1091
|
|
|
|
|
1092
|
|
|
// assert there are as many expected relations as actual ones |
|
1093
|
|
|
$this->assertEquals( |
|
1094
|
|
|
count($expectedRelations), |
|
1095
|
|
|
count($actualRelations), |
|
1096
|
|
|
"Expected '" . count($expectedRelations) |
|
1097
|
|
|
. "' relations found '" . count($actualRelations) . "'" |
|
1098
|
|
|
); |
|
1099
|
|
|
|
|
1100
|
|
|
// assert each relation |
|
1101
|
|
|
foreach ($actualRelations as $relation) { |
|
1102
|
|
|
$destination = $relation->destinationContentInfo; |
|
1103
|
|
|
$expected = $expectedRelations[$destination->id]->destinationContentInfo; |
|
1104
|
|
|
$this->assertNotEmpty($expected, "Non expected relation with '{$destination->id}' id found"); |
|
1105
|
|
|
$this->assertEquals( |
|
1106
|
|
|
$expected->id, |
|
1107
|
|
|
$destination->id, |
|
1108
|
|
|
"Expected relation with '{$expected->id}' id found '{$destination->id}' id" |
|
1109
|
|
|
); |
|
1110
|
|
|
$this->assertEquals( |
|
1111
|
|
|
$expected->name, |
|
1112
|
|
|
$destination->name, |
|
1113
|
|
|
"Expected relation with '{$expected->name}' name found '{$destination->name}' name" |
|
1114
|
|
|
); |
|
1115
|
|
|
|
|
1116
|
|
|
// remove from list |
|
1117
|
|
|
unset($expectedRelations[$destination->id]); |
|
1118
|
|
|
} |
|
1119
|
|
|
|
|
1120
|
|
|
// verify all expected relations were found |
|
1121
|
|
|
$this->assertEquals( |
|
1122
|
|
|
0, |
|
1123
|
|
|
count($expectedRelations), |
|
1124
|
|
|
"Expected to find '" . (count($expectedRelations) + count($actualRelations)) |
|
1125
|
|
|
. "' relations found '" . count($actualRelations) . "'" |
|
1126
|
|
|
); |
|
1127
|
|
|
} |
|
1128
|
|
|
|
|
1129
|
|
|
/** |
|
1130
|
|
|
* Test copying Content to the authorized Location (limited by policies). |
|
1131
|
|
|
*/ |
|
1132
|
|
|
public function testCopyContentToAuthorizedLocation() |
|
1133
|
|
|
{ |
|
1134
|
|
|
$locationService = $this->repository->getLocationService(); |
|
1135
|
|
|
$roleService = $this->repository->getRoleService(); |
|
1136
|
|
|
|
|
1137
|
|
|
// Create and publish folders for the test case |
|
1138
|
|
|
$folderDraft = $this->createContentDraft('folder', 2, ['name' => 'Folder1']); |
|
1139
|
|
|
$this->contentService->publishVersion($folderDraft->versionInfo); |
|
1140
|
|
|
$authorizedFolderDraft = $this->createContentDraft('folder', 2, ['name' => 'AuthorizedFolder']); |
|
1141
|
|
|
$authorizedFolder = $this->contentService->publishVersion($authorizedFolderDraft->versionInfo); |
|
1142
|
|
|
|
|
1143
|
|
|
// Prepare Role for the test case |
|
1144
|
|
|
$roleIdentifier = 'authorized_folder'; |
|
1145
|
|
|
$roleCreateStruct = $roleService->newRoleCreateStruct($roleIdentifier); |
|
1146
|
|
|
$locationLimitation = new LocationLimitation( |
|
1147
|
|
|
['limitationValues' => [$authorizedFolder->contentInfo->mainLocationId]] |
|
1148
|
|
|
); |
|
1149
|
|
|
$roleCreateStruct->addPolicy($roleService->newPolicyCreateStruct('content', 'read')); |
|
1150
|
|
|
$roleCreateStruct->addPolicy($roleService->newPolicyCreateStruct('content', 'versionread')); |
|
1151
|
|
|
$roleCreateStruct->addPolicy($roleService->newPolicyCreateStruct('content', 'manage_locations')); |
|
1152
|
|
|
|
|
1153
|
|
|
$policyCreateStruct = $roleService->newPolicyCreateStruct('content', 'create'); |
|
1154
|
|
|
$policyCreateStruct->addLimitation($locationLimitation); |
|
1155
|
|
|
$roleCreateStruct->addPolicy($policyCreateStruct); |
|
1156
|
|
|
|
|
1157
|
|
|
$roleDraft = $roleService->createRole($roleCreateStruct); |
|
1158
|
|
|
$roleService->publishRoleDraft($roleDraft); |
|
1159
|
|
|
|
|
1160
|
|
|
// Create a user with that Role |
|
1161
|
|
|
$user = $this->createCustomUserVersion1('Users', $roleIdentifier); |
|
1162
|
|
|
$this->permissionResolver->setCurrentUserReference($user); |
|
1163
|
|
|
|
|
1164
|
|
|
// Test copying Content to the authorized Location |
|
1165
|
|
|
$this->contentService->copyContent( |
|
1166
|
|
|
$authorizedFolder->contentInfo, |
|
1167
|
|
|
$locationService->newLocationCreateStruct( |
|
1168
|
|
|
$authorizedFolder->contentInfo->mainLocationId |
|
1169
|
|
|
) |
|
1170
|
|
|
); |
|
1171
|
|
|
} |
|
1172
|
|
|
|
|
1173
|
|
|
/** |
|
1174
|
|
|
* Test copying Content to the authorized Location (limited by policies). |
|
1175
|
|
|
*/ |
|
1176
|
|
|
public function testCopyContentToAuthorizedLocationWithSubtreeLimitation() |
|
1177
|
|
|
{ |
|
1178
|
|
|
$locationService = $this->repository->getLocationService(); |
|
1179
|
|
|
|
|
1180
|
|
|
// Create and publish folders for the test case |
|
1181
|
|
|
$folderDraft = $this->createContentDraft('folder', 2, ['name' => 'Folder1']); |
|
1182
|
|
|
$this->contentService->publishVersion($folderDraft->versionInfo); |
|
1183
|
|
|
$authorizedFolderDraft = $this->createContentDraft('folder', 2, ['name' => 'AuthorizedFolder']); |
|
1184
|
|
|
$authorizedFolder = $this->contentService->publishVersion($authorizedFolderDraft->versionInfo); |
|
1185
|
|
|
|
|
1186
|
|
|
// Prepare Role for the test case |
|
1187
|
|
|
$roleIdentifier = 'authorized_subree'; |
|
1188
|
|
|
$subtreeLimitation = new SubtreeLimitation( |
|
1189
|
|
|
['limitationValues' => ['/1/2']] |
|
1190
|
|
|
); |
|
1191
|
|
|
$policiesData = [ |
|
1192
|
|
|
[ |
|
1193
|
|
|
'module' => 'content', |
|
1194
|
|
|
'function' => 'read', |
|
1195
|
|
|
'limitations' => [$subtreeLimitation], |
|
1196
|
|
|
], |
|
1197
|
|
|
[ |
|
1198
|
|
|
'module' => 'content', |
|
1199
|
|
|
'function' => 'versionread', |
|
1200
|
|
|
'limitations' => [$subtreeLimitation], |
|
1201
|
|
|
], |
|
1202
|
|
|
[ |
|
1203
|
|
|
'module' => 'content', |
|
1204
|
|
|
'function' => 'create', |
|
1205
|
|
|
'limitations' => [$subtreeLimitation], |
|
1206
|
|
|
], |
|
1207
|
|
|
[ |
|
1208
|
|
|
'module' => 'content', |
|
1209
|
|
|
'function' => 'manage_locations', |
|
1210
|
|
|
], |
|
1211
|
|
|
]; |
|
1212
|
|
|
|
|
1213
|
|
|
$this->createRoleWithPolicies($roleIdentifier, $policiesData); |
|
1214
|
|
|
|
|
1215
|
|
|
// Create a user with that Role |
|
1216
|
|
|
$user = $this->createCustomUserVersion1('Users', $roleIdentifier); |
|
1217
|
|
|
$this->permissionResolver->setCurrentUserReference($user); |
|
1218
|
|
|
|
|
1219
|
|
|
// Test copying Content to the authorized Location |
|
1220
|
|
|
$this->contentService->copyContent( |
|
1221
|
|
|
$authorizedFolder->contentInfo, |
|
1222
|
|
|
$locationService->newLocationCreateStruct( |
|
1223
|
|
|
$authorizedFolder->contentInfo->mainLocationId |
|
1224
|
|
|
) |
|
1225
|
|
|
); |
|
1226
|
|
|
} |
|
1227
|
|
|
|
|
1228
|
|
|
/** |
|
1229
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
|
1230
|
|
|
* |
|
1231
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
|
1232
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
|
1233
|
|
|
*/ |
|
1234
|
|
|
private function getContentInfoForAnonymousUser(): ContentInfo |
|
1235
|
|
|
{ |
|
1236
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
|
1237
|
|
|
|
|
1238
|
|
|
return $this->contentService->loadContentInfo($anonymousUserId); |
|
1239
|
|
|
} |
|
1240
|
|
|
|
|
1241
|
|
|
private function setRestrictedEditorUser(): void |
|
1242
|
|
|
{ |
|
1243
|
|
|
$this->permissionResolver->setCurrentUserReference($this->createAnonymousWithEditorRole()); |
|
1244
|
|
|
} |
|
1245
|
|
|
} |
|
1246
|
|
|
|