Code Duplication    Length = 21-31 lines in 3 locations

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

@@ 1839-1859 (lines=21) @@
1836
     * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUser()
1837
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testGetRoleAssignments
1838
     */
1839
    public function testAssignRoleToUser()
1840
    {
1841
        $repository = $this->getRepository();
1842
        $roleService = $repository->getRoleService();
1843
1844
        /* BEGIN: Use Case */
1845
        $user = $this->createUserVersion1();
1846
1847
        // Load the existing "Administrator" role
1848
        $role = $roleService->loadRoleByIdentifier('Administrator');
1849
1850
        // Assign the "Administrator" role to the newly created user
1851
        $roleService->assignRoleToUser($role, $user);
1852
1853
        // The assignments array will contain the new role<->user assignment
1854
        $roleAssignments = $roleService->getRoleAssignments($role);
1855
        /* END: Use Case */
1856
1857
        // Administrator + Example User
1858
        $this->assertEquals(2, count($roleAssignments));
1859
    }
1860
1861
    /**
1862
     * Test for the assignRoleToUser() method.
@@ 2012-2042 (lines=31) @@
2009
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser
2010
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier
2011
     */
2012
    public function testAssignRoleToUserThrowsInvalidArgumentException()
2013
    {
2014
        $repository = $this->getRepository();
2015
2016
        /* BEGIN: Use Case */
2017
        $roleService = $repository->getRoleService();
2018
2019
        // Load the existing "Anonymous" role
2020
        $role = $roleService->loadRoleByIdentifier('Anonymous');
2021
2022
        // Get current user
2023
        $currentUser = $repository->getCurrentUser();
2024
2025
        // Assign the "Anonymous" role to the current user
2026
        try {
2027
            $roleService->assignRoleToUser(
2028
                $role,
2029
                $currentUser
2030
            );
2031
        } catch (Exception $e) {
2032
            $this->fail('Got exception at first valid attempt to assign role');
2033
        }
2034
2035
        // Re-Assign the "Anonymous" role to the current user
2036
        // This call will fail with an InvalidArgumentException, because limitation is already assigned
2037
        $roleService->assignRoleToUser(
2038
            $role,
2039
            $currentUser
2040
        );
2041
        /* END: Use Case */
2042
    }
2043
2044
    /**
2045
     * Test for the assignRoleToUser() method.
@@ 2254-2274 (lines=21) @@
2251
     * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUserGroup()
2252
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testGetRoleAssignments
2253
     */
2254
    public function testAssignRoleToUserGroup()
2255
    {
2256
        $repository = $this->getRepository();
2257
        $roleService = $repository->getRoleService();
2258
2259
        /* BEGIN: Use Case */
2260
        $userGroup = $this->createUserGroupVersion1();
2261
2262
        // Load the existing "Administrator" role
2263
        $role = $roleService->loadRoleByIdentifier('Administrator');
2264
2265
        // Assign the "Administrator" role to the newly created user group
2266
        $roleService->assignRoleToUserGroup($role, $userGroup);
2267
2268
        // The assignments array will contain the new role<->group assignment
2269
        $roleAssignments = $roleService->getRoleAssignments($role);
2270
        /* END: Use Case */
2271
2272
        // Administrator + Example Group
2273
        $this->assertEquals(2, count($roleAssignments));
2274
    }
2275
2276
    /**
2277
     * Test for the assignRoleToUserGroup() method.