| @@ 80-106 (lines=27) @@ | ||
| 77 | * @see \eZ\Publish\API\Repository\UserService::createUserGroup() |
|
| 78 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUserGroup |
|
| 79 | */ |
|
| 80 | public function testCreateUserGroupThrowsUnauthorizedException() |
|
| 81 | { |
|
| 82 | $this->expectException(\eZ\Publish\API\Repository\Exceptions\UnauthorizedException::class); |
|
| 83 | ||
| 84 | $repository = $this->getRepository(); |
|
| 85 | $userService = $repository->getUserService(); |
|
| 86 | $permissionResolver = $repository->getPermissionResolver(); |
|
| 87 | ||
| 88 | $editorsGroupId = $this->generateId('group', 13); |
|
| 89 | ||
| 90 | /* BEGIN: Use Case */ |
|
| 91 | $user = $this->createUserVersion1(); |
|
| 92 | ||
| 93 | // Load the parent group |
|
| 94 | $parentUserGroup = $userService->loadUserGroup($editorsGroupId); |
|
| 95 | ||
| 96 | // Now set the currently created "Editor" as current user |
|
| 97 | $permissionResolver->setCurrentUserReference($user); |
|
| 98 | ||
| 99 | // Instantiate a new group create struct |
|
| 100 | $userGroupCreate = $userService->newUserGroupCreateStruct('eng-GB'); |
|
| 101 | $userGroupCreate->setField('name', 'Example Group'); |
|
| 102 | ||
| 103 | // This call will fail with an "UnauthorizedException" |
|
| 104 | $userService->createUserGroup($userGroupCreate, $parentUserGroup); |
|
| 105 | /* END: Use Case */ |
|
| 106 | } |
|
| 107 | ||
| 108 | /** |
|
| 109 | * Test for the deleteUserGroup() method. |
|
| @@ 340-372 (lines=33) @@ | ||
| 337 | * @see \eZ\Publish\API\Repository\UserService::unAssignUssrFromUserGroup() |
|
| 338 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testUnAssignUserFromUserGroup |
|
| 339 | */ |
|
| 340 | public function testUnAssignUserFromUserGroupThrowsUnauthorizedException() |
|
| 341 | { |
|
| 342 | $this->expectException(\eZ\Publish\API\Repository\Exceptions\UnauthorizedException::class); |
|
| 343 | ||
| 344 | $repository = $this->getRepository(); |
|
| 345 | $userService = $repository->getUserService(); |
|
| 346 | $permissionResolver = $repository->getPermissionResolver(); |
|
| 347 | ||
| 348 | $editorsGroupId = $this->generateId('group', 13); |
|
| 349 | $memberGroupId = $this->generateId('group', 11); |
|
| 350 | ||
| 351 | /* BEGIN: Use Case */ |
|
| 352 | // $memberGroupId is the ID of the "Members" group in an eZ Publish |
|
| 353 | // demo installation |
|
| 354 | ||
| 355 | $user = $this->createUserVersion1(); |
|
| 356 | ||
| 357 | // Assign group to newly created user |
|
| 358 | $userService->assignUserToUserGroup( |
|
| 359 | $user, |
|
| 360 | $userService->loadUserGroup($memberGroupId) |
|
| 361 | ); |
|
| 362 | ||
| 363 | // Now set the currently created "Editor" as current user |
|
| 364 | $permissionResolver->setCurrentUserReference($user); |
|
| 365 | ||
| 366 | // This call will fail with an "UnauthorizedException" |
|
| 367 | $userService->unAssignUserFromUserGroup( |
|
| 368 | $user, |
|
| 369 | $userService->loadUserGroup($editorsGroupId) |
|
| 370 | ); |
|
| 371 | /* END: Use Case */ |
|
| 372 | } |
|
| 373 | ||
| 374 | /** |
|
| 375 | * Test for the loadUserGroupsOfUser() method. |
|
| @@ 2312-2347 (lines=36) @@ | ||
| 2309 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier |
|
| 2310 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup |
|
| 2311 | */ |
|
| 2312 | public function testAssignRoleToUserGroupThrowsInvalidArgumentException() |
|
| 2313 | { |
|
| 2314 | $this->expectException(\eZ\Publish\API\Repository\Exceptions\InvalidArgumentException::class); |
|
| 2315 | ||
| 2316 | $repository = $this->getRepository(); |
|
| 2317 | ||
| 2318 | $mainGroupId = $this->generateId('group', 4); |
|
| 2319 | /* BEGIN: Use Case */ |
|
| 2320 | // $mainGroupId is the ID of the main "Users" group |
|
| 2321 | ||
| 2322 | $userService = $repository->getUserService(); |
|
| 2323 | $roleService = $repository->getRoleService(); |
|
| 2324 | ||
| 2325 | $userGroup = $userService->loadUserGroup($mainGroupId); |
|
| 2326 | ||
| 2327 | // Load the existing "Anonymous" role |
|
| 2328 | $role = $roleService->loadRoleByIdentifier('Anonymous'); |
|
| 2329 | ||
| 2330 | // Assign the "Anonymous" role to the newly created user group |
|
| 2331 | try { |
|
| 2332 | $roleService->assignRoleToUserGroup( |
|
| 2333 | $role, |
|
| 2334 | $userGroup |
|
| 2335 | ); |
|
| 2336 | } catch (Exception $e) { |
|
| 2337 | $this->fail('Got exception at first valid attempt to assign role'); |
|
| 2338 | } |
|
| 2339 | ||
| 2340 | // Re-Assign the "Anonymous" role to the newly created user group |
|
| 2341 | // This call will fail with an InvalidArgumentException, because role is already assigned |
|
| 2342 | $roleService->assignRoleToUserGroup( |
|
| 2343 | $role, |
|
| 2344 | $userGroup |
|
| 2345 | ); |
|
| 2346 | /* END: Use Case */ |
|
| 2347 | } |
|
| 2348 | ||
| 2349 | /** |
|
| 2350 | * Test for the assignRoleToUserGroup() method. |
|