Code Duplication    Length = 30-32 lines in 2 locations

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

@@ 396-427 (lines=32) @@
393
     * @see \eZ\Publish\API\Repository\RoleService::createRole()
394
     * @expectedException \eZ\Publish\API\Repository\Exceptions\LimitationValidationException
395
     */
396
    public function testCreateRoleThrowsLimitationValidationException()
397
    {
398
        $repository = $this->getRepository();
399
400
        /* BEGIN: Use Case */
401
        $roleService = $repository->getRoleService();
402
403
        // Create new role create struct
404
        $roleCreate = $roleService->newRoleCreateStruct('Lumberjack');
405
406
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
407
        // $roleCreate->mainLanguageCode = 'eng-US';
408
409
        // Create new subtree limitation
410
        $limitation = new SubtreeLimitation(
411
            [
412
                'limitationValues' => ['/mountain/forest/tree/42/'],
413
            ]
414
        );
415
416
        // Create policy create struct and add limitation to it
417
        $policyCreate = $roleService->newPolicyCreateStruct('content', 'remove');
418
        $policyCreate->addLimitation($limitation);
419
420
        // Add policy create struct to role create struct
421
        $roleCreate->addPolicy($policyCreate);
422
423
        // This call will fail with an LimitationValidationException, because subtree
424
        // "/mountain/forest/tree/42/" does not exist
425
        $roleService->createRole($roleCreate);
426
        /* END: Use Case */
427
    }
428
429
    /**
430
     * Test for the createRole() method.
@@ 1290-1319 (lines=30) @@
1287
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewPolicyCreateStruct
1288
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleDraft
1289
     */
1290
    public function testAddPolicyByRoleDraftThrowsLimitationValidationException()
1291
    {
1292
        $repository = $this->getRepository();
1293
1294
        /* BEGIN: Use Case */
1295
        $roleService = $repository->getRoleService();
1296
1297
        $roleCreate = $roleService->newRoleCreateStruct('Lumberjack');
1298
1299
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
1300
        // $roleCreate->mainLanguageCode = 'eng-US';
1301
1302
        $roleDraft = $roleService->createRole($roleCreate);
1303
1304
        // Create new subtree limitation
1305
        $limitation = new SubtreeLimitation(
1306
            [
1307
                'limitationValues' => ['/mountain/forest/tree/42/'],
1308
            ]
1309
        );
1310
1311
        // Create policy create struct and add limitation to it
1312
        $policyCreateStruct = $roleService->newPolicyCreateStruct('content', 'remove');
1313
        $policyCreateStruct->addLimitation($limitation);
1314
1315
        // This call will fail with an LimitationValidationException, because subtree
1316
        // "/mountain/forest/tree/42/" does not exist
1317
        $roleService->addPolicyByRoleDraft($roleDraft, $policyCreateStruct);
1318
        /* END: Use Case */
1319
    }
1320
1321
    /**
1322
     * Test for the createRole() method.