Code Duplication    Length = 42-42 lines in 2 locations

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

@@ 2159-2200 (lines=42) @@
2156
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser
2157
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleWithAddPolicy
2158
     */
2159
    public function testGetRoleAssignmentsForUserDirect()
2160
    {
2161
        $repository = $this->getRepository();
2162
        $roleService = $repository->getRoleService();
2163
2164
        /* BEGIN: Use Case */
2165
        $user = $this->createUserVersion1();
2166
2167
        // Instantiate a role create and add some policies
2168
        $roleCreate = $roleService->newRoleCreateStruct('Example Role');
2169
2170
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
2171
        // $roleCreate->mainLanguageCode = 'eng-US';
2172
2173
        $roleCreate->addPolicy(
2174
            $roleService->newPolicyCreateStruct('user', 'login')
2175
        );
2176
        $roleCreate->addPolicy(
2177
            $roleService->newPolicyCreateStruct('content', 'read')
2178
        );
2179
        $roleCreate->addPolicy(
2180
            $roleService->newPolicyCreateStruct('content', 'edit')
2181
        );
2182
2183
        // Create the new role instance
2184
        $roleDraft = $roleService->createRole($roleCreate);
2185
        $roleService->publishRoleDraft($roleDraft);
2186
        $role = $roleService->loadRole($roleDraft->id);
2187
2188
        // Assign role to new user
2189
        $roleService->assignRoleToUser($role, $user);
2190
2191
        // Load the currently assigned role
2192
        $roleAssignments = $roleService->getRoleAssignmentsForUser($user);
2193
        /* END: Use Case */
2194
2195
        $this->assertEquals(1, count($roleAssignments));
2196
        $this->assertInstanceOf(
2197
            '\\eZ\\Publish\\API\\Repository\\Values\\User\\UserRoleAssignment',
2198
            reset($roleAssignments)
2199
        );
2200
    }
2201
2202
    /**
2203
     * Test for the getRoleAssignmentsForUser() method.
@@ 2655-2696 (lines=42) @@
2652
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup
2653
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleWithAddPolicy
2654
     */
2655
    public function testGetRoleAssignmentsForUserGroup()
2656
    {
2657
        $repository = $this->getRepository();
2658
        $roleService = $repository->getRoleService();
2659
2660
        /* BEGIN: Use Case */
2661
        $userGroup = $this->createUserGroupVersion1();
2662
2663
        // Instantiate a role create and add some policies
2664
        $roleCreate = $roleService->newRoleCreateStruct('Example Role');
2665
2666
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
2667
        // $roleCreate->mainLanguageCode = 'eng-US';
2668
2669
        $roleCreate->addPolicy(
2670
            $roleService->newPolicyCreateStruct('user', 'login')
2671
        );
2672
        $roleCreate->addPolicy(
2673
            $roleService->newPolicyCreateStruct('content', 'read')
2674
        );
2675
        $roleCreate->addPolicy(
2676
            $roleService->newPolicyCreateStruct('content', 'edit')
2677
        );
2678
2679
        // Create the new role instance
2680
        $roleDraft = $roleService->createRole($roleCreate);
2681
        $roleService->publishRoleDraft($roleDraft);
2682
        $role = $roleService->loadRole($roleDraft->id);
2683
2684
        // Assign role to new user group
2685
        $roleService->assignRoleToUserGroup($role, $userGroup);
2686
2687
        // Load the currently assigned role
2688
        $roleAssignments = $roleService->getRoleAssignmentsForUserGroup($userGroup);
2689
        /* END: Use Case */
2690
2691
        $this->assertEquals(1, count($roleAssignments));
2692
        $this->assertInstanceOf(
2693
            '\\eZ\\Publish\\API\\Repository\\Values\\User\\UserGroupRoleAssignment',
2694
            reset($roleAssignments)
2695
        );
2696
    }
2697
2698
    /**
2699
     * Test for the loadPoliciesByUserId() method.