Code Duplication    Length = 42-42 lines in 2 locations

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

@@ 2210-2251 (lines=42) @@
2207
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser
2208
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleWithAddPolicy
2209
     */
2210
    public function testGetRoleAssignmentsForUserDirect()
2211
    {
2212
        $repository = $this->getRepository();
2213
        $roleService = $repository->getRoleService();
2214
2215
        /* BEGIN: Use Case */
2216
        $user = $this->createUserVersion1();
2217
2218
        // Instantiate a role create and add some policies
2219
        $roleCreate = $roleService->newRoleCreateStruct('Example Role');
2220
2221
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
2222
        // $roleCreate->mainLanguageCode = 'eng-US';
2223
2224
        $roleCreate->addPolicy(
2225
            $roleService->newPolicyCreateStruct('user', 'login')
2226
        );
2227
        $roleCreate->addPolicy(
2228
            $roleService->newPolicyCreateStruct('content', 'read')
2229
        );
2230
        $roleCreate->addPolicy(
2231
            $roleService->newPolicyCreateStruct('content', 'edit')
2232
        );
2233
2234
        // Create the new role instance
2235
        $roleDraft = $roleService->createRole($roleCreate);
2236
        $roleService->publishRoleDraft($roleDraft);
2237
        $role = $roleService->loadRole($roleDraft->id);
2238
2239
        // Assign role to new user
2240
        $roleService->assignRoleToUser($role, $user);
2241
2242
        // Load the currently assigned role
2243
        $roleAssignments = $roleService->getRoleAssignmentsForUser($user);
2244
        /* END: Use Case */
2245
2246
        $this->assertEquals(1, count($roleAssignments));
2247
        $this->assertInstanceOf(
2248
            '\\eZ\\Publish\\API\\Repository\\Values\\User\\UserRoleAssignment',
2249
            reset($roleAssignments)
2250
        );
2251
    }
2252
2253
    /**
2254
     * Test for the getRoleAssignmentsForUser() method.
@@ 2736-2777 (lines=42) @@
2733
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup
2734
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleWithAddPolicy
2735
     */
2736
    public function testGetRoleAssignmentsForUserGroup()
2737
    {
2738
        $repository = $this->getRepository();
2739
        $roleService = $repository->getRoleService();
2740
2741
        /* BEGIN: Use Case */
2742
        $userGroup = $this->createUserGroupVersion1();
2743
2744
        // Instantiate a role create and add some policies
2745
        $roleCreate = $roleService->newRoleCreateStruct('Example Role');
2746
2747
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
2748
        // $roleCreate->mainLanguageCode = 'eng-US';
2749
2750
        $roleCreate->addPolicy(
2751
            $roleService->newPolicyCreateStruct('user', 'login')
2752
        );
2753
        $roleCreate->addPolicy(
2754
            $roleService->newPolicyCreateStruct('content', 'read')
2755
        );
2756
        $roleCreate->addPolicy(
2757
            $roleService->newPolicyCreateStruct('content', 'edit')
2758
        );
2759
2760
        // Create the new role instance
2761
        $roleDraft = $roleService->createRole($roleCreate);
2762
        $roleService->publishRoleDraft($roleDraft);
2763
        $role = $roleService->loadRole($roleDraft->id);
2764
2765
        // Assign role to new user group
2766
        $roleService->assignRoleToUserGroup($role, $userGroup);
2767
2768
        // Load the currently assigned role
2769
        $roleAssignments = $roleService->getRoleAssignmentsForUserGroup($userGroup);
2770
        /* END: Use Case */
2771
2772
        $this->assertEquals(1, count($roleAssignments));
2773
        $this->assertInstanceOf(
2774
            '\\eZ\\Publish\\API\\Repository\\Values\\User\\UserGroupRoleAssignment',
2775
            reset($roleAssignments)
2776
        );
2777
    }
2778
2779
    /**
2780
     * Test for the loadPoliciesByUserId() method.