Code Duplication    Length = 21-31 lines in 4 locations

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

@@ 558-579 (lines=22) @@
555
     * @see \eZ\Publish\API\Repository\RoleService::loadRoleByIdentifier()
556
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRole
557
     */
558
    public function testLoadRoleByIdentifier()
559
    {
560
        $repository = $this->getRepository();
561
562
        /* BEGIN: Use Case */
563
564
        $roleService = $repository->getRoleService();
565
        $roleCreate = $roleService->newRoleCreateStruct('roleName');
566
567
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
568
        // $roleCreate->mainLanguageCode = 'eng-US';
569
570
        $roleDraft = $roleService->createRole($roleCreate);
571
        $roleService->publishRoleDraft($roleDraft);
572
573
        // Load the newly created role by its identifier
574
        $role = $roleService->loadRoleByIdentifier('roleName');
575
576
        /* END: Use Case */
577
578
        $this->assertEquals('roleName', $role->identifier);
579
    }
580
581
    /**
582
     * Test for the loadRoleByIdentifier() method.
@@ 1870-1890 (lines=21) @@
1867
     * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUser()
1868
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testGetRoleAssignments
1869
     */
1870
    public function testAssignRoleToUser()
1871
    {
1872
        $repository = $this->getRepository();
1873
        $roleService = $repository->getRoleService();
1874
1875
        /* BEGIN: Use Case */
1876
        $user = $this->createUserVersion1();
1877
1878
        // Load the existing "Administrator" role
1879
        $role = $roleService->loadRoleByIdentifier('Administrator');
1880
1881
        // Assign the "Administrator" role to the newly created user
1882
        $roleService->assignRoleToUser($role, $user);
1883
1884
        // The assignments array will contain the new role<->user assignment
1885
        $roleAssignments = $roleService->getRoleAssignments($role);
1886
        /* END: Use Case */
1887
1888
        // Administrator + Example User
1889
        $this->assertEquals(2, count($roleAssignments));
1890
    }
1891
1892
    /**
1893
     * Test for the assignRoleToUser() method.
@@ 2043-2073 (lines=31) @@
2040
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser
2041
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier
2042
     */
2043
    public function testAssignRoleToUserThrowsInvalidArgumentException()
2044
    {
2045
        $repository = $this->getRepository();
2046
2047
        /* BEGIN: Use Case */
2048
        $roleService = $repository->getRoleService();
2049
2050
        // Load the existing "Anonymous" role
2051
        $role = $roleService->loadRoleByIdentifier('Anonymous');
2052
2053
        // Get current user
2054
        $currentUser = $repository->getCurrentUser();
2055
2056
        // Assign the "Anonymous" role to the current user
2057
        try {
2058
            $roleService->assignRoleToUser(
2059
                $role,
2060
                $currentUser
2061
            );
2062
        } catch (Exception $e) {
2063
            $this->fail('Got exception at first valid attempt to assign role');
2064
        }
2065
2066
        // Re-Assign the "Anonymous" role to the current user
2067
        // This call will fail with an InvalidArgumentException, because limitation is already assigned
2068
        $roleService->assignRoleToUser(
2069
            $role,
2070
            $currentUser
2071
        );
2072
        /* END: Use Case */
2073
    }
2074
2075
    /**
2076
     * Test for the assignRoleToUser() method.
@@ 2285-2305 (lines=21) @@
2282
     * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUserGroup()
2283
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testGetRoleAssignments
2284
     */
2285
    public function testAssignRoleToUserGroup()
2286
    {
2287
        $repository = $this->getRepository();
2288
        $roleService = $repository->getRoleService();
2289
2290
        /* BEGIN: Use Case */
2291
        $userGroup = $this->createUserGroupVersion1();
2292
2293
        // Load the existing "Administrator" role
2294
        $role = $roleService->loadRoleByIdentifier('Administrator');
2295
2296
        // Assign the "Administrator" role to the newly created user group
2297
        $roleService->assignRoleToUserGroup($role, $userGroup);
2298
2299
        // The assignments array will contain the new role<->group assignment
2300
        $roleAssignments = $roleService->getRoleAssignments($role);
2301
        /* END: Use Case */
2302
2303
        // Administrator + Example Group
2304
        $this->assertEquals(2, count($roleAssignments));
2305
    }
2306
2307
    /**
2308
     * Test for the assignRoleToUserGroup() method.