Code Duplication    Length = 21-31 lines in 3 locations

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

@@ 1908-1928 (lines=21) @@
1905
     * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUser()
1906
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testGetRoleAssignments
1907
     */
1908
    public function testAssignRoleToUser()
1909
    {
1910
        $repository = $this->getRepository();
1911
        $roleService = $repository->getRoleService();
1912
1913
        /* BEGIN: Use Case */
1914
        $user = $this->createUserVersion1();
1915
1916
        // Load the existing "Administrator" role
1917
        $role = $roleService->loadRoleByIdentifier('Administrator');
1918
1919
        // Assign the "Administrator" role to the newly created user
1920
        $roleService->assignRoleToUser($role, $user);
1921
1922
        // The assignments array will contain the new role<->user assignment
1923
        $roleAssignments = $roleService->getRoleAssignments($role);
1924
        /* END: Use Case */
1925
1926
        // Administrator + Example User
1927
        $this->assertEquals(2, count($roleAssignments));
1928
    }
1929
1930
    /**
1931
     * Test for the assignRoleToUser() method.
@@ 2081-2111 (lines=31) @@
2078
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser
2079
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier
2080
     */
2081
    public function testAssignRoleToUserThrowsInvalidArgumentException()
2082
    {
2083
        $repository = $this->getRepository();
2084
2085
        /* BEGIN: Use Case */
2086
        $roleService = $repository->getRoleService();
2087
2088
        // Load the existing "Anonymous" role
2089
        $role = $roleService->loadRoleByIdentifier('Anonymous');
2090
2091
        // Get current user
2092
        $currentUser = $repository->getCurrentUser();
2093
2094
        // Assign the "Anonymous" role to the current user
2095
        try {
2096
            $roleService->assignRoleToUser(
2097
                $role,
2098
                $currentUser
2099
            );
2100
        } catch (Exception $e) {
2101
            $this->fail('Got exception at first valid attempt to assign role');
2102
        }
2103
2104
        // Re-Assign the "Anonymous" role to the current user
2105
        // This call will fail with an InvalidArgumentException, because limitation is already assigned
2106
        $roleService->assignRoleToUser(
2107
            $role,
2108
            $currentUser
2109
        );
2110
        /* END: Use Case */
2111
    }
2112
2113
    /**
2114
     * Test for the assignRoleToUser() method.
@@ 2323-2343 (lines=21) @@
2320
     * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUserGroup()
2321
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testGetRoleAssignments
2322
     */
2323
    public function testAssignRoleToUserGroup()
2324
    {
2325
        $repository = $this->getRepository();
2326
        $roleService = $repository->getRoleService();
2327
2328
        /* BEGIN: Use Case */
2329
        $userGroup = $this->createUserGroupVersion1();
2330
2331
        // Load the existing "Administrator" role
2332
        $role = $roleService->loadRoleByIdentifier('Administrator');
2333
2334
        // Assign the "Administrator" role to the newly created user group
2335
        $roleService->assignRoleToUserGroup($role, $userGroup);
2336
2337
        // The assignments array will contain the new role<->group assignment
2338
        $roleAssignments = $roleService->getRoleAssignments($role);
2339
        /* END: Use Case */
2340
2341
        // Administrator + Example Group
2342
        $this->assertEquals(2, count($roleAssignments));
2343
    }
2344
2345
    /**
2346
     * Test for the assignRoleToUserGroup() method.