Code Duplication    Length = 21-31 lines in 4 locations

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

@@ 652-673 (lines=22) @@
649
     * @see \eZ\Publish\API\Repository\RoleService::loadRoleByIdentifier()
650
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRole
651
     */
652
    public function testLoadRoleByIdentifier()
653
    {
654
        $repository = $this->getRepository();
655
656
        /* BEGIN: Use Case */
657
658
        $roleService = $repository->getRoleService();
659
        $roleCreate = $roleService->newRoleCreateStruct('roleName');
660
661
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
662
        // $roleCreate->mainLanguageCode = 'eng-US';
663
664
        $roleDraft = $roleService->createRole($roleCreate);
665
        $roleService->publishRoleDraft($roleDraft);
666
667
        // Load the newly created role by its identifier
668
        $role = $roleService->loadRoleByIdentifier('roleName');
669
670
        /* END: Use Case */
671
672
        $this->assertEquals('roleName', $role->identifier);
673
    }
674
675
    /**
676
     * Test for the loadRoleByIdentifier() method.
@@ 1933-1953 (lines=21) @@
1930
     * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUser()
1931
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testGetRoleAssignments
1932
     */
1933
    public function testAssignRoleToUser()
1934
    {
1935
        $repository = $this->getRepository();
1936
        $roleService = $repository->getRoleService();
1937
1938
        /* BEGIN: Use Case */
1939
        $user = $this->createUserVersion1();
1940
1941
        // Load the existing "Administrator" role
1942
        $role = $roleService->loadRoleByIdentifier('Administrator');
1943
1944
        // Assign the "Administrator" role to the newly created user
1945
        $roleService->assignRoleToUser($role, $user);
1946
1947
        // The assignments array will contain the new role<->user assignment
1948
        $roleAssignments = $roleService->getRoleAssignments($role);
1949
        /* END: Use Case */
1950
1951
        // Administrator + Example User
1952
        $this->assertEquals(2, count($roleAssignments));
1953
    }
1954
1955
    /**
1956
     * Test for the assignRoleToUser() method.
@@ 2106-2136 (lines=31) @@
2103
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser
2104
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier
2105
     */
2106
    public function testAssignRoleToUserThrowsInvalidArgumentException()
2107
    {
2108
        $repository = $this->getRepository();
2109
2110
        /* BEGIN: Use Case */
2111
        $roleService = $repository->getRoleService();
2112
2113
        // Load the existing "Anonymous" role
2114
        $role = $roleService->loadRoleByIdentifier('Anonymous');
2115
2116
        // Get current user
2117
        $currentUser = $repository->getCurrentUser();
2118
2119
        // Assign the "Anonymous" role to the current user
2120
        try {
2121
            $roleService->assignRoleToUser(
2122
                $role,
2123
                $currentUser
2124
            );
2125
        } catch (Exception $e) {
2126
            $this->fail('Got exception at first valid attempt to assign role');
2127
        }
2128
2129
        // Re-Assign the "Anonymous" role to the current user
2130
        // This call will fail with an InvalidArgumentException, because limitation is already assigned
2131
        $roleService->assignRoleToUser(
2132
            $role,
2133
            $currentUser
2134
        );
2135
        /* END: Use Case */
2136
    }
2137
2138
    /**
2139
     * Test for the assignRoleToUser() method.
@@ 2348-2368 (lines=21) @@
2345
     * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUserGroup()
2346
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testGetRoleAssignments
2347
     */
2348
    public function testAssignRoleToUserGroup()
2349
    {
2350
        $repository = $this->getRepository();
2351
        $roleService = $repository->getRoleService();
2352
2353
        /* BEGIN: Use Case */
2354
        $userGroup = $this->createUserGroupVersion1();
2355
2356
        // Load the existing "Administrator" role
2357
        $role = $roleService->loadRoleByIdentifier('Administrator');
2358
2359
        // Assign the "Administrator" role to the newly created user group
2360
        $roleService->assignRoleToUserGroup($role, $userGroup);
2361
2362
        // The assignments array will contain the new role<->group assignment
2363
        $roleAssignments = $roleService->getRoleAssignments($role);
2364
        /* END: Use Case */
2365
2366
        // Administrator + Example Group
2367
        $this->assertEquals(2, count($roleAssignments));
2368
    }
2369
2370
    /**
2371
     * Test for the assignRoleToUserGroup() method.