Code Duplication    Length = 32-34 lines in 3 locations

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

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