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.
@@ 1937-1957 (lines=21) @@
1934
     * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUser()
1935
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testGetRoleAssignments
1936
     */
1937
    public function testAssignRoleToUser()
1938
    {
1939
        $repository = $this->getRepository();
1940
        $roleService = $repository->getRoleService();
1941
1942
        /* BEGIN: Use Case */
1943
        $user = $this->createUserVersion1();
1944
1945
        // Load the existing "Administrator" role
1946
        $role = $roleService->loadRoleByIdentifier('Administrator');
1947
1948
        // Assign the "Administrator" role to the newly created user
1949
        $roleService->assignRoleToUser($role, $user);
1950
1951
        // The assignments array will contain the new role<->user assignment
1952
        $roleAssignments = $roleService->getRoleAssignments($role);
1953
        /* END: Use Case */
1954
1955
        // Administrator + Example User
1956
        $this->assertEquals(2, count($roleAssignments));
1957
    }
1958
1959
    /**
1960
     * Test for the assignRoleToUser() method.
@@ 2110-2140 (lines=31) @@
2107
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser
2108
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier
2109
     */
2110
    public function testAssignRoleToUserThrowsInvalidArgumentException()
2111
    {
2112
        $repository = $this->getRepository();
2113
2114
        /* BEGIN: Use Case */
2115
        $roleService = $repository->getRoleService();
2116
2117
        // Load the existing "Anonymous" role
2118
        $role = $roleService->loadRoleByIdentifier('Anonymous');
2119
2120
        // Get current user
2121
        $currentUser = $repository->getCurrentUser();
2122
2123
        // Assign the "Anonymous" role to the current user
2124
        try {
2125
            $roleService->assignRoleToUser(
2126
                $role,
2127
                $currentUser
2128
            );
2129
        } catch (Exception $e) {
2130
            $this->fail('Got exception at first valid attempt to assign role');
2131
        }
2132
2133
        // Re-Assign the "Anonymous" role to the current user
2134
        // This call will fail with an InvalidArgumentException, because limitation is already assigned
2135
        $roleService->assignRoleToUser(
2136
            $role,
2137
            $currentUser
2138
        );
2139
        /* END: Use Case */
2140
    }
2141
2142
    /**
2143
     * Test for the assignRoleToUser() method.
@@ 2352-2372 (lines=21) @@
2349
     * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUserGroup()
2350
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testGetRoleAssignments
2351
     */
2352
    public function testAssignRoleToUserGroup()
2353
    {
2354
        $repository = $this->getRepository();
2355
        $roleService = $repository->getRoleService();
2356
2357
        /* BEGIN: Use Case */
2358
        $userGroup = $this->createUserGroupVersion1();
2359
2360
        // Load the existing "Administrator" role
2361
        $role = $roleService->loadRoleByIdentifier('Administrator');
2362
2363
        // Assign the "Administrator" role to the newly created user group
2364
        $roleService->assignRoleToUserGroup($role, $userGroup);
2365
2366
        // The assignments array will contain the new role<->group assignment
2367
        $roleAssignments = $roleService->getRoleAssignments($role);
2368
        /* END: Use Case */
2369
2370
        // Administrator + Example Group
2371
        $this->assertEquals(2, count($roleAssignments));
2372
    }
2373
2374
    /**
2375
     * Test for the assignRoleToUserGroup() method.