Code Duplication    Length = 42-42 lines in 2 locations

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

@@ 2230-2271 (lines=42) @@
2227
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser
2228
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleWithAddPolicy
2229
     */
2230
    public function testGetRoleAssignmentsForUserDirect()
2231
    {
2232
        $repository = $this->getRepository();
2233
        $roleService = $repository->getRoleService();
2234
2235
        /* BEGIN: Use Case */
2236
        $user = $this->createUserVersion1();
2237
2238
        // Instantiate a role create and add some policies
2239
        $roleCreate = $roleService->newRoleCreateStruct('Example Role');
2240
2241
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
2242
        // $roleCreate->mainLanguageCode = 'eng-US';
2243
2244
        $roleCreate->addPolicy(
2245
            $roleService->newPolicyCreateStruct('user', 'login')
2246
        );
2247
        $roleCreate->addPolicy(
2248
            $roleService->newPolicyCreateStruct('content', 'read')
2249
        );
2250
        $roleCreate->addPolicy(
2251
            $roleService->newPolicyCreateStruct('content', 'edit')
2252
        );
2253
2254
        // Create the new role instance
2255
        $roleDraft = $roleService->createRole($roleCreate);
2256
        $roleService->publishRoleDraft($roleDraft);
2257
        $role = $roleService->loadRole($roleDraft->id);
2258
2259
        // Assign role to new user
2260
        $roleService->assignRoleToUser($role, $user);
2261
2262
        // Load the currently assigned role
2263
        $roleAssignments = $roleService->getRoleAssignmentsForUser($user);
2264
        /* END: Use Case */
2265
2266
        $this->assertEquals(1, count($roleAssignments));
2267
        $this->assertInstanceOf(
2268
            '\\eZ\\Publish\\API\\Repository\\Values\\User\\UserRoleAssignment',
2269
            reset($roleAssignments)
2270
        );
2271
    }
2272
2273
    /**
2274
     * Test for the getRoleAssignmentsForUser() method.
@@ 2726-2767 (lines=42) @@
2723
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup
2724
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleWithAddPolicy
2725
     */
2726
    public function testGetRoleAssignmentsForUserGroup()
2727
    {
2728
        $repository = $this->getRepository();
2729
        $roleService = $repository->getRoleService();
2730
2731
        /* BEGIN: Use Case */
2732
        $userGroup = $this->createUserGroupVersion1();
2733
2734
        // Instantiate a role create and add some policies
2735
        $roleCreate = $roleService->newRoleCreateStruct('Example Role');
2736
2737
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
2738
        // $roleCreate->mainLanguageCode = 'eng-US';
2739
2740
        $roleCreate->addPolicy(
2741
            $roleService->newPolicyCreateStruct('user', 'login')
2742
        );
2743
        $roleCreate->addPolicy(
2744
            $roleService->newPolicyCreateStruct('content', 'read')
2745
        );
2746
        $roleCreate->addPolicy(
2747
            $roleService->newPolicyCreateStruct('content', 'edit')
2748
        );
2749
2750
        // Create the new role instance
2751
        $roleDraft = $roleService->createRole($roleCreate);
2752
        $roleService->publishRoleDraft($roleDraft);
2753
        $role = $roleService->loadRole($roleDraft->id);
2754
2755
        // Assign role to new user group
2756
        $roleService->assignRoleToUserGroup($role, $userGroup);
2757
2758
        // Load the currently assigned role
2759
        $roleAssignments = $roleService->getRoleAssignmentsForUserGroup($userGroup);
2760
        /* END: Use Case */
2761
2762
        $this->assertEquals(1, count($roleAssignments));
2763
        $this->assertInstanceOf(
2764
            '\\eZ\\Publish\\API\\Repository\\Values\\User\\UserGroupRoleAssignment',
2765
            reset($roleAssignments)
2766
        );
2767
    }
2768
2769
    /**
2770
     * Test for the loadPoliciesByUserId() method.