Complex classes like UserHandlerTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use UserHandlerTest, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
26 | class UserHandlerTest extends TestCase |
||
27 | { |
||
28 | private const TEST_USER_ID = 42; |
||
29 | |||
30 | /** |
||
31 | * @throws \Doctrine\DBAL\DBALException |
||
32 | */ |
||
33 | protected function getUserHandler(User\Gateway $userGateway = null): Handler |
||
34 | { |
||
35 | $dbHandler = $this->getDatabaseHandler(); |
||
36 | |||
37 | return new User\Handler( |
||
38 | $userGateway ?? new User\Gateway\DoctrineDatabase($this->getDatabaseConnection()), |
||
39 | new User\Role\Gateway\DoctrineDatabase($this->getDatabaseConnection()), |
||
40 | new User\Mapper(), |
||
41 | new LimitationConverter([new ObjectStateLimitationHandler($dbHandler)]) |
||
42 | ); |
||
43 | } |
||
44 | |||
45 | protected function getValidUser() |
||
46 | { |
||
47 | $user = new Persistence\User(); |
||
48 | $user->id = self::TEST_USER_ID; |
||
49 | $user->login = 'kore'; |
||
50 | $user->email = '[email protected]'; |
||
51 | $user->passwordHash = '1234567890'; |
||
52 | $user->hashAlgorithm = 2; |
||
53 | $user->isEnabled = true; |
||
54 | $user->maxLogin = 23; |
||
55 | $user->passwordUpdatedAt = 1569229200; |
||
56 | |||
57 | return $user; |
||
58 | } |
||
59 | |||
60 | protected function getValidUserToken($time = null) |
||
61 | { |
||
62 | $userToken = new Persistence\User\UserTokenUpdateStruct(); |
||
63 | $userToken->userId = self::TEST_USER_ID; |
||
64 | $userToken->hashKey = md5('hash'); |
||
65 | $userToken->time = $time ?? (new DateTime())->add(new DateInterval('P1D'))->getTimestamp(); |
||
66 | |||
67 | return $userToken; |
||
68 | } |
||
69 | |||
70 | public function testCreateUser() |
||
71 | { |
||
72 | $handler = $this->getUserHandler(); |
||
73 | |||
74 | $this->expectException(NotImplementedException::class); |
||
75 | $handler->create($this->getValidUser()); |
||
76 | } |
||
77 | |||
78 | protected function getGatewayReturnValue(): array |
||
79 | { |
||
80 | return [ |
||
81 | $this->getDummyUser( |
||
82 | self::TEST_USER_ID, |
||
83 | 'kore', |
||
84 | '[email protected]' |
||
85 | ), |
||
86 | ]; |
||
87 | } |
||
88 | |||
89 | protected function getDummyUser( |
||
90 | int $id, |
||
91 | string $login, |
||
92 | string $email |
||
93 | ): array { |
||
94 | return [ |
||
95 | 'contentobject_id' => $id, |
||
96 | 'login' => $login, |
||
97 | 'email' => $email, |
||
98 | 'password_hash' => '1234567890', |
||
99 | 'password_hash_type' => 2, |
||
100 | 'is_enabled' => true, |
||
101 | 'max_login' => 23, |
||
102 | 'password_updated_at' => 1569229200, |
||
103 | ]; |
||
104 | } |
||
105 | |||
106 | public function testLoadUser() |
||
107 | { |
||
108 | $gatewayMock = $this |
||
109 | ->createMock(User\Gateway::class); |
||
110 | |||
111 | $gatewayMock |
||
|
|||
112 | ->method('load') |
||
113 | ->with(self::TEST_USER_ID) |
||
114 | ->willReturn($this->getGatewayReturnValue()); |
||
115 | |||
116 | $handler = $this->getUserHandler($gatewayMock); |
||
117 | |||
118 | $user = $this->getValidUser(); |
||
119 | |||
120 | $this->assertEquals( |
||
121 | $user, |
||
122 | $handler->load($user->id) |
||
123 | ); |
||
124 | } |
||
125 | |||
126 | public function testLoadUnknownUser() |
||
127 | { |
||
128 | $this->expectException(NotFoundException::class); |
||
129 | $gatewayMock = $this |
||
130 | ->createMock(User\Gateway::class); |
||
131 | |||
132 | $gatewayMock |
||
133 | ->method('load') |
||
134 | ->with(1337) |
||
135 | ->willReturn([]); |
||
136 | |||
137 | $handler = $this->getUserHandler($gatewayMock); |
||
138 | |||
139 | $handler->load(1337); |
||
140 | } |
||
141 | |||
142 | public function testLoadUserByLogin() |
||
143 | { |
||
144 | $gatewayMock = $this |
||
145 | ->createMock(User\Gateway::class); |
||
146 | |||
147 | $gatewayMock |
||
148 | ->method('loadByLogin') |
||
149 | ->with('kore') |
||
150 | ->willReturn($this->getGatewayReturnValue()); |
||
151 | |||
152 | $handler = $this->getUserHandler($gatewayMock); |
||
153 | $user = $this->getValidUser(); |
||
154 | |||
155 | $loadedUser = $handler->loadByLogin($user->login); |
||
156 | $this->assertEquals( |
||
157 | $user, |
||
158 | $loadedUser |
||
159 | ); |
||
160 | } |
||
161 | |||
162 | public function testLoadMultipleUsersByLogin() |
||
163 | { |
||
164 | $this->expectException(LogicException::class); |
||
165 | |||
166 | $gatewayMock = $this |
||
167 | ->createMock(User\Gateway::class); |
||
168 | |||
169 | $gatewayMock |
||
170 | ->method('loadByLogin') |
||
171 | ->with('kore') |
||
172 | ->willReturn([ |
||
173 | $this->getDummyUser(self::TEST_USER_ID, 'kore', '[email protected]'), |
||
174 | $this->getDummyUser(self::TEST_USER_ID + 1, 'kore', '[email protected]'), |
||
175 | ]); |
||
176 | |||
177 | $handler = $this->getUserHandler($gatewayMock); |
||
178 | $user = $this->getValidUser(); |
||
179 | |||
180 | $handler->loadByLogin($user->login); |
||
181 | } |
||
182 | |||
183 | public function testLoadMultipleUsersByEmail() |
||
184 | { |
||
185 | $this->expectException(LogicException::class); |
||
186 | |||
187 | $gatewayMock = $this |
||
188 | ->createMock(User\Gateway::class); |
||
189 | |||
190 | $gatewayMock |
||
191 | ->method('loadByEmail') |
||
192 | ->with('[email protected]') |
||
193 | ->willReturn([ |
||
194 | $this->getDummyUser(self::TEST_USER_ID, 'kore_a', '[email protected]'), |
||
195 | $this->getDummyUser(self::TEST_USER_ID + 1, 'kore_b', '[email protected]'), |
||
196 | ]); |
||
197 | |||
198 | $handler = $this->getUserHandler($gatewayMock); |
||
199 | $user = $this->getValidUser(); |
||
200 | |||
201 | $handler->loadByEmail($user->email); |
||
202 | } |
||
203 | |||
204 | public function testLoadUserByEmailNotFound() |
||
205 | { |
||
206 | $this->expectException(NotFoundException::class); |
||
207 | |||
208 | $handler = $this->getUserHandler(); |
||
209 | $user = $this->getValidUser(); |
||
210 | |||
211 | $handler->loadByLogin($user->email); |
||
212 | } |
||
213 | |||
214 | public function testLoadUserByEmail() |
||
215 | { |
||
216 | $gatewayMock = $this |
||
217 | ->createMock(User\Gateway::class); |
||
218 | |||
219 | $gatewayMock |
||
220 | ->method('loadByEmail') |
||
221 | ->with('[email protected]') |
||
222 | ->willReturn($this->getGatewayReturnValue()); |
||
223 | |||
224 | $handler = $this->getUserHandler($gatewayMock); |
||
225 | $validUser = $this->getValidUser(); |
||
226 | |||
227 | $user = $handler->loadByEmail($validUser->email); |
||
228 | $this->assertEquals( |
||
229 | $validUser, |
||
230 | $user |
||
231 | ); |
||
232 | } |
||
233 | |||
234 | public function testLoadUsersByEmail() |
||
235 | { |
||
236 | $gatewayMock = $this |
||
237 | ->createMock(User\Gateway::class); |
||
238 | |||
239 | $gatewayMock |
||
240 | ->method('loadByEmail') |
||
241 | ->with('[email protected]') |
||
242 | ->willReturn($this->getGatewayReturnValue()); |
||
243 | |||
244 | $handler = $this->getUserHandler($gatewayMock); |
||
245 | $user = $this->getValidUser(); |
||
246 | |||
247 | $users = $handler->loadUsersByEmail($user->email); |
||
248 | $this->assertEquals( |
||
249 | $user, |
||
250 | $users[0] |
||
251 | ); |
||
252 | } |
||
253 | |||
254 | public function testLoadUserByTokenNotFound() |
||
255 | { |
||
256 | $this->expectException(NotFoundException::class); |
||
257 | |||
258 | $handler = $this->getUserHandler(); |
||
259 | $handler->updateUserToken($this->getValidUserToken()); |
||
260 | |||
261 | $handler->loadUserByToken('asd'); |
||
262 | } |
||
263 | |||
264 | public function testLoadUserByToken() |
||
265 | { |
||
266 | $gatewayMock = $this |
||
267 | ->createMock(User\Gateway::class); |
||
268 | |||
269 | $userToken = $this->getValidUserToken(); |
||
270 | $gatewayMock |
||
271 | ->method('loadUserByToken') |
||
272 | ->with($userToken->hashKey) |
||
273 | ->willReturn($this->getGatewayReturnValue()); |
||
274 | |||
275 | $handler = $this->getUserHandler($gatewayMock); |
||
276 | $user = $this->getValidUser(); |
||
277 | $handler->updateUserToken($userToken); |
||
278 | |||
279 | $loadedUser = $handler->loadUserByToken($userToken->hashKey); |
||
280 | $this->assertEquals( |
||
281 | $user, |
||
282 | $loadedUser |
||
283 | ); |
||
284 | } |
||
285 | |||
286 | public function testUpdateUserToken() |
||
287 | { |
||
288 | $handler = $this->getUserHandler(); |
||
289 | |||
290 | $handler->updateUserToken($this->getValidUserToken(1234567890)); |
||
291 | |||
292 | $this->assertQueryResult( |
||
293 | [['0800fc577294c34e0b28ad2839435945', 1, 1234567890, self::TEST_USER_ID]], |
||
294 | $this->handler->createSelectQuery()->select( |
||
295 | ['hash_key', 'id', 'time', 'user_id'] |
||
296 | )->from('ezuser_accountkey'), |
||
297 | 'Expected user data to be updated.' |
||
298 | ); |
||
299 | |||
300 | $handler->updateUserToken($this->getValidUserToken(2234567890)); |
||
301 | |||
302 | $this->assertQueryResult( |
||
303 | [['0800fc577294c34e0b28ad2839435945', 1, 2234567890, self::TEST_USER_ID]], |
||
304 | $this->handler->createSelectQuery()->select( |
||
305 | ['hash_key', 'id', 'time', 'user_id'] |
||
306 | )->from('ezuser_accountkey'), |
||
307 | 'Expected user token data to be updated.' |
||
308 | ); |
||
309 | } |
||
310 | |||
311 | public function testExpireUserToken() |
||
312 | { |
||
313 | $handler = $this->getUserHandler(); |
||
314 | |||
315 | $handler->updateUserToken($userToken = $this->getValidUserToken(1234567890)); |
||
316 | |||
317 | $this->assertQueryResult( |
||
318 | [['0800fc577294c34e0b28ad2839435945', 1, 1234567890, self::TEST_USER_ID]], |
||
319 | $this->handler->createSelectQuery()->select( |
||
320 | ['hash_key', 'id', 'time', 'user_id'] |
||
321 | )->from('ezuser_accountkey'), |
||
322 | 'Expected user data to be updated.' |
||
323 | ); |
||
324 | |||
325 | $handler->expireUserToken($userToken->hashKey); |
||
326 | |||
327 | $this->assertQueryResult( |
||
328 | [['0800fc577294c34e0b28ad2839435945', 1, 0, self::TEST_USER_ID]], |
||
329 | $this->handler->createSelectQuery()->select( |
||
330 | ['hash_key', 'id', 'time', 'user_id'] |
||
331 | )->from('ezuser_accountkey'), |
||
332 | 'Expected user token to be expired.' |
||
333 | ); |
||
334 | } |
||
335 | |||
336 | public function testDeleteNonExistingUser() |
||
337 | { |
||
338 | $handler = $this->getUserHandler(); |
||
339 | |||
340 | $this->expectException(NotImplementedException::class); |
||
341 | $handler->delete(1337); |
||
342 | } |
||
343 | |||
344 | public function testUpdateUser() |
||
345 | { |
||
346 | $handler = $this->getUserHandler(); |
||
347 | $user = $this->getValidUser(); |
||
348 | |||
349 | $user->login = 'New_lögin'; |
||
350 | $this->expectException(NotImplementedException::class); |
||
351 | $handler->update($user); |
||
352 | } |
||
353 | |||
354 | public function testUpdateUserSettings() |
||
355 | { |
||
356 | $handler = $this->getUserHandler(); |
||
357 | $user = $this->getValidUser(); |
||
358 | |||
359 | $user->maxLogin = 42; |
||
360 | $this->expectException(NotImplementedException::class); |
||
361 | $handler->update($user); |
||
362 | } |
||
363 | |||
364 | public function testCreateNewRoleWithoutPolicies() |
||
365 | { |
||
366 | $handler = $this->getUserHandler(); |
||
367 | |||
368 | $createStruct = new Persistence\User\RoleCreateStruct(); |
||
369 | $createStruct->identifier = 'Test'; |
||
370 | |||
371 | $handler->createRole($createStruct); |
||
372 | |||
373 | $this->assertQueryResult( |
||
374 | [[1, 'Test', -1]], |
||
375 | $this->handler->createSelectQuery()->select('id', 'name', 'version')->from('ezrole'), |
||
376 | 'Expected a new role draft.' |
||
377 | ); |
||
378 | } |
||
379 | |||
380 | public function testCreateRoleDraftWithoutPolicies() |
||
381 | { |
||
382 | $handler = $this->getUserHandler(); |
||
383 | |||
384 | $createStruct = new Persistence\User\RoleCreateStruct(); |
||
385 | $createStruct->identifier = 'Test'; |
||
386 | |||
387 | $roleDraft = $handler->createRole($createStruct); |
||
388 | $handler->publishRoleDraft($roleDraft->id); |
||
389 | |||
390 | $handler->createRoleDraft($roleDraft->id); |
||
391 | |||
392 | $publishedRoleId = 1; |
||
393 | $this->assertQueryResult( |
||
394 | [ |
||
395 | [$publishedRoleId, 'Test', APIRole::STATUS_DEFINED], |
||
396 | [2, 'Test', $publishedRoleId], |
||
397 | ], |
||
398 | $this->handler->createSelectQuery()->select('id', 'name', 'version')->from('ezrole'), |
||
399 | 'Expected a role and a role draft.' |
||
400 | ); |
||
401 | } |
||
402 | |||
403 | public function testCreateNewRoleRoleId() |
||
404 | { |
||
405 | $handler = $this->getUserHandler(); |
||
406 | |||
407 | $createStruct = new Persistence\User\RoleCreateStruct(); |
||
408 | $createStruct->identifier = 'Test'; |
||
409 | |||
410 | $roleDraft = $handler->createRole($createStruct); |
||
411 | |||
412 | $this->assertSame(1, $roleDraft->id); |
||
413 | } |
||
414 | |||
415 | public function testLoadRole() |
||
416 | { |
||
417 | $handler = $this->getUserHandler(); |
||
418 | |||
419 | $createStruct = new Persistence\User\RoleCreateStruct(); |
||
420 | $createStruct->identifier = 'Test'; |
||
421 | |||
422 | $roleDraft = $handler->createRole($createStruct); |
||
423 | $handler->publishRoleDraft($roleDraft->id); |
||
424 | $role = $handler->loadRole($roleDraft->id); |
||
425 | |||
426 | $this->assertEquals( |
||
427 | $roleDraft->id, |
||
428 | $role->id |
||
429 | ); |
||
430 | } |
||
431 | |||
432 | public function testLoadRoleWithPolicies() |
||
433 | { |
||
434 | $handler = $this->getUserHandler(); |
||
435 | |||
436 | $createStruct = new Persistence\User\RoleCreateStruct(); |
||
437 | $createStruct->identifier = 'Test'; |
||
438 | |||
439 | $roleDraft = $handler->createRole($createStruct); |
||
440 | |||
441 | $policy = new Persistence\User\Policy(); |
||
442 | $policy->module = 'foo'; |
||
443 | $policy->function = 'bar'; |
||
444 | |||
445 | $handler->addPolicyByRoleDraft($roleDraft->id, $policy); |
||
446 | $handler->publishRoleDraft($roleDraft->id); |
||
447 | |||
448 | $loaded = $handler->loadRole($roleDraft->id); |
||
449 | $this->assertEquals( |
||
450 | [ |
||
451 | new Persistence\User\Policy( |
||
452 | [ |
||
453 | 'id' => 1, |
||
454 | 'roleId' => 1, |
||
455 | 'module' => 'foo', |
||
456 | 'function' => 'bar', |
||
457 | 'limitations' => '*', |
||
458 | 'originalId' => null, |
||
459 | ] |
||
460 | ), |
||
461 | ], |
||
462 | $loaded->policies |
||
463 | ); |
||
464 | } |
||
465 | |||
466 | public function testLoadRoleWithPoliciesAndGroups() |
||
467 | { |
||
468 | $handler = $this->getUserHandler(); |
||
469 | |||
470 | $createStruct = new Persistence\User\RoleCreateStruct(); |
||
471 | $createStruct->identifier = 'Test'; |
||
472 | |||
473 | $roleDraft = $handler->createRole($createStruct); |
||
474 | |||
475 | $policy = new Persistence\User\Policy(); |
||
476 | $policy->module = 'foo'; |
||
477 | $policy->function = 'bar'; |
||
478 | |||
479 | $handler->addPolicyByRoleDraft($roleDraft->id, $policy); |
||
480 | |||
481 | $handler->assignRole(23, $roleDraft->id); |
||
482 | $handler->assignRole(42, $roleDraft->id); |
||
483 | |||
484 | $handler->publishRoleDraft($roleDraft->id); |
||
485 | |||
486 | $loaded = $handler->loadRole($roleDraft->id); |
||
487 | $this->assertEquals( |
||
488 | [ |
||
489 | new Persistence\User\Policy( |
||
490 | [ |
||
491 | 'id' => 1, |
||
492 | 'roleId' => 1, |
||
493 | 'module' => 'foo', |
||
494 | 'function' => 'bar', |
||
495 | 'limitations' => '*', |
||
496 | 'originalId' => null, |
||
497 | ] |
||
498 | ), |
||
499 | ], |
||
500 | $loaded->policies |
||
501 | ); |
||
502 | } |
||
503 | |||
504 | public function testLoadRoleWithPolicyLimitations() |
||
505 | { |
||
506 | $handler = $this->getUserHandler(); |
||
507 | |||
508 | $createStruct = new Persistence\User\RoleCreateStruct(); |
||
509 | $createStruct->identifier = 'Test'; |
||
510 | |||
511 | $roleDraft = $handler->createRole($createStruct); |
||
512 | |||
513 | $policy = new Persistence\User\Policy(); |
||
514 | $policy->module = 'foo'; |
||
515 | $policy->function = 'bar'; |
||
516 | $policy->limitations = [ |
||
517 | 'Subtree' => ['/1', '/1/2'], |
||
518 | 'Foo' => ['Bar'], |
||
519 | ]; |
||
520 | |||
521 | $handler->addPolicyByRoleDraft($roleDraft->id, $policy); |
||
522 | $handler->publishRoleDraft($roleDraft->id); |
||
523 | |||
524 | $loaded = $handler->loadRole($roleDraft->id); |
||
525 | $this->assertEquals( |
||
526 | [ |
||
527 | new Persistence\User\Policy( |
||
528 | [ |
||
529 | 'id' => 1, |
||
530 | 'roleId' => 1, |
||
531 | 'module' => 'foo', |
||
532 | 'function' => 'bar', |
||
533 | 'limitations' => [ |
||
534 | 'Subtree' => ['/1', '/1/2'], |
||
535 | 'Foo' => ['Bar'], |
||
536 | ], |
||
537 | 'originalId' => null, |
||
538 | ] |
||
539 | ), |
||
540 | ], |
||
541 | $loaded->policies |
||
542 | ); |
||
543 | } |
||
544 | |||
545 | public function testLoadRoles() |
||
546 | { |
||
547 | $handler = $this->getUserHandler(); |
||
548 | |||
549 | $this->assertEquals( |
||
550 | [], |
||
551 | $handler->loadRoles() |
||
552 | ); |
||
553 | |||
554 | $role = $this->createTestRole($handler); |
||
555 | |||
556 | $this->assertEquals( |
||
557 | [$role], |
||
558 | $handler->loadRoles() |
||
559 | ); |
||
560 | } |
||
561 | |||
562 | public function testUpdateRole() |
||
563 | { |
||
564 | $handler = $this->getUserHandler(); |
||
565 | |||
566 | $role = $this->createTestRole($handler); |
||
567 | |||
568 | $update = new Persistence\User\RoleUpdateStruct(); |
||
569 | $update->id = $role->id; |
||
570 | $update->identifier = 'Changed'; |
||
571 | |||
572 | $handler->updateRole($update); |
||
573 | |||
574 | $this->assertQueryResult( |
||
575 | [[1, 'Changed']], |
||
576 | $this->handler->createSelectQuery()->select('id', 'name')->from('ezrole'), |
||
577 | 'Expected a changed role.' |
||
578 | ); |
||
579 | } |
||
580 | |||
581 | public function testDeleteRole() |
||
582 | { |
||
583 | $this->insertDatabaseFixture(__DIR__ . '/../../../../Repository/Tests/Service/Integration/Legacy/_fixtures/test_data.php'); |
||
584 | $handler = $this->getUserHandler(); |
||
585 | |||
586 | // 3 is the ID of Editor role |
||
587 | $handler->deleteRole(3); |
||
588 | |||
589 | $this->assertQueryResult( |
||
590 | [], |
||
591 | $this->handler->createSelectQuery()->select('id')->from('ezrole')->where('id = 3'), |
||
592 | 'Expected an empty set.' |
||
593 | ); |
||
594 | |||
595 | $this->assertQueryResult( |
||
596 | [], |
||
597 | $this->handler->createSelectQuery()->select('role_id')->from('ezpolicy')->where('role_id = 3'), |
||
598 | 'Expected an empty set.' |
||
599 | ); |
||
600 | |||
601 | $this->assertQueryResult( |
||
602 | [], |
||
603 | $this->handler->createSelectQuery()->select('role_id')->from('ezuser_role')->where('role_id = 3'), |
||
604 | 'Expected an empty set.' |
||
605 | ); |
||
606 | } |
||
607 | |||
608 | public function testDeleteRoleDraft() |
||
609 | { |
||
610 | $this->insertDatabaseFixture(__DIR__ . '/../../../../Repository/Tests/Service/Integration/Legacy/_fixtures/test_data.php'); |
||
611 | $handler = $this->getUserHandler(); |
||
612 | |||
613 | // 3 is the ID of Editor role |
||
614 | $roleDraft = $handler->createRoleDraft(3); |
||
615 | $handler->deleteRole($roleDraft->id, APIRole::STATUS_DRAFT); |
||
616 | |||
617 | $this->assertQueryResult( |
||
618 | [['3', APIRole::STATUS_DEFINED]], |
||
619 | $this->handler->createSelectQuery()->select('id, version')->from('ezrole')->where('id = 3'), |
||
620 | 'Expected a published role.' |
||
621 | ); |
||
622 | |||
623 | $this->assertQueryResult( |
||
624 | [[implode("\n", array_fill(0, 28, '3, ' . APIRole::STATUS_DEFINED))]], |
||
625 | $this->handler->createSelectQuery()->select('role_id, original_id')->from('ezpolicy')->where('role_id = 3'), |
||
626 | 'Expected 28 policies for the published role.' |
||
627 | ); |
||
628 | |||
629 | $this->assertQueryResult( |
||
630 | [[3], [3]], |
||
631 | $this->handler->createSelectQuery()->select('role_id')->from('ezuser_role')->where('role_id = 3'), |
||
632 | 'Expected that role assignments still exist.' |
||
633 | ); |
||
634 | } |
||
635 | |||
636 | public function testAddPolicyToRoleLimitations() |
||
637 | { |
||
638 | $handler = $this->getUserHandler(); |
||
639 | |||
640 | $role = $this->createTestRole($handler); |
||
641 | |||
642 | $policy = new Persistence\User\Policy(); |
||
643 | $policy->module = 'foo'; |
||
644 | $policy->function = 'bar'; |
||
645 | |||
646 | $handler->addPolicy($role->id, $policy); |
||
647 | |||
648 | $this->assertQueryResult( |
||
649 | [[1, 'foo', 'bar', 1]], |
||
650 | $this->handler->createSelectQuery()->select('id', 'module_name', 'function_name', 'role_id')->from('ezpolicy'), |
||
651 | 'Expected a new policy.' |
||
652 | ); |
||
653 | } |
||
654 | |||
655 | public function testAddPolicyPolicyId() |
||
656 | { |
||
657 | $handler = $this->getUserHandler(); |
||
658 | |||
659 | $role = $this->createTestRole($handler); |
||
660 | |||
661 | $policy = new Persistence\User\Policy(); |
||
662 | $policy->module = 'foo'; |
||
663 | $policy->function = 'bar'; |
||
664 | |||
665 | $policy = $handler->addPolicy($role->id, $policy); |
||
666 | |||
667 | $this->assertEquals(1, $policy->id); |
||
668 | } |
||
669 | |||
670 | public function testAddPolicyLimitations() |
||
671 | { |
||
672 | $this->createTestRoleWithTestPolicy(); |
||
673 | |||
674 | $this->assertQueryResult( |
||
675 | [ |
||
676 | [1, 'Subtree', 1], |
||
677 | [2, 'Foo', 1], |
||
678 | ], |
||
679 | $this->handler->createSelectQuery()->select('id', 'identifier', 'policy_id')->from('ezpolicy_limitation'), |
||
680 | 'Expected a new policy.' |
||
681 | ); |
||
682 | } |
||
683 | |||
684 | public function testAddPolicyLimitationValues() |
||
685 | { |
||
686 | $this->createTestRoleWithTestPolicy(); |
||
687 | |||
688 | $this->assertQueryResult( |
||
689 | [ |
||
690 | [1, '/1', 1], |
||
691 | [2, '/1/2', 1], |
||
692 | [3, 'Bar', 2], |
||
693 | ], |
||
694 | $this->handler->createSelectQuery()->select('id', 'value', 'limitation_id')->from('ezpolicy_limitation_value'), |
||
695 | 'Expected a new policy.' |
||
696 | ); |
||
697 | } |
||
698 | |||
699 | protected function createRole() |
||
724 | |||
725 | public function testImplicitlyCreatePolicies() |
||
738 | |||
739 | public function testDeletePolicy() |
||
755 | |||
756 | public function testDeletePolicyLimitations() |
||
757 | { |
||
758 | $handler = $this->getUserHandler(); |
||
759 | |||
760 | $roleDraft = $this->createRole(); |
||
761 | $handler->deletePolicy($roleDraft->policies[0]->id, $roleDraft->policies[0]->roleId); |
||
762 | |||
763 | $this->assertQueryResult( |
||
764 | [[3, 'Foo', 2]], |
||
765 | $this->handler->createSelectQuery()->select('*')->from('ezpolicy_limitation') |
||
766 | ); |
||
767 | } |
||
768 | |||
769 | public function testDeletePolicyLimitationValues() |
||
770 | { |
||
771 | $handler = $this->getUserHandler(); |
||
772 | |||
773 | $roleDraft = $this->createRole(); |
||
774 | $handler->deletePolicy($roleDraft->policies[0]->id, $roleDraft->policies[0]->roleId); |
||
775 | |||
776 | $this->assertQueryResult( |
||
777 | [[4, 3, 'Blubb']], |
||
778 | $this->handler->createSelectQuery()->select('*')->from('ezpolicy_limitation_value') |
||
779 | ); |
||
780 | } |
||
781 | |||
782 | public function testUpdatePolicies() |
||
811 | |||
812 | public function testAddRoleToUser() |
||
831 | |||
832 | public function testAddRoleToUserWithLimitation() |
||
857 | |||
858 | public function testAddRoleToUserWithComplexLimitation() |
||
886 | |||
887 | public function testRemoveUserRoleAssociation() |
||
913 | |||
914 | public function testLoadPoliciesForUser() |
||
938 | |||
939 | public function testLoadRoleAssignmentsByGroupId() |
||
982 | |||
983 | public function testLoadRoleAssignmentsByGroupIdInherited() |
||
1001 | |||
1002 | public function testLoadComplexRoleAssignments() |
||
1069 | |||
1070 | public function testLoadRoleAssignmentsByRoleId() |
||
1102 | |||
1103 | public function testLoadRoleDraftByRoleId() |
||
1115 | |||
1116 | public function testRoleDraftOnlyHavePolicyDraft() |
||
1152 | |||
1153 | /** |
||
1154 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
1155 | */ |
||
1156 | private function createTestRole(User\Handler $handler): Role |
||
1157 | { |
||
1158 | $createStruct = new Persistence\User\RoleCreateStruct(); |
||
1159 | $createStruct->identifier = 'Test'; |
||
1160 | |||
1161 | $roleDraft = $handler->createRole($createStruct); |
||
1162 | $handler->publishRoleDraft($roleDraft->id); |
||
1163 | |||
1164 | return $handler->loadRole($roleDraft->id); |
||
1165 | } |
||
1166 | |||
1167 | /** |
||
1168 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
1169 | */ |
||
1170 | private function createTestRoleWithTestPolicy(): void |
||
1171 | { |
||
1172 | $handler = $this->getUserHandler(); |
||
1173 | |||
1174 | $role = $this->createTestRole($handler); |
||
1175 | |||
1176 | $policy = new Persistence\User\Policy(); |
||
1177 | $policy->module = 'foo'; |
||
1178 | $policy->function = 'bar'; |
||
1179 | $policy->limitations = [ |
||
1180 | 'Subtree' => ['/1', '/1/2'], |
||
1181 | 'Foo' => ['Bar'], |
||
1182 | ]; |
||
1183 | |||
1184 | $handler->addPolicy($role->id, $policy); |
||
1185 | } |
||
1186 | } |
||
1187 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.