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
            array(
412
                'limitationValues' => array('/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.
@@ 1292-1321 (lines=30) @@
1289
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewPolicyCreateStruct
1290
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleDraft
1291
     */
1292
    public function testAddPolicyByRoleDraftThrowsLimitationValidationException()
1293
    {
1294
        $repository = $this->getRepository();
1295
1296
        /* BEGIN: Use Case */
1297
        $roleService = $repository->getRoleService();
1298
1299
        $roleCreate = $roleService->newRoleCreateStruct('Lumberjack');
1300
1301
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
1302
        // $roleCreate->mainLanguageCode = 'eng-US';
1303
1304
        $roleDraft = $roleService->createRole($roleCreate);
1305
1306
        // Create new subtree limitation
1307
        $limitation = new SubtreeLimitation(
1308
            array(
1309
                'limitationValues' => array('/mountain/forest/tree/42/'),
1310
            )
1311
        );
1312
1313
        // Create policy create struct and add limitation to it
1314
        $policyCreateStruct = $roleService->newPolicyCreateStruct('content', 'remove');
1315
        $policyCreateStruct->addLimitation($limitation);
1316
1317
        // This call will fail with an LimitationValidationException, because subtree
1318
        // "/mountain/forest/tree/42/" does not exist
1319
        $roleService->addPolicyByRoleDraft($roleDraft, $policyCreateStruct);
1320
        /* END: Use Case */
1321
    }
1322
1323
    /**
1324
     * Test for the createRole() method.