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.
@@ 2706-2747 (lines=42) @@
2703
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup
2704
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleWithAddPolicy
2705
     */
2706
    public function testGetRoleAssignmentsForUserGroup()
2707
    {
2708
        $repository = $this->getRepository();
2709
        $roleService = $repository->getRoleService();
2710
2711
        /* BEGIN: Use Case */
2712
        $userGroup = $this->createUserGroupVersion1();
2713
2714
        // Instantiate a role create and add some policies
2715
        $roleCreate = $roleService->newRoleCreateStruct('Example Role');
2716
2717
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
2718
        // $roleCreate->mainLanguageCode = 'eng-US';
2719
2720
        $roleCreate->addPolicy(
2721
            $roleService->newPolicyCreateStruct('user', 'login')
2722
        );
2723
        $roleCreate->addPolicy(
2724
            $roleService->newPolicyCreateStruct('content', 'read')
2725
        );
2726
        $roleCreate->addPolicy(
2727
            $roleService->newPolicyCreateStruct('content', 'edit')
2728
        );
2729
2730
        // Create the new role instance
2731
        $roleDraft = $roleService->createRole($roleCreate);
2732
        $roleService->publishRoleDraft($roleDraft);
2733
        $role = $roleService->loadRole($roleDraft->id);
2734
2735
        // Assign role to new user group
2736
        $roleService->assignRoleToUserGroup($role, $userGroup);
2737
2738
        // Load the currently assigned role
2739
        $roleAssignments = $roleService->getRoleAssignmentsForUserGroup($userGroup);
2740
        /* END: Use Case */
2741
2742
        $this->assertEquals(1, count($roleAssignments));
2743
        $this->assertInstanceOf(
2744
            '\\eZ\\Publish\\API\\Repository\\Values\\User\\UserGroupRoleAssignment',
2745
            reset($roleAssignments)
2746
        );
2747
    }
2748
2749
    /**
2750
     * Test for the loadPoliciesByUserId() method.