1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the RepositoryTest 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
|
|
|
* @version //autogentag// |
10
|
|
|
*/ |
11
|
|
|
namespace eZ\Publish\API\Repository\Tests; |
12
|
|
|
|
13
|
|
|
use Exception; |
14
|
|
|
use eZ\Publish\Core\Repository\Values\User\UserReference; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Test case for operations in the Repository using in memory storage. |
18
|
|
|
* |
19
|
|
|
* @see eZ\Publish\API\Repository\Repository |
20
|
|
|
* @group integration |
21
|
|
|
*/ |
22
|
|
|
class RepositoryTest extends BaseTest |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Test for the getContentService() method. |
26
|
|
|
* |
27
|
|
|
* @group content |
28
|
|
|
* @group user |
29
|
|
|
* |
30
|
|
|
* @see \eZ\Publish\API\Repository\Repository::getContentService() |
31
|
|
|
*/ |
32
|
|
|
public function testGetContentService() |
33
|
|
|
{ |
34
|
|
|
$repository = $this->getRepository(); |
35
|
|
|
$this->assertInstanceOf( |
36
|
|
|
'\\eZ\\Publish\\API\\Repository\\ContentService', |
37
|
|
|
$repository->getContentService() |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Test for the getContentLanguageService() method. |
43
|
|
|
* |
44
|
|
|
* @group language |
45
|
|
|
* |
46
|
|
|
* @see \eZ\Publish\API\Repository\Repository::getContentLanguageService() |
47
|
|
|
*/ |
48
|
|
|
public function testGetContentLanguageService() |
49
|
|
|
{ |
50
|
|
|
$repository = $this->getRepository(); |
51
|
|
|
$this->assertInstanceOf( |
52
|
|
|
'\\eZ\\Publish\\API\\Repository\\LanguageService', |
53
|
|
|
$repository->getContentLanguageService() |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Test for the getContentTypeService() method. |
59
|
|
|
* |
60
|
|
|
* @group content-type |
61
|
|
|
* @group field-type |
62
|
|
|
* @group user |
63
|
|
|
* |
64
|
|
|
* @see \eZ\Publish\API\Repository\Repository::getContentTypeService() |
65
|
|
|
*/ |
66
|
|
|
public function testGetContentTypeService() |
67
|
|
|
{ |
68
|
|
|
$repository = $this->getRepository(); |
69
|
|
|
$this->assertInstanceOf( |
70
|
|
|
'\\eZ\\Publish\\API\\Repository\\ContentTypeService', |
71
|
|
|
$repository->getContentTypeService() |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Test for the getLocationService() method. |
77
|
|
|
* |
78
|
|
|
* @group location |
79
|
|
|
* |
80
|
|
|
* @see \eZ\Publish\API\Repository\Repository::getLocationService() |
81
|
|
|
*/ |
82
|
|
|
public function testGetLocationService() |
83
|
|
|
{ |
84
|
|
|
$repository = $this->getRepository(); |
85
|
|
|
$this->assertInstanceOf( |
86
|
|
|
'\\eZ\\Publish\\API\\Repository\\LocationService', |
87
|
|
|
$repository->getLocationService() |
88
|
|
|
); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Test for the getSectionService() method. |
93
|
|
|
* |
94
|
|
|
* @group section |
95
|
|
|
* |
96
|
|
|
* @see \eZ\Publish\API\Repository\Repository::getSectionService() |
97
|
|
|
*/ |
98
|
|
|
public function testGetSectionService() |
99
|
|
|
{ |
100
|
|
|
$repository = $this->getRepository(); |
101
|
|
|
$this->assertInstanceOf( |
102
|
|
|
'\\eZ\\Publish\\API\\Repository\\SectionService', |
103
|
|
|
$repository->getSectionService() |
104
|
|
|
); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Test for the getUserService() method. |
109
|
|
|
* |
110
|
|
|
* @group user |
111
|
|
|
* |
112
|
|
|
* @see \eZ\Publish\API\Repository\Repository::getUserService() |
113
|
|
|
*/ |
114
|
|
|
public function testGetUserService() |
115
|
|
|
{ |
116
|
|
|
$repository = $this->getRepository(); |
117
|
|
|
$this->assertInstanceOf( |
118
|
|
|
'\\eZ\\Publish\\API\\Repository\\UserService', |
119
|
|
|
$repository->getUserService() |
120
|
|
|
); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Test for the getTrashService() method. |
125
|
|
|
* |
126
|
|
|
* @group trash |
127
|
|
|
* |
128
|
|
|
* @see \eZ\Publish\API\Repository\Repository::getTrashService() |
129
|
|
|
*/ |
130
|
|
|
public function testGetTrashService() |
131
|
|
|
{ |
132
|
|
|
$repository = $this->getRepository(); |
133
|
|
|
$this->assertInstanceOf( |
134
|
|
|
'\\eZ\\Publish\\API\\Repository\\TrashService', |
135
|
|
|
$repository->getTrashService() |
136
|
|
|
); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Test for the getRoleService() method. |
141
|
|
|
* |
142
|
|
|
* @group role |
143
|
|
|
* |
144
|
|
|
* @see \eZ\Publish\API\Repository\Repository::getRoleService() |
145
|
|
|
*/ |
146
|
|
|
public function testGetRoleService() |
147
|
|
|
{ |
148
|
|
|
$repository = $this->getRepository(); |
149
|
|
|
$this->assertInstanceOf( |
150
|
|
|
'\\eZ\\Publish\\API\\Repository\\RoleService', |
151
|
|
|
$repository->getRoleService() |
152
|
|
|
); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Test for the getURLAliasService() method. |
157
|
|
|
* |
158
|
|
|
* @group url-alias |
159
|
|
|
* |
160
|
|
|
* @see \eZ\Publish\API\Repository\Repository::getURLAliasService() |
161
|
|
|
*/ |
162
|
|
|
public function testGetURLAliasService() |
163
|
|
|
{ |
164
|
|
|
$repository = $this->getRepository(); |
165
|
|
|
$this->assertInstanceOf( |
166
|
|
|
'\\eZ\\Publish\\API\\Repository\\URLAliasService', |
167
|
|
|
$repository->getURLAliasService() |
168
|
|
|
); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Test for the getUrlWildcardService() method. |
173
|
|
|
* |
174
|
|
|
* @group url-wildcard |
175
|
|
|
* |
176
|
|
|
* @see \eZ\Publish\API\Repository\Repository::getUrlWildcardService() |
177
|
|
|
*/ |
178
|
|
|
public function testGetURLWildcardService() |
179
|
|
|
{ |
180
|
|
|
$repository = $this->getRepository(); |
181
|
|
|
$this->assertInstanceOf( |
182
|
|
|
'\\eZ\\Publish\\API\\Repository\\URLWildcardService', |
183
|
|
|
$repository->getURLWildcardService() |
184
|
|
|
); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* Test for the getObjectStateService(). |
189
|
|
|
* |
190
|
|
|
* @group object-state |
191
|
|
|
* |
192
|
|
|
* @see \eZ\Publish\API\Repository\Repository::getObjectStateService() |
193
|
|
|
*/ |
194
|
|
|
public function testGetObjectStateService() |
195
|
|
|
{ |
196
|
|
|
$repository = $this->getRepository(); |
197
|
|
|
$this->assertInstanceOf( |
198
|
|
|
'\\eZ\\Publish\\API\\Repository\\ObjectStateService', |
199
|
|
|
$repository->getObjectStateService() |
200
|
|
|
); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* Test for the getFieldTypeService(). |
205
|
|
|
* |
206
|
|
|
* @group object-state |
207
|
|
|
* |
208
|
|
|
* @see \eZ\Publish\API\Repository\Repository::getFieldTypeService() |
209
|
|
|
*/ |
210
|
|
|
public function testGetFieldTypeService() |
211
|
|
|
{ |
212
|
|
|
$repository = $this->getRepository(); |
213
|
|
|
$this->assertInstanceOf( |
214
|
|
|
'\\eZ\\Publish\\API\\Repository\\FieldTypeService', |
215
|
|
|
$repository->getFieldTypeService() |
216
|
|
|
); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* Test for the getSearchService() method. |
221
|
|
|
* |
222
|
|
|
* @group search |
223
|
|
|
* |
224
|
|
|
* @see \eZ\Publish\API\Repository\Repository::getSearchService() |
225
|
|
|
*/ |
226
|
|
|
public function testGetSearchService() |
227
|
|
|
{ |
228
|
|
|
$repository = $this->getRepository(); |
229
|
|
|
|
230
|
|
|
$this->assertInstanceOf( |
231
|
|
|
'\\eZ\\Publish\\API\\Repository\\SearchService', |
232
|
|
|
$repository->getSearchService() |
233
|
|
|
); |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* Test for the getSearchService() method. |
238
|
|
|
* |
239
|
|
|
* @group permission |
240
|
|
|
* |
241
|
|
|
* @see \eZ\Publish\API\Repository\Repository::getPermissionResolver() |
242
|
|
|
*/ |
243
|
|
|
public function testGetPermissionResolver() |
244
|
|
|
{ |
245
|
|
|
$repository = $this->getRepository(); |
246
|
|
|
|
247
|
|
|
$this->assertInstanceOf( |
248
|
|
|
'\\eZ\\Publish\\API\\Repository\\PermissionResolver', |
249
|
|
|
$repository->getPermissionResolver() |
250
|
|
|
); |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* Test for the commit() method. |
255
|
|
|
* |
256
|
|
|
* @see \eZ\Publish\API\Repository\Repository::commit() |
257
|
|
|
*/ |
258
|
|
|
public function testCommit() |
259
|
|
|
{ |
260
|
|
|
$repository = $this->getRepository(); |
261
|
|
|
|
262
|
|
|
try { |
263
|
|
|
$repository->beginTransaction(); |
264
|
|
|
$repository->commit(); |
265
|
|
|
} catch (Exception $e) { |
266
|
|
|
// Cleanup hanging transaction on error |
267
|
|
|
$repository->rollback(); |
268
|
|
|
throw $e; |
269
|
|
|
} |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* Test for the commit() method. |
274
|
|
|
* |
275
|
|
|
* @see \eZ\Publish\API\Repository\Repository::commit() |
276
|
|
|
* @expectedException \RuntimeException |
277
|
|
|
*/ |
278
|
|
|
public function testCommitThrowsRuntimeException() |
279
|
|
|
{ |
280
|
|
|
$repository = $this->getRepository(); |
281
|
|
|
$repository->commit(); |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* Test for the rollback() method. |
286
|
|
|
* |
287
|
|
|
* @see \eZ\Publish\API\Repository\Repository::rollback() |
288
|
|
|
*/ |
289
|
|
|
public function testRollback() |
290
|
|
|
{ |
291
|
|
|
$repository = $this->getRepository(); |
292
|
|
|
$repository->beginTransaction(); |
293
|
|
|
$repository->rollback(); |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
/** |
297
|
|
|
* Test for the rollback() method. |
298
|
|
|
* |
299
|
|
|
* @see \eZ\Publish\API\Repository\Repository::rollback() |
300
|
|
|
* @expectedException \RuntimeException |
301
|
|
|
*/ |
302
|
|
|
public function testRollbackThrowsRuntimeException() |
303
|
|
|
{ |
304
|
|
|
$repository = $this->getRepository(); |
305
|
|
|
$repository->rollback(); |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* Test for the getCurrentUser() method. |
310
|
|
|
* |
311
|
|
|
* @group content |
312
|
|
|
* @group user |
313
|
|
|
* |
314
|
|
|
* @see \eZ\Publish\API\Repository\Repository::getCurrentUser() |
315
|
|
|
*/ |
316
|
|
|
public function testGetCurrentUserReturnsAnonymousUser() |
317
|
|
|
{ |
318
|
|
|
$repository = $this->getRepository(); |
319
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
320
|
|
|
$repository->setCurrentUser(new UserReference($anonymousUserId)); |
|
|
|
|
321
|
|
|
|
322
|
|
|
/* BEGIN: Use Case */ |
323
|
|
|
// $anonymousUserId is the ID of the "Anonymous" user in a eZ |
324
|
|
|
// Publish demo installation. |
325
|
|
|
// Only a UserReference has previously been set to the $repository |
326
|
|
|
$anonymousUser = $repository->getCurrentUser(); |
|
|
|
|
327
|
|
|
/* END: Use Case */ |
328
|
|
|
|
329
|
|
|
$this->assertInstanceOf( |
330
|
|
|
'\\eZ\\Publish\\API\\Repository\\Values\\User\\User', |
331
|
|
|
$anonymousUser |
332
|
|
|
); |
333
|
|
|
$this->assertEquals( |
334
|
|
|
$anonymousUser->id, |
335
|
|
|
$repository->getUserService()->loadUser($anonymousUserId)->id |
336
|
|
|
); |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
/** |
340
|
|
|
* Test for the setCurrentUser() method. |
341
|
|
|
* |
342
|
|
|
* @group content |
343
|
|
|
* @group user |
344
|
|
|
* |
345
|
|
|
* @see \eZ\Publish\API\Repository\Repository::setCurrentUser() |
346
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
347
|
|
|
*/ |
348
|
|
View Code Duplication |
public function testSetCurrentUser() |
349
|
|
|
{ |
350
|
|
|
$repository = $this->getRepository(); |
351
|
|
|
$repository->setCurrentUser(new UserReference($this->generateId('user', 10))); |
|
|
|
|
352
|
|
|
|
353
|
|
|
$administratorUserId = $this->generateId('user', 14); |
354
|
|
|
|
355
|
|
|
/* BEGIN: Use Case */ |
356
|
|
|
// $administratorUserId contains the ID of the administrator user |
357
|
|
|
|
358
|
|
|
$userService = $repository->getUserService(); |
359
|
|
|
|
360
|
|
|
// Load administrator user |
361
|
|
|
$administratorUser = $userService->loadUser($administratorUserId); |
362
|
|
|
|
363
|
|
|
// Set administrator user as current user |
364
|
|
|
$repository->setCurrentUser($administratorUser); |
|
|
|
|
365
|
|
|
/* END: Use Case */ |
366
|
|
|
|
367
|
|
|
$this->assertEquals( |
368
|
|
|
$administratorUserId, |
369
|
|
|
$repository->getCurrentUserReference()->getUserId() |
|
|
|
|
370
|
|
|
); |
371
|
|
|
|
372
|
|
|
$this->assertEquals( |
373
|
|
|
$administratorUser->getUserId(), |
374
|
|
|
$repository->getCurrentUser()->getUserId() |
|
|
|
|
375
|
|
|
); |
376
|
|
|
|
377
|
|
|
$this->assertSame( |
378
|
|
|
$administratorUser, |
379
|
|
|
$repository->getCurrentUser() |
|
|
|
|
380
|
|
|
); |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
/** |
384
|
|
|
* Test for the hasAccess() method. |
385
|
|
|
* |
386
|
|
|
* @see \eZ\Publish\API\Repository\Repository::hasAccess() |
387
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
388
|
|
|
*/ |
389
|
|
|
public function testHasAccessWithAnonymousUserNo() |
390
|
|
|
{ |
391
|
|
|
$repository = $this->getRepository(); |
392
|
|
|
|
393
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
394
|
|
|
/* BEGIN: Use Case */ |
395
|
|
|
// $anonymousUserId is the ID of the "Anonymous" user in a eZ |
396
|
|
|
// Publish demo installation. |
397
|
|
|
$userService = $repository->getUserService(); |
398
|
|
|
|
399
|
|
|
// Load anonymous user |
400
|
|
|
$anonymousUser = $userService->loadUser($anonymousUserId); |
401
|
|
|
|
402
|
|
|
// This call will return false because anonymous user does not have access |
403
|
|
|
// to content removal |
404
|
|
|
$hasAccess = $repository->hasAccess('content', 'remove', $anonymousUser); |
|
|
|
|
405
|
|
|
/* END: Use Case */ |
406
|
|
|
|
407
|
|
|
$this->assertFalse($hasAccess); |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
/** |
411
|
|
|
* Test for the hasAccess() method. |
412
|
|
|
* |
413
|
|
|
* @see \eZ\Publish\API\Repository\Repository::hasAccess() |
414
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
415
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessWithAnonymousUserNo |
416
|
|
|
*/ |
417
|
|
|
public function testHasAccessForCurrentUserNo() |
418
|
|
|
{ |
419
|
|
|
$repository = $this->getRepository(); |
420
|
|
|
|
421
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
422
|
|
|
/* BEGIN: Use Case */ |
423
|
|
|
// $anonymousUserId is the ID of the "Anonymous" user in a eZ |
424
|
|
|
// Publish demo installation. |
425
|
|
|
$userService = $repository->getUserService(); |
426
|
|
|
|
427
|
|
|
// Load anonymous user |
428
|
|
|
$anonymousUser = $userService->loadUser($anonymousUserId); |
429
|
|
|
|
430
|
|
|
// Set anonymous user as current user |
431
|
|
|
$repository->setCurrentUser($anonymousUser); |
|
|
|
|
432
|
|
|
|
433
|
|
|
// This call will return false because anonymous user does not have access |
434
|
|
|
// to content removal |
435
|
|
|
$hasAccess = $repository->hasAccess('content', 'remove'); |
|
|
|
|
436
|
|
|
/* END: Use Case */ |
437
|
|
|
|
438
|
|
|
$this->assertFalse($hasAccess); |
439
|
|
|
} |
440
|
|
|
|
441
|
|
|
/** |
442
|
|
|
* Test for the hasAccess() method. |
443
|
|
|
* |
444
|
|
|
* @see \eZ\Publish\API\Repository\Repository::hasAccess() |
445
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
446
|
|
|
*/ |
447
|
|
|
public function testHasAccessWithAdministratorUser() |
448
|
|
|
{ |
449
|
|
|
$repository = $this->getRepository(); |
450
|
|
|
|
451
|
|
|
$administratorUserId = $this->generateId('user', 14); |
452
|
|
|
|
453
|
|
|
/* BEGIN: Use Case */ |
454
|
|
|
// $administratorUserId contains the ID of the administrator user |
455
|
|
|
|
456
|
|
|
$userService = $repository->getUserService(); |
457
|
|
|
|
458
|
|
|
// Load administrator user |
459
|
|
|
$administratorUser = $userService->loadUser($administratorUserId); |
460
|
|
|
|
461
|
|
|
// This call will return true |
462
|
|
|
$hasAccess = $repository->hasAccess('content', 'read', $administratorUser); |
|
|
|
|
463
|
|
|
/* END: Use Case */ |
464
|
|
|
|
465
|
|
|
$this->assertTrue($hasAccess); |
466
|
|
|
} |
467
|
|
|
|
468
|
|
|
/** |
469
|
|
|
* Test for the hasAccess() method. |
470
|
|
|
* |
471
|
|
|
* @see \eZ\Publish\API\Repository\Repository::hasAccess() |
472
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
473
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testSetCurrentUser |
474
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessWithAdministratorUser |
475
|
|
|
*/ |
476
|
|
|
public function testHasAccessForCurrentUserYes() |
477
|
|
|
{ |
478
|
|
|
$repository = $this->getRepository(); |
479
|
|
|
|
480
|
|
|
$administratorUserId = $this->generateId('user', 14); |
481
|
|
|
|
482
|
|
|
/* BEGIN: Use Case */ |
483
|
|
|
// $administratorUserId contains the ID of the administrator user |
484
|
|
|
|
485
|
|
|
$userService = $repository->getUserService(); |
486
|
|
|
|
487
|
|
|
// Load administrator user |
488
|
|
|
$administratorUser = $userService->loadUser($administratorUserId); |
489
|
|
|
|
490
|
|
|
// Set administrator user as current user |
491
|
|
|
$repository->setCurrentUser($administratorUser); |
|
|
|
|
492
|
|
|
|
493
|
|
|
// This call will return true |
494
|
|
|
$hasAccess = $repository->hasAccess('content', 'read'); |
|
|
|
|
495
|
|
|
/* END: Use Case */ |
496
|
|
|
|
497
|
|
|
$this->assertTrue($hasAccess); |
498
|
|
|
} |
499
|
|
|
|
500
|
|
|
/** |
501
|
|
|
* Test for the hasAccess() method. |
502
|
|
|
* |
503
|
|
|
* @see \eZ\Publish\API\Repository\Repository::hasAccess() |
504
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
505
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testSetCurrentUser |
506
|
|
|
*/ |
507
|
|
View Code Duplication |
public function testHasAccessLimited() |
508
|
|
|
{ |
509
|
|
|
$repository = $this->getRepository(); |
510
|
|
|
|
511
|
|
|
/* BEGIN: Use Case */ |
512
|
|
|
$user = $this->createUserVersion1(); |
513
|
|
|
|
514
|
|
|
// Set created user as current user |
515
|
|
|
$repository->setCurrentUser($user); |
|
|
|
|
516
|
|
|
|
517
|
|
|
// This call will return an array of permission sets describing user's access |
518
|
|
|
// to reading content |
519
|
|
|
$permissionSets = $repository->hasAccess('content', 'read'); |
|
|
|
|
520
|
|
|
/* END: Use Case */ |
521
|
|
|
|
522
|
|
|
$this->assertInternalType( |
523
|
|
|
'array', |
524
|
|
|
$permissionSets |
525
|
|
|
); |
526
|
|
|
$this->assertNotEmpty($permissionSets); |
527
|
|
|
} |
528
|
|
|
|
529
|
|
|
/** |
530
|
|
|
* Test for the canUser() method. |
531
|
|
|
* |
532
|
|
|
* @see \eZ\Publish\API\Repository\Repository::canUser() |
533
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
534
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
535
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessForCurrentUserNo |
536
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
537
|
|
|
*/ |
538
|
|
|
public function testCanUserForAnonymousUserNo() |
539
|
|
|
{ |
540
|
|
|
$repository = $this->getRepository(); |
541
|
|
|
|
542
|
|
|
$homeId = $this->generateId('object', 57); |
543
|
|
|
|
544
|
|
|
$anonymousUserId = $this->generateId('user', 10); |
545
|
|
|
/* BEGIN: Use Case */ |
546
|
|
|
// $anonymousUserId is the ID of the "Anonymous" user in a eZ |
547
|
|
|
// Publish demo installation. |
548
|
|
|
// $homeId contains the ID of the "Home" frontpage |
549
|
|
|
|
550
|
|
|
$contentService = $repository->getContentService(); |
551
|
|
|
$userService = $repository->getUserService(); |
552
|
|
|
|
553
|
|
|
// Load anonymous user |
554
|
|
|
$anonymousUser = $userService->loadUser($anonymousUserId); |
555
|
|
|
|
556
|
|
|
// Set anonymous user as current user |
557
|
|
|
$repository->setCurrentUser($anonymousUser); |
|
|
|
|
558
|
|
|
|
559
|
|
|
// Load the ContentInfo for "Home" frontpage |
560
|
|
|
$contentInfo = $contentService->loadContentInfo($homeId); |
561
|
|
|
|
562
|
|
|
// This call will return false because anonymous user does not have access |
563
|
|
|
// to content removal and hence no permission to remove given content |
564
|
|
|
$canUser = $repository->canUser('content', 'remove', $contentInfo); |
|
|
|
|
565
|
|
|
|
566
|
|
|
// Performing an action without necessary permissions will fail with "UnauthorizedException" |
567
|
|
|
if (!$canUser) { |
568
|
|
|
$contentService->deleteContent($contentInfo); |
569
|
|
|
} |
570
|
|
|
/* END: Use Case */ |
571
|
|
|
} |
572
|
|
|
|
573
|
|
|
/** |
574
|
|
|
* Test for the canUser() method. |
575
|
|
|
* |
576
|
|
|
* @see \eZ\Publish\API\Repository\Repository::canUser() |
577
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
578
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
579
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessForCurrentUserYes |
580
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
581
|
|
|
*/ |
582
|
|
View Code Duplication |
public function testCanUserForAdministratorUser() |
583
|
|
|
{ |
584
|
|
|
$repository = $this->getRepository(); |
585
|
|
|
|
586
|
|
|
$administratorUserId = $this->generateId('user', 14); |
587
|
|
|
$homeId = $this->generateId('object', 57); |
588
|
|
|
|
589
|
|
|
/* BEGIN: Use Case */ |
590
|
|
|
// $administratorUserId contains the ID of the administrator user |
591
|
|
|
// $homeId contains the ID of the "Home" frontpage |
592
|
|
|
|
593
|
|
|
$contentService = $repository->getContentService(); |
594
|
|
|
$userService = $repository->getUserService(); |
595
|
|
|
|
596
|
|
|
// Load administrator user |
597
|
|
|
$administratorUser = $userService->loadUser($administratorUserId); |
598
|
|
|
|
599
|
|
|
// Set administrator user as current user |
600
|
|
|
$repository->setCurrentUser($administratorUser); |
|
|
|
|
601
|
|
|
|
602
|
|
|
// Load the ContentInfo for "Home" frontpage |
603
|
|
|
$contentInfo = $contentService->loadContentInfo($homeId); |
604
|
|
|
|
605
|
|
|
// This call will return true |
606
|
|
|
$canUser = $repository->canUser('content', 'remove', $contentInfo); |
|
|
|
|
607
|
|
|
|
608
|
|
|
// Performing an action having necessary permissions will succeed |
609
|
|
|
$contentService->deleteContent($contentInfo); |
610
|
|
|
/* END: Use Case */ |
611
|
|
|
|
612
|
|
|
$this->assertTrue($canUser); |
613
|
|
|
$contentService->loadContent($homeId); |
614
|
|
|
} |
615
|
|
|
|
616
|
|
|
/** |
617
|
|
|
* Test for the canUser() method. |
618
|
|
|
* |
619
|
|
|
* @see \eZ\Publish\API\Repository\Repository::canUser() |
620
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
621
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
622
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited |
623
|
|
|
*/ |
624
|
|
|
public function testCanUserWithLimitationYes() |
625
|
|
|
{ |
626
|
|
|
$repository = $this->getRepository(); |
627
|
|
|
|
628
|
|
|
$imagesFolderId = $this->generateId('object', 49); |
629
|
|
|
|
630
|
|
|
/* BEGIN: Use Case */ |
631
|
|
|
// $imagesFolderId contains the ID of the "Images" folder |
632
|
|
|
|
633
|
|
|
$user = $this->createUserVersion1(); |
634
|
|
|
|
635
|
|
|
// Set created user as current user |
636
|
|
|
$repository->setCurrentUser($user); |
|
|
|
|
637
|
|
|
|
638
|
|
|
$contentService = $repository->getContentService(); |
639
|
|
|
|
640
|
|
|
// Performing an action having necessary permissions will succeed |
641
|
|
|
$imagesFolder = $contentService->loadContent($imagesFolderId); |
642
|
|
|
|
643
|
|
|
// This call will return true |
644
|
|
|
$canUser = $repository->canUser('content', 'read', $imagesFolder); |
|
|
|
|
645
|
|
|
/* END: Use Case */ |
646
|
|
|
|
647
|
|
|
$this->assertTrue($canUser); |
648
|
|
|
} |
649
|
|
|
|
650
|
|
|
/** |
651
|
|
|
* Test for the canUser() method. |
652
|
|
|
* |
653
|
|
|
* @see \eZ\Publish\API\Repository\Repository::canUser() |
654
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
655
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
656
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited |
657
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
658
|
|
|
*/ |
659
|
|
|
public function testCanUserWithLimitationNo() |
660
|
|
|
{ |
661
|
|
|
$repository = $this->getRepository(); |
662
|
|
|
|
663
|
|
|
$administratorUserId = $this->generateId('user', 14); |
664
|
|
|
|
665
|
|
|
/* BEGIN: Use Case */ |
666
|
|
|
// $administratorUserId contains the ID of the administrator user |
667
|
|
|
|
668
|
|
|
$user = $this->createUserVersion1(); |
669
|
|
|
|
670
|
|
|
// Set created user as current user |
671
|
|
|
$repository->setCurrentUser($user); |
|
|
|
|
672
|
|
|
|
673
|
|
|
$userService = $repository->getUserService(); |
674
|
|
|
|
675
|
|
|
// Load administrator user using UserService, this does not check for permissions |
676
|
|
|
$administratorUser = $userService->loadUser($administratorUserId); |
677
|
|
|
|
678
|
|
|
// This call will return false as user with Editor role does not have |
679
|
|
|
// permission to read "Users" subtree |
680
|
|
|
$canUser = $repository->canUser('content', 'read', $administratorUser); |
|
|
|
|
681
|
|
|
|
682
|
|
|
$contentService = $repository->getContentService(); |
683
|
|
|
|
684
|
|
|
// Performing an action without necessary permissions will fail with "UnauthorizedException" |
685
|
|
|
if (!$canUser) { |
686
|
|
|
$content = $contentService->loadContent($administratorUserId); |
|
|
|
|
687
|
|
|
} |
688
|
|
|
/* END: Use Case */ |
689
|
|
|
} |
690
|
|
|
|
691
|
|
|
/** |
692
|
|
|
* Test for the canUser() method. |
693
|
|
|
* |
694
|
|
|
* @see \eZ\Publish\API\Repository\Repository::canUser() |
695
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
696
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentTypeService |
697
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testSetCurrentUser |
698
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited |
699
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
700
|
|
|
*/ |
701
|
|
|
public function testCanUserThrowsInvalidArgumentException() |
702
|
|
|
{ |
703
|
|
|
$repository = $this->getRepository(); |
704
|
|
|
|
705
|
|
|
$userGroupContentTypeId = $this->generateId('type', 3); |
706
|
|
|
|
707
|
|
|
/* BEGIN: Use Case */ |
708
|
|
|
// $userGroupContentTypeId contains the ID of the "UserGroup" ContentType |
709
|
|
|
|
710
|
|
|
$user = $this->createUserVersion1(); |
711
|
|
|
|
712
|
|
|
// Set created user as current user |
713
|
|
|
$repository->setCurrentUser($user); |
|
|
|
|
714
|
|
|
|
715
|
|
|
$contentTypeService = $repository->getContentTypeService(); |
716
|
|
|
|
717
|
|
|
// Load the "UserGroup" ContentType |
718
|
|
|
$userGroupContentType = $contentTypeService->loadContentType($userGroupContentTypeId); |
719
|
|
|
|
720
|
|
|
// This call will throw "InvalidArgumentException" because $userGroupContentType |
721
|
|
|
// is an instance of \eZ\Publish\API\Repository\Values\ContentType\ContentType, |
722
|
|
|
// which can not be checked for user access |
723
|
|
|
$canUser = $repository->canUser('content', 'create', $userGroupContentType); |
|
|
|
|
724
|
|
|
/* END: Use Case */ |
725
|
|
|
} |
726
|
|
|
|
727
|
|
|
/** |
728
|
|
|
* Test for the canUser() method. |
729
|
|
|
* |
730
|
|
|
* @see \eZ\Publish\API\Repository\Repository::canUser() |
731
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
732
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
733
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentTypeService |
734
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited |
735
|
|
|
*/ |
736
|
|
View Code Duplication |
public function testCanUserWithTargetYes() |
737
|
|
|
{ |
738
|
|
|
$repository = $this->getRepository(); |
739
|
|
|
|
740
|
|
|
$homeLocationId = $this->generateId('location', 2); |
741
|
|
|
|
742
|
|
|
/* BEGIN: Use Case */ |
743
|
|
|
// $homeLocationId contains the ID of the "Home" location |
744
|
|
|
|
745
|
|
|
$user = $this->createUserVersion1(); |
746
|
|
|
|
747
|
|
|
// Set created user as current user |
748
|
|
|
$repository->setCurrentUser($user); |
|
|
|
|
749
|
|
|
|
750
|
|
|
$contentTypeService = $repository->getContentTypeService(); |
751
|
|
|
|
752
|
|
|
$contentType = $contentTypeService->loadContentTypeByIdentifier('forums'); |
753
|
|
|
|
754
|
|
|
$contentService = $repository->getContentService(); |
755
|
|
|
|
756
|
|
|
$contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-US'); |
757
|
|
|
$contentCreateStruct->setField('title', 'My awesome forums'); |
758
|
|
|
$contentCreateStruct->remoteId = 'abcdef0123456789abcdef0123456789'; |
759
|
|
|
$contentCreateStruct->alwaysAvailable = true; |
760
|
|
|
|
761
|
|
|
$locationService = $repository->getLocationService(); |
762
|
|
|
$locationCreateStruct = $locationService->newLocationCreateStruct($homeLocationId); |
763
|
|
|
|
764
|
|
|
// This call will return true |
765
|
|
|
$canUser = $repository->canUser( |
|
|
|
|
766
|
|
|
'content', |
767
|
|
|
'create', |
768
|
|
|
$contentCreateStruct, |
769
|
|
|
$locationCreateStruct |
770
|
|
|
); |
771
|
|
|
|
772
|
|
|
// Performing an action having necessary permissions will succeed |
773
|
|
|
$contentDraft = $contentService->createContent( |
774
|
|
|
$contentCreateStruct, |
775
|
|
|
array($locationCreateStruct) |
776
|
|
|
); |
777
|
|
|
/* END: Use Case */ |
778
|
|
|
|
779
|
|
|
$this->assertTrue($canUser); |
780
|
|
|
$this->assertEquals( |
781
|
|
|
'My awesome forums', |
782
|
|
|
$contentDraft->getFieldValue('title')->text |
783
|
|
|
); |
784
|
|
|
} |
785
|
|
|
|
786
|
|
|
/** |
787
|
|
|
* Test for the canUser() method. |
788
|
|
|
* |
789
|
|
|
* @see \eZ\Publish\API\Repository\Repository::canUser() |
790
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
791
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
792
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentTypeService |
793
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited |
794
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
795
|
|
|
*/ |
796
|
|
View Code Duplication |
public function testCanUserWithTargetNo() |
797
|
|
|
{ |
798
|
|
|
$repository = $this->getRepository(); |
799
|
|
|
|
800
|
|
|
$homeLocationId = $this->generateId('location', 2); |
801
|
|
|
|
802
|
|
|
/* BEGIN: Use Case */ |
803
|
|
|
// $homeLocationId contains the ID of the "Home" frontpage location |
804
|
|
|
|
805
|
|
|
$user = $this->createUserVersion1(); |
806
|
|
|
|
807
|
|
|
// Set created user as current user |
808
|
|
|
$repository->setCurrentUser($user); |
|
|
|
|
809
|
|
|
|
810
|
|
|
$contentTypeService = $repository->getContentTypeService(); |
811
|
|
|
|
812
|
|
|
$contentType = $contentTypeService->loadContentTypeByIdentifier('forum'); |
813
|
|
|
|
814
|
|
|
$contentService = $repository->getContentService(); |
815
|
|
|
|
816
|
|
|
$contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-US'); |
817
|
|
|
$contentCreateStruct->setField('name', 'My awesome forum'); |
818
|
|
|
$contentCreateStruct->remoteId = 'abcdef0123456789abcdef0123456789'; |
819
|
|
|
$contentCreateStruct->alwaysAvailable = true; |
820
|
|
|
|
821
|
|
|
$locationService = $repository->getLocationService(); |
822
|
|
|
$locationCreateStruct = $locationService->newLocationCreateStruct($homeLocationId); |
823
|
|
|
|
824
|
|
|
// This call will return false because user with Editor role has permission to |
825
|
|
|
// create "forum" type content only under "folder" type content. |
826
|
|
|
$canUser = $repository->canUser( |
|
|
|
|
827
|
|
|
'content', |
828
|
|
|
'create', |
829
|
|
|
$contentCreateStruct, |
830
|
|
|
$locationCreateStruct |
831
|
|
|
); |
832
|
|
|
|
833
|
|
|
// Performing an action without necessary permissions will fail with "UnauthorizedException" |
834
|
|
|
if (!$canUser) { |
835
|
|
|
$contentDraft = $contentService->createContent( |
|
|
|
|
836
|
|
|
$contentCreateStruct, |
837
|
|
|
array($locationCreateStruct) |
838
|
|
|
); |
839
|
|
|
} |
840
|
|
|
/* END: Use Case */ |
841
|
|
|
} |
842
|
|
|
|
843
|
|
|
/** |
844
|
|
|
* Test for the canUser() method. |
845
|
|
|
* |
846
|
|
|
* @see \eZ\Publish\API\Repository\Repository::canUser() |
847
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
848
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
849
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentTypeService |
850
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited |
851
|
|
|
*/ |
852
|
|
View Code Duplication |
public function testCanUserWithMultipleTargetsYes() |
853
|
|
|
{ |
854
|
|
|
$repository = $this->getRepository(); |
855
|
|
|
|
856
|
|
|
$imagesLocationId = $this->generateId('location', 51); |
857
|
|
|
$filesLocationId = $this->generateId('location', 52); |
858
|
|
|
|
859
|
|
|
/* BEGIN: Use Case */ |
860
|
|
|
// $imagesLocationId contains the ID of the "Images" location |
861
|
|
|
// $filesLocationId contains the ID of the "Files" location |
862
|
|
|
|
863
|
|
|
$user = $this->createUserVersion1(); |
864
|
|
|
|
865
|
|
|
// Set created user as current user |
866
|
|
|
$repository->setCurrentUser($user); |
|
|
|
|
867
|
|
|
|
868
|
|
|
$contentTypeService = $repository->getContentTypeService(); |
869
|
|
|
|
870
|
|
|
$contentType = $contentTypeService->loadContentTypeByIdentifier('folder'); |
871
|
|
|
|
872
|
|
|
$contentService = $repository->getContentService(); |
873
|
|
|
|
874
|
|
|
$contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-US'); |
875
|
|
|
$contentCreateStruct->setField('name', 'My multipurpose folder'); |
876
|
|
|
$contentCreateStruct->remoteId = 'abcdef0123456789abcdef0123456789'; |
877
|
|
|
$contentCreateStruct->alwaysAvailable = true; |
878
|
|
|
|
879
|
|
|
$locationService = $repository->getLocationService(); |
880
|
|
|
$locationCreateStruct1 = $locationService->newLocationCreateStruct($imagesLocationId); |
881
|
|
|
$locationCreateStruct2 = $locationService->newLocationCreateStruct($filesLocationId); |
882
|
|
|
$locationCreateStructs = array($locationCreateStruct1, $locationCreateStruct2); |
883
|
|
|
|
884
|
|
|
// This call will return true |
885
|
|
|
$canUser = $repository->canUser( |
|
|
|
|
886
|
|
|
'content', |
887
|
|
|
'create', |
888
|
|
|
$contentCreateStruct, |
889
|
|
|
$locationCreateStructs |
890
|
|
|
); |
891
|
|
|
|
892
|
|
|
// Performing an action having necessary permissions will succeed |
893
|
|
|
$contentDraft = $contentService->createContent($contentCreateStruct, $locationCreateStructs); |
894
|
|
|
/* END: Use Case */ |
895
|
|
|
|
896
|
|
|
$this->assertTrue($canUser); |
897
|
|
|
$this->assertEquals( |
898
|
|
|
'My multipurpose folder', |
899
|
|
|
$contentDraft->getFieldValue('name')->text |
900
|
|
|
); |
901
|
|
|
} |
902
|
|
|
|
903
|
|
|
/** |
904
|
|
|
* Test for the canUser() method. |
905
|
|
|
* |
906
|
|
|
* @see \eZ\Publish\API\Repository\Repository::canUser() |
907
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
908
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
909
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentTypeService |
910
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited |
911
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
912
|
|
|
*/ |
913
|
|
View Code Duplication |
public function testCanUserWithMultipleTargetsNo() |
914
|
|
|
{ |
915
|
|
|
$repository = $this->getRepository(); |
916
|
|
|
|
917
|
|
|
$homeLocationId = $this->generateId('location', 2); |
918
|
|
|
$administratorUsersLocationId = $this->generateId('location', 13); |
919
|
|
|
|
920
|
|
|
/* BEGIN: Use Case */ |
921
|
|
|
// $homeLocationId contains the ID of the "Home" location |
922
|
|
|
// $administratorUsersLocationId contains the ID of the "Administrator users" location |
923
|
|
|
|
924
|
|
|
$user = $this->createUserVersion1(); |
925
|
|
|
|
926
|
|
|
// Set created user as current user |
927
|
|
|
$repository->setCurrentUser($user); |
|
|
|
|
928
|
|
|
|
929
|
|
|
$contentTypeService = $repository->getContentTypeService(); |
930
|
|
|
|
931
|
|
|
$contentType = $contentTypeService->loadContentTypeByIdentifier('forums'); |
932
|
|
|
|
933
|
|
|
$contentService = $repository->getContentService(); |
934
|
|
|
|
935
|
|
|
$contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-US'); |
936
|
|
|
$contentCreateStruct->setField('name', 'My awesome forums'); |
937
|
|
|
$contentCreateStruct->remoteId = 'abcdef0123456789abcdef0123456789'; |
938
|
|
|
$contentCreateStruct->alwaysAvailable = true; |
939
|
|
|
|
940
|
|
|
$locationService = $repository->getLocationService(); |
941
|
|
|
$locationCreateStruct1 = $locationService->newLocationCreateStruct($homeLocationId); |
942
|
|
|
$locationCreateStruct2 = $locationService->newLocationCreateStruct($administratorUsersLocationId); |
943
|
|
|
$locationCreateStructs = array($locationCreateStruct1, $locationCreateStruct2); |
944
|
|
|
|
945
|
|
|
// This call will return false because user with Editor role does not have permission to |
946
|
|
|
// create content in the "Administrator users" location subtree |
947
|
|
|
$canUser = $repository->canUser( |
|
|
|
|
948
|
|
|
'content', |
949
|
|
|
'create', |
950
|
|
|
$contentCreateStruct, |
951
|
|
|
$locationCreateStructs |
952
|
|
|
); |
953
|
|
|
|
954
|
|
|
// Performing an action without necessary permissions will fail with "UnauthorizedException" |
955
|
|
|
if (!$canUser) { |
956
|
|
|
$contentDraft = $contentService->createContent($contentCreateStruct, $locationCreateStructs); |
|
|
|
|
957
|
|
|
} |
958
|
|
|
/* END: Use Case */ |
959
|
|
|
} |
960
|
|
|
|
961
|
|
|
/** |
962
|
|
|
* Test for the canUser() method. |
963
|
|
|
* |
964
|
|
|
* @see \eZ\Publish\API\Repository\Repository::canUser() |
965
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
966
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
967
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testSetCurrentUser |
968
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited |
969
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
970
|
|
|
*/ |
971
|
|
|
public function testCanUserWithTargetThrowsInvalidArgumentException() |
972
|
|
|
{ |
973
|
|
|
$repository = $this->getRepository(); |
974
|
|
|
|
975
|
|
|
$homeId = $this->generateId('object', 57); |
976
|
|
|
|
977
|
|
|
/* BEGIN: Use Case */ |
978
|
|
|
// $homeId contains the ID of the "Home" frontpage |
979
|
|
|
|
980
|
|
|
$user = $this->createUserVersion1(); |
981
|
|
|
|
982
|
|
|
// Set created user as current user |
983
|
|
|
$repository->setCurrentUser($user); |
|
|
|
|
984
|
|
|
|
985
|
|
|
$contentService = $repository->getContentService(); |
986
|
|
|
|
987
|
|
|
// Load the ContentInfo for "Home" frontpage |
988
|
|
|
$contentInfo = $contentService->loadContentInfo($homeId); |
989
|
|
|
|
990
|
|
|
// This call will throw "InvalidArgumentException" because $targets argument must be an |
991
|
|
|
// instance of \eZ\Publish\API\Repository\Values\ValueObject class or an array of the same |
992
|
|
|
$canUser = $repository->canUser( |
|
|
|
|
993
|
|
|
'content', |
994
|
|
|
'remove', |
995
|
|
|
$contentInfo, |
996
|
|
|
new \stdClass() |
997
|
|
|
); |
998
|
|
|
/* END: Use Case */ |
999
|
|
|
} |
1000
|
|
|
|
1001
|
|
|
/** |
1002
|
|
|
* Test for the canUser() method. |
1003
|
|
|
* |
1004
|
|
|
* @see \eZ\Publish\API\Repository\Repository::canUser() |
1005
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
1006
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
1007
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentTypeService |
1008
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetURLAliasService |
1009
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testSetCurrentUser |
1010
|
|
|
* @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited |
1011
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
1012
|
|
|
*/ |
1013
|
|
View Code Duplication |
public function testCanUserWithTargetThrowsInvalidArgumentExceptionVariant() |
1014
|
|
|
{ |
1015
|
|
|
$repository = $this->getRepository(); |
1016
|
|
|
|
1017
|
|
|
/* BEGIN: Use Case */ |
1018
|
|
|
$user = $this->createUserVersion1(); |
1019
|
|
|
|
1020
|
|
|
// Set created user as current user |
1021
|
|
|
$repository->setCurrentUser($user); |
|
|
|
|
1022
|
|
|
|
1023
|
|
|
$contentTypeService = $repository->getContentTypeService(); |
1024
|
|
|
|
1025
|
|
|
$contentType = $contentTypeService->loadContentTypeByIdentifier('forum'); |
1026
|
|
|
|
1027
|
|
|
$contentService = $repository->getContentService(); |
1028
|
|
|
|
1029
|
|
|
$contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-US'); |
1030
|
|
|
$contentCreateStruct->setField('name', 'My awesome forum'); |
1031
|
|
|
$contentCreateStruct->remoteId = 'abcdef0123456789abcdef0123456789'; |
1032
|
|
|
$contentCreateStruct->alwaysAvailable = true; |
1033
|
|
|
|
1034
|
|
|
$urlAliasService = $repository->getURLAliasService(); |
1035
|
|
|
$rootUrlAlias = $urlAliasService->lookUp('/'); |
1036
|
|
|
|
1037
|
|
|
// This call will throw "InvalidArgumentException" because $rootAlias is not a valid target object |
1038
|
|
|
$canUser = $repository->canUser( |
|
|
|
|
1039
|
|
|
'content', |
1040
|
|
|
'create', |
1041
|
|
|
$contentCreateStruct, |
1042
|
|
|
$rootUrlAlias |
1043
|
|
|
); |
1044
|
|
|
/* END: Use Case */ |
1045
|
|
|
} |
1046
|
|
|
|
1047
|
|
|
/** |
1048
|
|
|
* Test for the canUser() method. |
1049
|
|
|
* |
1050
|
|
|
* @see \eZ\Publish\API\Repository\Repository::canUser() |
1051
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
1052
|
|
|
*/ |
1053
|
|
|
public function testCanUserThrowsBadStateException() |
1054
|
|
|
{ |
1055
|
|
|
$this->markTestIncomplete( |
1056
|
|
|
'Cannot be tested on current fixture since policy with unsupported limitation value is not available.' |
1057
|
|
|
); |
1058
|
|
|
} |
1059
|
|
|
} |
1060
|
|
|
|
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.