|
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
|
|
|
namespace eZ\Publish\Core\Persistence\Cache\Tests; |
|
10
|
|
|
|
|
11
|
|
|
use eZ\Publish\SPI\Persistence\User; |
|
12
|
|
|
use eZ\Publish\SPI\Persistence\User\Handler; |
|
13
|
|
|
use eZ\Publish\SPI\Persistence\User\Role; |
|
14
|
|
|
use eZ\Publish\SPI\Persistence\User\RoleAssignment; |
|
15
|
|
|
use eZ\Publish\SPI\Persistence\User\RoleUpdateStruct; |
|
16
|
|
|
use eZ\Publish\SPI\Persistence\User\RoleCreateStruct; |
|
17
|
|
|
use eZ\Publish\SPI\Persistence\User\Policy; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Test case for Persistence\Cache\UserHandler. |
|
21
|
|
|
*/ |
|
22
|
|
|
class UserHandlerTest extends AbstractCacheHandlerTest |
|
23
|
|
|
{ |
|
24
|
|
|
public function getHandlerMethodName() : string |
|
25
|
|
|
{ |
|
26
|
|
|
return 'userHandler'; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function getHandlerClassName() : string |
|
30
|
|
|
{ |
|
31
|
|
|
return Handler::class; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function providerForUnCachedMethods() : array |
|
35
|
|
|
{ |
|
36
|
|
|
$user = new User(['id' => 14]); |
|
37
|
|
|
$policy = new Policy(['id' => 13, 'roleId' => 9]); |
|
38
|
|
|
|
|
39
|
|
|
// string $method, array $arguments, array? $tags, string? $key |
|
40
|
|
|
return [ |
|
41
|
|
|
['create', [$user], ['content-fields-14']], |
|
42
|
|
|
['update', [$user], ['content-fields-14', 'user-14']], |
|
43
|
|
|
['delete', [14], ['content-fields-14', 'user-14']], |
|
44
|
|
|
['createRole', [new RoleCreateStruct()]], |
|
45
|
|
|
['createRoleDraft', [new RoleCreateStruct()]], |
|
46
|
|
|
['loadRole', [9, 1]], |
|
47
|
|
|
['loadRoleByIdentifier', ['member', 1]], |
|
48
|
|
|
['loadRoleDraftByRoleId', [9]], |
|
49
|
|
|
['loadRoles', []], |
|
50
|
|
|
['updateRole', [new RoleUpdateStruct(['id' => 9])], ['role-9']], |
|
51
|
|
|
['deleteRole', [9], ['role-9', 'role-assignment-role-list-9']], |
|
52
|
|
|
['deleteRole', [9, 1]], |
|
53
|
|
|
['addPolicyByRoleDraft', [9, $policy]], |
|
54
|
|
|
['addPolicy', [9, $policy], ['role-9']], |
|
55
|
|
|
['updatePolicy', [$policy], ['policy-13', 'role-9']], |
|
56
|
|
|
['deletePolicy', [13, 9], ['policy-13', 'role-9']], |
|
57
|
|
|
['loadPoliciesByUserId', [14]], |
|
58
|
|
|
['assignRole', [14, 9], ['role-assignment-group-list-14', 'role-assignment-role-list-9']], |
|
59
|
|
|
['unassignRole', [14, 9], ['role-assignment-group-list-14', 'role-assignment-role-list-9']], |
|
60
|
|
|
['removeRoleAssignment', [11], ['role-assignment-11']], |
|
61
|
|
|
]; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function providerForCachedLoadMethods() : array |
|
65
|
|
|
{ |
|
66
|
|
|
$user = new User(['id' => 14]); |
|
67
|
|
|
$role = new Role(['id' => 9]); |
|
68
|
|
|
$roleAssignment = new RoleAssignment(['id' => 11, 'roleId' => 9, 'contentId' => 14]); |
|
69
|
|
|
|
|
70
|
|
|
// string $method, array $arguments, string $key, mixed? $data |
|
71
|
|
|
return [ |
|
72
|
|
|
['load', [14], 'ez-user-14', $user], |
|
73
|
|
|
['loadByLogin', ['admin'], 'ez-user-admin-by-login', $user], |
|
74
|
|
|
['loadByEmail', ['[email protected]'], 'ez-user-nospam§ez.no-by-email', [$user]], |
|
75
|
|
|
['loadRole', [9], 'ez-role-9', $role], |
|
76
|
|
|
['loadRoleByIdentifier', ['member'], 'ez-role-member-by-identifier', $role], |
|
77
|
|
|
['loadRoleAssignment', [11], 'ez-role-assignment-11', $roleAssignment], |
|
78
|
|
|
['loadRoleAssignmentsByRoleId', [9], 'ez-role-assignment-9-by-role', [$roleAssignment]], |
|
79
|
|
|
['loadRoleAssignmentsByGroupId', [14], 'ez-role-assignment-14-by-group', [$roleAssignment]], |
|
80
|
|
|
['loadRoleAssignmentsByGroupId', [14, true], 'ez-role-assignment-14-by-group-inherited', [$roleAssignment]], |
|
81
|
|
|
]; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function testPublishRoleDraftFromExistingRole() |
|
85
|
|
|
{ |
|
86
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
|
87
|
|
|
|
|
88
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\User\\Handler'); |
|
89
|
|
|
$this->persistenceHandlerMock |
|
90
|
|
|
->expects($this->once()) |
|
91
|
|
|
->method('userHandler') |
|
92
|
|
|
->willReturn($innerHandlerMock); |
|
93
|
|
|
|
|
94
|
|
|
$roleDraftId = 33; |
|
95
|
|
|
$originalRoleId = 30; |
|
96
|
|
|
$innerHandlerMock |
|
97
|
|
|
->expects($this->once()) |
|
98
|
|
|
->method('loadRole') |
|
99
|
|
|
->with($roleDraftId, Role::STATUS_DRAFT) |
|
100
|
|
|
->willReturn(new Role(['originalId' => $originalRoleId])); |
|
101
|
|
|
|
|
102
|
|
|
$innerHandlerMock |
|
103
|
|
|
->expects($this->once()) |
|
104
|
|
|
->method('publishRoleDraft') |
|
105
|
|
|
->with($roleDraftId); |
|
106
|
|
|
|
|
107
|
|
|
$this->cacheMock |
|
108
|
|
|
->expects($this->once()) |
|
109
|
|
|
->method('invalidateTags') |
|
110
|
|
|
->with(['role-'.$originalRoleId]); |
|
111
|
|
|
|
|
112
|
|
|
$this->cacheMock |
|
113
|
|
|
->expects($this->never()) |
|
114
|
|
|
->method('deleteItem'); |
|
115
|
|
|
|
|
116
|
|
|
$handler = $this->persistenceCacheHandler->userHandler(); |
|
117
|
|
|
$handler->publishRoleDraft($roleDraftId); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public function testPublishNewRoleDraft() |
|
121
|
|
|
{ |
|
122
|
|
|
$this->loggerMock->expects($this->once())->method('logCall'); |
|
123
|
|
|
|
|
124
|
|
|
$innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\User\\Handler'); |
|
125
|
|
|
$this->persistenceHandlerMock |
|
126
|
|
|
->expects($this->once()) |
|
127
|
|
|
->method('userHandler') |
|
128
|
|
|
->willReturn($innerHandlerMock); |
|
129
|
|
|
|
|
130
|
|
|
$roleDraftId = 33; |
|
131
|
|
|
$innerHandlerMock |
|
132
|
|
|
->expects($this->at(0)) |
|
133
|
|
|
->method('loadRole') |
|
134
|
|
|
->with($roleDraftId, Role::STATUS_DRAFT) |
|
135
|
|
|
->willReturn(new Role(['originalId' => -1])); |
|
136
|
|
|
|
|
137
|
|
|
$innerHandlerMock |
|
138
|
|
|
->expects($this->at(1)) |
|
139
|
|
|
->method('publishRoleDraft') |
|
140
|
|
|
->with($roleDraftId); |
|
141
|
|
|
|
|
142
|
|
|
$this->cacheMock |
|
143
|
|
|
->expects($this->never()) |
|
144
|
|
|
->method($this->anything()); |
|
145
|
|
|
|
|
146
|
|
|
$handler = $this->persistenceCacheHandler->userHandler(); |
|
147
|
|
|
$handler->publishRoleDraft($roleDraftId); |
|
148
|
|
|
} |
|
149
|
|
|
} |
|
150
|
|
|
|