Code Duplication    Length = 21-31 lines in 4 locations

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

@@ 560-581 (lines=22) @@
557
     * @see \eZ\Publish\API\Repository\RoleService::loadRoleByIdentifier()
558
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRole
559
     */
560
    public function testLoadRoleByIdentifier()
561
    {
562
        $repository = $this->getRepository();
563
564
        /* BEGIN: Use Case */
565
566
        $roleService = $repository->getRoleService();
567
        $roleCreate = $roleService->newRoleCreateStruct('roleName');
568
569
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
570
        // $roleCreate->mainLanguageCode = 'eng-US';
571
572
        $roleDraft = $roleService->createRole($roleCreate);
573
        $roleService->publishRoleDraft($roleDraft);
574
575
        // Load the newly created role by its identifier
576
        $role = $roleService->loadRoleByIdentifier('roleName');
577
578
        /* END: Use Case */
579
580
        $this->assertEquals('roleName', $role->identifier);
581
    }
582
583
    /**
584
     * Test for the loadRoleByIdentifier() method.
@@ 1841-1861 (lines=21) @@
1838
     * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUser()
1839
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testGetRoleAssignments
1840
     */
1841
    public function testAssignRoleToUser()
1842
    {
1843
        $repository = $this->getRepository();
1844
        $roleService = $repository->getRoleService();
1845
1846
        /* BEGIN: Use Case */
1847
        $user = $this->createUserVersion1();
1848
1849
        // Load the existing "Administrator" role
1850
        $role = $roleService->loadRoleByIdentifier('Administrator');
1851
1852
        // Assign the "Administrator" role to the newly created user
1853
        $roleService->assignRoleToUser($role, $user);
1854
1855
        // The assignments array will contain the new role<->user assignment
1856
        $roleAssignments = $roleService->getRoleAssignments($role);
1857
        /* END: Use Case */
1858
1859
        // Administrator + Example User
1860
        $this->assertEquals(2, count($roleAssignments));
1861
    }
1862
1863
    /**
1864
     * Test for the assignRoleToUser() method.
@@ 2014-2044 (lines=31) @@
2011
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser
2012
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier
2013
     */
2014
    public function testAssignRoleToUserThrowsInvalidArgumentException()
2015
    {
2016
        $repository = $this->getRepository();
2017
2018
        /* BEGIN: Use Case */
2019
        $roleService = $repository->getRoleService();
2020
2021
        // Load the existing "Anonymous" role
2022
        $role = $roleService->loadRoleByIdentifier('Anonymous');
2023
2024
        // Get current user
2025
        $currentUser = $repository->getCurrentUser();
2026
2027
        // Assign the "Anonymous" role to the current user
2028
        try {
2029
            $roleService->assignRoleToUser(
2030
                $role,
2031
                $currentUser
2032
            );
2033
        } catch (Exception $e) {
2034
            $this->fail('Got exception at first valid attempt to assign role');
2035
        }
2036
2037
        // Re-Assign the "Anonymous" role to the current user
2038
        // This call will fail with an InvalidArgumentException, because limitation is already assigned
2039
        $roleService->assignRoleToUser(
2040
            $role,
2041
            $currentUser
2042
        );
2043
        /* END: Use Case */
2044
    }
2045
2046
    /**
2047
     * Test for the assignRoleToUser() method.
@@ 2256-2276 (lines=21) @@
2253
     * @see \eZ\Publish\API\Repository\RoleService::assignRoleToUserGroup()
2254
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testGetRoleAssignments
2255
     */
2256
    public function testAssignRoleToUserGroup()
2257
    {
2258
        $repository = $this->getRepository();
2259
        $roleService = $repository->getRoleService();
2260
2261
        /* BEGIN: Use Case */
2262
        $userGroup = $this->createUserGroupVersion1();
2263
2264
        // Load the existing "Administrator" role
2265
        $role = $roleService->loadRoleByIdentifier('Administrator');
2266
2267
        // Assign the "Administrator" role to the newly created user group
2268
        $roleService->assignRoleToUserGroup($role, $userGroup);
2269
2270
        // The assignments array will contain the new role<->group assignment
2271
        $roleAssignments = $roleService->getRoleAssignments($role);
2272
        /* END: Use Case */
2273
2274
        // Administrator + Example Group
2275
        $this->assertEquals(2, count($roleAssignments));
2276
    }
2277
2278
    /**
2279
     * Test for the assignRoleToUserGroup() method.