Code Duplication    Length = 32-34 lines in 3 locations

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

@@ 397-430 (lines=34) @@
394
     *
395
     * @see \eZ\Publish\API\Repository\RoleService::createRole()
396
     */
397
    public function testCreateRoleThrowsLimitationValidationException()
398
    {
399
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\LimitationValidationException::class);
400
401
        $repository = $this->getRepository();
402
403
        /* BEGIN: Use Case */
404
        $roleService = $repository->getRoleService();
405
406
        // Create new role create struct
407
        $roleCreate = $roleService->newRoleCreateStruct('Lumberjack');
408
409
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
410
        // $roleCreate->mainLanguageCode = 'eng-US';
411
412
        // Create new subtree limitation
413
        $limitation = new SubtreeLimitation(
414
            [
415
                'limitationValues' => ['/mountain/forest/tree/42/'],
416
            ]
417
        );
418
419
        // Create policy create struct and add limitation to it
420
        $policyCreate = $roleService->newPolicyCreateStruct('content', 'remove');
421
        $policyCreate->addLimitation($limitation);
422
423
        // Add policy create struct to role create struct
424
        $roleCreate->addPolicy($policyCreate);
425
426
        // This call will fail with an LimitationValidationException, because subtree
427
        // "/mountain/forest/tree/42/" does not exist
428
        $roleService->createRole($roleCreate);
429
        /* END: Use Case */
430
    }
431
432
    /**
433
     * Test for the createRole() method.
@@ 1070-1101 (lines=32) @@
1067
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewPolicyCreateStruct
1068
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleDraft
1069
     */
1070
    public function testAddPolicyByRoleDraftThrowsLimitationValidationException()
1071
    {
1072
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\LimitationValidationException::class);
1073
1074
        $repository = $this->getRepository();
1075
1076
        /* BEGIN: Use Case */
1077
        $roleService = $repository->getRoleService();
1078
1079
        $roleCreate = $roleService->newRoleCreateStruct('Lumberjack');
1080
1081
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
1082
        // $roleCreate->mainLanguageCode = 'eng-US';
1083
1084
        $roleDraft = $roleService->createRole($roleCreate);
1085
1086
        // Create new subtree limitation
1087
        $limitation = new SubtreeLimitation(
1088
            [
1089
                'limitationValues' => ['/mountain/forest/tree/42/'],
1090
            ]
1091
        );
1092
1093
        // Create policy create struct and add limitation to it
1094
        $policyCreateStruct = $roleService->newPolicyCreateStruct('content', 'remove');
1095
        $policyCreateStruct->addLimitation($limitation);
1096
1097
        // This call will fail with an LimitationValidationException, because subtree
1098
        // "/mountain/forest/tree/42/" does not exist
1099
        $roleService->addPolicyByRoleDraft($roleDraft, $policyCreateStruct);
1100
        /* END: Use Case */
1101
    }
1102
1103
    /**
1104
     * Test for the createRole() method.
@@ 2270-2301 (lines=32) @@
2267
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier
2268
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup
2269
     */
2270
    public function testAssignRoleToUserGroupWithRoleLimitationThrowsLimitationValidationException()
2271
    {
2272
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\LimitationValidationException::class);
2273
2274
        $repository = $this->getRepository();
2275
2276
        $mainGroupId = $this->generateId('group', 4);
2277
        /* BEGIN: Use Case */
2278
        // $mainGroupId is the ID of the main "Users" group
2279
2280
        $userService = $repository->getUserService();
2281
        $roleService = $repository->getRoleService();
2282
2283
        $userGroup = $userService->loadUserGroup($mainGroupId);
2284
2285
        // Load the existing "Anonymous" role
2286
        $role = $roleService->loadRoleByIdentifier('Anonymous');
2287
2288
        // Assign the "Anonymous" role to the newly created user group
2289
        // This call will fail with an LimitationValidationException, because subtree "/lorem/ipsum/42/"
2290
        // does not exists
2291
        $roleService->assignRoleToUserGroup(
2292
            $role,
2293
            $userGroup,
2294
            new SubtreeLimitation(
2295
                [
2296
                    'limitationValues' => ['/lorem/ipsum/42/'],
2297
                ]
2298
            )
2299
        );
2300
        /* END: Use Case */
2301
    }
2302
2303
    /**
2304
     * Test for the assignRoleToUserGroup() method.