Code Duplication    Length = 30-33 lines in 3 locations

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

@@ 1719-1750 (lines=32) @@
1716
     * @see \eZ\Publish\API\Repository\RoleService::removePolicyByRoleDraft()
1717
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAddPolicyByRoleDraft
1718
     */
1719
    public function testRemovePolicyByRoleDraft()
1720
    {
1721
        $repository = $this->getRepository();
1722
1723
        /* BEGIN: Use Case */
1724
        $roleService = $repository->getRoleService();
1725
1726
        // Instantiate a new role create
1727
        $roleCreate = $roleService->newRoleCreateStruct('newRole');
1728
1729
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
1730
        // $roleCreate->mainLanguageCode = 'eng-US';
1731
1732
        // Create a new role with two policies
1733
        $roleDraft = $roleService->createRole($roleCreate);
1734
        $roleService->addPolicyByRoleDraft(
1735
            $roleDraft,
1736
            $roleService->newPolicyCreateStruct('content', 'create')
1737
        );
1738
        $roleService->addPolicyByRoleDraft(
1739
            $roleDraft,
1740
            $roleService->newPolicyCreateStruct('content', 'delete')
1741
        );
1742
1743
        // Delete all policies from the new role
1744
        foreach ($roleDraft->getPolicies() as $policy) {
1745
            $roleDraft = $roleService->removePolicyByRoleDraft($roleDraft, $policy);
1746
        }
1747
        /* END: Use Case */
1748
1749
        $this->assertSame([], $roleDraft->getPolicies());
1750
    }
1751
1752
    /**
1753
     * Test for the deletePolicy() method.
@@ 2952-2981 (lines=30) @@
2949
     * @see \eZ\Publish\API\Repository\RoleService::publishRoleDraft()
2950
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleDraft
2951
     */
2952
    public function testPublishRoleDraft()
2953
    {
2954
        $repository = $this->getRepository();
2955
2956
        /* BEGIN: Use Case */
2957
        $roleService = $repository->getRoleService();
2958
        $roleCreate = $roleService->newRoleCreateStruct('newRole');
2959
2960
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
2961
        // $roleCreate->mainLanguageCode = 'eng-US';
2962
2963
        $roleDraft = $roleService->createRole($roleCreate);
2964
2965
        $roleDraft = $roleService->addPolicyByRoleDraft(
2966
            $roleDraft,
2967
            $roleService->newPolicyCreateStruct('content', 'delete')
2968
        );
2969
        $roleDraft = $roleService->addPolicyByRoleDraft(
2970
            $roleDraft,
2971
            $roleService->newPolicyCreateStruct('content', 'create')
2972
        );
2973
2974
        $roleService->publishRoleDraft($roleDraft);
2975
        /* END: Use Case */
2976
2977
        $this->assertInstanceOf(
2978
            '\\eZ\\Publish\\API\\Repository\\Values\\User\\Role',
2979
            $roleService->loadRoleByIdentifier($roleCreate->identifier)
2980
        );
2981
    }
2982
2983
    /**
2984
     * Test for the publishRoleDraft() method.

eZ/Publish/API/Repository/Tests/RoleServiceAuthorizationTest.php 1 location

@@ 296-328 (lines=33) @@
293
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testRemovePolicyByRoleDraft
294
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser
295
     */
296
    public function testRemovePolicyThrowsUnauthorizedException()
297
    {
298
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\UnauthorizedException::class);
299
300
        $repository = $this->getRepository();
301
        $roleService = $repository->getRoleService();
302
303
        /* BEGIN: Use Case */
304
        $user = $this->createUserVersion1();
305
306
        $roleCreate = $roleService->newRoleCreateStruct('newRole');
307
308
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
309
        // $roleCreate->mainLanguageCode = 'eng-US';
310
311
        // Create a new role with two policies
312
        $roleDraft = $roleService->createRole($roleCreate);
313
        $roleService->addPolicyByRoleDraft(
314
            $roleDraft,
315
            $roleService->newPolicyCreateStruct('content', 'create')
316
        );
317
        $roleDraft = $roleService->addPolicyByRoleDraft(
318
            $roleDraft,
319
            $roleService->newPolicyCreateStruct('content', 'delete')
320
        );
321
322
        // Set "Editor" user as current user.
323
        $repository->setCurrentUser($user);
324
325
        // This call will fail with an "UnauthorizedException"
326
        $roleService->removePolicyByRoleDraft($roleDraft, $roleDraft->getPolicies()[0]);
327
        /* END: Use Case */
328
    }
329
330
    /**
331
     * Test for the deletePolicy() method.