Complex classes like UserServiceTest 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 UserServiceTest, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
40 | class UserServiceTest extends BaseTest |
||
41 | { |
||
42 | // Example password matching default rules |
||
43 | private const EXAMPLE_PASSWORD = 'P@ssword123!'; |
||
44 | |||
45 | private const EXAMPLE_PASSWORD_TTL = 30; |
||
46 | private const EXAMPLE_PASSWORD_TTL_WARNING = 14; |
||
47 | |||
48 | /** |
||
49 | * Test for the loadUserGroup() method. |
||
50 | * |
||
51 | * @see \eZ\Publish\API\Repository\UserService::loadUserGroup() |
||
52 | */ |
||
53 | public function testLoadUserGroup() |
||
54 | { |
||
55 | $repository = $this->getRepository(); |
||
56 | |||
57 | $mainGroupId = $this->generateId('group', 4); |
||
58 | /* BEGIN: Use Case */ |
||
59 | // $mainGroupId is the ID of the main "Users" group |
||
60 | |||
61 | $userService = $repository->getUserService(); |
||
62 | |||
63 | $userGroup = $userService->loadUserGroup($mainGroupId); |
||
64 | /* END: Use Case */ |
||
65 | |||
66 | $this->assertInstanceOf(UserGroup::class, $userGroup); |
||
67 | |||
68 | // User group happens to also be a Content; isUserGroup() should be true and isUser() should be false |
||
69 | $this->assertTrue($userService->isUserGroup($userGroup), 'isUserGroup() => false on a user group'); |
||
70 | $this->assertFalse($userService->isUser($userGroup), 'isUser() => true on a user group'); |
||
71 | $this->assertSame(0, $userGroup->parentId, 'parentId should be equal `0` because it is top level node'); |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * Test for the loadUserGroup() method to ensure that DomainUserGroupObject is created properly even if a user |
||
76 | * has no access to parent of UserGroup. |
||
77 | * |
||
78 | * @see \eZ\Publish\API\Repository\UserService::loadUserGroup() |
||
79 | */ |
||
80 | public function testLoadUserGroupWithNoAccessToParent() |
||
81 | { |
||
82 | $repository = $this->getRepository(); |
||
83 | |||
84 | $mainGroupId = $this->generateId('group', 4); |
||
85 | /* BEGIN: Use Case */ |
||
86 | // $mainGroupId is the ID of the main "Users" group |
||
87 | |||
88 | $userService = $repository->getUserService(); |
||
89 | |||
90 | $user = $this->createUserWithPolicies( |
||
91 | 'user', |
||
92 | [ |
||
93 | ['module' => 'content', 'function' => 'read'], |
||
94 | ], |
||
95 | new SubtreeLimitation(['limitationValues' => ['/1/5']]) |
||
96 | ); |
||
97 | $repository->getPermissionResolver()->setCurrentUserReference($user); |
||
98 | |||
99 | $userGroup = $userService->loadUserGroup($mainGroupId); |
||
100 | /* END: Use Case */ |
||
101 | |||
102 | $this->assertInstanceOf(UserGroup::class, $userGroup); |
||
103 | |||
104 | // User group happens to also be a Content; isUserGroup() should be true and isUser() should be false |
||
105 | $this->assertTrue($userService->isUserGroup($userGroup), 'isUserGroup() => false on a user group'); |
||
106 | $this->assertFalse($userService->isUser($userGroup), 'isUser() => true on a user group'); |
||
107 | $this->assertSame(0, $userGroup->parentId, 'parentId should be equal `0` because it is top level node'); |
||
108 | } |
||
109 | |||
110 | /** |
||
111 | * Test for the loadUserGroup() method. |
||
112 | * |
||
113 | * @see \eZ\Publish\API\Repository\UserService::loadUserGroup() |
||
114 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
115 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testLoadUserGroup |
||
116 | */ |
||
117 | public function testLoadUserGroupThrowsNotFoundException() |
||
118 | { |
||
119 | $repository = $this->getRepository(); |
||
120 | |||
121 | $nonExistingGroupId = $this->generateId('group', self::DB_INT_MAX); |
||
122 | /* BEGIN: Use Case */ |
||
123 | $userService = $repository->getUserService(); |
||
124 | |||
125 | // This call will fail with a NotFoundException |
||
126 | $userService->loadUserGroup($nonExistingGroupId); |
||
127 | /* END: Use Case */ |
||
128 | } |
||
129 | |||
130 | /** |
||
131 | * Test for the loadSubUserGroups() method. |
||
132 | * |
||
133 | * @see \eZ\Publish\API\Repository\UserService::loadSubUserGroups() |
||
134 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testLoadUserGroup |
||
135 | */ |
||
136 | public function testLoadSubUserGroups() |
||
137 | { |
||
138 | $repository = $this->getRepository(); |
||
139 | |||
140 | $mainGroupId = $this->generateId('group', 4); |
||
141 | /* BEGIN: Use Case */ |
||
142 | // $mainGroupId is the ID of the main "Users" group |
||
143 | |||
144 | $userService = $repository->getUserService(); |
||
145 | |||
146 | $userGroup = $userService->loadUserGroup($mainGroupId); |
||
147 | |||
148 | $subUserGroups = $userService->loadSubUserGroups($userGroup); |
||
149 | foreach ($subUserGroups as $subUserGroup) { |
||
150 | // Do something with the $subUserGroup |
||
151 | $this->assertInstanceOf(UserGroup::class, $subUserGroup); |
||
152 | } |
||
153 | /* END: Use Case */ |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * Test loading sub groups throwing NotFoundException. |
||
158 | * |
||
159 | * @covers \eZ\Publish\API\Repository\UserService::loadSubUserGroups |
||
160 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
161 | */ |
||
162 | public function testLoadSubUserGroupsThrowsNotFoundException() |
||
163 | { |
||
164 | $repository = $this->getRepository(); |
||
165 | $userService = $repository->getUserService(); |
||
166 | |||
167 | $parentGroup = new UserGroup( |
||
168 | [ |
||
169 | 'content' => new Content( |
||
170 | [ |
||
171 | 'versionInfo' => new VersionInfo( |
||
172 | [ |
||
173 | 'contentInfo' => new ContentInfo( |
||
174 | ['id' => 123456] |
||
175 | ), |
||
176 | ] |
||
177 | ), |
||
178 | 'internalFields' => [], |
||
179 | ] |
||
180 | ), |
||
181 | ] |
||
182 | ); |
||
183 | $userService->loadSubUserGroups($parentGroup); |
||
184 | } |
||
185 | |||
186 | /** |
||
187 | * Test for the newUserGroupCreateStruct() method. |
||
188 | * |
||
189 | * @return \eZ\Publish\API\Repository\Values\User\UserGroupCreateStruct |
||
190 | * |
||
191 | * @see \eZ\Publish\API\Repository\UserService::newUserGroupCreateStruct() |
||
192 | * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeByIdentifier |
||
193 | */ |
||
194 | public function testNewUserGroupCreateStruct() |
||
195 | { |
||
196 | $repository = $this->getRepository(); |
||
197 | |||
198 | /* BEGIN: Use Case */ |
||
199 | $userService = $repository->getUserService(); |
||
200 | |||
201 | $groupCreate = $userService->newUserGroupCreateStruct('eng-US'); |
||
202 | /* END: Use Case */ |
||
203 | |||
204 | $this->assertInstanceOf( |
||
205 | '\\eZ\\Publish\\API\\Repository\\Values\\User\\UserGroupCreateStruct', |
||
206 | $groupCreate |
||
207 | ); |
||
208 | |||
209 | return $groupCreate; |
||
210 | } |
||
211 | |||
212 | /** |
||
213 | * Test for the newUserGroupCreateStruct() method. |
||
214 | * |
||
215 | * @param \eZ\Publish\API\Repository\Values\User\UserGroupCreateStruct $groupCreate |
||
216 | * |
||
217 | * @see \eZ\Publish\API\Repository\UserService::newUserGroupCreateStruct() |
||
218 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testNewUserGroupCreateStruct |
||
219 | */ |
||
220 | public function testNewUserGroupCreateStructSetsMainLanguageCode($groupCreate) |
||
221 | { |
||
222 | $this->assertEquals('eng-US', $groupCreate->mainLanguageCode); |
||
223 | } |
||
224 | |||
225 | /** |
||
226 | * Test for the newUserGroupCreateStruct() method. |
||
227 | * |
||
228 | * @param \eZ\Publish\API\Repository\Values\User\UserGroupCreateStruct $groupCreate |
||
229 | * |
||
230 | * @see \eZ\Publish\API\Repository\UserService::newUserGroupCreateStruct() |
||
231 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testNewUserGroupCreateStruct |
||
232 | */ |
||
233 | public function testNewUserGroupCreateStructSetsContentType($groupCreate) |
||
234 | { |
||
235 | $this->assertInstanceOf( |
||
236 | '\\eZ\\Publish\\API\\Repository\\Values\\ContentType\\ContentType', |
||
237 | $groupCreate->contentType |
||
238 | ); |
||
239 | } |
||
240 | |||
241 | /** |
||
242 | * Test for the newUserGroupCreateStruct() method. |
||
243 | * |
||
244 | * @see \eZ\Publish\API\Repository\UserService::newUserGroupCreateStruct($mainLanguageCode, $contentType) |
||
245 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testNewUserGroupCreateStruct |
||
246 | * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeByIdentifier |
||
247 | */ |
||
248 | public function testNewUserGroupCreateStructWithSecondParameter() |
||
249 | { |
||
250 | if ($this->isVersion4()) { |
||
251 | $this->markTestSkipped('This test is only relevant for eZ Publish versions > 4'); |
||
252 | } |
||
253 | |||
254 | $repository = $this->getRepository(); |
||
255 | |||
256 | /* BEGIN: Use Case */ |
||
257 | $contentTypeService = $repository->getContentTypeService(); |
||
258 | $userService = $repository->getUserService(); |
||
259 | |||
260 | // Load the default ContentType for user groups |
||
261 | $groupType = $contentTypeService->loadContentTypeByIdentifier('user_group'); |
||
262 | |||
263 | // Instantiate a new group create struct |
||
264 | $groupCreate = $userService->newUserGroupCreateStruct( |
||
265 | 'eng-US', |
||
266 | $groupType |
||
267 | ); |
||
268 | /* END: Use Case */ |
||
269 | |||
270 | $this->assertSame($groupType, $groupCreate->contentType); |
||
271 | } |
||
272 | |||
273 | /** |
||
274 | * Test for the createUserGroup() method. |
||
275 | * |
||
276 | * @return \eZ\Publish\API\Repository\Values\User\UserGroup |
||
277 | * |
||
278 | * @see \eZ\Publish\API\Repository\UserService::createUserGroup() |
||
279 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testNewUserGroupCreateStruct |
||
280 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testLoadUserGroup |
||
281 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
282 | */ |
||
283 | public function testCreateUserGroup() |
||
284 | { |
||
285 | /* BEGIN: Use Case */ |
||
286 | $userGroup = $this->createUserGroupVersion1(); |
||
287 | /* END: Use Case */ |
||
288 | |||
289 | $this->assertInstanceOf( |
||
290 | UserGroup::class, |
||
291 | $userGroup |
||
292 | ); |
||
293 | |||
294 | $versionInfo = $userGroup->getVersionInfo(); |
||
295 | |||
296 | $this->assertEquals(APIVersionInfo::STATUS_PUBLISHED, $versionInfo->status); |
||
297 | $this->assertEquals(1, $versionInfo->versionNo); |
||
298 | |||
299 | return $userGroup; |
||
300 | } |
||
301 | |||
302 | /** |
||
303 | * Test for the createUserGroup() method. |
||
304 | * |
||
305 | * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup |
||
306 | * |
||
307 | * @see \eZ\Publish\API\Repository\UserService::createUserGroup() |
||
308 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUserGroup |
||
309 | */ |
||
310 | public function testCreateUserGroupSetsExpectedProperties($userGroup) |
||
311 | { |
||
312 | $this->assertEquals( |
||
313 | [ |
||
314 | 'parentId' => $this->generateId('group', 4), |
||
315 | ], |
||
316 | [ |
||
317 | 'parentId' => $userGroup->parentId, |
||
318 | ] |
||
319 | ); |
||
320 | } |
||
321 | |||
322 | /** |
||
323 | * Test for the createUserGroup() method. |
||
324 | * |
||
325 | * @see \eZ\Publish\API\Repository\UserService::createUserGroup() |
||
326 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
327 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUserGroup |
||
328 | */ |
||
329 | public function testCreateUserGroupThrowsInvalidArgumentException() |
||
330 | { |
||
331 | $repository = $this->getRepository(); |
||
332 | |||
333 | $mainGroupId = $this->generateId('group', 4); |
||
334 | /* BEGIN: Use Case */ |
||
335 | // $mainGroupId is the ID of the main "Users" group |
||
336 | |||
337 | $userService = $repository->getUserService(); |
||
338 | |||
339 | // Load main group |
||
340 | $parentUserGroup = $userService->loadUserGroup($mainGroupId); |
||
341 | |||
342 | // Instantiate a new create struct |
||
343 | $userGroupCreate = $userService->newUserGroupCreateStruct('eng-US'); |
||
344 | $userGroupCreate->setField('name', 'Example Group'); |
||
345 | $userGroupCreate->remoteId = '5f7f0bdb3381d6a461d8c29ff53d908f'; |
||
346 | |||
347 | // This call will fail with an "InvalidArgumentException", because the |
||
348 | // specified remoteId is already used for the "Members" user group. |
||
349 | $userService->createUserGroup( |
||
350 | $userGroupCreate, |
||
351 | $parentUserGroup |
||
352 | ); |
||
353 | /* END: Use Case */ |
||
354 | } |
||
355 | |||
356 | /** |
||
357 | * Test for the createUserGroup() method. |
||
358 | * |
||
359 | * @see \eZ\Publish\API\Repository\UserService::createUserGroup() |
||
360 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
361 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUserGroup |
||
362 | */ |
||
363 | public function testCreateUserGroupThrowsInvalidArgumentExceptionFieldTypeNotAccept() |
||
364 | { |
||
365 | $repository = $this->getRepository(); |
||
366 | |||
367 | $mainGroupId = $this->generateId('group', 4); |
||
368 | /* BEGIN: Use Case */ |
||
369 | // $mainGroupId is the ID of the main "Users" group |
||
370 | |||
371 | $userService = $repository->getUserService(); |
||
372 | |||
373 | // Load main group |
||
374 | $parentUserGroup = $userService->loadUserGroup($mainGroupId); |
||
375 | |||
376 | // Instantiate a new create struct |
||
377 | $userGroupCreate = $userService->newUserGroupCreateStruct('eng-US'); |
||
378 | $userGroupCreate->setField('name', new \stdClass()); |
||
379 | |||
380 | // This call will fail with an "InvalidArgumentException", because the |
||
381 | // specified remoteId is already used for the "Members" user group. |
||
382 | $userService->createUserGroup( |
||
383 | $userGroupCreate, |
||
384 | $parentUserGroup |
||
385 | ); |
||
386 | /* END: Use Case */ |
||
387 | } |
||
388 | |||
389 | /** |
||
390 | * Test for the createUserGroup() method. |
||
391 | * |
||
392 | * @see \eZ\Publish\API\Repository\UserService::createUserGroup() |
||
393 | * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException |
||
394 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUserGroup |
||
395 | */ |
||
396 | public function testCreateUserGroupWhenMissingField() |
||
397 | { |
||
398 | $repository = $this->getRepository(); |
||
399 | |||
400 | $mainGroupId = $this->generateId('group', 4); |
||
401 | /* BEGIN: Use Case */ |
||
402 | // $mainGroupId is the ID of the main "Users" group |
||
403 | |||
404 | $userService = $repository->getUserService(); |
||
405 | |||
406 | // Load main group |
||
407 | $parentUserGroup = $userService->loadUserGroup($mainGroupId); |
||
408 | |||
409 | // Instantiate a new create struct |
||
410 | $userGroupCreate = $userService->newUserGroupCreateStruct('eng-US'); |
||
411 | |||
412 | // This call will fail with a "ContentFieldValidationException", because the |
||
413 | // only mandatory field "name" is not set. |
||
414 | $userService->createUserGroup($userGroupCreate, $parentUserGroup); |
||
415 | /* END: Use Case */ |
||
416 | } |
||
417 | |||
418 | /** |
||
419 | * Test for the createUserGroup() method. |
||
420 | * |
||
421 | * @return \eZ\Publish\API\Repository\Values\User\UserGroup |
||
422 | * |
||
423 | * @see \eZ\Publish\API\Repository\UserService::createUserGroup() |
||
424 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testNewUserGroupCreateStruct |
||
425 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testLoadUserGroup |
||
426 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
427 | */ |
||
428 | public function testCreateUserGroupInTransactionWithRollback() |
||
429 | { |
||
430 | $repository = $this->getRepository(); |
||
431 | |||
432 | $mainGroupId = $this->generateId('group', 4); |
||
433 | /* BEGIN: Use Case */ |
||
434 | // $mainGroupId is the ID of the main "Users" group |
||
435 | |||
436 | $userService = $repository->getUserService(); |
||
437 | |||
438 | $repository->beginTransaction(); |
||
439 | |||
440 | try { |
||
441 | // Load main group |
||
442 | $parentUserGroup = $userService->loadUserGroup($mainGroupId); |
||
443 | |||
444 | // Instantiate a new create struct |
||
445 | $userGroupCreate = $userService->newUserGroupCreateStruct('eng-US'); |
||
446 | $userGroupCreate->setField('name', 'Example Group'); |
||
447 | |||
448 | // Create the new user group |
||
449 | $createdUserGroupId = $userService->createUserGroup( |
||
450 | $userGroupCreate, |
||
451 | $parentUserGroup |
||
452 | )->id; |
||
453 | } catch (Exception $e) { |
||
454 | // Cleanup hanging transaction on error |
||
455 | $repository->rollback(); |
||
456 | throw $e; |
||
457 | } |
||
458 | |||
459 | $repository->rollback(); |
||
460 | |||
461 | try { |
||
462 | // Throws exception since creation of user group was rolled back |
||
463 | $loadedGroup = $userService->loadUserGroup($createdUserGroupId); |
||
|
|||
464 | } catch (NotFoundException $e) { |
||
465 | return; |
||
466 | } |
||
467 | /* END: Use Case */ |
||
468 | |||
469 | $this->fail('User group object still exists after rollback.'); |
||
470 | } |
||
471 | |||
472 | /** |
||
473 | * Test for the deleteUserGroup() method. |
||
474 | * |
||
475 | * @see \eZ\Publish\API\Repository\UserService::deleteUserGroup() |
||
476 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
477 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUserGroup |
||
478 | */ |
||
479 | public function testDeleteUserGroup() |
||
480 | { |
||
481 | $repository = $this->getRepository(); |
||
482 | $userService = $repository->getUserService(); |
||
483 | |||
484 | /* BEGIN: Use Case */ |
||
485 | $userGroup = $this->createUserGroupVersion1(); |
||
486 | |||
487 | // Delete the currently created user group again |
||
488 | $userService->deleteUserGroup($userGroup); |
||
489 | /* END: Use Case */ |
||
490 | |||
491 | // We use the NotFoundException here for verification |
||
492 | $userService->loadUserGroup($userGroup->id); |
||
493 | } |
||
494 | |||
495 | /** |
||
496 | * Test deleting user group throwing NotFoundException. |
||
497 | * |
||
498 | * @covers \eZ\Publish\API\Repository\UserService::deleteUserGroup |
||
499 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
500 | */ |
||
501 | public function testDeleteUserGroupThrowsNotFoundException() |
||
502 | { |
||
503 | $repository = $this->getRepository(); |
||
504 | $userService = $repository->getUserService(); |
||
505 | |||
506 | $userGroup = new UserGroup( |
||
507 | [ |
||
508 | 'content' => new Content( |
||
509 | [ |
||
510 | 'versionInfo' => new VersionInfo( |
||
511 | ['contentInfo' => new ContentInfo(['id' => 123456])] |
||
512 | ), |
||
513 | 'internalFields' => [], |
||
514 | ] |
||
515 | ), |
||
516 | ] |
||
517 | ); |
||
518 | $userService->deleteUserGroup($userGroup); |
||
519 | } |
||
520 | |||
521 | /** |
||
522 | * Test for the moveUserGroup() method. |
||
523 | * |
||
524 | * @see \eZ\Publish\API\Repository\UserService::moveUserGroup() |
||
525 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUserGroup |
||
526 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testLoadSubUserGroups |
||
527 | */ |
||
528 | public function testMoveUserGroup() |
||
529 | { |
||
530 | $repository = $this->getRepository(); |
||
531 | $userService = $repository->getUserService(); |
||
532 | |||
533 | $membersGroupId = $this->generateId('group', 13); |
||
534 | /* BEGIN: Use Case */ |
||
535 | // $membersGroupId is the ID of the "Members" user group in an eZ |
||
536 | // Publish demo installation |
||
537 | |||
538 | $userGroup = $this->createUserGroupVersion1(); |
||
539 | |||
540 | // Load the new parent group |
||
541 | $membersUserGroup = $userService->loadUserGroup($membersGroupId); |
||
542 | |||
543 | // Move user group from "Users" to "Members" |
||
544 | $userService->moveUserGroup($userGroup, $membersUserGroup); |
||
545 | |||
546 | // Reload the user group to get an updated $parentId |
||
547 | $userGroup = $userService->loadUserGroup($userGroup->id); |
||
548 | |||
549 | $this->refreshSearch($repository); |
||
550 | |||
551 | // The returned array will no contain $userGroup |
||
552 | $subUserGroups = $userService->loadSubUserGroups( |
||
553 | $membersUserGroup |
||
554 | ); |
||
555 | /* END: Use Case */ |
||
556 | |||
557 | $subUserGroupIds = array_map( |
||
558 | function ($content) { |
||
559 | return $content->id; |
||
560 | }, |
||
561 | $subUserGroups |
||
562 | ); |
||
563 | |||
564 | $this->assertEquals($membersGroupId, $userGroup->parentId); |
||
565 | $this->assertEquals([$userGroup->id], $subUserGroupIds); |
||
566 | } |
||
567 | |||
568 | /** |
||
569 | * Test moving a user group below another group throws NotFoundException. |
||
570 | * |
||
571 | * @covers \eZ\Publish\API\Repository\UserService::moveUserGroup |
||
572 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
573 | */ |
||
574 | public function testMoveUserGroupThrowsNotFoundException() |
||
575 | { |
||
576 | $repository = $this->getRepository(); |
||
577 | $userService = $repository->getUserService(); |
||
578 | |||
579 | $userGroupToMove = new UserGroup( |
||
580 | [ |
||
581 | 'content' => new Content( |
||
582 | [ |
||
583 | 'versionInfo' => new VersionInfo( |
||
584 | ['contentInfo' => new ContentInfo(['id' => 123456])] |
||
585 | ), |
||
586 | 'internalFields' => [], |
||
587 | ] |
||
588 | ), |
||
589 | ] |
||
590 | ); |
||
591 | $parentUserGroup = new UserGroup( |
||
592 | [ |
||
593 | 'content' => new Content( |
||
594 | [ |
||
595 | 'versionInfo' => new VersionInfo( |
||
596 | ['contentInfo' => new ContentInfo(['id' => 123455])] |
||
597 | ), |
||
598 | 'internalFields' => [], |
||
599 | ] |
||
600 | ), |
||
601 | ] |
||
602 | ); |
||
603 | $userService->moveUserGroup($userGroupToMove, $parentUserGroup); |
||
604 | } |
||
605 | |||
606 | /** |
||
607 | * Test for the newUserGroupUpdateStruct() method. |
||
608 | * |
||
609 | * @covers \eZ\Publish\API\Repository\UserService::newUserGroupUpdateStruct |
||
610 | */ |
||
611 | public function testNewUserGroupUpdateStruct() |
||
612 | { |
||
613 | $repository = $this->getRepository(); |
||
614 | |||
615 | /* BEGIN: Use Case */ |
||
616 | $userService = $repository->getUserService(); |
||
617 | |||
618 | $groupUpdate = $userService->newUserGroupUpdateStruct(); |
||
619 | /* END: Use Case */ |
||
620 | |||
621 | $this->assertInstanceOf( |
||
622 | UserGroupUpdateStruct::class, |
||
623 | $groupUpdate |
||
624 | ); |
||
625 | |||
626 | $this->assertNull($groupUpdate->contentUpdateStruct); |
||
627 | $this->assertNull($groupUpdate->contentMetadataUpdateStruct); |
||
628 | } |
||
629 | |||
630 | /** |
||
631 | * Test for the updateUserGroup() method. |
||
632 | * |
||
633 | * @see \eZ\Publish\API\Repository\UserService::updateUserGroup() |
||
634 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUserGroup |
||
635 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testNewUserGroupUpdateStruct |
||
636 | */ |
||
637 | public function testUpdateUserGroup() |
||
638 | { |
||
639 | $repository = $this->getRepository(); |
||
640 | $userService = $repository->getUserService(); |
||
641 | |||
642 | /* BEGIN: Use Case */ |
||
643 | $userGroup = $this->createUserGroupVersion1(); |
||
644 | |||
645 | // Create a group update struct and change nothing |
||
646 | $groupUpdate = $userService->newUserGroupUpdateStruct(); |
||
647 | |||
648 | // This update will do nothing |
||
649 | $userGroup = $userService->updateUserGroup( |
||
650 | $userGroup, |
||
651 | $groupUpdate |
||
652 | ); |
||
653 | /* END: Use Case */ |
||
654 | |||
655 | $this->assertInstanceOf( |
||
656 | UserGroup::class, |
||
657 | $userGroup |
||
658 | ); |
||
659 | |||
660 | $this->assertEquals(1, $userGroup->getVersionInfo()->versionNo); |
||
661 | } |
||
662 | |||
663 | /** |
||
664 | * Test for the updateUserGroup() method. |
||
665 | * |
||
666 | * @see \eZ\Publish\API\Repository\UserService::updateUserGroup() |
||
667 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUserGroup |
||
668 | */ |
||
669 | public function testUpdateUserGroupWithSubContentUpdateStruct() |
||
670 | { |
||
671 | $repository = $this->getRepository(); |
||
672 | $userService = $repository->getUserService(); |
||
673 | |||
674 | /* BEGIN: Use Case */ |
||
675 | $userGroup = $this->createUserGroupVersion1(); |
||
676 | |||
677 | // Load the content service |
||
678 | $contentService = $repository->getContentService(); |
||
679 | |||
680 | // Create a content update struct and update the group name |
||
681 | $contentUpdate = $contentService->newContentUpdateStruct(); |
||
682 | $contentUpdate->setField('name', 'Sindelfingen', 'eng-US'); |
||
683 | |||
684 | // Create a group update struct and set content update struct |
||
685 | $groupUpdate = $userService->newUserGroupUpdateStruct(); |
||
686 | $groupUpdate->contentUpdateStruct = $contentUpdate; |
||
687 | |||
688 | // This will update the name and the increment the group version number |
||
689 | $userGroup = $userService->updateUserGroup( |
||
690 | $userGroup, |
||
691 | $groupUpdate |
||
692 | ); |
||
693 | /* END: Use Case */ |
||
694 | |||
695 | $this->assertEquals('Sindelfingen', $userGroup->getFieldValue('name', 'eng-US')); |
||
696 | |||
697 | $versionInfo = $userGroup->getVersionInfo(); |
||
698 | |||
699 | $this->assertEquals(APIVersionInfo::STATUS_PUBLISHED, $versionInfo->status); |
||
700 | $this->assertEquals(2, $versionInfo->versionNo); |
||
701 | } |
||
702 | |||
703 | /** |
||
704 | * Test for the updateUserGroup() method. |
||
705 | * |
||
706 | * @see \eZ\Publish\API\Repository\UserService::updateUserGroup() |
||
707 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUserGroup |
||
708 | */ |
||
709 | public function testUpdateUserGroupWithSubContentMetadataUpdateStruct() |
||
710 | { |
||
711 | $repository = $this->getRepository(); |
||
712 | $userService = $repository->getUserService(); |
||
713 | |||
714 | /* BEGIN: Use Case */ |
||
715 | $userGroup = $this->createUserGroupVersion1(); |
||
716 | |||
717 | // Load the content service |
||
718 | $contentService = $repository->getContentService(); |
||
719 | |||
720 | // Create a metadata update struct and change the remoteId |
||
721 | $metadataUpdate = $contentService->newContentMetadataUpdateStruct(); |
||
722 | $metadataUpdate->remoteId = '3c61299780663bafa3af2101e52125da'; |
||
723 | |||
724 | // Create a group update struct and set content update struct |
||
725 | $groupUpdate = $userService->newUserGroupUpdateStruct(); |
||
726 | $groupUpdate->contentMetadataUpdateStruct = $metadataUpdate; |
||
727 | |||
728 | // This will update the name and the increment the group version number |
||
729 | $userGroup = $userService->updateUserGroup( |
||
730 | $userGroup, |
||
731 | $groupUpdate |
||
732 | ); |
||
733 | /* END: Use Case */ |
||
734 | |||
735 | $this->assertEquals( |
||
736 | '3c61299780663bafa3af2101e52125da', |
||
737 | $userGroup->contentInfo->remoteId |
||
738 | ); |
||
739 | |||
740 | $versionInfo = $userGroup->getVersionInfo(); |
||
741 | |||
742 | $this->assertEquals(APIVersionInfo::STATUS_PUBLISHED, $versionInfo->status); |
||
743 | $this->assertEquals(1, $versionInfo->versionNo); |
||
744 | } |
||
745 | |||
746 | /** |
||
747 | * Test for the updateUserGroup() method. |
||
748 | * |
||
749 | * @see \eZ\Publish\API\Repository\UserService::updateUserGroup() |
||
750 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
751 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUserGroup |
||
752 | */ |
||
753 | public function testUpdateUserGroupThrowsInvalidArgumentExceptionOnFieldTypeNotAccept() |
||
754 | { |
||
755 | $repository = $this->getRepository(); |
||
756 | $userService = $repository->getUserService(); |
||
757 | |||
758 | /* BEGIN: Use Case */ |
||
759 | $userGroup = $this->createUserGroupVersion1(); |
||
760 | |||
761 | // Load the content service |
||
762 | $contentService = $repository->getContentService(); |
||
763 | |||
764 | // Create a content update struct and update the group name |
||
765 | $contentUpdate = $contentService->newContentUpdateStruct(); |
||
766 | // An object of stdClass is not accepted as a value by the field "name" |
||
767 | $contentUpdate->setField('name', new \stdClass(), 'eng-US'); |
||
768 | |||
769 | // Create a group update struct and set content update struct |
||
770 | $groupUpdate = $userService->newUserGroupUpdateStruct(); |
||
771 | $groupUpdate->contentUpdateStruct = $contentUpdate; |
||
772 | |||
773 | // This call will fail with an InvalidArgumentException, because the |
||
774 | // field "name" does not accept the given value |
||
775 | $userService->updateUserGroup($userGroup, $groupUpdate); |
||
776 | /* END: Use Case */ |
||
777 | } |
||
778 | |||
779 | /** |
||
780 | * Test for the newUserCreateStruct() method. |
||
781 | * |
||
782 | * @see \eZ\Publish\API\Repository\UserService::newUserCreateStruct() |
||
783 | */ |
||
784 | public function testNewUserCreateStruct() |
||
806 | |||
807 | /** |
||
808 | * Test updating a user group throws ContentFieldValidationException. |
||
809 | * |
||
810 | * @covers \eZ\Publish\API\Repository\UserService::updateUserGroup |
||
811 | * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException |
||
812 | */ |
||
813 | public function testUpdateUserGroupThrowsContentFieldValidationExceptionOnRequiredFieldEmpty() |
||
814 | { |
||
815 | $repository = $this->getRepository(); |
||
816 | $userService = $repository->getUserService(); |
||
817 | $contentService = $repository->getContentService(); |
||
818 | |||
819 | $userGroup = $userService->loadUserGroup(42); |
||
820 | $userGroupUpdateStruct = $userService->newUserGroupUpdateStruct(); |
||
821 | $userGroupUpdateStruct->contentUpdateStruct = $contentService->newContentUpdateStruct(); |
||
822 | $userGroupUpdateStruct->contentUpdateStruct->setField('name', '', 'eng-US'); |
||
823 | |||
824 | $userService->updateUserGroup($userGroup, $userGroupUpdateStruct); |
||
825 | } |
||
826 | |||
827 | /** |
||
828 | * Test for the newUserCreateStruct() method. |
||
829 | * |
||
830 | * @param \eZ\Publish\API\Repository\Values\User\UserCreateStruct $userCreate |
||
831 | * |
||
832 | * @see \eZ\Publish\API\Repository\UserService::newUserCreateStruct() |
||
833 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testNewUserCreateStruct |
||
834 | */ |
||
835 | public function testNewUserCreateStructSetsExpectedProperties($userCreate) |
||
852 | |||
853 | /** |
||
854 | * Test for the newUserCreateStruct() method. |
||
855 | * |
||
856 | * @see \eZ\Publish\API\Repository\UserService::newUserCreateStruct($login, $email, $password, $mainLanguageCode, $contentType) |
||
857 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testNewUserCreateStruct |
||
858 | * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeByIdentifier |
||
859 | */ |
||
860 | public function testNewUserCreateStructWithFifthParameter() |
||
885 | |||
886 | /** |
||
887 | * Test for creating user with Active Directory login name. |
||
888 | */ |
||
889 | public function testNewUserWithDomainName() |
||
898 | |||
899 | /** |
||
900 | * Test for the createUser() method. |
||
901 | * |
||
902 | * @return \eZ\Publish\API\Repository\Values\User\User |
||
903 | * |
||
904 | * @see \eZ\Publish\API\Repository\UserService::createUser() |
||
905 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testLoadUserGroup |
||
906 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testNewUserCreateStruct |
||
907 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
908 | */ |
||
909 | public function testCreateUser() |
||
922 | |||
923 | /** |
||
924 | * Test for the createUser() method. |
||
925 | * |
||
926 | * @param \eZ\Publish\API\Repository\Values\User\User $user |
||
927 | * |
||
928 | * @see \eZ\Publish\API\Repository\UserService::createUser() |
||
929 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser |
||
930 | */ |
||
931 | public function testCreateUserSetsExpectedProperties(User $user) |
||
946 | |||
947 | /** |
||
948 | * Test for the createUser() method. |
||
949 | * |
||
950 | * @see \eZ\Publish\API\Repository\UserService::createUser() |
||
951 | * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException |
||
952 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser |
||
953 | */ |
||
954 | public function testCreateUserWhenMissingField() |
||
985 | |||
986 | /** |
||
987 | * Test for the createUser() method. |
||
988 | * |
||
989 | * @see \eZ\Publish\API\Repository\UserService::createUser() |
||
990 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
991 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser |
||
992 | */ |
||
993 | public function testCreateUserThrowsInvalidArgumentExceptionOnFieldTypeNotAccept() |
||
1024 | |||
1025 | /** |
||
1026 | * Test for the createUser() method. |
||
1027 | * |
||
1028 | * @covers \eZ\Publish\API\Repository\UserService::createUser |
||
1029 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
1030 | * @expectedExceptionMessage Argument 'userCreateStruct' is invalid: User with provided login already exists |
||
1031 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser |
||
1032 | */ |
||
1033 | public function testCreateUserThrowsInvalidArgumentException() |
||
1064 | |||
1065 | /** |
||
1066 | * Test for the createUser() method. |
||
1067 | * |
||
1068 | * @return \eZ\Publish\API\Repository\Values\User\User |
||
1069 | * |
||
1070 | * @see \eZ\Publish\API\Repository\UserService::createUser() |
||
1071 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testLoadUserGroup |
||
1072 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testNewUserCreateStruct |
||
1073 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
1074 | */ |
||
1075 | public function testCreateUserInTransactionWithRollback() |
||
1103 | |||
1104 | /** |
||
1105 | * Test creating a user throwing NotFoundException. |
||
1106 | * |
||
1107 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
1108 | * @covers \eZ\Publish\API\Repository\UserService::createUser |
||
1109 | */ |
||
1110 | public function testCreateUserThrowsNotFoundException() |
||
1135 | |||
1136 | /** |
||
1137 | * Test creating a user throwing UserPasswordValidationException when password doesn't follow specific rules. |
||
1138 | * |
||
1139 | * @expectedException \eZ\Publish\Core\Base\Exceptions\UserPasswordValidationException |
||
1140 | * @expectedExceptionMessage Argument 'password' is invalid: Password doesn't match the following rules: User password must be at least 8 characters long, User password must include at least one upper case letter, User password must include at least one number, User password must include at least one special character |
||
1141 | * @covers \eZ\Publish\API\Repository\UserService::createUser |
||
1142 | */ |
||
1143 | public function testCreateUserWithWeakPasswordThrowsUserPasswordValidationException() |
||
1153 | |||
1154 | /** |
||
1155 | * Opposite test case for testCreateUserWithWeakPasswordThrowsUserPasswordValidationException. |
||
1156 | * |
||
1157 | * @covers \eZ\Publish\API\Repository\UserService::createUser |
||
1158 | */ |
||
1159 | public function testCreateUserWithStrongPassword() |
||
1169 | |||
1170 | /** |
||
1171 | * Test for the loadUser() method. |
||
1172 | * |
||
1173 | * @see \eZ\Publish\API\Repository\UserService::loadUser() |
||
1174 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser |
||
1175 | */ |
||
1176 | public function testLoadUser() |
||
1195 | |||
1196 | /** |
||
1197 | * Test for the loadUser() method. |
||
1198 | * |
||
1199 | * @see \eZ\Publish\API\Repository\UserService::loadUser() |
||
1200 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
1201 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testLoadUser |
||
1202 | */ |
||
1203 | public function testLoadUserThrowsNotFoundException() |
||
1216 | |||
1217 | /** |
||
1218 | * Test for the loadAnonymousUser() method. |
||
1219 | * |
||
1220 | * @see \eZ\Publish\API\Repository\UserService::loadAnonymousUser() |
||
1221 | */ |
||
1222 | public function testLoadAnonymousUser() |
||
1243 | |||
1244 | /** |
||
1245 | * Test for the loadUserByCredentials() method. |
||
1246 | * |
||
1247 | * @see \eZ\Publish\API\Repository\UserService::loadUserByCredentials() |
||
1248 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser |
||
1249 | */ |
||
1250 | public function testLoadUserByCredentials() |
||
1265 | |||
1266 | /** |
||
1267 | * Test for the loadUserByCredentials() method. |
||
1268 | * |
||
1269 | * @see \eZ\Publish\API\Repository\UserService::loadUserByCredentials() |
||
1270 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
1271 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testLoadUserByCredentials |
||
1272 | */ |
||
1273 | public function testLoadUserByCredentialsThrowsNotFoundExceptionForUnknownPassword() |
||
1287 | |||
1288 | /** |
||
1289 | * Test for the loadUserByCredentials() method. |
||
1290 | * |
||
1291 | * @see \eZ\Publish\API\Repository\UserService::loadUserByCredentials() |
||
1292 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
1293 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testLoadUserByCredentials |
||
1294 | */ |
||
1295 | public function testLoadUserByCredentialsThrowsNotFoundExceptionForUnknownPasswordEmtpy() |
||
1309 | |||
1310 | /** |
||
1311 | * Test for the loadUserByCredentials() method. |
||
1312 | * |
||
1313 | * @see \eZ\Publish\API\Repository\UserService::loadUserByCredentials() |
||
1314 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
1315 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testLoadUserByCredentials |
||
1316 | */ |
||
1317 | public function testLoadUserByCredentialsThrowsNotFoundExceptionForUnknownLogin() |
||
1331 | |||
1332 | /** |
||
1333 | * Test for the loadUserByCredentials() method. |
||
1334 | * |
||
1335 | * @see \eZ\Publish\API\Repository\UserService::loadUserByCredentials() |
||
1336 | * @expectedException \eZ\Publish\Core\Base\Exceptions\InvalidArgumentValue |
||
1337 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testLoadUserByCredentials |
||
1338 | */ |
||
1339 | public function testLoadUserByCredentialsThrowsInvalidArgumentValueForEmptyLogin() |
||
1353 | |||
1354 | /** |
||
1355 | * Test for the loadUserByLogin() method. |
||
1356 | * |
||
1357 | * @see \eZ\Publish\API\Repository\UserService::loadUserByLogin() |
||
1358 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser |
||
1359 | */ |
||
1360 | public function testLoadUserByLogin() |
||
1389 | |||
1390 | /** |
||
1391 | * Test for the loadUserByLogin() method. |
||
1392 | * |
||
1393 | * @see \eZ\Publish\API\Repository\UserService::loadUserByLogin() |
||
1394 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
1395 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testLoadUserByLogin |
||
1396 | */ |
||
1397 | public function testLoadUserByLoginThrowsNotFoundExceptionForUnknownLogin() |
||
1411 | |||
1412 | /** |
||
1413 | * Test for the loadUserByLogin() method. |
||
1414 | * |
||
1415 | * @see \eZ\Publish\API\Repository\UserService::loadUserByLogin() |
||
1416 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testLoadUserByLogin |
||
1417 | */ |
||
1418 | public function testLoadUserByLoginWorksForLoginWithWrongCase() |
||
1447 | |||
1448 | /** |
||
1449 | * Test for the loadUserByLogin() method. |
||
1450 | * |
||
1451 | * In some cases people use email as login name, make sure system works as exepcted when asking for user by email. |
||
1452 | * |
||
1453 | * @see \eZ\Publish\API\Repository\UserService::loadUserByLogin() |
||
1454 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
1455 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testLoadUserByLogin |
||
1456 | */ |
||
1457 | public function testLoadUserByLoginThrowsNotFoundExceptionForUnknownLoginByEmail() |
||
1470 | |||
1471 | /** |
||
1472 | * Test for the loadUsersByEmail() method. |
||
1473 | * |
||
1474 | * @see \eZ\Publish\API\Repository\UserService::loadUsersByEmail() |
||
1475 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser |
||
1476 | */ |
||
1477 | public function testLoadUserByEmail() |
||
1492 | |||
1493 | /** |
||
1494 | * Test for the loadUsersByEmail() method. |
||
1495 | * |
||
1496 | * @see \eZ\Publish\API\Repository\UserService::loadUsersByEmail() |
||
1497 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testLoadUserByEmail |
||
1498 | */ |
||
1499 | public function testLoadUserByEmailReturnsEmptyInUnknownEmail() |
||
1515 | |||
1516 | /** |
||
1517 | * Test for the deleteUser() method. |
||
1518 | * |
||
1519 | * @see \eZ\Publish\API\Repository\UserService::deleteUser() |
||
1520 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
1521 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser |
||
1522 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testLoadUser |
||
1523 | */ |
||
1524 | public function testDeleteUser() |
||
1540 | |||
1541 | /** |
||
1542 | * Test for the deleteUser() method. |
||
1543 | * |
||
1544 | * @covers \eZ\Publish\API\Repository\UserService::deleteUser() |
||
1545 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser |
||
1546 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testLoadUser |
||
1547 | */ |
||
1548 | public function testDeleteUserDeletesRelatedBookmarks() |
||
1575 | |||
1576 | /** |
||
1577 | * Test for the newUserUpdateStruct() method. |
||
1578 | * |
||
1579 | * @see \eZ\Publish\API\Repository\UserService::newUserUpdateStruct() |
||
1580 | */ |
||
1581 | public function testNewUserUpdateStruct() |
||
1610 | |||
1611 | /** |
||
1612 | * Test for the updateUser() method. |
||
1613 | * |
||
1614 | * @return \eZ\Publish\API\Repository\Values\User\User |
||
1615 | * |
||
1616 | * @see \eZ\Publish\API\Repository\UserService::updateUser() |
||
1617 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser |
||
1618 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testNewUserUpdateStruct |
||
1619 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
||
1620 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata |
||
1621 | */ |
||
1622 | public function testUpdateUser() |
||
1647 | |||
1648 | /** |
||
1649 | * Test for the updateUser() and loadUsersByEmail() method on change to email. |
||
1650 | */ |
||
1651 | public function testUpdateUserEmail(): void |
||
1674 | |||
1675 | /** |
||
1676 | * Test for the updateUser() method. |
||
1677 | * |
||
1678 | * @return \eZ\Publish\API\Repository\Values\User\User |
||
1679 | * |
||
1680 | * @see \eZ\Publish\API\Repository\UserService::updateUser() |
||
1681 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser |
||
1682 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testNewUserUpdateStruct |
||
1683 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
||
1684 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata |
||
1685 | */ |
||
1686 | public function testUpdateUserNoPassword() |
||
1748 | |||
1749 | /** |
||
1750 | * Test for the updateUser() method. |
||
1751 | * |
||
1752 | * @param \eZ\Publish\API\Repository\Values\User\User $user |
||
1753 | * |
||
1754 | * @see \eZ\Publish\API\Repository\UserService::updateUser() |
||
1755 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUser |
||
1756 | */ |
||
1757 | public function testUpdateUserUpdatesExpectedProperties(User $user) |
||
1774 | |||
1775 | /** |
||
1776 | * Test for the updateUser() method. |
||
1777 | * |
||
1778 | * @param \eZ\Publish\API\Repository\Values\User\User $user |
||
1779 | * |
||
1780 | * @see \eZ\Publish\API\Repository\UserService::updateUser() |
||
1781 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUser |
||
1782 | */ |
||
1783 | public function testUpdateUserReturnsPublishedVersion(User $user) |
||
1790 | |||
1791 | /** |
||
1792 | * Test for the updateUser() method. |
||
1793 | * |
||
1794 | * @see \eZ\Publish\API\Repository\UserService::updateUser() |
||
1795 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUser |
||
1796 | */ |
||
1797 | public function testUpdateUserWithContentMetadataUpdateStruct() |
||
1828 | |||
1829 | /** |
||
1830 | * Test for the updateUser() method. |
||
1831 | * |
||
1832 | * @see \eZ\Publish\API\Repository\UserService::updateUser() |
||
1833 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUser |
||
1834 | */ |
||
1835 | public function testUpdateUserWithContentUpdateStruct() |
||
1870 | |||
1871 | /** |
||
1872 | * Test for the updateUser() method. |
||
1873 | * |
||
1874 | * @see \eZ\Publish\API\Repository\UserService::updateUser() |
||
1875 | * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException |
||
1876 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUser |
||
1877 | */ |
||
1878 | public function testUpdateUserWhenMissingField() |
||
1906 | |||
1907 | /** |
||
1908 | * Test for the updateUser() method. |
||
1909 | * |
||
1910 | * @see \eZ\Publish\API\Repository\UserService::updateUser() |
||
1911 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
1912 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUpdateUser |
||
1913 | */ |
||
1914 | public function testUpdateUserThrowsInvalidArgumentExceptionOnFieldTypeNotAccept() |
||
1942 | |||
1943 | /** |
||
1944 | * Test updating a user throwing UserPasswordValidationException when password doesn't follow specified rules. |
||
1945 | * |
||
1946 | * @expectedException \eZ\Publish\Core\Base\Exceptions\UserPasswordValidationException |
||
1947 | * @expectedExceptionMessage Argument 'password' is invalid: Password doesn't match the following rules: User password must be at least 8 characters long, User password must include at least one upper case letter, User password must include at least one number, User password must include at least one special character |
||
1948 | * @covers \eZ\Publish\API\Repository\UserService::updateUser |
||
1949 | */ |
||
1950 | public function testUpdateUserWithWeakPasswordThrowsUserPasswordValidationException() |
||
1966 | |||
1967 | /** |
||
1968 | * Opposite test case for testUpdateUserWithWeakPasswordThrowsUserPasswordValidationException. |
||
1969 | * |
||
1970 | * @covers \eZ\Publish\API\Repository\UserService::updateUser |
||
1971 | */ |
||
1972 | public function testUpdateUserWithStrongPassword() |
||
1988 | |||
1989 | /** |
||
1990 | * Test for the loadUserGroupsOfUser() method. |
||
1991 | * |
||
1992 | * @covers \eZ\Publish\API\Repository\UserService::loadUserGroupsOfUser |
||
1993 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser |
||
1994 | */ |
||
1995 | public function testLoadUserGroupsOfUser() |
||
2014 | |||
2015 | /** |
||
2016 | * Test for the loadUsersOfUserGroup() method. |
||
2017 | * |
||
2018 | * @covers \eZ\Publish\API\Repository\UserService::loadUsersOfUserGroup |
||
2019 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser |
||
2020 | */ |
||
2021 | public function testLoadUsersOfUserGroup() |
||
2042 | |||
2043 | /** |
||
2044 | * Test for the assignUserToUserGroup() method. |
||
2045 | * |
||
2046 | * @see \eZ\Publish\API\Repository\UserService::assignUserToUserGroup() |
||
2047 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testLoadUserGroupsOfUser |
||
2048 | */ |
||
2049 | public function testAssignUserToUserGroup() |
||
2084 | |||
2085 | /** |
||
2086 | * Test for the assignUserToUserGroup() method. |
||
2087 | * |
||
2088 | * @covers \eZ\Publish\API\Repository\UserService::assignUserToUserGroup |
||
2089 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
2090 | * @expectedExceptionMessage Argument 'user' is invalid: user is already in the given user group |
||
2091 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testAssignUserToUserGroup |
||
2092 | */ |
||
2093 | public function testAssignUserToUserGroupThrowsInvalidArgumentException() |
||
2112 | |||
2113 | /** |
||
2114 | * Test for the unAssignUssrFromUserGroup() method. |
||
2115 | * |
||
2116 | * @see \eZ\Publish\API\Repository\UserService::unAssignUssrFromUserGroup() |
||
2117 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testLoadUserGroupsOfUser |
||
2118 | */ |
||
2119 | public function testUnAssignUserFromUserGroup() |
||
2154 | |||
2155 | /** |
||
2156 | * Test for the unAssignUserFromUserGroup() method. |
||
2157 | * |
||
2158 | * @see \eZ\Publish\API\Repository\UserService::unAssignUserFromUserGroup() |
||
2159 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
2160 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUnAssignUserFromUserGroup |
||
2161 | */ |
||
2162 | public function testUnAssignUserFromUserGroupThrowsInvalidArgumentException() |
||
2181 | |||
2182 | /** |
||
2183 | * Test for the unAssignUserFromUserGroup() method removing user from the last group. |
||
2184 | * |
||
2185 | * @covers \eZ\Publish\API\Repository\UserService::unAssignUserFromUserGroup |
||
2186 | * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
2187 | * @expectedExceptionMessage Argument 'user' has a bad state: user only has one user group, cannot unassign from last group |
||
2188 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUnAssignUserFromUserGroup |
||
2189 | */ |
||
2190 | public function testUnAssignUserFromUserGroupThrowsBadStateArgumentException() |
||
2207 | |||
2208 | /** |
||
2209 | * Test that multi-language logic for the loadUserGroup method respects prioritized language list. |
||
2210 | * |
||
2211 | * @covers \eZ\Publish\API\Repository\UserService::loadUserGroup |
||
2212 | * @dataProvider getPrioritizedLanguageList |
||
2213 | * @param string[] $prioritizedLanguages |
||
2214 | * @param string|null $expectedLanguageCode language code of expected translation |
||
2215 | */ |
||
2216 | public function testLoadUserGroupWithPrioritizedLanguagesList( |
||
2239 | |||
2240 | /** |
||
2241 | * Test that multi-language logic works correctly after updating user group main language. |
||
2242 | * |
||
2243 | * @covers \eZ\Publish\API\Repository\UserService::loadUserGroup |
||
2244 | * @dataProvider getPrioritizedLanguageList |
||
2245 | * @param string[] $prioritizedLanguages |
||
2246 | * @param string|null $expectedLanguageCode language code of expected translation |
||
2247 | */ |
||
2248 | public function testLoadUserGroupWithPrioritizedLanguagesListAfterMainLanguageUpdate( |
||
2278 | |||
2279 | /** |
||
2280 | * Test that multi-language logic for the loadSubUserGroups method respects prioritized language list. |
||
2281 | * |
||
2282 | * @covers \eZ\Publish\API\Repository\UserService::loadSubUserGroups |
||
2283 | * @dataProvider getPrioritizedLanguageList |
||
2284 | * @param string[] $prioritizedLanguages |
||
2285 | * @param string|null $expectedLanguageCode language code of expected translation |
||
2286 | */ |
||
2287 | public function testLoadSubUserGroupsWithPrioritizedLanguagesList( |
||
2318 | |||
2319 | /** |
||
2320 | * Test that multi-language logic for the loadUser method respects prioritized language list. |
||
2321 | * |
||
2322 | * @covers \eZ\Publish\API\Repository\UserService::loadUser |
||
2323 | * @dataProvider getPrioritizedLanguageList |
||
2324 | * @param string[] $prioritizedLanguages |
||
2325 | * @param string|null $expectedLanguageCode language code of expected translation |
||
2326 | */ |
||
2327 | public function testLoadUserWithPrioritizedLanguagesList( |
||
2353 | |||
2354 | /** |
||
2355 | * Test that multi-language logic for the loadUser method works correctly after updating |
||
2356 | * user content main language. |
||
2357 | * |
||
2358 | * @covers \eZ\Publish\API\Repository\UserService::loadUserGroup |
||
2359 | * @dataProvider getPrioritizedLanguageList |
||
2360 | * @param string[] $prioritizedLanguages |
||
2361 | * @param string|null $expectedLanguageCode language code of expected translation |
||
2362 | */ |
||
2363 | public function testLoadUserWithPrioritizedLanguagesListAfterMainLanguageUpdate( |
||
2397 | |||
2398 | /** |
||
2399 | * Test that multi-language logic for the loadUserByLogin method respects prioritized language list. |
||
2400 | * |
||
2401 | * @covers \eZ\Publish\API\Repository\UserService::loadUserByLogin |
||
2402 | * @dataProvider getPrioritizedLanguageList |
||
2403 | * @param string[] $prioritizedLanguages |
||
2404 | * @param string|null $expectedLanguageCode language code of expected translation |
||
2405 | */ |
||
2406 | public function testLoadUserByLoginWithPrioritizedLanguagesList( |
||
2432 | |||
2433 | /** |
||
2434 | * Test that multi-language logic for the loadUserByCredentials method respects |
||
2435 | * prioritized language list. |
||
2436 | * |
||
2437 | * @covers \eZ\Publish\API\Repository\UserService::loadUserByCredentials |
||
2438 | * @dataProvider getPrioritizedLanguageList |
||
2439 | * @param string[] $prioritizedLanguages |
||
2440 | * @param string|null $expectedLanguageCode language code of expected translation |
||
2441 | */ |
||
2442 | public function testLoadUserByCredentialsWithPrioritizedLanguagesList( |
||
2472 | |||
2473 | /** |
||
2474 | * Test that multi-language logic for the loadUsersByEmail method respects |
||
2475 | * prioritized language list. |
||
2476 | * |
||
2477 | * @covers \eZ\Publish\API\Repository\UserService::loadUsersByEmail |
||
2478 | * @dataProvider getPrioritizedLanguageList |
||
2479 | * @param string[] $prioritizedLanguages |
||
2480 | * @param string|null $expectedLanguageCode language code of expected translation |
||
2481 | */ |
||
2482 | public function testLoadUsersByEmailWithPrioritizedLanguagesList( |
||
2510 | |||
2511 | /** |
||
2512 | * Test that multi-language logic for the loadUserGroupsOfUser method respects |
||
2513 | * prioritized language list. |
||
2514 | * |
||
2515 | * @covers \eZ\Publish\API\Repository\UserService::loadUserGroupsOfUser |
||
2516 | * @dataProvider getPrioritizedLanguageList |
||
2517 | * @param string[] $prioritizedLanguages |
||
2518 | * @param string|null $expectedLanguageCode language code of expected translation |
||
2519 | */ |
||
2520 | public function testLoadUserGroupsOfUserWithPrioritizedLanguagesList( |
||
2541 | |||
2542 | /** |
||
2543 | * Test that multi-language logic for the loadUsersOfUserGroup method respects |
||
2544 | * prioritized language list. |
||
2545 | * |
||
2546 | * @covers \eZ\Publish\API\Repository\UserService::loadUsersOfUserGroup |
||
2547 | * @dataProvider getPrioritizedLanguageList |
||
2548 | * @param string[] $prioritizedLanguages |
||
2549 | * @param string|null $expectedLanguageCode language code of expected translation |
||
2550 | */ |
||
2551 | public function testLoadUsersOfUserGroupWithPrioritizedLanguagesList( |
||
2583 | |||
2584 | /** |
||
2585 | * Get prioritized languages list data. |
||
2586 | * |
||
2587 | * Test cases using this data provider should expect the following arguments: |
||
2588 | * <code> |
||
2589 | * array $prioritizedLanguagesList |
||
2590 | * string $expectedLanguage (if null - use main language) |
||
2591 | * </code> |
||
2592 | * |
||
2593 | * @return array |
||
2594 | */ |
||
2595 | public function getPrioritizedLanguageList() |
||
2608 | |||
2609 | /** |
||
2610 | * @param int $parentGroupId |
||
2611 | * @return \eZ\Publish\API\Repository\Values\User\UserGroup |
||
2612 | */ |
||
2613 | private function createMultiLanguageUserGroup($parentGroupId = 4) |
||
2631 | |||
2632 | /** |
||
2633 | * Create a user group fixture in a variable named <b>$userGroup</b>,. |
||
2634 | * |
||
2635 | * @return \eZ\Publish\API\Repository\Values\User\UserGroup |
||
2636 | */ |
||
2637 | private function createUserGroupVersion1() |
||
2663 | |||
2664 | /** |
||
2665 | * Create user with multiple translations of User Content fields. |
||
2666 | * |
||
2667 | * @param int $userGroupId User group ID (default 13 - Editors) |
||
2668 | * |
||
2669 | * @return \eZ\Publish\API\Repository\Values\User\User |
||
2670 | */ |
||
2671 | private function createMultiLanguageUser($userGroupId = 13) |
||
2700 | |||
2701 | /** |
||
2702 | * Test for the createUser() method. |
||
2703 | * |
||
2704 | * @see \eZ\Publish\API\Repository\UserService::createUser() |
||
2705 | */ |
||
2706 | public function testCreateUserInvalidPasswordHashTypeThrowsException() |
||
2746 | |||
2747 | /** |
||
2748 | * Test loading User by Token. |
||
2749 | * |
||
2750 | * @covers \eZ\Publish\API\Repository\UserService::loadUserByToken |
||
2751 | */ |
||
2752 | public function testLoadUserByToken() |
||
2770 | |||
2771 | /** |
||
2772 | * Test trying to load User by invalid Token. |
||
2773 | * |
||
2774 | * @covers \eZ\Publish\API\Repository\UserService::loadUserByToken |
||
2775 | */ |
||
2776 | public function testLoadUserByTokenThrowsNotFoundException() |
||
2793 | |||
2794 | /** |
||
2795 | * Test updating User Token. |
||
2796 | * |
||
2797 | * @covers \eZ\Publish\API\Repository\UserService::updateUserToken() |
||
2798 | * |
||
2799 | * @depends testLoadUserByToken |
||
2800 | * |
||
2801 | * @param string $originalUserToken |
||
2802 | */ |
||
2803 | public function testUpdateUserToken($originalUserToken) |
||
2819 | |||
2820 | /** |
||
2821 | * Test invalidating (expiring) User Token. |
||
2822 | * |
||
2823 | * @covers \eZ\Publish\API\Repository\UserService::expireUserToken() |
||
2824 | * |
||
2825 | * @depends testLoadUserByToken |
||
2826 | * |
||
2827 | * @param string $userToken |
||
2828 | */ |
||
2829 | public function testExpireUserToken($userToken) |
||
2844 | |||
2845 | /** |
||
2846 | * @covers \eZ\Publish\API\Repository\UserService::validatePassword() |
||
2847 | */ |
||
2848 | public function testValidatePasswordWithDefaultContext() |
||
2858 | |||
2859 | /** |
||
2860 | * @covers \eZ\Publish\API\Repository\UserService::validatePassword() |
||
2861 | * @dataProvider dataProviderForValidatePassword |
||
2862 | */ |
||
2863 | public function testValidatePassword(string $password, array $expectedErrorr) |
||
2878 | |||
2879 | /** |
||
2880 | * Data provider for testValidatePassword. |
||
2881 | * |
||
2882 | * @return array |
||
2883 | */ |
||
2884 | public function dataProviderForValidatePassword(): array |
||
2904 | |||
2905 | public function testGetPasswordInfo(): void |
||
2937 | |||
2938 | public function testGetPasswordInfoIfExpirationIsDisabled(): void |
||
2951 | |||
2952 | public function testGetPasswordInfoIfExpirationWarningIsDisabled(): void |
||
2974 | |||
2975 | public function createTestUser(ContentType $contentType): User |
||
2979 | |||
2980 | /** |
||
2981 | * Creates a user with given password. |
||
2982 | * |
||
2983 | * @param string $password |
||
2984 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType |
||
2985 | * |
||
2986 | * @return \eZ\Publish\API\Repository\Values\User\User |
||
2987 | */ |
||
2988 | private function createTestUserWithPassword(string $password, ContentType $contentType): User |
||
3010 | |||
3011 | /** |
||
3012 | * Creates the User Content Type with password constraints. |
||
3013 | * |
||
3014 | * @return \eZ\Publish\API\Repository\Values\ContentType\ContentType |
||
3015 | */ |
||
3016 | private function createUserContentTypeWithStrongPassword(): ContentType |
||
3028 | |||
3029 | private function createUserContentTypeWithPasswordExpirationDate( |
||
3038 | |||
3039 | private function createUserContentTypeWithAccountSettings( |
||
3135 | } |
||
3136 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.