1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File contains Test 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\Core\Persistence\Cache\Tests; |
12
|
|
|
|
13
|
|
|
use eZ\Publish\Core\Base\Exceptions\NotFoundException; |
14
|
|
|
use eZ\Publish\SPI\Persistence\User; |
15
|
|
|
use eZ\Publish\SPI\Persistence\User\Role; |
16
|
|
|
use eZ\Publish\SPI\Persistence\User\RoleAssignment; |
17
|
|
|
use eZ\Publish\SPI\Persistence\User\RoleUpdateStruct; |
18
|
|
|
use eZ\Publish\SPI\Persistence\User\Policy; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Test case for Persistence\Cache\UserHandler. |
22
|
|
|
*/ |
23
|
|
|
class UserHandlerTest extends HandlerTest |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Commented lines represent cached functions covered by specific unit tests further down. |
27
|
|
|
* |
28
|
|
|
* @return array |
29
|
|
|
*/ |
30
|
|
|
public function providerForUnCachedMethods() |
31
|
|
|
{ |
32
|
|
|
return array( |
33
|
|
|
//array( 'create', array( new User ) ), |
34
|
|
|
array('load', array(14)), |
35
|
|
|
array('loadByLogin', array('admin')), |
36
|
|
|
array('loadByEmail', array('[email protected]')), |
37
|
|
|
//array( 'update', array( new User ) ), |
38
|
|
|
//array( 'delete', array( 14 ) ), |
39
|
|
|
//array( 'createRole', array( new Role ) ), |
40
|
|
|
//array( 'loadRole', array( 22 ) ), |
41
|
|
|
array('loadRoleByIdentifier', array('users')), |
42
|
|
|
array('loadRoles', array()), |
43
|
|
|
array('loadRoleAssignmentsByRoleId', array(22)), |
44
|
|
|
//array( 'loadRoleAssignmentsByGroupId', array( 44, true ) ), |
45
|
|
|
//array( 'updateRole', array( new RoleUpdateStruct ) ), |
46
|
|
|
//array( 'deleteRole', array( 22 ) ), |
47
|
|
|
//array( 'addPolicy', array( 22, new Policy ) ), |
48
|
|
|
//array( 'updatePolicy', array( new Policy ) ), |
49
|
|
|
//array( 'deletePolicy', array( 22, 66 ) ), |
50
|
|
|
array('loadPoliciesByUserId', array(14)), |
51
|
|
|
//array( 'assignRole', array( 44, 22, array( 42 ) ) ), |
52
|
|
|
//array( 'unassignRole', array( 44, 22 ) ), |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @dataProvider providerForUnCachedMethods |
58
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UserHandler |
59
|
|
|
*/ |
60
|
|
View Code Duplication |
public function testUnCachedMethods($method, array $arguments) |
61
|
|
|
{ |
62
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
63
|
|
|
$this->cacheMock |
64
|
|
|
->expects($this->never()) |
65
|
|
|
->method($this->anything()); |
66
|
|
|
|
67
|
|
|
$innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\User\\Handler'); |
68
|
|
|
$this->persistenceHandlerMock |
69
|
|
|
->expects($this->once()) |
70
|
|
|
->method('userHandler') |
71
|
|
|
->will($this->returnValue($innerHandler)); |
72
|
|
|
|
73
|
|
|
$expects = $innerHandler |
74
|
|
|
->expects($this->once()) |
75
|
|
|
->method($method); |
76
|
|
|
|
77
|
|
|
if (isset($arguments[2])) { |
78
|
|
|
$expects->with($arguments[0], $arguments[1], $arguments[2]); |
79
|
|
|
} elseif (isset($arguments[1])) { |
80
|
|
|
$expects->with($arguments[0], $arguments[1]); |
81
|
|
|
} elseif (isset($arguments[0])) { |
82
|
|
|
$expects->with($arguments[0]); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
$expects->will($this->returnValue(null)); |
86
|
|
|
|
87
|
|
|
$handler = $this->persistenceCacheHandler->userHandler(); |
88
|
|
|
call_user_func_array(array($handler, $method), $arguments); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UserHandler::create |
93
|
|
|
*/ |
94
|
|
View Code Duplication |
public function testCreate() |
95
|
|
|
{ |
96
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
97
|
|
|
|
98
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\User\\Handler'); |
99
|
|
|
$this->persistenceHandlerMock |
100
|
|
|
->expects($this->once()) |
101
|
|
|
->method('userHandler') |
102
|
|
|
->will($this->returnValue($innerHandlerMock)); |
103
|
|
|
|
104
|
|
|
$innerHandlerMock |
105
|
|
|
->expects($this->once()) |
106
|
|
|
->method('create') |
107
|
|
|
->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\User')) |
108
|
|
|
->will( |
109
|
|
|
$this->returnValue(true) |
110
|
|
|
); |
111
|
|
|
|
112
|
|
|
$this->cacheMock |
113
|
|
|
->expects($this->at(0)) |
114
|
|
|
->method('clear') |
115
|
|
|
->with('content', 42) |
116
|
|
|
->will($this->returnValue(true)); |
117
|
|
|
|
118
|
|
|
$handler = $this->persistenceCacheHandler->userHandler(); |
119
|
|
|
$handler->create(new User(array('id' => 42))); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UserHandler::update |
124
|
|
|
*/ |
125
|
|
View Code Duplication |
public function testUpdate() |
126
|
|
|
{ |
127
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
128
|
|
|
|
129
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\User\\Handler'); |
130
|
|
|
$this->persistenceHandlerMock |
131
|
|
|
->expects($this->once()) |
132
|
|
|
->method('userHandler') |
133
|
|
|
->will($this->returnValue($innerHandlerMock)); |
134
|
|
|
|
135
|
|
|
$innerHandlerMock |
136
|
|
|
->expects($this->once()) |
137
|
|
|
->method('update') |
138
|
|
|
->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\User')) |
139
|
|
|
->will( |
140
|
|
|
$this->returnValue(true) |
141
|
|
|
); |
142
|
|
|
|
143
|
|
|
$this->cacheMock |
144
|
|
|
->expects($this->at(0)) |
145
|
|
|
->method('clear') |
146
|
|
|
->with('content', 42) |
147
|
|
|
->will($this->returnValue(true)); |
148
|
|
|
|
149
|
|
|
$handler = $this->persistenceCacheHandler->userHandler(); |
150
|
|
|
$handler->update(new User(array('id' => 42))); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UserHandler::delete |
155
|
|
|
*/ |
156
|
|
View Code Duplication |
public function testDelete() |
157
|
|
|
{ |
158
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
159
|
|
|
|
160
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\User\\Handler'); |
161
|
|
|
$this->persistenceHandlerMock |
162
|
|
|
->expects($this->once()) |
163
|
|
|
->method('userHandler') |
164
|
|
|
->will($this->returnValue($innerHandlerMock)); |
165
|
|
|
|
166
|
|
|
$innerHandlerMock |
167
|
|
|
->expects($this->once()) |
168
|
|
|
->method('delete') |
169
|
|
|
->with(14) |
170
|
|
|
->will( |
171
|
|
|
$this->returnValue(true) |
172
|
|
|
); |
173
|
|
|
|
174
|
|
|
$this->cacheMock |
175
|
|
|
->expects($this->at(0)) |
176
|
|
|
->method('clear') |
177
|
|
|
->with('content', 14) |
178
|
|
|
->will($this->returnValue(true)); |
179
|
|
|
|
180
|
|
|
$this->cacheMock |
181
|
|
|
->expects($this->at(1)) |
182
|
|
|
->method('clear') |
183
|
|
|
->with('user', 'role', 'assignments', 'byGroup', 14) |
184
|
|
|
->will($this->returnValue(true)); |
185
|
|
|
|
186
|
|
|
$this->cacheMock |
187
|
|
|
->expects($this->at(2)) |
188
|
|
|
->method('clear') |
189
|
|
|
->with('user', 'role', 'assignments', 'byGroup', 'inherited', 14) |
190
|
|
|
->will($this->returnValue(true)); |
191
|
|
|
|
192
|
|
|
$handler = $this->persistenceCacheHandler->userHandler(); |
193
|
|
|
$handler->delete(14); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UserHandler::loadRole |
198
|
|
|
*/ |
199
|
|
View Code Duplication |
public function testLoadRoleIsMiss() |
200
|
|
|
{ |
201
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
202
|
|
|
|
203
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
204
|
|
|
$this->cacheMock |
205
|
|
|
->expects($this->once()) |
206
|
|
|
->method('getItem') |
207
|
|
|
->with('user', 'role', 33) |
208
|
|
|
->will($this->returnValue($cacheItemMock)); |
209
|
|
|
|
210
|
|
|
$cacheItemMock |
211
|
|
|
->expects($this->once()) |
212
|
|
|
->method('get') |
213
|
|
|
->will($this->returnValue(null)); |
214
|
|
|
|
215
|
|
|
$cacheItemMock |
216
|
|
|
->expects($this->once()) |
217
|
|
|
->method('isMiss') |
218
|
|
|
->will($this->returnValue(true)); |
219
|
|
|
|
220
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\User\\Handler'); |
221
|
|
|
$this->persistenceHandlerMock |
222
|
|
|
->expects($this->once()) |
223
|
|
|
->method('userHandler') |
224
|
|
|
->will($this->returnValue($innerHandlerMock)); |
225
|
|
|
|
226
|
|
|
$innerHandlerMock |
227
|
|
|
->expects($this->once()) |
228
|
|
|
->method('loadRole') |
229
|
|
|
->with(33) |
230
|
|
|
->will( |
231
|
|
|
$this->returnValue(new Role()) |
232
|
|
|
); |
233
|
|
|
|
234
|
|
|
$cacheItemMock |
235
|
|
|
->expects($this->once()) |
236
|
|
|
->method('set') |
237
|
|
|
->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\User\\Role')) |
238
|
|
|
->will($this->returnValue($cacheItemMock)); |
239
|
|
|
|
240
|
|
|
$cacheItemMock |
241
|
|
|
->expects($this->once()) |
242
|
|
|
->method('save') |
243
|
|
|
->with(); |
244
|
|
|
|
245
|
|
|
$handler = $this->persistenceCacheHandler->userHandler(); |
246
|
|
|
$handler->loadRole(33); |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UserHandler::loadRole |
251
|
|
|
*/ |
252
|
|
View Code Duplication |
public function testLoadRoleHasCache() |
253
|
|
|
{ |
254
|
|
|
$this->loggerMock->expects($this->never())->method('logCall'); |
255
|
|
|
|
256
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
257
|
|
|
$this->cacheMock |
258
|
|
|
->expects($this->once()) |
259
|
|
|
->method('getItem') |
260
|
|
|
->with('user', 'role', 33) |
261
|
|
|
->will($this->returnValue($cacheItemMock)); |
262
|
|
|
|
263
|
|
|
$cacheItemMock |
264
|
|
|
->expects($this->once()) |
265
|
|
|
->method('get') |
266
|
|
|
->will($this->returnValue(new Role())); |
267
|
|
|
|
268
|
|
|
$cacheItemMock |
269
|
|
|
->expects($this->once()) |
270
|
|
|
->method('isMiss') |
271
|
|
|
->will($this->returnValue(false)); |
272
|
|
|
|
273
|
|
|
$this->persistenceHandlerMock |
274
|
|
|
->expects($this->never()) |
275
|
|
|
->method($this->anything()); |
276
|
|
|
|
277
|
|
|
$cacheItemMock |
278
|
|
|
->expects($this->never()) |
279
|
|
|
->method('set'); |
280
|
|
|
|
281
|
|
|
$handler = $this->persistenceCacheHandler->userHandler(); |
282
|
|
|
$handler->loadRole(33); |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
/** |
286
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UserHandler::loadRoleAssignmentsByGroupId |
287
|
|
|
*/ |
288
|
|
View Code Duplication |
public function testLoadRoleAssignmentsByGroupIdIsMiss() |
289
|
|
|
{ |
290
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
291
|
|
|
|
292
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
293
|
|
|
$this->cacheMock |
294
|
|
|
->expects($this->once()) |
295
|
|
|
->method('getItem') |
296
|
|
|
->with('user', 'role', 'assignments', 'byGroup', 42) |
297
|
|
|
->will($this->returnValue($cacheItemMock)); |
298
|
|
|
|
299
|
|
|
$cacheItemMock |
300
|
|
|
->expects($this->once()) |
301
|
|
|
->method('get') |
302
|
|
|
->will($this->returnValue(null)); |
303
|
|
|
|
304
|
|
|
$cacheItemMock |
305
|
|
|
->expects($this->once()) |
306
|
|
|
->method('isMiss') |
307
|
|
|
->will($this->returnValue(true)); |
308
|
|
|
|
309
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\User\\Handler'); |
310
|
|
|
$this->persistenceHandlerMock |
311
|
|
|
->expects($this->once()) |
312
|
|
|
->method('userHandler') |
313
|
|
|
->will($this->returnValue($innerHandlerMock)); |
314
|
|
|
|
315
|
|
|
$innerHandlerMock |
316
|
|
|
->expects($this->once()) |
317
|
|
|
->method('loadRoleAssignmentsByGroupId') |
318
|
|
|
->with(42, false) |
319
|
|
|
->will( |
320
|
|
|
$this->returnValue( |
321
|
|
|
array( |
322
|
|
|
new RoleAssignment(array('roleId' => 33)), |
323
|
|
|
) |
324
|
|
|
) |
325
|
|
|
); |
326
|
|
|
|
327
|
|
|
$cacheItemMock |
328
|
|
|
->expects($this->once()) |
329
|
|
|
->method('set') |
330
|
|
|
->with($this->isType('array')) |
331
|
|
|
->will($this->returnValue($cacheItemMock)); |
332
|
|
|
|
333
|
|
|
$cacheItemMock |
334
|
|
|
->expects($this->once()) |
335
|
|
|
->method('save') |
336
|
|
|
->with(); |
337
|
|
|
|
338
|
|
|
$handler = $this->persistenceCacheHandler->userHandler(); |
339
|
|
|
$roleAssignments = $handler->loadRoleAssignmentsByGroupId(42); |
340
|
|
|
|
341
|
|
|
$this->assertEquals(1, count($roleAssignments)); |
342
|
|
|
$this->assertInstanceOf('\\eZ\\Publish\\SPI\\Persistence\\User\\RoleAssignment', $roleAssignments[0]); |
343
|
|
|
$this->assertEquals(33, $roleAssignments[0]->roleId); |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
/** |
347
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UserHandler::loadRoleAssignmentsByGroupId |
348
|
|
|
*/ |
349
|
|
View Code Duplication |
public function testLoadRoleAssignmentsByGroupIdHasCache() |
350
|
|
|
{ |
351
|
|
|
$this->loggerMock->expects($this->never())->method('logCall'); |
352
|
|
|
|
353
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
354
|
|
|
$this->cacheMock |
355
|
|
|
->expects($this->once()) |
356
|
|
|
->method('getItem') |
357
|
|
|
->with('user', 'role', 'assignments', 'byGroup', 42) |
358
|
|
|
->will($this->returnValue($cacheItemMock)); |
359
|
|
|
|
360
|
|
|
$cacheItemMock |
361
|
|
|
->expects($this->once()) |
362
|
|
|
->method('get') |
363
|
|
|
->will( |
364
|
|
|
$this->returnValue(array(new RoleAssignment(array('roleId' => 33)))) |
365
|
|
|
); |
366
|
|
|
|
367
|
|
|
$cacheItemMock |
368
|
|
|
->expects($this->once()) |
369
|
|
|
->method('isMiss') |
370
|
|
|
->will($this->returnValue(false)); |
371
|
|
|
|
372
|
|
|
$this->persistenceHandlerMock |
373
|
|
|
->expects($this->never()) |
374
|
|
|
->method($this->anything()); |
375
|
|
|
|
376
|
|
|
$cacheItemMock |
377
|
|
|
->expects($this->never()) |
378
|
|
|
->method('set'); |
379
|
|
|
|
380
|
|
|
$handler = $this->persistenceCacheHandler->userHandler(); |
381
|
|
|
$roleAssignments = $handler->loadRoleAssignmentsByGroupId(42); |
382
|
|
|
|
383
|
|
|
$this->assertEquals(1, count($roleAssignments)); |
384
|
|
|
$this->assertInstanceOf('\\eZ\\Publish\\SPI\\Persistence\\User\\RoleAssignment', $roleAssignments[0]); |
385
|
|
|
$this->assertEquals(33, $roleAssignments[0]->roleId); |
386
|
|
|
} |
387
|
|
|
|
388
|
|
|
/** |
389
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UserHandler::loadRoleAssignmentsByGroupId |
390
|
|
|
*/ |
391
|
|
View Code Duplication |
public function testLoadRoleAssignmentsByGroupIdInheritedIsMiss() |
392
|
|
|
{ |
393
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
394
|
|
|
|
395
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
396
|
|
|
$this->cacheMock |
397
|
|
|
->expects($this->once()) |
398
|
|
|
->method('getItem') |
399
|
|
|
->with('user', 'role', 'assignments', 'byGroup', 'inherited', '42') |
400
|
|
|
->will($this->returnValue($cacheItemMock)); |
401
|
|
|
|
402
|
|
|
$cacheItemMock |
403
|
|
|
->expects($this->once()) |
404
|
|
|
->method('get') |
405
|
|
|
->will($this->returnValue(null)); |
406
|
|
|
|
407
|
|
|
$cacheItemMock |
408
|
|
|
->expects($this->once()) |
409
|
|
|
->method('isMiss') |
410
|
|
|
->will($this->returnValue(true)); |
411
|
|
|
|
412
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\User\\Handler'); |
413
|
|
|
$this->persistenceHandlerMock |
414
|
|
|
->expects($this->once()) |
415
|
|
|
->method('userHandler') |
416
|
|
|
->will($this->returnValue($innerHandlerMock)); |
417
|
|
|
|
418
|
|
|
$innerHandlerMock |
419
|
|
|
->expects($this->once()) |
420
|
|
|
->method('loadRoleAssignmentsByGroupId') |
421
|
|
|
->with(42, true) |
422
|
|
|
->will( |
423
|
|
|
$this->returnValue(array(new RoleAssignment(array('roleId' => 33)))) |
424
|
|
|
); |
425
|
|
|
|
426
|
|
|
$cacheItemMock |
427
|
|
|
->expects($this->once()) |
428
|
|
|
->method('set') |
429
|
|
|
->with($this->isType('array')) |
430
|
|
|
->will($this->returnValue($cacheItemMock)); |
431
|
|
|
|
432
|
|
|
$cacheItemMock |
433
|
|
|
->expects($this->once()) |
434
|
|
|
->method('save') |
435
|
|
|
->with(); |
436
|
|
|
|
437
|
|
|
$handler = $this->persistenceCacheHandler->userHandler(); |
438
|
|
|
$roleAssignments = $handler->loadRoleAssignmentsByGroupId(42, true); |
439
|
|
|
|
440
|
|
|
$this->assertEquals(1, count($roleAssignments)); |
441
|
|
|
$this->assertInstanceOf('\\eZ\\Publish\\SPI\\Persistence\\User\\RoleAssignment', $roleAssignments[0]); |
442
|
|
|
$this->assertEquals(33, $roleAssignments[0]->roleId); |
443
|
|
|
} |
444
|
|
|
|
445
|
|
|
/** |
446
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UserHandler::loadRoleAssignmentsByGroupId |
447
|
|
|
*/ |
448
|
|
View Code Duplication |
public function testLoadRoleAssignmentsByGroupIdInheritedHasCache() |
449
|
|
|
{ |
450
|
|
|
$this->loggerMock->expects($this->never())->method('logCall'); |
451
|
|
|
|
452
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
453
|
|
|
$this->cacheMock |
454
|
|
|
->expects($this->once()) |
455
|
|
|
->method('getItem') |
456
|
|
|
->with('user', 'role', 'assignments', 'byGroup', 'inherited', '42') |
457
|
|
|
->will($this->returnValue($cacheItemMock)); |
458
|
|
|
|
459
|
|
|
$cacheItemMock |
460
|
|
|
->expects($this->once()) |
461
|
|
|
->method('get') |
462
|
|
|
->will( |
463
|
|
|
$this->returnValue(array(new RoleAssignment(array('roleId' => 33)))) |
464
|
|
|
); |
465
|
|
|
|
466
|
|
|
$cacheItemMock |
467
|
|
|
->expects($this->once()) |
468
|
|
|
->method('isMiss') |
469
|
|
|
->will($this->returnValue(false)); |
470
|
|
|
|
471
|
|
|
$this->persistenceHandlerMock |
472
|
|
|
->expects($this->never()) |
473
|
|
|
->method($this->anything()); |
474
|
|
|
|
475
|
|
|
$cacheItemMock |
476
|
|
|
->expects($this->never()) |
477
|
|
|
->method('set'); |
478
|
|
|
|
479
|
|
|
$handler = $this->persistenceCacheHandler->userHandler(); |
480
|
|
|
$roleAssignments = $handler->loadRoleAssignmentsByGroupId(42, true); |
481
|
|
|
|
482
|
|
|
$this->assertEquals(1, count($roleAssignments)); |
483
|
|
|
$this->assertInstanceOf('\\eZ\\Publish\\SPI\\Persistence\\User\\RoleAssignment', $roleAssignments[0]); |
484
|
|
|
$this->assertEquals(33, $roleAssignments[0]->roleId); |
485
|
|
|
} |
486
|
|
|
|
487
|
|
|
/** |
488
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UserHandler::createRole |
489
|
|
|
*/ |
490
|
|
View Code Duplication |
public function testCreateRole() |
491
|
|
|
{ |
492
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
493
|
|
|
|
494
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\User\\Handler'); |
495
|
|
|
$this->persistenceHandlerMock |
496
|
|
|
->expects($this->once()) |
497
|
|
|
->method('userHandler') |
498
|
|
|
->will($this->returnValue($innerHandlerMock)); |
499
|
|
|
|
500
|
|
|
$innerHandlerMock |
501
|
|
|
->expects($this->once()) |
502
|
|
|
->method('createRole') |
503
|
|
|
->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\User\\RoleCreateStruct')) |
504
|
|
|
->will( |
505
|
|
|
$this->returnValue( |
506
|
|
|
new Role( |
507
|
|
|
['id' => 33, 'name' => 'Editors', 'identifier' => 'intranet', 'status' => Role::STATUS_DEFINED] |
508
|
|
|
) |
509
|
|
|
) |
510
|
|
|
); |
511
|
|
|
|
512
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
513
|
|
|
$this->cacheMock |
514
|
|
|
->expects($this->never()) |
515
|
|
|
->method('getItem'); |
516
|
|
|
|
517
|
|
|
$cacheItemMock |
518
|
|
|
->expects($this->never()) |
519
|
|
|
->method('set'); |
520
|
|
|
|
521
|
|
|
$cacheItemMock |
522
|
|
|
->expects($this->never()) |
523
|
|
|
->method('get'); |
524
|
|
|
|
525
|
|
|
$handler = $this->persistenceCacheHandler->userHandler(); |
526
|
|
|
$handler->createRole(new User\RoleCreateStruct()); |
527
|
|
|
} |
528
|
|
|
|
529
|
|
|
/** |
530
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UserHandler::createRoleDraft |
531
|
|
|
*/ |
532
|
|
|
public function testCreateRoleDraft() |
533
|
|
|
{ |
534
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
535
|
|
|
|
536
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\User\\Handler'); |
537
|
|
|
$this->persistenceHandlerMock |
538
|
|
|
->expects($this->once()) |
539
|
|
|
->method('userHandler') |
540
|
|
|
->will($this->returnValue($innerHandlerMock)); |
541
|
|
|
|
542
|
|
|
$innerHandlerMock |
543
|
|
|
->expects($this->once()) |
544
|
|
|
->method('createRoleDraft') |
545
|
|
|
->with(33) |
546
|
|
|
->will( |
547
|
|
|
$this->returnValue( |
548
|
|
|
new Role( |
549
|
|
|
['id' => 33, 'name' => 'Editors', 'identifier' => 'intranet', 'status' => Role::STATUS_DRAFT] |
550
|
|
|
) |
551
|
|
|
) |
552
|
|
|
); |
553
|
|
|
|
554
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
555
|
|
|
$this->cacheMock |
556
|
|
|
->expects($this->never()) |
557
|
|
|
->method('getItem'); |
558
|
|
|
|
559
|
|
|
$cacheItemMock |
560
|
|
|
->expects($this->never()) |
561
|
|
|
->method('set'); |
562
|
|
|
|
563
|
|
|
$cacheItemMock |
564
|
|
|
->expects($this->never()) |
565
|
|
|
->method('get'); |
566
|
|
|
|
567
|
|
|
$handler = $this->persistenceCacheHandler->userHandler(); |
568
|
|
|
$role = new Role(['id' => 33]); |
569
|
|
|
$handler->createRoleDraft($role->id); |
570
|
|
|
} |
571
|
|
|
|
572
|
|
|
/** |
573
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UserHandler::updateRole |
574
|
|
|
*/ |
575
|
|
View Code Duplication |
public function testUpdateRole() |
576
|
|
|
{ |
577
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
578
|
|
|
|
579
|
|
|
$innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\User\\Handler'); |
580
|
|
|
$this->persistenceHandlerMock |
581
|
|
|
->expects($this->once()) |
582
|
|
|
->method('userHandler') |
583
|
|
|
->will($this->returnValue($innerHandler)); |
584
|
|
|
|
585
|
|
|
$innerHandler |
586
|
|
|
->expects($this->once()) |
587
|
|
|
->method('updateRole') |
588
|
|
|
->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\User\\RoleUpdateStruct')); |
589
|
|
|
|
590
|
|
|
$roleUpdateStruct = new RoleUpdateStruct(); |
591
|
|
|
$roleUpdateStruct->id = 42; |
592
|
|
|
|
593
|
|
|
$this->cacheMock |
594
|
|
|
->expects($this->once()) |
595
|
|
|
->method('clear') |
596
|
|
|
->with('user', 'role', $roleUpdateStruct->id) |
597
|
|
|
->will($this->returnValue(true)); |
598
|
|
|
|
599
|
|
|
$this->cacheMock |
600
|
|
|
->expects($this->never()) |
601
|
|
|
->method('getItem'); |
602
|
|
|
|
603
|
|
|
$handler = $this->persistenceCacheHandler->userHandler(); |
604
|
|
|
$handler->updateRole($roleUpdateStruct); |
605
|
|
|
} |
606
|
|
|
|
607
|
|
|
/** |
608
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UserHandler::updateRole |
609
|
|
|
*/ |
610
|
|
View Code Duplication |
public function testUpdateRoleDraft() |
611
|
|
|
{ |
612
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
613
|
|
|
|
614
|
|
|
$innerHandler = $this->getMock('eZ\\Publish\\SPI\\Persistence\\User\\Handler'); |
615
|
|
|
$this->persistenceHandlerMock |
616
|
|
|
->expects($this->once()) |
617
|
|
|
->method('userHandler') |
618
|
|
|
->will($this->returnValue($innerHandler)); |
619
|
|
|
|
620
|
|
|
$innerHandler |
621
|
|
|
->expects($this->once()) |
622
|
|
|
->method('updateRole') |
623
|
|
|
->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\User\\RoleUpdateStruct')); |
624
|
|
|
|
625
|
|
|
$roleUpdateStruct = new RoleUpdateStruct(); |
626
|
|
|
$roleUpdateStruct->id = 42; |
627
|
|
|
|
628
|
|
|
$this->cacheMock |
629
|
|
|
->expects($this->once()) |
630
|
|
|
->method('clear') |
631
|
|
|
->with('user', 'role', $roleUpdateStruct->id) |
632
|
|
|
->will($this->returnValue(true)); |
633
|
|
|
|
634
|
|
|
$this->cacheMock |
635
|
|
|
->expects($this->never()) |
636
|
|
|
->method('getItem'); |
637
|
|
|
|
638
|
|
|
$handler = $this->persistenceCacheHandler->userHandler(); |
639
|
|
|
$handler->updateRole($roleUpdateStruct); |
640
|
|
|
} |
641
|
|
|
|
642
|
|
|
/** |
643
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UserHandler::deleteRole |
644
|
|
|
*/ |
645
|
|
View Code Duplication |
public function testDeleteRole() |
646
|
|
|
{ |
647
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
648
|
|
|
|
649
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\User\\Handler'); |
650
|
|
|
$this->persistenceHandlerMock |
651
|
|
|
->expects($this->once()) |
652
|
|
|
->method('userHandler') |
653
|
|
|
->will($this->returnValue($innerHandlerMock)); |
654
|
|
|
|
655
|
|
|
$innerHandlerMock |
656
|
|
|
->expects($this->once()) |
657
|
|
|
->method('deleteRole') |
658
|
|
|
->with(33) |
659
|
|
|
->will( |
660
|
|
|
$this->returnValue(true) |
661
|
|
|
); |
662
|
|
|
|
663
|
|
|
$this->cacheMock |
664
|
|
|
->expects($this->at(0)) |
665
|
|
|
->method('clear') |
666
|
|
|
->with('user', 'role', 33) |
667
|
|
|
->will($this->returnValue(true)); |
668
|
|
|
|
669
|
|
|
$this->cacheMock |
670
|
|
|
->expects($this->at(1)) |
671
|
|
|
->method('clear') |
672
|
|
|
->with('user', 'role', 'assignments') |
673
|
|
|
->will($this->returnValue(true)); |
674
|
|
|
|
675
|
|
|
$handler = $this->persistenceCacheHandler->userHandler(); |
676
|
|
|
$handler->deleteRole(33); |
677
|
|
|
} |
678
|
|
|
|
679
|
|
|
/** |
680
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UserHandler::deleteRole |
681
|
|
|
*/ |
682
|
|
|
public function testDeleteRoleDraft() |
683
|
|
|
{ |
684
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
685
|
|
|
|
686
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\User\\Handler'); |
687
|
|
|
$this->persistenceHandlerMock |
688
|
|
|
->expects($this->once()) |
689
|
|
|
->method('userHandler') |
690
|
|
|
->will($this->returnValue($innerHandlerMock)); |
691
|
|
|
|
692
|
|
|
$innerHandlerMock |
693
|
|
|
->expects($this->once()) |
694
|
|
|
->method('deleteRole') |
695
|
|
|
->with(33, Role::STATUS_DRAFT) |
696
|
|
|
->will( |
697
|
|
|
$this->returnValue(true) |
698
|
|
|
); |
699
|
|
|
|
700
|
|
|
$this->cacheMock |
701
|
|
|
->expects($this->never()) |
702
|
|
|
->method('clear'); |
703
|
|
|
|
704
|
|
|
$handler = $this->persistenceCacheHandler->userHandler(); |
705
|
|
|
$handler->deleteRole(33, Role::STATUS_DRAFT); |
706
|
|
|
} |
707
|
|
|
|
708
|
|
|
public function testPublishRoleDraftFromExistingRole() |
709
|
|
|
{ |
710
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
711
|
|
|
|
712
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\User\\Handler'); |
713
|
|
|
$this->persistenceHandlerMock |
714
|
|
|
->expects($this->once()) |
715
|
|
|
->method('userHandler') |
716
|
|
|
->willReturn($innerHandlerMock); |
717
|
|
|
|
718
|
|
|
$roleDraftId = 33; |
719
|
|
|
$originalRoleId = 30; |
720
|
|
|
$innerHandlerMock |
721
|
|
|
->expects($this->exactly(2)) |
722
|
|
|
->method('loadRole') |
723
|
|
|
->willReturnMap([ |
724
|
|
|
[$roleDraftId, Role::STATUS_DRAFT, new Role(['originalId' => $originalRoleId])], |
725
|
|
|
[$originalRoleId, Role::STATUS_DEFINED, new Role(['id' => $originalRoleId])], |
726
|
|
|
]); |
727
|
|
|
$innerHandlerMock |
728
|
|
|
->expects($this->once()) |
729
|
|
|
->method('publishRoleDraft') |
730
|
|
|
->with($roleDraftId); |
731
|
|
|
|
732
|
|
|
$this->cacheMock |
733
|
|
|
->expects($this->once()) |
734
|
|
|
->method('clear') |
735
|
|
|
->with('user', 'role', 'assignments') |
736
|
|
|
->will($this->returnValue(true)); |
737
|
|
|
|
738
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
739
|
|
|
$this->cacheMock |
740
|
|
|
->expects($this->once()) |
741
|
|
|
->method('getItem') |
742
|
|
|
->with('user', 'role', $originalRoleId) |
743
|
|
|
->will($this->returnValue($cacheItemMock)); |
744
|
|
|
|
745
|
|
|
$cacheItemMock |
746
|
|
|
->expects($this->once()) |
747
|
|
|
->method('set') |
748
|
|
|
->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\User\\Role')) |
749
|
|
|
->will($this->returnValue($cacheItemMock)); |
750
|
|
|
|
751
|
|
|
$cacheItemMock |
752
|
|
|
->expects($this->once()) |
753
|
|
|
->method('save') |
754
|
|
|
->with(); |
755
|
|
|
|
756
|
|
|
$handler = $this->persistenceCacheHandler->userHandler(); |
757
|
|
|
$handler->publishRoleDraft($roleDraftId); |
758
|
|
|
} |
759
|
|
|
|
760
|
|
|
public function testPublishNewRoleDraft() |
761
|
|
|
{ |
762
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
763
|
|
|
|
764
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\User\\Handler'); |
765
|
|
|
$this->persistenceHandlerMock |
766
|
|
|
->expects($this->once()) |
767
|
|
|
->method('userHandler') |
768
|
|
|
->willReturn($innerHandlerMock); |
769
|
|
|
|
770
|
|
|
$roleDraftId = 33; |
771
|
|
|
$originalRoleId = -1; |
772
|
|
|
$innerHandlerMock |
773
|
|
|
->expects($this->at(0)) |
774
|
|
|
->method('loadRole') |
775
|
|
|
->with($roleDraftId, Role::STATUS_DRAFT) |
776
|
|
|
->willReturn(new Role(['originalId' => $originalRoleId])); |
777
|
|
|
$innerHandlerMock |
778
|
|
|
->expects($this->at(1)) |
779
|
|
|
->method('publishRoleDraft') |
780
|
|
|
->with($roleDraftId); |
781
|
|
|
$innerHandlerMock |
782
|
|
|
->expects($this->at(2)) |
783
|
|
|
->method('loadRole') |
784
|
|
|
->with($originalRoleId, Role::STATUS_DEFINED) |
785
|
|
|
->willThrowException(new NotFoundException('foo', 'bar')); |
786
|
|
|
$innerHandlerMock |
787
|
|
|
->expects($this->at(3)) |
788
|
|
|
->method('loadRole') |
789
|
|
|
->with($roleDraftId, Role::STATUS_DEFINED) |
790
|
|
|
->willReturn(new Role(['id' => $roleDraftId])); |
791
|
|
|
|
792
|
|
|
$this->cacheMock |
793
|
|
|
->expects($this->once()) |
794
|
|
|
->method('clear') |
795
|
|
|
->with('user', 'role', 'assignments') |
796
|
|
|
->will($this->returnValue(true)); |
797
|
|
|
|
798
|
|
|
$cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
799
|
|
|
$this->cacheMock |
800
|
|
|
->expects($this->once()) |
801
|
|
|
->method('getItem') |
802
|
|
|
->with('user', 'role', $roleDraftId) |
803
|
|
|
->will($this->returnValue($cacheItemMock)); |
804
|
|
|
|
805
|
|
|
$cacheItemMock |
806
|
|
|
->expects($this->once()) |
807
|
|
|
->method('set') |
808
|
|
|
->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\User\\Role')) |
809
|
|
|
->will($this->returnValue($cacheItemMock)); |
810
|
|
|
|
811
|
|
|
$cacheItemMock |
812
|
|
|
->expects($this->once()) |
813
|
|
|
->method('save') |
814
|
|
|
->with(); |
815
|
|
|
|
816
|
|
|
$handler = $this->persistenceCacheHandler->userHandler(); |
817
|
|
|
$handler->publishRoleDraft($roleDraftId); |
818
|
|
|
} |
819
|
|
|
|
820
|
|
|
/** |
821
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UserHandler::addPolicy |
822
|
|
|
*/ |
823
|
|
View Code Duplication |
public function testAddPolicy() |
824
|
|
|
{ |
825
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
826
|
|
|
|
827
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\User\\Handler'); |
828
|
|
|
$this->persistenceHandlerMock |
829
|
|
|
->expects($this->once()) |
830
|
|
|
->method('userHandler') |
831
|
|
|
->will($this->returnValue($innerHandlerMock)); |
832
|
|
|
|
833
|
|
|
$innerHandlerMock |
834
|
|
|
->expects($this->once()) |
835
|
|
|
->method('addPolicy') |
836
|
|
|
->with(33, $this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\User\\Policy')) |
837
|
|
|
->will( |
838
|
|
|
$this->returnValue(new Policy()) |
839
|
|
|
); |
840
|
|
|
|
841
|
|
|
$this->cacheMock |
842
|
|
|
->expects($this->once()) |
843
|
|
|
->method('clear') |
844
|
|
|
->with('user', 'role', 33) |
845
|
|
|
->will($this->returnValue(true)); |
846
|
|
|
|
847
|
|
|
$handler = $this->persistenceCacheHandler->userHandler(); |
848
|
|
|
$handler->addPolicy(33, new Policy()); |
849
|
|
|
} |
850
|
|
|
|
851
|
|
|
/** |
852
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UserHandler::addPolicyByRoleDraft |
853
|
|
|
*/ |
854
|
|
|
public function testAddPolicyByRoleDraft() |
855
|
|
|
{ |
856
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
857
|
|
|
|
858
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\User\\Handler'); |
859
|
|
|
$this->persistenceHandlerMock |
860
|
|
|
->expects($this->once()) |
861
|
|
|
->method('userHandler') |
862
|
|
|
->will($this->returnValue($innerHandlerMock)); |
863
|
|
|
|
864
|
|
|
$innerHandlerMock |
865
|
|
|
->expects($this->once()) |
866
|
|
|
->method('addPolicyByRoleDraft') |
867
|
|
|
->with(33, $this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\User\\Policy')) |
868
|
|
|
->will( |
869
|
|
|
$this->returnValue(new Policy()) |
870
|
|
|
); |
871
|
|
|
|
872
|
|
|
$this->cacheMock |
873
|
|
|
->expects($this->never()) |
874
|
|
|
->method('clear'); |
875
|
|
|
|
876
|
|
|
$handler = $this->persistenceCacheHandler->userHandler(); |
877
|
|
|
$handler->addPolicyByRoleDraft(33, new Policy()); |
878
|
|
|
} |
879
|
|
|
|
880
|
|
|
/** |
881
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UserHandler::updatePolicy |
882
|
|
|
*/ |
883
|
|
View Code Duplication |
public function testUpdatePolicy() |
884
|
|
|
{ |
885
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
886
|
|
|
|
887
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\User\\Handler'); |
888
|
|
|
$this->persistenceHandlerMock |
889
|
|
|
->expects($this->once()) |
890
|
|
|
->method('userHandler') |
891
|
|
|
->will($this->returnValue($innerHandlerMock)); |
892
|
|
|
|
893
|
|
|
$innerHandlerMock |
894
|
|
|
->expects($this->once()) |
895
|
|
|
->method('updatePolicy') |
896
|
|
|
->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\User\\Policy')) |
897
|
|
|
->will( |
898
|
|
|
$this->returnValue(new Policy(array('roleId' => 33))) |
899
|
|
|
); |
900
|
|
|
|
901
|
|
|
$this->cacheMock |
902
|
|
|
->expects($this->once()) |
903
|
|
|
->method('clear') |
904
|
|
|
->with('user', 'role', 33) |
905
|
|
|
->will($this->returnValue(true)); |
906
|
|
|
|
907
|
|
|
$handler = $this->persistenceCacheHandler->userHandler(); |
908
|
|
|
$handler->updatePolicy(new Policy(array('roleId' => 33))); |
909
|
|
|
} |
910
|
|
|
|
911
|
|
|
/** |
912
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UserHandler::deletePolicy |
913
|
|
|
*/ |
914
|
|
|
public function testDeletePolicy() |
915
|
|
|
{ |
916
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
917
|
|
|
|
918
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\User\\Handler'); |
919
|
|
|
$this->persistenceHandlerMock |
920
|
|
|
->expects($this->once()) |
921
|
|
|
->method('userHandler') |
922
|
|
|
->will($this->returnValue($innerHandlerMock)); |
923
|
|
|
|
924
|
|
|
$innerHandlerMock |
925
|
|
|
->expects($this->once()) |
926
|
|
|
->method('deletePolicy') |
927
|
|
|
->with(55) |
928
|
|
|
->will( |
929
|
|
|
$this->returnValue(true) |
930
|
|
|
); |
931
|
|
|
|
932
|
|
|
$this->cacheMock |
933
|
|
|
->expects($this->once()) |
934
|
|
|
->method('clear') |
935
|
|
|
->with('user', 'role') |
936
|
|
|
->will($this->returnValue(true)); |
937
|
|
|
|
938
|
|
|
$handler = $this->persistenceCacheHandler->userHandler(); |
939
|
|
|
$handler->deletePolicy(55); |
940
|
|
|
} |
941
|
|
|
|
942
|
|
|
/** |
943
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UserHandler::assignRole |
944
|
|
|
*/ |
945
|
|
View Code Duplication |
public function testAssignRole() |
946
|
|
|
{ |
947
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
948
|
|
|
|
949
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\User\\Handler'); |
950
|
|
|
$this->persistenceHandlerMock |
951
|
|
|
->expects($this->once()) |
952
|
|
|
->method('userHandler') |
953
|
|
|
->will($this->returnValue($innerHandlerMock)); |
954
|
|
|
|
955
|
|
|
$innerHandlerMock |
956
|
|
|
->expects($this->once()) |
957
|
|
|
->method('assignRole') |
958
|
|
|
->with(33, 22) |
959
|
|
|
->will( |
960
|
|
|
$this->returnValue(true) |
961
|
|
|
); |
962
|
|
|
|
963
|
|
|
$this->cacheMock |
964
|
|
|
->expects($this->at(0)) |
965
|
|
|
->method('clear') |
966
|
|
|
->with('user', 'role', 22) |
967
|
|
|
->will($this->returnValue(true)); |
968
|
|
|
|
969
|
|
|
$this->cacheMock |
970
|
|
|
->expects($this->at(1)) |
971
|
|
|
->method('clear') |
972
|
|
|
->with('user', 'role', 'assignments', 'byGroup', 33) |
973
|
|
|
->will($this->returnValue(true)); |
974
|
|
|
|
975
|
|
|
$this->cacheMock |
976
|
|
|
->expects($this->at(2)) |
977
|
|
|
->method('clear') |
978
|
|
|
->with('user', 'role', 'assignments', 'byGroup', 'inherited') |
979
|
|
|
->will($this->returnValue(true)); |
980
|
|
|
|
981
|
|
|
$handler = $this->persistenceCacheHandler->userHandler(); |
982
|
|
|
$handler->assignRole(33, 22); |
983
|
|
|
} |
984
|
|
|
|
985
|
|
|
/** |
986
|
|
|
* @covers eZ\Publish\Core\Persistence\Cache\UserHandler::unassignRole |
987
|
|
|
*/ |
988
|
|
View Code Duplication |
public function testUnassignRole() |
989
|
|
|
{ |
990
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
991
|
|
|
|
992
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\User\\Handler'); |
993
|
|
|
$this->persistenceHandlerMock |
994
|
|
|
->expects($this->once()) |
995
|
|
|
->method('userHandler') |
996
|
|
|
->will($this->returnValue($innerHandlerMock)); |
997
|
|
|
|
998
|
|
|
$innerHandlerMock |
999
|
|
|
->expects($this->once()) |
1000
|
|
|
->method('unassignRole') |
1001
|
|
|
->with(33, 22) |
1002
|
|
|
->will( |
1003
|
|
|
$this->returnValue(true) |
1004
|
|
|
); |
1005
|
|
|
|
1006
|
|
|
$this->cacheMock |
1007
|
|
|
->expects($this->at(0)) |
1008
|
|
|
->method('clear') |
1009
|
|
|
->with('user', 'role', 22) |
1010
|
|
|
->will($this->returnValue(true)); |
1011
|
|
|
|
1012
|
|
|
$this->cacheMock |
1013
|
|
|
->expects($this->at(1)) |
1014
|
|
|
->method('clear') |
1015
|
|
|
->with('user', 'role', 'assignments', 'byGroup', 33) |
1016
|
|
|
->will($this->returnValue(true)); |
1017
|
|
|
|
1018
|
|
|
$this->cacheMock |
1019
|
|
|
->expects($this->at(2)) |
1020
|
|
|
->method('clear') |
1021
|
|
|
->with('user', 'role', 'assignments', 'byGroup', 'inherited') |
1022
|
|
|
->will($this->returnValue(true)); |
1023
|
|
|
|
1024
|
|
|
$handler = $this->persistenceCacheHandler->userHandler(); |
1025
|
|
|
$handler->unassignRole(33, 22); |
1026
|
|
|
} |
1027
|
|
|
} |
1028
|
|
|
|