Code Duplication    Length = 28-30 lines in 2 locations

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

@@ 2103-2130 (lines=28) @@
2100
     * @see \eZ\Publish\API\Repository\RoleService::removeRoleAssignment()
2101
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser
2102
     */
2103
    public function testRemoveRoleAssignment()
2104
    {
2105
        $repository = $this->getRepository();
2106
        $roleService = $repository->getRoleService();
2107
2108
        /* BEGIN: Use Case */
2109
        $user = $this->createUserVersion1();
2110
2111
        // Load the existing "Member" role
2112
        $role = $roleService->loadRoleByIdentifier('Member');
2113
2114
        // Assign the "Member" role to the newly created user
2115
        $roleService->assignRoleToUser($role, $user);
2116
2117
        // Unassign user from role
2118
        $roleAssignments = $roleService->getRoleAssignmentsForUser($user);
2119
        foreach ($roleAssignments as $roleAssignment) {
2120
            if ($roleAssignment->role->id === $role->id) {
2121
                $roleService->removeRoleAssignment($roleAssignment);
2122
            }
2123
        }
2124
        // The assignments array will not contain the new role<->user assignment
2125
        $roleAssignments = $roleService->getRoleAssignments($role);
2126
        /* END: Use Case */
2127
2128
        // Members + Editors + Partners
2129
        $this->assertCount(3, $roleAssignments);
2130
    }
2131
2132
    /**
2133
     * Test for the getRoleAssignmentsForUser() method.
@@ 2546-2575 (lines=30) @@
2543
     * @see \eZ\Publish\API\Repository\RoleService::removeRoleAssignment()
2544
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup
2545
     */
2546
    public function testRemoveRoleAssignmentFromUserGroup()
2547
    {
2548
        $repository = $this->getRepository();
2549
        $roleService = $repository->getRoleService();
2550
2551
        /* BEGIN: Use Case */
2552
        $userGroup = $this->createUserGroupVersion1();
2553
2554
        // Load the existing "Member" role
2555
        $role = $roleService->loadRoleByIdentifier('Member');
2556
2557
        // Assign the "Member" role to the newly created user group
2558
        $roleService->assignRoleToUserGroup($role, $userGroup);
2559
2560
        // Unassign group from role
2561
        $roleAssignments = $roleService->getRoleAssignmentsForUserGroup($userGroup);
2562
2563
        // This call will fail with an "UnauthorizedException"
2564
        foreach ($roleAssignments as $roleAssignment) {
2565
            if ($roleAssignment->role->id === $role->id) {
2566
                $roleService->removeRoleAssignment($roleAssignment);
2567
            }
2568
        }
2569
        // The assignments array will not contain the new role<->group assignment
2570
        $roleAssignments = $roleService->getRoleAssignments($role);
2571
        /* END: Use Case */
2572
2573
        // Members + Editors + Partners
2574
        $this->assertCount(3, $roleAssignments);
2575
    }
2576
2577
    /**
2578
     * Test unassigning role by assignment.