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.
@@ 2269-2300 (lines=32) @@
2266
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier
2267
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup
2268
     */
2269
    public function testAssignRoleToUserGroupWithRoleLimitationThrowsLimitationValidationException()
2270
    {
2271
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\LimitationValidationException::class);
2272
2273
        $repository = $this->getRepository();
2274
2275
        $mainGroupId = $this->generateId('group', 4);
2276
        /* BEGIN: Use Case */
2277
        // $mainGroupId is the ID of the main "Users" group
2278
2279
        $userService = $repository->getUserService();
2280
        $roleService = $repository->getRoleService();
2281
2282
        $userGroup = $userService->loadUserGroup($mainGroupId);
2283
2284
        // Load the existing "Anonymous" role
2285
        $role = $roleService->loadRoleByIdentifier('Anonymous');
2286
2287
        // Assign the "Anonymous" role to the newly created user group
2288
        // This call will fail with an LimitationValidationException, because subtree "/lorem/ipsum/42/"
2289
        // does not exists
2290
        $roleService->assignRoleToUserGroup(
2291
            $role,
2292
            $userGroup,
2293
            new SubtreeLimitation(
2294
                [
2295
                    'limitationValues' => ['/lorem/ipsum/42/'],
2296
                ]
2297
            )
2298
        );
2299
        /* END: Use Case */
2300
    }
2301
2302
    /**
2303
     * Test for the assignRoleToUserGroup() method.