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\Values\Content\Location; |
12
|
|
|
use eZ\Publish\API\Repository\Values\User\Limitation\LocationLimitation; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Test case for operations in the ContentServiceAuthorization using in memory storage. |
16
|
|
|
* |
17
|
|
|
* @see eZ\Publish\API\Repository\ContentService |
18
|
|
|
* @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testLoadAnonymousUser |
19
|
|
|
* @group integration |
20
|
|
|
* @group authorization |
21
|
|
|
*/ |
22
|
|
|
class ContentServiceAuthorizationTest extends BaseContentServiceTest |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Test for the createContent() method. |
26
|
|
|
* |
27
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContent() |
28
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
29
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
30
|
|
|
*/ |
31
|
|
View Code Duplication |
public function testCreateContentThrowsUnauthorizedException() |
32
|
|
|
{ |
33
|
|
|
if ($this->isVersion4()) { |
34
|
|
|
$this->markTestSkipped('This test requires eZ Publish 5'); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
$repository = $this->getRepository(); |
38
|
|
|
|
39
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
40
|
|
|
/* BEGIN: Use Case */ |
41
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
42
|
|
|
// demo installation |
43
|
|
|
// Load the user service |
44
|
|
|
$userService = $repository->getUserService(); |
45
|
|
|
|
46
|
|
|
// Set anonymous user |
47
|
|
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
|
|
|
48
|
|
|
|
49
|
|
|
$contentTypeService = $repository->getContentTypeService(); |
50
|
|
|
|
51
|
|
|
$contentType = $contentTypeService->loadContentTypeByIdentifier('forum'); |
52
|
|
|
|
53
|
|
|
$contentService = $repository->getContentService(); |
54
|
|
|
|
55
|
|
|
$contentCreate = $contentService->newContentCreateStruct($contentType, 'eng-US'); |
56
|
|
|
$contentCreate->setField('name', 'Awesome Sindelfingen forum'); |
57
|
|
|
|
58
|
|
|
$contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; |
59
|
|
|
$contentCreate->alwaysAvailable = true; |
60
|
|
|
|
61
|
|
|
// This call will fail with a "UnauthorizedException" |
62
|
|
|
$contentService->createContent($contentCreate); |
63
|
|
|
/* END: Use Case */ |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Test for the createContent() method. |
68
|
|
|
* |
69
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContent($contentCreateStruct, $locationCreateStructs) |
70
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
71
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
72
|
|
|
*/ |
73
|
|
|
public function testCreateContentThrowsUnauthorizedExceptionWithSecondParameter() |
74
|
|
|
{ |
75
|
|
|
$repository = $this->getRepository(); |
76
|
|
|
|
77
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
78
|
|
|
/* BEGIN: Use Case */ |
79
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
80
|
|
|
// demo installation |
81
|
|
|
// Load the user service |
82
|
|
|
$userService = $repository->getUserService(); |
83
|
|
|
|
84
|
|
|
// Set anonymous user |
85
|
|
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
|
|
|
86
|
|
|
|
87
|
|
|
$this->createContentDraftVersion1(); |
88
|
|
|
/* END: Use Case */ |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Test for the loadContentInfo() method. |
93
|
|
|
* |
94
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentInfo() |
95
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
96
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
97
|
|
|
*/ |
98
|
|
|
public function testLoadContentInfoThrowsUnauthorizedException() |
99
|
|
|
{ |
100
|
|
|
$repository = $this->getRepository(); |
101
|
|
|
|
102
|
|
|
$contentId = $this->generateId('object', 10); |
103
|
|
|
/* BEGIN: Use Case */ |
104
|
|
|
$contentService = $repository->getContentService(); |
105
|
|
|
|
106
|
|
|
$pseudoEditor = $this->createAnonymousWithEditorRole(); |
107
|
|
|
|
108
|
|
|
// Set restricted editor user |
109
|
|
|
$repository->setCurrentUser($pseudoEditor); |
|
|
|
|
110
|
|
|
|
111
|
|
|
// This call will fail with a "UnauthorizedException" |
112
|
|
|
// $contentId contains a content object ID not accessible for anonymous |
113
|
|
|
$contentService->loadContentInfo($contentId); |
114
|
|
|
/* END: Use Case */ |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Test for the loadContentInfoByRemoteId() method. |
119
|
|
|
* |
120
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentInfoByRemoteId() |
121
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
122
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfoByRemoteId |
123
|
|
|
*/ |
124
|
|
View Code Duplication |
public function testLoadContentInfoByRemoteIdThrowsUnauthorizedException() |
125
|
|
|
{ |
126
|
|
|
$repository = $this->getRepository(); |
127
|
|
|
|
128
|
|
|
/* BEGIN: Use Case */ |
129
|
|
|
// RemoteId of the "Anonymous User" in an eZ Publish demo installation |
130
|
|
|
$anonymousRemoteId = 'faaeb9be3bd98ed09f606fc16d144eca'; |
131
|
|
|
|
132
|
|
|
$contentService = $repository->getContentService(); |
133
|
|
|
|
134
|
|
|
$pseudoEditor = $this->createAnonymousWithEditorRole(); |
135
|
|
|
|
136
|
|
|
// Set restricted editor user |
137
|
|
|
$repository->setCurrentUser($pseudoEditor); |
|
|
|
|
138
|
|
|
|
139
|
|
|
// This call will fail with a "UnauthorizedException" |
140
|
|
|
$contentService->loadContentInfoByRemoteId($anonymousRemoteId); |
141
|
|
|
/* END: Use Case */ |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Test for the loadVersionInfo() method. |
146
|
|
|
* |
147
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadVersionInfo() |
148
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
149
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo |
150
|
|
|
*/ |
151
|
|
|
public function testLoadVersionInfoThrowsUnauthorizedException() |
152
|
|
|
{ |
153
|
|
|
$repository = $this->getRepository(); |
154
|
|
|
|
155
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
156
|
|
|
/* BEGIN: Use Case */ |
157
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
158
|
|
|
// demo installation |
159
|
|
|
|
160
|
|
|
$contentService = $repository->getContentService(); |
161
|
|
|
|
162
|
|
|
// Load the ContentInfo for "Anonymous User" |
163
|
|
|
$contentInfo = $contentService->loadContentInfo($anonymousUserId); |
164
|
|
|
|
165
|
|
|
$pseudoEditor = $this->createAnonymousWithEditorRole(); |
166
|
|
|
|
167
|
|
|
// Set restricted editor user |
168
|
|
|
$repository->setCurrentUser($pseudoEditor); |
|
|
|
|
169
|
|
|
|
170
|
|
|
// This call will fail with a "UnauthorizedException" |
171
|
|
|
$contentService->loadVersionInfo($contentInfo); |
172
|
|
|
/* END: Use Case */ |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Test for the loadVersionInfo() method. |
177
|
|
|
* |
178
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadVersionInfo($contentInfo, $versionNo) |
179
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
180
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoWithSecondParameter |
181
|
|
|
*/ |
182
|
|
|
public function testLoadVersionInfoThrowsUnauthorizedExceptionWithSecondParameter() |
183
|
|
|
{ |
184
|
|
|
$repository = $this->getRepository(); |
185
|
|
|
|
186
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
187
|
|
|
/* BEGIN: Use Case */ |
188
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
189
|
|
|
// demo installation |
190
|
|
|
|
191
|
|
|
$contentService = $repository->getContentService(); |
192
|
|
|
|
193
|
|
|
// Load the ContentInfo for "Anonymous User" |
194
|
|
|
$contentInfo = $contentService->loadContentInfo($anonymousUserId); |
195
|
|
|
|
196
|
|
|
$pseudoEditor = $this->createAnonymousWithEditorRole(); |
197
|
|
|
|
198
|
|
|
// Set restricted editor user |
199
|
|
|
$repository->setCurrentUser($pseudoEditor); |
|
|
|
|
200
|
|
|
|
201
|
|
|
// This call will fail with a "UnauthorizedException" |
202
|
|
|
$contentService->loadVersionInfo($contentInfo, 2); |
203
|
|
|
/* END: Use Case */ |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Test for the loadVersionInfoById() method. |
208
|
|
|
* |
209
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadVersionInfoById() |
210
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
211
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoById |
212
|
|
|
*/ |
213
|
|
View Code Duplication |
public function testLoadVersionInfoByIdThrowsUnauthorizedException() |
214
|
|
|
{ |
215
|
|
|
$repository = $this->getRepository(); |
216
|
|
|
|
217
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
218
|
|
|
/* BEGIN: Use Case */ |
219
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
220
|
|
|
// demo installation |
221
|
|
|
|
222
|
|
|
$contentService = $repository->getContentService(); |
223
|
|
|
|
224
|
|
|
$pseudoEditor = $this->createAnonymousWithEditorRole(); |
225
|
|
|
|
226
|
|
|
// Set restricted editor user |
227
|
|
|
$repository->setCurrentUser($pseudoEditor); |
|
|
|
|
228
|
|
|
|
229
|
|
|
// This call will fail with a "UnauthorizedException" |
230
|
|
|
$contentService->loadVersionInfoById($anonymousUserId); |
231
|
|
|
/* END: Use Case */ |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* Test for the loadVersionInfoById() method. |
236
|
|
|
* |
237
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadVersionInfoById($contentId, $versionNo) |
238
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
239
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoByIdWithSecondParameter |
240
|
|
|
*/ |
241
|
|
View Code Duplication |
public function testLoadVersionInfoByIdThrowsUnauthorizedExceptionWithSecondParameter() |
242
|
|
|
{ |
243
|
|
|
$repository = $this->getRepository(); |
244
|
|
|
|
245
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
246
|
|
|
/* BEGIN: Use Case */ |
247
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
248
|
|
|
// demo installation |
249
|
|
|
|
250
|
|
|
$contentService = $repository->getContentService(); |
251
|
|
|
|
252
|
|
|
$pseudoEditor = $this->createAnonymousWithEditorRole(); |
253
|
|
|
|
254
|
|
|
// Set restricted editor user |
255
|
|
|
$repository->setCurrentUser($pseudoEditor); |
|
|
|
|
256
|
|
|
|
257
|
|
|
// This call will fail with a "UnauthorizedException" |
258
|
|
|
$contentService->loadVersionInfoById($anonymousUserId, 2); |
259
|
|
|
/* END: Use Case */ |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* Test for the loadVersionInfoById() method. |
264
|
|
|
* |
265
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadVersionInfoById($contentId, $versionNo) |
266
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
267
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoById |
268
|
|
|
*/ |
269
|
|
|
public function testLoadVersionInfoByIdThrowsUnauthorizedExceptionForFirstDraft() |
270
|
|
|
{ |
271
|
|
|
$repository = $this->getRepository(); |
272
|
|
|
|
273
|
|
|
$contentService = $repository->getContentService(); |
274
|
|
|
|
275
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
276
|
|
|
/* BEGIN: Use Case */ |
277
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
278
|
|
|
// demo installation |
279
|
|
|
$contentDraft = $this->createContentDraftVersion1(); |
280
|
|
|
|
281
|
|
|
// Load the user service |
282
|
|
|
$userService = $repository->getUserService(); |
283
|
|
|
|
284
|
|
|
// Set anonymous user |
285
|
|
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
|
|
|
286
|
|
|
|
287
|
|
|
// This call will fail with a "UnauthorizedException" |
288
|
|
|
$contentService->loadVersionInfoById( |
289
|
|
|
$contentDraft->id, |
290
|
|
|
$contentDraft->contentInfo->currentVersionNo |
291
|
|
|
); |
292
|
|
|
/* END: Use Case */ |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
/** |
296
|
|
|
* Test for the loadContentByContentInfo() method. |
297
|
|
|
* |
298
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentByContentInfo() |
299
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
300
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByContentInfo |
301
|
|
|
*/ |
302
|
|
|
public function testLoadContentByContentInfoThrowsUnauthorizedException() |
303
|
|
|
{ |
304
|
|
|
$repository = $this->getRepository(); |
305
|
|
|
|
306
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
307
|
|
|
/* BEGIN: Use Case */ |
308
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
309
|
|
|
// demo installation |
310
|
|
|
|
311
|
|
|
$contentService = $repository->getContentService(); |
312
|
|
|
|
313
|
|
|
// Load the ContentInfo for "Anonymous User" |
314
|
|
|
$contentInfo = $contentService->loadContentInfo($anonymousUserId); |
315
|
|
|
|
316
|
|
|
$pseudoEditor = $this->createAnonymousWithEditorRole(); |
317
|
|
|
|
318
|
|
|
// Set restricted editor user |
319
|
|
|
$repository->setCurrentUser($pseudoEditor); |
|
|
|
|
320
|
|
|
|
321
|
|
|
// This call will fail with a "UnauthorizedException" |
322
|
|
|
$contentService->loadContentByContentInfo($contentInfo); |
323
|
|
|
/* END: Use Case */ |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* Test for the loadContentByContentInfo() method. |
328
|
|
|
* |
329
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentByContentInfo($contentInfo, $languages) |
330
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
331
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByContentInfoWithLanguageParameters |
332
|
|
|
*/ |
333
|
|
|
public function testLoadContentByContentInfoThrowsUnauthorizedExceptionWithSecondParameter() |
334
|
|
|
{ |
335
|
|
|
$repository = $this->getRepository(); |
336
|
|
|
|
337
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
338
|
|
|
/* BEGIN: Use Case */ |
339
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
340
|
|
|
// demo installation |
341
|
|
|
|
342
|
|
|
$contentService = $repository->getContentService(); |
343
|
|
|
|
344
|
|
|
// Load the ContentInfo for "Anonymous User" |
345
|
|
|
$contentInfo = $contentService->loadContentInfo($anonymousUserId); |
346
|
|
|
|
347
|
|
|
$pseudoEditor = $this->createAnonymousWithEditorRole(); |
348
|
|
|
|
349
|
|
|
// Set restricted editor user |
350
|
|
|
$repository->setCurrentUser($pseudoEditor); |
|
|
|
|
351
|
|
|
|
352
|
|
|
// This call will fail with a "UnauthorizedException" |
353
|
|
|
$contentService->loadContentByContentInfo($contentInfo, array('eng-US')); |
354
|
|
|
/* END: Use Case */ |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
/** |
358
|
|
|
* Test for the loadContentByContentInfo() method. |
359
|
|
|
* |
360
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentByContentInfo($contentInfo, $languages, $versionNo) |
361
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
362
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByContentInfoWithVersionNumberParameter |
363
|
|
|
*/ |
364
|
|
|
public function testLoadContentByContentInfoThrowsUnauthorizedExceptionWithThirdParameter() |
365
|
|
|
{ |
366
|
|
|
$repository = $this->getRepository(); |
367
|
|
|
|
368
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
369
|
|
|
/* BEGIN: Use Case */ |
370
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
371
|
|
|
// demo installation |
372
|
|
|
|
373
|
|
|
$contentService = $repository->getContentService(); |
374
|
|
|
|
375
|
|
|
// Load the ContentInfo for "Anonymous User" |
376
|
|
|
$contentInfo = $contentService->loadContentInfo($anonymousUserId); |
377
|
|
|
|
378
|
|
|
$pseudoEditor = $this->createAnonymousWithEditorRole(); |
379
|
|
|
|
380
|
|
|
// Set restricted editor user |
381
|
|
|
$repository->setCurrentUser($pseudoEditor); |
|
|
|
|
382
|
|
|
|
383
|
|
|
// This call will fail with a "UnauthorizedException" |
384
|
|
|
$contentService->loadContentByContentInfo($contentInfo, array('eng-US'), 2); |
385
|
|
|
/* END: Use Case */ |
386
|
|
|
} |
387
|
|
|
|
388
|
|
|
/** |
389
|
|
|
* Test for the loadContentByVersionInfo() method. |
390
|
|
|
* |
391
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentByVersionInfo() |
392
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
393
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByVersionInfo |
394
|
|
|
*/ |
395
|
|
|
public function testLoadContentByVersionInfoThrowsUnauthorizedException() |
396
|
|
|
{ |
397
|
|
|
$repository = $this->getRepository(); |
398
|
|
|
|
399
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
400
|
|
|
/* BEGIN: Use Case */ |
401
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
402
|
|
|
// demo installation |
403
|
|
|
|
404
|
|
|
$contentService = $repository->getContentService(); |
405
|
|
|
|
406
|
|
|
// Load the ContentInfo for "Anonymous User" |
407
|
|
|
$contentInfo = $contentService->loadContentInfo($anonymousUserId); |
408
|
|
|
|
409
|
|
|
// Load the current VersionInfo |
410
|
|
|
$versionInfo = $contentService->loadVersionInfo($contentInfo); |
411
|
|
|
|
412
|
|
|
$pseudoEditor = $this->createAnonymousWithEditorRole(); |
413
|
|
|
|
414
|
|
|
// Set restricted editor user |
415
|
|
|
$repository->setCurrentUser($pseudoEditor); |
|
|
|
|
416
|
|
|
|
417
|
|
|
// This call will fail with a "UnauthorizedException" |
418
|
|
|
$contentService->loadContentByVersionInfo($versionInfo); |
419
|
|
|
/* END: Use Case */ |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
/** |
423
|
|
|
* Test for the loadContentByVersionInfo() method. |
424
|
|
|
* |
425
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentByVersionInfo($versionInfo, $languages) |
426
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
427
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByVersionInfoWithSecondParameter |
428
|
|
|
*/ |
429
|
|
|
public function testLoadContentByVersionInfoThrowsUnauthorizedExceptionWithSecondParameter() |
430
|
|
|
{ |
431
|
|
|
$repository = $this->getRepository(); |
432
|
|
|
|
433
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
434
|
|
|
/* BEGIN: Use Case */ |
435
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
436
|
|
|
// demo installation |
437
|
|
|
|
438
|
|
|
$contentService = $repository->getContentService(); |
439
|
|
|
|
440
|
|
|
// Load the ContentInfo for "Anonymous User" |
441
|
|
|
$contentInfo = $contentService->loadContentInfo($anonymousUserId); |
442
|
|
|
|
443
|
|
|
// Load the current VersionInfo |
444
|
|
|
$versionInfo = $contentService->loadVersionInfo($contentInfo); |
445
|
|
|
|
446
|
|
|
$pseudoEditor = $this->createAnonymousWithEditorRole(); |
447
|
|
|
|
448
|
|
|
// Set restricted editor user |
449
|
|
|
$repository->setCurrentUser($pseudoEditor); |
|
|
|
|
450
|
|
|
|
451
|
|
|
// This call will fail with a "UnauthorizedException" |
452
|
|
|
$contentService->loadContentByVersionInfo($versionInfo, array('eng-US')); |
453
|
|
|
/* END: Use Case */ |
454
|
|
|
} |
455
|
|
|
|
456
|
|
|
/** |
457
|
|
|
* Test for the loadContent() method. |
458
|
|
|
* |
459
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContent() |
460
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
461
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
462
|
|
|
*/ |
463
|
|
|
public function testLoadContentThrowsUnauthorizedException() |
464
|
|
|
{ |
465
|
|
|
$repository = $this->getRepository(); |
466
|
|
|
|
467
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
468
|
|
|
/* BEGIN: Use Case */ |
469
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
470
|
|
|
// demo installation |
471
|
|
|
|
472
|
|
|
$contentService = $repository->getContentService(); |
473
|
|
|
|
474
|
|
|
$pseudoEditor = $this->createAnonymousWithEditorRole(); |
475
|
|
|
|
476
|
|
|
// Set restricted editor user |
477
|
|
|
$repository->setCurrentUser($pseudoEditor); |
|
|
|
|
478
|
|
|
|
479
|
|
|
// This call will fail with a "UnauthorizedException" |
480
|
|
|
$contentService->loadContent($anonymousUserId); |
481
|
|
|
/* END: Use Case */ |
482
|
|
|
} |
483
|
|
|
|
484
|
|
|
/** |
485
|
|
|
* Test for the loadContent() method. |
486
|
|
|
* |
487
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContent($contentId, $languages) |
488
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
489
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentWithSecondParameter |
490
|
|
|
*/ |
491
|
|
|
public function testLoadContentThrowsUnauthorizedExceptionWithSecondParameter() |
492
|
|
|
{ |
493
|
|
|
$repository = $this->getRepository(); |
494
|
|
|
|
495
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
496
|
|
|
/* BEGIN: Use Case */ |
497
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
498
|
|
|
// demo installation |
499
|
|
|
|
500
|
|
|
$contentService = $repository->getContentService(); |
501
|
|
|
|
502
|
|
|
$pseudoEditor = $this->createAnonymousWithEditorRole(); |
503
|
|
|
|
504
|
|
|
// Set restricted editor user |
505
|
|
|
$repository->setCurrentUser($pseudoEditor); |
|
|
|
|
506
|
|
|
|
507
|
|
|
// This call will fail with a "UnauthorizedException" |
508
|
|
|
$contentService->loadContent($anonymousUserId, array('eng-US')); |
509
|
|
|
/* END: Use Case */ |
510
|
|
|
} |
511
|
|
|
|
512
|
|
|
/** |
513
|
|
|
* Test for the loadContent() method. |
514
|
|
|
* |
515
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContent($contentId, $languages, $versionNo) |
516
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
517
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentWithThirdParameter |
518
|
|
|
*/ |
519
|
|
|
public function testLoadContentThrowsUnauthorizedExceptionWithThirdParameter() |
520
|
|
|
{ |
521
|
|
|
$repository = $this->getRepository(); |
522
|
|
|
|
523
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
524
|
|
|
/* BEGIN: Use Case */ |
525
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
526
|
|
|
// demo installation |
527
|
|
|
|
528
|
|
|
$contentService = $repository->getContentService(); |
529
|
|
|
|
530
|
|
|
$pseudoEditor = $this->createAnonymousWithEditorRole(); |
531
|
|
|
|
532
|
|
|
// Set restricted editor user |
533
|
|
|
$repository->setCurrentUser($pseudoEditor); |
|
|
|
|
534
|
|
|
|
535
|
|
|
// This call will fail with a "UnauthorizedException" |
536
|
|
|
$contentService->loadContent($anonymousUserId, array('eng-US'), 2); |
537
|
|
|
/* END: Use Case */ |
538
|
|
|
} |
539
|
|
|
|
540
|
|
|
/** |
541
|
|
|
* Test for the loadContent() method on a draft. |
542
|
|
|
* |
543
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContent() |
544
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
545
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
546
|
|
|
*/ |
547
|
|
|
public function testLoadContentThrowsUnauthorizedExceptionOnDrafts() |
548
|
|
|
{ |
549
|
|
|
/** @var $repository \eZ\Publish\API\Repository\Repository */ |
550
|
|
|
$repository = $this->getRepository(); |
551
|
|
|
|
552
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
553
|
|
|
/* BEGIN: Use Case */ |
554
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
555
|
|
|
// demo installation |
556
|
|
|
$user = $this->createUserVersion1(); |
557
|
|
|
|
558
|
|
|
// Set new editor as a content owner |
559
|
|
|
$repository->setCurrentUser($user); |
|
|
|
|
560
|
|
|
|
561
|
|
|
// Create draft with this user |
562
|
|
|
$draft = $this->createContentDraftVersion1(2, 'folder'); |
563
|
|
|
|
564
|
|
|
// Load anonymous user |
565
|
|
|
$userService = $repository->getUserService(); |
566
|
|
|
$user = $userService->loadUser($anonymousUserId); |
567
|
|
|
$repository->setCurrentUser($user); |
|
|
|
|
568
|
|
|
|
569
|
|
|
// Try to load the draft with anonymous user to make sure access won't be allowed by throwing an exception |
570
|
|
|
$contentService = $repository->getContentService(); |
571
|
|
|
$contentService->loadContent($draft->id); |
572
|
|
|
/* END: Use Case */ |
573
|
|
|
} |
574
|
|
|
|
575
|
|
|
/** |
576
|
|
|
* Test for the ContentService::loadContent() method on an archive. |
577
|
|
|
* |
578
|
|
|
* This test the version permission on loading archived versions |
579
|
|
|
* |
580
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContent() |
581
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
582
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
583
|
|
|
*/ |
584
|
|
|
public function testLoadContentThrowsUnauthorizedExceptionsOnArchives() |
585
|
|
|
{ |
586
|
|
|
/** @var $repository \eZ\Publish\API\Repository\Repository */ |
587
|
|
|
$repository = $this->getRepository(); |
588
|
|
|
|
589
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
590
|
|
|
/* BEGIN: Use Case */ |
591
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
592
|
|
|
// demo installation |
593
|
|
|
// get necessary services |
594
|
|
|
$contentTypeService = $repository->getContentTypeService(); |
595
|
|
|
$contentService = $repository->getContentService(); |
596
|
|
|
$locationSercice = $repository->getLocationService(); |
597
|
|
|
|
598
|
|
|
// set admin as current user |
599
|
|
|
$repository->setCurrentUser($repository->getUserService()->loadUserByLogin('admin')); |
|
|
|
|
600
|
|
|
|
601
|
|
|
// create folder |
602
|
|
|
$newStruct = $contentService->newContentCreateStruct( |
603
|
|
|
$contentTypeService->loadContentTypeByIdentifier('folder'), |
604
|
|
|
'eng-US' |
605
|
|
|
); |
606
|
|
|
$newStruct->setField('name', 'Test Folder'); |
607
|
|
|
$draft = $contentService->createContent( |
608
|
|
|
$newStruct, |
609
|
|
|
array($locationSercice->newLocationCreateStruct(2)) |
610
|
|
|
); |
611
|
|
|
$object = $contentService->publishVersion($draft->versionInfo); |
612
|
|
|
|
613
|
|
|
// update folder to make an archived version |
614
|
|
|
$updateStruct = $contentService->newContentUpdateStruct(); |
615
|
|
|
$updateStruct->setField('name', 'Test Folder Updated'); |
616
|
|
|
$draftUpdated = $contentService->updateContent( |
617
|
|
|
$contentService->createContentDraft($object->contentInfo)->versionInfo, |
618
|
|
|
$updateStruct |
619
|
|
|
); |
620
|
|
|
$objectUpdated = $contentService->publishVersion($draftUpdated->versionInfo); |
621
|
|
|
|
622
|
|
|
// set an anonymous as current user |
623
|
|
|
$repository->setCurrentUser($repository->getUserService()->loadUser($anonymousUserId)); |
|
|
|
|
624
|
|
|
|
625
|
|
|
// throws an unauthorized exception since anonymous user don't have access to archived versions |
626
|
|
|
$contentService->loadContent($objectUpdated->id, null, 1); |
627
|
|
|
/* END: Use Case */ |
628
|
|
|
} |
629
|
|
|
|
630
|
|
|
/** |
631
|
|
|
* Test for the loadContentByRemoteId() method. |
632
|
|
|
* |
633
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentByRemoteId() |
634
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
635
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByRemoteId |
636
|
|
|
*/ |
637
|
|
View Code Duplication |
public function testLoadContentByRemoteIdThrowsUnauthorizedException() |
638
|
|
|
{ |
639
|
|
|
$repository = $this->getRepository(); |
640
|
|
|
|
641
|
|
|
/* BEGIN: Use Case */ |
642
|
|
|
// Remote id of the "Anonymous" user in a eZ Publish demo installation |
643
|
|
|
$anonymousRemoteId = 'faaeb9be3bd98ed09f606fc16d144eca'; |
644
|
|
|
|
645
|
|
|
$contentService = $repository->getContentService(); |
646
|
|
|
|
647
|
|
|
$pseudoEditor = $this->createAnonymousWithEditorRole(); |
648
|
|
|
|
649
|
|
|
// Set restricted editor user |
650
|
|
|
$repository->setCurrentUser($pseudoEditor); |
|
|
|
|
651
|
|
|
|
652
|
|
|
// This call will fail with a "UnauthorizedException" |
653
|
|
|
$contentService->loadContentByRemoteId($anonymousRemoteId); |
654
|
|
|
/* END: Use Case */ |
655
|
|
|
} |
656
|
|
|
|
657
|
|
|
/** |
658
|
|
|
* Test for the loadContentByRemoteId() method. |
659
|
|
|
* |
660
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentByRemoteId($remoteId, $languages) |
661
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
662
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByRemoteIdWithSecondParameter |
663
|
|
|
*/ |
664
|
|
View Code Duplication |
public function testLoadContentByRemoteIdThrowsUnauthorizedExceptionWithSecondParameter() |
665
|
|
|
{ |
666
|
|
|
$repository = $this->getRepository(); |
667
|
|
|
|
668
|
|
|
/* BEGIN: Use Case */ |
669
|
|
|
// Remote id of the "Anonymous" user in a eZ Publish demo installation |
670
|
|
|
$anonymousRemoteId = 'faaeb9be3bd98ed09f606fc16d144eca'; |
671
|
|
|
|
672
|
|
|
$contentService = $repository->getContentService(); |
673
|
|
|
|
674
|
|
|
$pseudoEditor = $this->createAnonymousWithEditorRole(); |
675
|
|
|
|
676
|
|
|
// Set restricted editor user |
677
|
|
|
$repository->setCurrentUser($pseudoEditor); |
|
|
|
|
678
|
|
|
|
679
|
|
|
// This call will fail with a "UnauthorizedException" |
680
|
|
|
$contentService->loadContentByRemoteId($anonymousRemoteId, array('eng-US')); |
681
|
|
|
/* END: Use Case */ |
682
|
|
|
} |
683
|
|
|
|
684
|
|
|
/** |
685
|
|
|
* Test for the loadContentByRemoteId() method. |
686
|
|
|
* |
687
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentByRemoteId($remoteId, $languages, $versionNo) |
688
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
689
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByRemoteIdWithThirdParameter |
690
|
|
|
*/ |
691
|
|
View Code Duplication |
public function testLoadContentByRemoteIdThrowsUnauthorizedExceptionWithThirdParameter() |
692
|
|
|
{ |
693
|
|
|
$repository = $this->getRepository(); |
694
|
|
|
|
695
|
|
|
/* BEGIN: Use Case */ |
696
|
|
|
// Remote id of the "Anonymous" user in a eZ Publish demo installation |
697
|
|
|
$anonymousRemoteId = 'faaeb9be3bd98ed09f606fc16d144eca'; |
698
|
|
|
|
699
|
|
|
$contentService = $repository->getContentService(); |
700
|
|
|
|
701
|
|
|
$pseudoEditor = $this->createAnonymousWithEditorRole(); |
702
|
|
|
|
703
|
|
|
// Set restricted editor user |
704
|
|
|
$repository->setCurrentUser($pseudoEditor); |
|
|
|
|
705
|
|
|
|
706
|
|
|
// This call will fail with a "UnauthorizedException" |
707
|
|
|
$contentService->loadContentByRemoteId($anonymousRemoteId, array('eng-US'), 2); |
708
|
|
|
/* END: Use Case */ |
709
|
|
|
} |
710
|
|
|
|
711
|
|
|
/** |
712
|
|
|
* Test for the updateContentMetadata() method. |
713
|
|
|
* |
714
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::updateContentMetadata() |
715
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
716
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata |
717
|
|
|
*/ |
718
|
|
|
public function testUpdateContentMetadataThrowsUnauthorizedException() |
719
|
|
|
{ |
720
|
|
|
$repository = $this->getRepository(); |
721
|
|
|
|
722
|
|
|
$contentService = $repository->getContentService(); |
723
|
|
|
|
724
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
725
|
|
|
/* BEGIN: Use Case */ |
726
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
727
|
|
|
// demo installation |
728
|
|
|
$content = $this->createContentVersion1(); |
729
|
|
|
|
730
|
|
|
// Get ContentInfo instance. |
731
|
|
|
$contentInfo = $content->contentInfo; |
732
|
|
|
|
733
|
|
|
// Load the user service |
734
|
|
|
$userService = $repository->getUserService(); |
735
|
|
|
|
736
|
|
|
// Set anonymous user |
737
|
|
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
|
|
|
738
|
|
|
|
739
|
|
|
// Creates a metadata update struct |
740
|
|
|
$metadataUpdate = $contentService->newContentMetadataUpdateStruct(); |
741
|
|
|
|
742
|
|
|
$metadataUpdate->remoteId = 'aaaabbbbccccddddeeeeffff11112222'; |
743
|
|
|
$metadataUpdate->mainLanguageCode = 'eng-US'; |
744
|
|
|
$metadataUpdate->alwaysAvailable = false; |
745
|
|
|
$metadataUpdate->publishedDate = $this->createDateTime(); |
746
|
|
|
$metadataUpdate->modificationDate = $this->createDateTime(); |
747
|
|
|
|
748
|
|
|
// This call will fail with a "UnauthorizedException" |
749
|
|
|
$contentService->updateContentMetadata( |
750
|
|
|
$contentInfo, |
751
|
|
|
$metadataUpdate |
752
|
|
|
); |
753
|
|
|
/* END: Use Case */ |
754
|
|
|
} |
755
|
|
|
|
756
|
|
|
/** |
757
|
|
|
* Test for the deleteContent() method. |
758
|
|
|
* |
759
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::deleteContent() |
760
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
761
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteContent |
762
|
|
|
*/ |
763
|
|
|
public function testDeleteContentThrowsUnauthorizedException() |
764
|
|
|
{ |
765
|
|
|
$repository = $this->getRepository(); |
766
|
|
|
$contentService = $repository->getContentService(); |
767
|
|
|
|
768
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
769
|
|
|
/* BEGIN: Use Case */ |
770
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
771
|
|
|
// demo installation |
772
|
|
|
$contentVersion2 = $this->createContentVersion2(); |
773
|
|
|
|
774
|
|
|
// Get ContentInfo instance |
775
|
|
|
$contentInfo = $contentVersion2->contentInfo; |
776
|
|
|
|
777
|
|
|
// Load the user service |
778
|
|
|
$userService = $repository->getUserService(); |
779
|
|
|
|
780
|
|
|
// Set anonymous user |
781
|
|
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
|
|
|
782
|
|
|
|
783
|
|
|
// This call will fail with a "UnauthorizedException" |
784
|
|
|
$contentService->deleteContent($contentInfo); |
785
|
|
|
/* END: Use Case */ |
786
|
|
|
} |
787
|
|
|
|
788
|
|
|
/** |
789
|
|
|
* Test for the createContentDraft() method. |
790
|
|
|
* |
791
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
792
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
793
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
794
|
|
|
*/ |
795
|
|
|
public function testCreateContentDraftThrowsUnauthorizedException() |
796
|
|
|
{ |
797
|
|
|
$repository = $this->getRepository(); |
798
|
|
|
|
799
|
|
|
$contentService = $repository->getContentService(); |
800
|
|
|
|
801
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
802
|
|
|
/* BEGIN: Use Case */ |
803
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
804
|
|
|
// demo installation |
805
|
|
|
$content = $this->createContentVersion1(); |
806
|
|
|
|
807
|
|
|
// Get ContentInfo instance |
808
|
|
|
$contentInfo = $content->contentInfo; |
809
|
|
|
|
810
|
|
|
// Load the user service |
811
|
|
|
$userService = $repository->getUserService(); |
812
|
|
|
|
813
|
|
|
// Set anonymous user |
814
|
|
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
|
|
|
815
|
|
|
|
816
|
|
|
// This call will fail with a "UnauthorizedException" |
817
|
|
|
$contentService->createContentDraft($contentInfo); |
818
|
|
|
/* END: Use Case */ |
819
|
|
|
} |
820
|
|
|
|
821
|
|
|
/** |
822
|
|
|
* Test for the createContentDraft() method. |
823
|
|
|
* |
824
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::createContentDraft($contentInfo, $versionInfo) |
825
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
826
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraftWithSecondParameter |
827
|
|
|
*/ |
828
|
|
View Code Duplication |
public function testCreateContentDraftThrowsUnauthorizedExceptionWithSecondParameter() |
829
|
|
|
{ |
830
|
|
|
$repository = $this->getRepository(); |
831
|
|
|
|
832
|
|
|
$contentService = $repository->getContentService(); |
833
|
|
|
|
834
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
835
|
|
|
/* BEGIN: Use Case */ |
836
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
837
|
|
|
// demo installation |
838
|
|
|
$content = $this->createContentVersion1(); |
839
|
|
|
|
840
|
|
|
// Get ContentInfo and VersionInfo instances |
841
|
|
|
$contentInfo = $content->contentInfo; |
842
|
|
|
$versionInfo = $content->getVersionInfo(); |
843
|
|
|
|
844
|
|
|
// Load the user service |
845
|
|
|
$userService = $repository->getUserService(); |
846
|
|
|
|
847
|
|
|
// Set anonymous user |
848
|
|
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
|
|
|
849
|
|
|
|
850
|
|
|
// This call will fail with a "UnauthorizedException" |
851
|
|
|
$contentService->createContentDraft($contentInfo, $versionInfo); |
852
|
|
|
/* END: Use Case */ |
853
|
|
|
} |
854
|
|
|
|
855
|
|
|
/** |
856
|
|
|
* Test for the loadContentDrafts() method. |
857
|
|
|
* |
858
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentDrafts() |
859
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
860
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentDrafts |
861
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentDrafts |
862
|
|
|
*/ |
863
|
|
|
public function testLoadContentDraftsThrowsUnauthorizedException() |
864
|
|
|
{ |
865
|
|
|
$repository = $this->getRepository(); |
866
|
|
|
|
867
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
868
|
|
|
/* BEGIN: Use Case */ |
869
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
870
|
|
|
// demo installation |
871
|
|
|
$contentService = $repository->getContentService(); |
872
|
|
|
|
873
|
|
|
// Load the user service |
874
|
|
|
$userService = $repository->getUserService(); |
875
|
|
|
|
876
|
|
|
// Set anonymous user |
877
|
|
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
|
|
|
878
|
|
|
|
879
|
|
|
// This call will fail with a "UnauthorizedException" |
880
|
|
|
$contentService->loadContentDrafts(); |
881
|
|
|
/* END: Use Case */ |
882
|
|
|
} |
883
|
|
|
|
884
|
|
|
/** |
885
|
|
|
* Test for the loadContentDrafts() method. |
886
|
|
|
* |
887
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadContentDrafts($user) |
888
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
889
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentDrafts |
890
|
|
|
*/ |
891
|
|
|
public function testLoadContentDraftsThrowsUnauthorizedExceptionWithFirstParameter() |
892
|
|
|
{ |
893
|
|
|
$repository = $this->getRepository(); |
894
|
|
|
|
895
|
|
|
$administratorUserId = $this->generateId('user', 14); |
896
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
897
|
|
|
/* BEGIN: Use Case */ |
898
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
899
|
|
|
// demo installation |
900
|
|
|
// $administratorUserId is the ID of the "Administrator" user in a eZ |
901
|
|
|
// Publish demo installation. |
902
|
|
|
|
903
|
|
|
$contentService = $repository->getContentService(); |
904
|
|
|
|
905
|
|
|
// Load the user service |
906
|
|
|
$userService = $repository->getUserService(); |
907
|
|
|
|
908
|
|
|
// Load the "Administrator" user |
909
|
|
|
$administratorUser = $userService->loadUser($administratorUserId); |
910
|
|
|
|
911
|
|
|
// Set anonymous user |
912
|
|
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
|
|
|
913
|
|
|
|
914
|
|
|
// This call will fail with a "UnauthorizedException" |
915
|
|
|
$contentService->loadContentDrafts($administratorUser); |
916
|
|
|
/* END: Use Case */ |
917
|
|
|
} |
918
|
|
|
|
919
|
|
|
/** |
920
|
|
|
* Test for the updateContent() method. |
921
|
|
|
* |
922
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::updateContent() |
923
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
924
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
925
|
|
|
*/ |
926
|
|
View Code Duplication |
public function testUpdateContentThrowsUnauthorizedException() |
927
|
|
|
{ |
928
|
|
|
$repository = $this->getRepository(); |
929
|
|
|
$contentService = $repository->getContentService(); |
930
|
|
|
|
931
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
|
|
|
|
932
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
933
|
|
|
/* BEGIN: Use Case */ |
934
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
935
|
|
|
// demo installation |
936
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
937
|
|
|
// demo installation |
938
|
|
|
$draftVersion2 = $this->createContentDraftVersion2(); |
939
|
|
|
|
940
|
|
|
// Get VersionInfo instance |
941
|
|
|
$versionInfo = $draftVersion2->getVersionInfo(); |
942
|
|
|
|
943
|
|
|
// Load the user service |
944
|
|
|
$userService = $repository->getUserService(); |
945
|
|
|
|
946
|
|
|
// Set anonymous user |
947
|
|
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
|
|
|
948
|
|
|
|
949
|
|
|
// Create an update struct and modify some fields |
950
|
|
|
$contentUpdate = $contentService->newContentUpdateStruct(); |
951
|
|
|
$contentUpdate->setField('name', 'An awesome² story about ezp.'); |
952
|
|
|
$contentUpdate->setField('name', 'An awesome²³ story about ezp.', 'eng-GB'); |
953
|
|
|
|
954
|
|
|
$contentUpdate->initialLanguageCode = 'eng-US'; |
955
|
|
|
|
956
|
|
|
// This call will fail with a "UnauthorizedException" |
957
|
|
|
$contentService->updateContent($versionInfo, $contentUpdate); |
958
|
|
|
/* END: Use Case */ |
959
|
|
|
} |
960
|
|
|
|
961
|
|
|
/** |
962
|
|
|
* Test for the publishVersion() method. |
963
|
|
|
* |
964
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
965
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
966
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
967
|
|
|
*/ |
968
|
|
|
public function testPublishVersionThrowsUnauthorizedException() |
969
|
|
|
{ |
970
|
|
|
$repository = $this->getRepository(); |
971
|
|
|
$contentService = $repository->getContentService(); |
972
|
|
|
|
973
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
974
|
|
|
/* BEGIN: Use Case */ |
975
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
976
|
|
|
// demo installation |
977
|
|
|
$draft = $this->createContentDraftVersion1(); |
978
|
|
|
|
979
|
|
|
// Load the user service |
980
|
|
|
$userService = $repository->getUserService(); |
981
|
|
|
|
982
|
|
|
// Set anonymous user |
983
|
|
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
|
|
|
984
|
|
|
|
985
|
|
|
// This call will fail with a "UnauthorizedException" |
986
|
|
|
$contentService->publishVersion($draft->getVersionInfo()); |
987
|
|
|
/* END: Use Case */ |
988
|
|
|
} |
989
|
|
|
|
990
|
|
|
/** |
991
|
|
|
* Test for the deleteVersion() method. |
992
|
|
|
* |
993
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::deleteVersion() |
994
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
995
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteVersion |
996
|
|
|
*/ |
997
|
|
|
public function testDeleteVersionThrowsUnauthorizedException() |
998
|
|
|
{ |
999
|
|
|
$repository = $this->getRepository(); |
1000
|
|
|
$contentService = $repository->getContentService(); |
1001
|
|
|
|
1002
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
1003
|
|
|
/* BEGIN: Use Case */ |
1004
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
1005
|
|
|
// demo installation |
1006
|
|
|
$draft = $this->createContentDraftVersion1(); |
1007
|
|
|
|
1008
|
|
|
// Load the user service |
1009
|
|
|
$userService = $repository->getUserService(); |
1010
|
|
|
|
1011
|
|
|
// Set anonymous user |
1012
|
|
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
|
|
|
1013
|
|
|
|
1014
|
|
|
// This call will fail with a "UnauthorizedException", because "content" |
1015
|
|
|
// "versionremove" permission is missing. |
1016
|
|
|
$contentService->deleteVersion($draft->getVersionInfo()); |
1017
|
|
|
/* END: Use Case */ |
1018
|
|
|
} |
1019
|
|
|
|
1020
|
|
|
/** |
1021
|
|
|
* Test for the loadVersions() method. |
1022
|
|
|
* |
1023
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadVersions() |
1024
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
1025
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersions |
1026
|
|
|
*/ |
1027
|
|
|
public function testLoadVersionsThrowsUnauthorizedException() |
1028
|
|
|
{ |
1029
|
|
|
$repository = $this->getRepository(); |
1030
|
|
|
|
1031
|
|
|
$contentService = $repository->getContentService(); |
1032
|
|
|
|
1033
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
1034
|
|
|
/* BEGIN: Use Case */ |
1035
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
1036
|
|
|
// demo installation |
1037
|
|
|
$contentVersion2 = $this->createContentVersion2(); |
1038
|
|
|
|
1039
|
|
|
// Get ContentInfo instance of version 2 |
1040
|
|
|
$contentInfo = $contentVersion2->contentInfo; |
1041
|
|
|
|
1042
|
|
|
// Load the user service |
1043
|
|
|
$userService = $repository->getUserService(); |
1044
|
|
|
|
1045
|
|
|
// Set anonymous user |
1046
|
|
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
|
|
|
1047
|
|
|
|
1048
|
|
|
// This call will fail with a "UnauthorizedException" |
1049
|
|
|
$contentService->loadVersions($contentInfo); |
1050
|
|
|
/* END: Use Case */ |
1051
|
|
|
} |
1052
|
|
|
|
1053
|
|
|
/** |
1054
|
|
|
* Test for the copyContent() method. |
1055
|
|
|
* |
1056
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::copyContent() |
1057
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
1058
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCopyContent |
1059
|
|
|
*/ |
1060
|
|
View Code Duplication |
public function testCopyContentThrowsUnauthorizedException() |
1061
|
|
|
{ |
1062
|
|
|
$parentLocationId = $this->generateId('location', 52); |
1063
|
|
|
|
1064
|
|
|
$repository = $this->getRepository(); |
1065
|
|
|
|
1066
|
|
|
$contentService = $repository->getContentService(); |
1067
|
|
|
$locationService = $repository->getLocationService(); |
1068
|
|
|
|
1069
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
1070
|
|
|
/* BEGIN: Use Case */ |
1071
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
1072
|
|
|
// demo installation |
1073
|
|
|
$contentVersion2 = $this->createMultipleLanguageContentVersion2(); |
1074
|
|
|
|
1075
|
|
|
// Get ContentInfo instance of version 2 |
1076
|
|
|
$contentInfo = $contentVersion2->contentInfo; |
1077
|
|
|
|
1078
|
|
|
// Load the user service |
1079
|
|
|
$userService = $repository->getUserService(); |
1080
|
|
|
|
1081
|
|
|
// Set anonymous user |
1082
|
|
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
|
|
|
1083
|
|
|
|
1084
|
|
|
// Configure new target location |
1085
|
|
|
$targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId); |
1086
|
|
|
|
1087
|
|
|
$targetLocationCreate->priority = 42; |
1088
|
|
|
$targetLocationCreate->hidden = true; |
1089
|
|
|
$targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789'; |
1090
|
|
|
$targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID; |
1091
|
|
|
$targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC; |
1092
|
|
|
|
1093
|
|
|
// This call will fail with a "UnauthorizedException" |
1094
|
|
|
$contentService->copyContent( |
1095
|
|
|
$contentInfo, |
1096
|
|
|
$targetLocationCreate |
1097
|
|
|
); |
1098
|
|
|
/* END: Use Case */ |
1099
|
|
|
} |
1100
|
|
|
|
1101
|
|
|
/** |
1102
|
|
|
* Test for the copyContent() method. |
1103
|
|
|
* |
1104
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::copyContent($contentInfo, $destinationLocationCreateStruct, $versionInfo) |
1105
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
1106
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCopyContentWithThirdParameter |
1107
|
|
|
*/ |
1108
|
|
View Code Duplication |
public function testCopyContentThrowsUnauthorizedExceptionWithThirdParameter() |
1109
|
|
|
{ |
1110
|
|
|
$parentLocationId = $this->generateId('location', 52); |
1111
|
|
|
|
1112
|
|
|
$repository = $this->getRepository(); |
1113
|
|
|
|
1114
|
|
|
$contentService = $repository->getContentService(); |
1115
|
|
|
$locationService = $repository->getLocationService(); |
1116
|
|
|
|
1117
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
1118
|
|
|
/* BEGIN: Use Case */ |
1119
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
1120
|
|
|
// demo installation |
1121
|
|
|
$contentVersion2 = $this->createContentVersion2(); |
1122
|
|
|
|
1123
|
|
|
// Load the user service |
1124
|
|
|
$userService = $repository->getUserService(); |
1125
|
|
|
|
1126
|
|
|
// Set anonymous user |
1127
|
|
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
|
|
|
1128
|
|
|
|
1129
|
|
|
// Configure new target location |
1130
|
|
|
$targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId); |
1131
|
|
|
|
1132
|
|
|
$targetLocationCreate->priority = 42; |
1133
|
|
|
$targetLocationCreate->hidden = true; |
1134
|
|
|
$targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789'; |
1135
|
|
|
$targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID; |
1136
|
|
|
$targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC; |
1137
|
|
|
|
1138
|
|
|
// This call will fail with a "UnauthorizedException" |
1139
|
|
|
$contentService->copyContent( |
1140
|
|
|
$contentVersion2->contentInfo, |
1141
|
|
|
$targetLocationCreate, |
1142
|
|
|
$contentService->loadVersionInfo($contentVersion2->contentInfo, 1) |
1143
|
|
|
); |
1144
|
|
|
/* END: Use Case */ |
1145
|
|
|
} |
1146
|
|
|
|
1147
|
|
|
/** |
1148
|
|
|
* Test for the loadRelations() method. |
1149
|
|
|
* |
1150
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadRelations() |
1151
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
1152
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadRelations |
1153
|
|
|
*/ |
1154
|
|
View Code Duplication |
public function testLoadRelationsThrowsUnauthorizedException() |
1155
|
|
|
{ |
1156
|
|
|
$repository = $this->getRepository(); |
1157
|
|
|
|
1158
|
|
|
$contentService = $repository->getContentService(); |
1159
|
|
|
|
1160
|
|
|
/* BEGIN: Use Case */ |
1161
|
|
|
$user = $this->createMediaUserVersion1(); |
1162
|
|
|
|
1163
|
|
|
// Remote id of the "Setup" page of a eZ Publish demo installation. |
1164
|
|
|
$setupRemoteId = '241d538ce310074e602f29f49e44e938'; |
1165
|
|
|
|
1166
|
|
|
$versionInfo = $contentService->loadVersionInfo( |
1167
|
|
|
$contentService->loadContentInfoByRemoteId( |
1168
|
|
|
$setupRemoteId |
1169
|
|
|
) |
1170
|
|
|
); |
1171
|
|
|
|
1172
|
|
|
// Set media editor as current user |
1173
|
|
|
$repository->setCurrentUser($user); |
|
|
|
|
1174
|
|
|
|
1175
|
|
|
// This call will fail with a "UnauthorizedException" |
1176
|
|
|
$contentService->loadRelations($versionInfo); |
1177
|
|
|
/* END: Use Case */ |
1178
|
|
|
} |
1179
|
|
|
|
1180
|
|
|
/** |
1181
|
|
|
* Test for the loadRelations() method. |
1182
|
|
|
* |
1183
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadRelations() |
1184
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
1185
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadRelations |
1186
|
|
|
*/ |
1187
|
|
|
public function testLoadRelationsForDraftVersionThrowsUnauthorizedException() |
1188
|
|
|
{ |
1189
|
|
|
$repository = $this->getRepository(); |
1190
|
|
|
|
1191
|
|
|
$contentService = $repository->getContentService(); |
1192
|
|
|
|
1193
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
1194
|
|
|
/* BEGIN: Use Case */ |
1195
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
1196
|
|
|
// demo installation |
1197
|
|
|
$draft = $this->createContentDraftVersion1(); |
1198
|
|
|
|
1199
|
|
|
// Load the user service |
1200
|
|
|
$userService = $repository->getUserService(); |
1201
|
|
|
|
1202
|
|
|
// Set anonymous user |
1203
|
|
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
|
|
|
1204
|
|
|
|
1205
|
|
|
// This call will fail with a "UnauthorizedException" |
1206
|
|
|
$contentService->loadRelations($draft->versionInfo); |
1207
|
|
|
/* END: Use Case */ |
1208
|
|
|
} |
1209
|
|
|
|
1210
|
|
|
/** |
1211
|
|
|
* Test for the loadReverseRelations() method. |
1212
|
|
|
* |
1213
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadReverseRelations() |
1214
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
1215
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadReverseRelations |
1216
|
|
|
*/ |
1217
|
|
View Code Duplication |
public function testLoadReverseRelationsThrowsUnauthorizedException() |
1218
|
|
|
{ |
1219
|
|
|
$repository = $this->getRepository(); |
1220
|
|
|
|
1221
|
|
|
$contentService = $repository->getContentService(); |
1222
|
|
|
|
1223
|
|
|
/* BEGIN: Use Case */ |
1224
|
|
|
$user = $this->createMediaUserVersion1(); |
1225
|
|
|
|
1226
|
|
|
// Remote id of the "Media" page of a eZ Publish demo installation. |
1227
|
|
|
$mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262'; |
1228
|
|
|
|
1229
|
|
|
$contentInfo = $contentService->loadContentInfoByRemoteId( |
1230
|
|
|
$mediaRemoteId |
1231
|
|
|
); |
1232
|
|
|
|
1233
|
|
|
// Set media editor as current user |
1234
|
|
|
$repository->setCurrentUser($user); |
|
|
|
|
1235
|
|
|
|
1236
|
|
|
// This call will fail with a "UnauthorizedException" |
1237
|
|
|
$contentService->loadReverseRelations($contentInfo); |
1238
|
|
|
/* END: Use Case */ |
1239
|
|
|
} |
1240
|
|
|
|
1241
|
|
|
/** |
1242
|
|
|
* Test for the addRelation() method. |
1243
|
|
|
* |
1244
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::addRelation() |
1245
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
1246
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation |
1247
|
|
|
*/ |
1248
|
|
|
public function testAddRelationThrowsUnauthorizedException() |
1249
|
|
|
{ |
1250
|
|
|
$repository = $this->getRepository(); |
1251
|
|
|
|
1252
|
|
|
$contentService = $repository->getContentService(); |
1253
|
|
|
|
1254
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
1255
|
|
|
/* BEGIN: Use Case */ |
1256
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
1257
|
|
|
// demo installation |
1258
|
|
|
// Remote id of the "Media" page of a eZ Publish demo installation. |
1259
|
|
|
$mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262'; |
1260
|
|
|
|
1261
|
|
|
$draft = $this->createContentDraftVersion1(); |
1262
|
|
|
|
1263
|
|
|
// Get the draft's version info |
1264
|
|
|
$versionInfo = $draft->getVersionInfo(); |
1265
|
|
|
|
1266
|
|
|
// Load other content object |
1267
|
|
|
$media = $contentService->loadContentInfoByRemoteId($mediaRemoteId); |
1268
|
|
|
|
1269
|
|
|
// Load the user service |
1270
|
|
|
$userService = $repository->getUserService(); |
1271
|
|
|
|
1272
|
|
|
// Set anonymous user |
1273
|
|
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
|
|
|
1274
|
|
|
|
1275
|
|
|
// This call will fail with a "UnauthorizedException" |
1276
|
|
|
$contentService->addRelation( |
1277
|
|
|
$versionInfo, |
1278
|
|
|
$media |
1279
|
|
|
); |
1280
|
|
|
/* END: Use Case */ |
1281
|
|
|
} |
1282
|
|
|
|
1283
|
|
|
/** |
1284
|
|
|
* Test for the deleteRelation() method. |
1285
|
|
|
* |
1286
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::deleteRelation() |
1287
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
1288
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteRelation |
1289
|
|
|
*/ |
1290
|
|
|
public function testDeleteRelationThrowsUnauthorizedException() |
1291
|
|
|
{ |
1292
|
|
|
$repository = $this->getRepository(); |
1293
|
|
|
|
1294
|
|
|
$contentService = $repository->getContentService(); |
1295
|
|
|
|
1296
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
1297
|
|
|
/* BEGIN: Use Case */ |
1298
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
1299
|
|
|
// demo installation |
1300
|
|
|
// Remote ids of the "Media" and the "Demo Design" page of a eZ Publish |
1301
|
|
|
// demo installation. |
1302
|
|
|
$mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262'; |
1303
|
|
|
$demoDesignRemoteId = '8b8b22fe3c6061ed500fbd2b377b885f'; |
1304
|
|
|
|
1305
|
|
|
$draft = $this->createContentDraftVersion1(); |
1306
|
|
|
|
1307
|
|
|
// Get the draft's version info |
1308
|
|
|
$versionInfo = $draft->getVersionInfo(); |
1309
|
|
|
|
1310
|
|
|
$media = $contentService->loadContentInfoByRemoteId($mediaRemoteId); |
1311
|
|
|
$demoDesign = $contentService->loadContentInfoByRemoteId($demoDesignRemoteId); |
1312
|
|
|
|
1313
|
|
|
// Establish some relations |
1314
|
|
|
$contentService->addRelation($draft->getVersionInfo(), $media); |
1315
|
|
|
$contentService->addRelation($draft->getVersionInfo(), $demoDesign); |
1316
|
|
|
|
1317
|
|
|
// Load the user service |
1318
|
|
|
$userService = $repository->getUserService(); |
1319
|
|
|
|
1320
|
|
|
// Set anonymous user |
1321
|
|
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
|
|
|
1322
|
|
|
|
1323
|
|
|
// This call will fail with a "UnauthorizedException" |
1324
|
|
|
$contentService->deleteRelation($versionInfo, $media); |
1325
|
|
|
/* END: Use Case */ |
1326
|
|
|
} |
1327
|
|
|
|
1328
|
|
|
/** |
1329
|
|
|
* Creates a pseudo editor with a limitation to objects in the "Media/Images" |
1330
|
|
|
* subtree. |
1331
|
|
|
* |
1332
|
|
|
* @return \eZ\Publish\API\Repository\Values\User\User |
1333
|
|
|
*/ |
1334
|
|
|
private function createAnonymousWithEditorRole() |
1335
|
|
|
{ |
1336
|
|
|
$repository = $this->getRepository(); |
1337
|
|
|
|
1338
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
1339
|
|
|
/* BEGIN: Use Case */ |
1340
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
1341
|
|
|
// demo installation |
1342
|
|
|
$roleService = $repository->getRoleService(); |
1343
|
|
|
$userService = $repository->getUserService(); |
1344
|
|
|
|
1345
|
|
|
$user = $userService->loadUser($anonymousUserId); |
1346
|
|
|
$role = $roleService->loadRoleByIdentifier('Editor'); |
1347
|
|
|
|
1348
|
|
|
// Assign "Editor" role with limitation to "Media/Images" |
1349
|
|
|
$roleService->assignRoleToUser( |
1350
|
|
|
$role, |
1351
|
|
|
$user, |
1352
|
|
|
new \eZ\Publish\API\Repository\Values\User\Limitation\SubtreeLimitation( |
1353
|
|
|
array( |
1354
|
|
|
'limitationValues' => array('/1/43/51/'), |
1355
|
|
|
) |
1356
|
|
|
) |
1357
|
|
|
); |
1358
|
|
|
|
1359
|
|
|
$pseudoEditor = $userService->loadUser($user->id); |
1360
|
|
|
/* END: Inline */ |
1361
|
|
|
|
1362
|
|
|
return $pseudoEditor; |
1363
|
|
|
} |
1364
|
|
|
|
1365
|
|
|
/** |
1366
|
|
|
* Test that for an user that doesn't have access (read permissions) to an |
1367
|
|
|
* related object, executing loadRelations() would not throw any exception, |
1368
|
|
|
* only that the non-readable related object(s) won't be loaded. |
1369
|
|
|
* |
1370
|
|
|
* @see \eZ\Publish\API\Repository\ContentService::loadRelations() |
1371
|
|
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation |
1372
|
|
|
*/ |
1373
|
|
|
public function testLoadRelationsWithUnauthorizedRelations() |
1374
|
|
|
{ |
1375
|
|
|
$repository = $this->getRepository(); |
1376
|
|
|
|
1377
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
1378
|
|
|
/* BEGIN: Use Case */ |
1379
|
|
|
// $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
1380
|
|
|
// demo installation |
1381
|
|
|
$mainLanguage = 'eng-GB'; |
1382
|
|
|
|
1383
|
|
|
$contentService = $repository->getContentService(); |
1384
|
|
|
$contenTypeService = $repository->getContentTypeService(); |
1385
|
|
|
$locationService = $repository->getLocationService(); |
1386
|
|
|
$sectionService = $repository->getSectionService(); |
1387
|
|
|
$userService = $repository->getUserService(); |
1388
|
|
|
|
1389
|
|
|
// set the current user as admin to create the environment to test |
1390
|
|
|
$repository->setCurrentUser($userService->loadUserByLogin('admin')); |
|
|
|
|
1391
|
|
|
|
1392
|
|
|
// create section |
1393
|
|
|
// since anonymous users have their read permissions to specific sections |
1394
|
|
|
// the created section will be non-readable to them |
1395
|
|
|
$sectionCreate = $sectionService->newSectionCreateStruct(); |
1396
|
|
|
$sectionCreate->identifier = 'private'; |
1397
|
|
|
$sectionCreate->name = 'Private Section'; |
1398
|
|
|
$section = $sectionService->createSection($sectionCreate); |
1399
|
|
|
|
1400
|
|
|
// create objects for testing |
1401
|
|
|
// here we will create 4 objects which 2 will be readable by an anonymous |
1402
|
|
|
// user, and the other 2 wont these last 2 will go to a private section |
1403
|
|
|
// where anonymous can't read, just like: |
1404
|
|
|
// readable object 1 -> /Main Folder |
1405
|
|
|
// readable object 2 -> /Main Folder/Available Folder |
1406
|
|
|
// non-readable object 1 -> /Restricted Folder |
1407
|
|
|
// non-readable object 2 -> /Restricted Folder/Unavailable Folder |
1408
|
|
|
// |
1409
|
|
|
// here is created - readable object 1 -> /Main Folder |
1410
|
|
|
$mainFolderCreate = $contentService->newContentCreateStruct( |
1411
|
|
|
$contenTypeService->loadContentTypeByIdentifier('folder'), |
1412
|
|
|
$mainLanguage |
1413
|
|
|
); |
1414
|
|
|
$mainFolderCreate->setField('name', 'Main Folder'); |
1415
|
|
|
$mainFolder = $contentService->publishVersion( |
1416
|
|
|
$contentService->createContent( |
1417
|
|
|
$mainFolderCreate, |
1418
|
|
|
array($locationService->newLocationCreateStruct(2)) |
1419
|
|
|
)->versionInfo |
1420
|
|
|
); |
1421
|
|
|
|
1422
|
|
|
// here is created readable object 2 -> /Main Folder/Available Folder |
1423
|
|
|
$availableFolderCreate = $contentService->newContentCreateStruct( |
1424
|
|
|
$contenTypeService->loadContentTypeByIdentifier('folder'), |
1425
|
|
|
$mainLanguage |
1426
|
|
|
); |
1427
|
|
|
$availableFolderCreate->setField('name', 'Avaliable Folder'); |
1428
|
|
|
$availableFolder = $contentService->publishVersion( |
1429
|
|
|
$contentService->createContent( |
1430
|
|
|
$availableFolderCreate, |
1431
|
|
|
array($locationService->newLocationCreateStruct($mainFolder->contentInfo->mainLocationId)) |
1432
|
|
|
)->versionInfo |
1433
|
|
|
); |
1434
|
|
|
|
1435
|
|
|
// here is created the non-readable object 1 -> /Restricted Folder |
1436
|
|
|
$restrictedFolderCreate = $contentService->newContentCreateStruct( |
1437
|
|
|
$contenTypeService->loadContentTypeByIdentifier('folder'), |
1438
|
|
|
$mainLanguage |
1439
|
|
|
); |
1440
|
|
|
$restrictedFolderCreate->setField('name', 'Restricted Folder'); |
1441
|
|
|
$restrictedFolderCreate->sectionId = $section->id; |
1442
|
|
|
$restrictedFolder = $contentService->publishVersion( |
1443
|
|
|
$contentService->createContent( |
1444
|
|
|
$restrictedFolderCreate, |
1445
|
|
|
array($locationService->newLocationCreateStruct(2)) |
1446
|
|
|
)->versionInfo |
1447
|
|
|
); |
1448
|
|
|
|
1449
|
|
|
// here is created non-readable object 2 -> /Restricted Folder/Unavailable Folder |
1450
|
|
|
$unavailableFolderCreate = $contentService->newContentCreateStruct( |
1451
|
|
|
$contenTypeService->loadContentTypeByIdentifier('folder'), |
1452
|
|
|
$mainLanguage |
1453
|
|
|
); |
1454
|
|
|
$unavailableFolderCreate->setField('name', 'Unavailable Folder'); |
1455
|
|
|
$unavailableFolder = $contentService->publishVersion( |
1456
|
|
|
$contentService->createContent( |
1457
|
|
|
$unavailableFolderCreate, |
1458
|
|
|
array($locationService->newLocationCreateStruct($restrictedFolder->contentInfo->mainLocationId)) |
1459
|
|
|
)->versionInfo |
1460
|
|
|
); |
1461
|
|
|
|
1462
|
|
|
// this will be our test object, which will have all the relations (as source) |
1463
|
|
|
// and it is readable by the anonymous user |
1464
|
|
|
$testFolderCreate = $contentService->newContentCreateStruct( |
1465
|
|
|
$contenTypeService->loadContentTypeByIdentifier('folder'), |
1466
|
|
|
$mainLanguage |
1467
|
|
|
); |
1468
|
|
|
$testFolderCreate->setField('name', 'Test Folder'); |
1469
|
|
|
$testFolderDraft = $contentService->createContent( |
1470
|
|
|
$testFolderCreate, |
1471
|
|
|
array($locationService->newLocationCreateStruct(2)) |
1472
|
|
|
)->versionInfo; |
1473
|
|
|
|
1474
|
|
|
// add relations to test folder (as source) |
1475
|
|
|
// the first 2 will be read by the user |
1476
|
|
|
// and the other 2 wont |
1477
|
|
|
// |
1478
|
|
|
// create relation from Test Folder to Main Folder |
1479
|
|
|
$mainRelation = $contentService->addRelation( |
1480
|
|
|
$testFolderDraft, |
1481
|
|
|
$mainFolder->getVersionInfo()->getContentInfo() |
1482
|
|
|
); |
1483
|
|
|
// create relation from Test Folder to Available Folder |
1484
|
|
|
$availableRelation = $contentService->addRelation( |
1485
|
|
|
$testFolderDraft, |
1486
|
|
|
$availableFolder->getVersionInfo()->getContentInfo() |
1487
|
|
|
); |
1488
|
|
|
// create relation from Test Folder to Restricted Folder |
1489
|
|
|
$contentService->addRelation( |
1490
|
|
|
$testFolderDraft, |
1491
|
|
|
$restrictedFolder->getVersionInfo()->getContentInfo() |
1492
|
|
|
); |
1493
|
|
|
//create relation from Test Folder to Unavailable Folder |
1494
|
|
|
$contentService->addRelation( |
1495
|
|
|
$testFolderDraft, |
1496
|
|
|
$unavailableFolder->getVersionInfo()->getContentInfo() |
1497
|
|
|
); |
1498
|
|
|
|
1499
|
|
|
// publish Test Folder |
1500
|
|
|
$testFolder = $contentService->publishVersion($testFolderDraft); |
1501
|
|
|
|
1502
|
|
|
// set the current user to be an anonymous user since we want to test that |
1503
|
|
|
// if the user doesn't have access to an related object that object wont |
1504
|
|
|
// be loaded and no exception will be thrown |
1505
|
|
|
$repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
|
|
|
1506
|
|
|
|
1507
|
|
|
// finaly load relations ( verify no exception is thrown ) |
1508
|
|
|
$actualRelations = $contentService->loadRelations($testFolder->getVersionInfo()); |
1509
|
|
|
|
1510
|
|
|
/* END: Use case */ |
1511
|
|
|
|
1512
|
|
|
// assert results |
1513
|
|
|
// verify that the only expected relations are from the 2 readable objects |
1514
|
|
|
// Main Folder and Available Folder |
1515
|
|
|
$expectedRelations = array( |
1516
|
|
|
$mainRelation->destinationContentInfo->id => $mainRelation, |
1517
|
|
|
$availableRelation->destinationContentInfo->id => $availableRelation, |
1518
|
|
|
); |
1519
|
|
|
|
1520
|
|
|
// assert there are as many expected relations as actual ones |
1521
|
|
|
$this->assertEquals( |
1522
|
|
|
count($expectedRelations), |
1523
|
|
|
count($actualRelations), |
1524
|
|
|
"Expected '" . count($expectedRelations) |
1525
|
|
|
. "' relations found '" . count($actualRelations) . "'" |
1526
|
|
|
); |
1527
|
|
|
|
1528
|
|
|
// assert each relation |
1529
|
|
|
foreach ($actualRelations as $relation) { |
1530
|
|
|
$destination = $relation->destinationContentInfo; |
1531
|
|
|
$expected = $expectedRelations[$destination->id]->destinationContentInfo; |
1532
|
|
|
$this->assertNotEmpty($expected, "Non expected relation with '{$destination->id}' id found"); |
1533
|
|
|
$this->assertEquals( |
1534
|
|
|
$expected->id, |
1535
|
|
|
$destination->id, |
1536
|
|
|
"Expected relation with '{$expected->id}' id found '{$destination->id}' id" |
1537
|
|
|
); |
1538
|
|
|
$this->assertEquals( |
1539
|
|
|
$expected->name, |
1540
|
|
|
$destination->name, |
1541
|
|
|
"Expected relation with '{$expected->name}' name found '{$destination->name}' name" |
1542
|
|
|
); |
1543
|
|
|
|
1544
|
|
|
// remove from list |
1545
|
|
|
unset($expectedRelations[$destination->id]); |
1546
|
|
|
} |
1547
|
|
|
|
1548
|
|
|
// verify all expected relations were found |
1549
|
|
|
$this->assertEquals( |
1550
|
|
|
0, |
1551
|
|
|
count($expectedRelations), |
1552
|
|
|
"Expected to find '" . (count($expectedRelations) + count($actualRelations)) |
1553
|
|
|
. "' relations found '" . count($actualRelations) . "'" |
1554
|
|
|
); |
1555
|
|
|
} |
1556
|
|
|
|
1557
|
|
|
/** |
1558
|
|
|
* Test copying Content to the authorized Location (limited by policies). |
1559
|
|
|
*/ |
1560
|
|
|
public function testCopyContentToAuthorizedLocation() |
1561
|
|
|
{ |
1562
|
|
|
$repository = $this->getRepository(); |
1563
|
|
|
$contentService = $repository->getContentService(); |
1564
|
|
|
$locationService = $repository->getLocationService(); |
1565
|
|
|
$roleService = $repository->getRoleService(); |
1566
|
|
|
|
1567
|
|
|
// Create and publish folders for the test case |
1568
|
|
|
$folderDraft = $this->createContentDraft('folder', 2, ['name' => 'Folder1']); |
1569
|
|
|
$contentService->publishVersion($folderDraft->versionInfo); |
1570
|
|
|
$authorizedFolderDraft = $this->createContentDraft('folder', 2, ['name' => 'AuthorizedFolder']); |
1571
|
|
|
$authorizedFolder = $contentService->publishVersion($authorizedFolderDraft->versionInfo); |
1572
|
|
|
|
1573
|
|
|
// Prepare Role for the test case |
1574
|
|
|
$roleIdentifier = 'authorized_folder'; |
1575
|
|
|
$roleCreateStruct = $roleService->newRoleCreateStruct($roleIdentifier); |
1576
|
|
|
$locationLimitation = new LocationLimitation( |
1577
|
|
|
['limitationValues' => [$authorizedFolder->contentInfo->mainLocationId]] |
1578
|
|
|
); |
1579
|
|
|
$roleCreateStruct->addPolicy($roleService->newPolicyCreateStruct('content', 'read')); |
1580
|
|
|
$roleCreateStruct->addPolicy($roleService->newPolicyCreateStruct('content', 'versionread')); |
1581
|
|
|
|
1582
|
|
|
$policyCreateStruct = $roleService->newPolicyCreateStruct('content', 'create'); |
1583
|
|
|
$policyCreateStruct->addLimitation($locationLimitation); |
1584
|
|
|
$roleCreateStruct->addPolicy($policyCreateStruct); |
1585
|
|
|
|
1586
|
|
|
// check if content/publish policy is available (@since 6.8) |
1587
|
|
|
$limitations = $roleService->getLimitationTypesByModuleFunction('content', 'publish'); |
1588
|
|
|
if (array_key_exists('Node', $limitations)) { |
1589
|
|
|
$policyCreateStruct = $roleService->newPolicyCreateStruct('content', 'publish'); |
1590
|
|
|
$policyCreateStruct->addLimitation($locationLimitation); |
1591
|
|
|
$roleCreateStruct->addPolicy($policyCreateStruct); |
1592
|
|
|
} |
1593
|
|
|
|
1594
|
|
|
$roleDraft = $roleService->createRole($roleCreateStruct); |
1595
|
|
|
$roleService->publishRoleDraft($roleDraft); |
1596
|
|
|
|
1597
|
|
|
// Create a user with that Role |
1598
|
|
|
$user = $this->createCustomUserVersion1('Users', $roleIdentifier); |
1599
|
|
|
$repository->getPermissionResolver()->setCurrentUserReference($user); |
1600
|
|
|
|
1601
|
|
|
// Test copying Content to the authorized Location |
1602
|
|
|
$contentService->copyContent( |
1603
|
|
|
$authorizedFolder->contentInfo, |
1604
|
|
|
$locationService->newLocationCreateStruct( |
1605
|
|
|
$authorizedFolder->contentInfo->mainLocationId |
1606
|
|
|
) |
1607
|
|
|
); |
1608
|
|
|
} |
1609
|
|
|
} |
1610
|
|
|
|
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.