Code Duplication    Length = 28-28 lines in 2 locations

eZ/Publish/API/Repository/Tests/RoleServiceAuthorizationTest.php 1 location

@@ 500-527 (lines=28) @@
497
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testRemoveRoleAssignment
498
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser
499
     */
500
    public function testRemoveRoleAssignmentThrowsUnauthorizedException()
501
    {
502
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\UnauthorizedException::class);
503
504
        $repository = $this->getRepository();
505
        $roleService = $repository->getRoleService();
506
        $permissionResolver = $repository->getPermissionResolver();
507
508
        /* BEGIN: Use Case */
509
        $user = $this->createUserVersion1();
510
511
        $role = $this->createRole();
512
513
        // Assign new role to "Editor" user
514
        $roleService->assignRoleToUser($role, $user);
515
516
        // Set "Editor" user as current user.
517
        $permissionResolver->setCurrentUserReference($user);
518
        $roleAssignments = $roleService->getRoleAssignmentsForUser($user);
519
520
        // This call will fail with an "UnauthorizedException"
521
        foreach ($roleAssignments as $roleAssignment) {
522
            if ($roleAssignment->role->id === $role->id) {
523
                $roleService->removeRoleAssignment($roleAssignment);
524
            }
525
        }
526
        /* END: Use Case */
527
    }
528
529
    /**
530
     * Test for the getRoleAssignments() method.

eZ/Publish/API/Repository/Tests/RoleServiceTest.php 1 location

@@ 2151-2178 (lines=28) @@
2148
     * @see \eZ\Publish\API\Repository\RoleService::removeRoleAssignment()
2149
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser
2150
     */
2151
    public function testRemoveRoleAssignment()
2152
    {
2153
        $repository = $this->getRepository();
2154
        $roleService = $repository->getRoleService();
2155
2156
        /* BEGIN: Use Case */
2157
        $user = $this->createUserVersion1();
2158
2159
        // Load the existing "Member" role
2160
        $role = $roleService->loadRoleByIdentifier('Member');
2161
2162
        // Assign the "Member" role to the newly created user
2163
        $roleService->assignRoleToUser($role, $user);
2164
2165
        // Unassign user from role
2166
        $roleAssignments = $roleService->getRoleAssignmentsForUser($user);
2167
        foreach ($roleAssignments as $roleAssignment) {
2168
            if ($roleAssignment->role->id === $role->id) {
2169
                $roleService->removeRoleAssignment($roleAssignment);
2170
            }
2171
        }
2172
        // The assignments array will not contain the new role<->user assignment
2173
        $roleAssignments = $roleService->getRoleAssignments($role);
2174
        /* END: Use Case */
2175
2176
        // Members + Editors + Partners
2177
        $this->assertCount(3, $roleAssignments);
2178
    }
2179
2180
    /**
2181
     * Test for the getRoleAssignmentsForUser() method.