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