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