Code Duplication    Length = 32-34 lines in 3 locations

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

@@ 415-448 (lines=34) @@
412
     *
413
     * @see \eZ\Publish\API\Repository\RoleService::createRole()
414
     */
415
    public function testCreateRoleThrowsLimitationValidationException()
416
    {
417
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\LimitationValidationException::class);
418
419
        $repository = $this->getRepository();
420
421
        /* BEGIN: Use Case */
422
        $roleService = $repository->getRoleService();
423
424
        // Create new role create struct
425
        $roleCreate = $roleService->newRoleCreateStruct('Lumberjack');
426
427
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
428
        // $roleCreate->mainLanguageCode = 'eng-US';
429
430
        // Create new subtree limitation
431
        $limitation = new SubtreeLimitation(
432
            [
433
                'limitationValues' => ['/mountain/forest/tree/42/'],
434
            ]
435
        );
436
437
        // Create policy create struct and add limitation to it
438
        $policyCreate = $roleService->newPolicyCreateStruct('content', 'remove');
439
        $policyCreate->addLimitation($limitation);
440
441
        // Add policy create struct to role create struct
442
        $roleCreate->addPolicy($policyCreate);
443
444
        // This call will fail with an LimitationValidationException, because subtree
445
        // "/mountain/forest/tree/42/" does not exist
446
        $roleService->createRole($roleCreate);
447
        /* END: Use Case */
448
    }
449
450
    /**
451
     * Test for the createRole() method.
@@ 1206-1237 (lines=32) @@
1203
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewPolicyCreateStruct
1204
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleDraft
1205
     */
1206
    public function testAddPolicyByRoleDraftThrowsLimitationValidationException()
1207
    {
1208
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\LimitationValidationException::class);
1209
1210
        $repository = $this->getRepository();
1211
1212
        /* BEGIN: Use Case */
1213
        $roleService = $repository->getRoleService();
1214
1215
        $roleCreate = $roleService->newRoleCreateStruct('Lumberjack');
1216
1217
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
1218
        // $roleCreate->mainLanguageCode = 'eng-US';
1219
1220
        $roleDraft = $roleService->createRole($roleCreate);
1221
1222
        // Create new subtree limitation
1223
        $limitation = new SubtreeLimitation(
1224
            [
1225
                'limitationValues' => ['/mountain/forest/tree/42/'],
1226
            ]
1227
        );
1228
1229
        // Create policy create struct and add limitation to it
1230
        $policyCreateStruct = $roleService->newPolicyCreateStruct('content', 'remove');
1231
        $policyCreateStruct->addLimitation($limitation);
1232
1233
        // This call will fail with an LimitationValidationException, because subtree
1234
        // "/mountain/forest/tree/42/" does not exist
1235
        $roleService->addPolicyByRoleDraft($roleDraft, $policyCreateStruct);
1236
        /* END: Use Case */
1237
    }
1238
1239
    /**
1240
     * Test for the createRole() method.
@@ 2405-2436 (lines=32) @@
2402
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier
2403
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup
2404
     */
2405
    public function testAssignRoleToUserGroupWithRoleLimitationThrowsLimitationValidationException()
2406
    {
2407
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\LimitationValidationException::class);
2408
2409
        $repository = $this->getRepository();
2410
2411
        $mainGroupId = $this->generateId('group', 4);
2412
        /* BEGIN: Use Case */
2413
        // $mainGroupId is the ID of the main "Users" group
2414
2415
        $userService = $repository->getUserService();
2416
        $roleService = $repository->getRoleService();
2417
2418
        $userGroup = $userService->loadUserGroup($mainGroupId);
2419
2420
        // Load the existing "Anonymous" role
2421
        $role = $roleService->loadRoleByIdentifier('Anonymous');
2422
2423
        // Assign the "Anonymous" role to the newly created user group
2424
        // This call will fail with an LimitationValidationException, because subtree "/lorem/ipsum/42/"
2425
        // does not exists
2426
        $roleService->assignRoleToUserGroup(
2427
            $role,
2428
            $userGroup,
2429
            new SubtreeLimitation(
2430
                [
2431
                    'limitationValues' => ['/lorem/ipsum/42/'],
2432
                ]
2433
            )
2434
        );
2435
        /* END: Use Case */
2436
    }
2437
2438
    /**
2439
     * Test for the assignRoleToUserGroup() method.