Code Duplication    Length = 28-30 lines in 2 locations

eZ/Publish/API/Repository/Tests/RoleServiceTest.php 2 locations

@@ 1968-1995 (lines=28) @@
1965
     * @see \eZ\Publish\API\Repository\RoleService::removeRoleAssignment()
1966
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser
1967
     */
1968
    public function testRemoveRoleAssignment()
1969
    {
1970
        $repository = $this->getRepository();
1971
        $roleService = $repository->getRoleService();
1972
1973
        /* BEGIN: Use Case */
1974
        $user = $this->createUserVersion1();
1975
1976
        // Load the existing "Member" role
1977
        $role = $roleService->loadRoleByIdentifier('Member');
1978
1979
        // Assign the "Member" role to the newly created user
1980
        $roleService->assignRoleToUser($role, $user);
1981
1982
        // Unassign user from role
1983
        $roleAssignments = $roleService->getRoleAssignmentsForUser($user);
1984
        foreach ($roleAssignments as $roleAssignment) {
1985
            if ($roleAssignment->role->id === $role->id) {
1986
                $roleService->removeRoleAssignment($roleAssignment);
1987
            }
1988
        }
1989
        // The assignments array will not contain the new role<->user assignment
1990
        $roleAssignments = $roleService->getRoleAssignments($role);
1991
        /* END: Use Case */
1992
1993
        // Members + Editors + Partners
1994
        $this->assertCount(3, $roleAssignments);
1995
    }
1996
1997
    /**
1998
     * Test for the getRoleAssignmentsForUser() method.
@@ 2411-2440 (lines=30) @@
2408
     * @see \eZ\Publish\API\Repository\RoleService::removeRoleAssignment()
2409
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup
2410
     */
2411
    public function testRemoveRoleAssignmentFromUserGroup()
2412
    {
2413
        $repository = $this->getRepository();
2414
        $roleService = $repository->getRoleService();
2415
2416
        /* BEGIN: Use Case */
2417
        $userGroup = $this->createUserGroupVersion1();
2418
2419
        // Load the existing "Member" role
2420
        $role = $roleService->loadRoleByIdentifier('Member');
2421
2422
        // Assign the "Member" role to the newly created user group
2423
        $roleService->assignRoleToUserGroup($role, $userGroup);
2424
2425
        // Unassign group from role
2426
        $roleAssignments = $roleService->getRoleAssignmentsForUserGroup($userGroup);
2427
2428
        // This call will fail with an "UnauthorizedException"
2429
        foreach ($roleAssignments as $roleAssignment) {
2430
            if ($roleAssignment->role->id === $role->id) {
2431
                $roleService->removeRoleAssignment($roleAssignment);
2432
            }
2433
        }
2434
        // The assignments array will not contain the new role<->group assignment
2435
        $roleAssignments = $roleService->getRoleAssignments($role);
2436
        /* END: Use Case */
2437
2438
        // Members + Editors + Partners
2439
        $this->assertCount(3, $roleAssignments);
2440
    }
2441
2442
    /**
2443
     * Test unassigning role by assignment.