Code Duplication    Length = 42-42 lines in 2 locations

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

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