Code Duplication    Length = 30-32 lines in 2 locations

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

@@ 310-341 (lines=32) @@
307
     * @see \eZ\Publish\API\Repository\RoleService::createRole()
308
     * @expectedException \eZ\Publish\API\Repository\Exceptions\LimitationValidationException
309
     */
310
    public function testCreateRoleThrowsLimitationValidationException()
311
    {
312
        $repository = $this->getRepository();
313
314
        /* BEGIN: Use Case */
315
        $roleService = $repository->getRoleService();
316
317
        // Create new role create struct
318
        $roleCreate = $roleService->newRoleCreateStruct('Lumberjack');
319
320
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
321
        // $roleCreate->mainLanguageCode = 'eng-US';
322
323
        // Create new subtree limitation
324
        $limitation = new SubtreeLimitation(
325
            array(
326
                'limitationValues' => array('/mountain/forest/tree/42/'),
327
            )
328
        );
329
330
        // Create policy create struct and add limitation to it
331
        $policyCreate = $roleService->newPolicyCreateStruct('content', 'remove');
332
        $policyCreate->addLimitation($limitation);
333
334
        // Add policy create struct to role create struct
335
        $roleCreate->addPolicy($policyCreate);
336
337
        // This call will fail with an LimitationValidationException, because subtree
338
        // "/mountain/forest/tree/42/" does not exist
339
        $roleService->createRole($roleCreate);
340
        /* END: Use Case */
341
    }
342
343
    /**
344
     * Test for the createRole() method.
@@ 1271-1300 (lines=30) @@
1268
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewPolicyCreateStruct
1269
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleDraft
1270
     */
1271
    public function testAddPolicyByRoleDraftThrowsLimitationValidationException()
1272
    {
1273
        $repository = $this->getRepository();
1274
1275
        /* BEGIN: Use Case */
1276
        $roleService = $repository->getRoleService();
1277
1278
        $roleCreate = $roleService->newRoleCreateStruct('Lumberjack');
1279
1280
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
1281
        // $roleCreate->mainLanguageCode = 'eng-US';
1282
1283
        $roleDraft = $roleService->createRole($roleCreate);
1284
1285
        // Create new subtree limitation
1286
        $limitation = new SubtreeLimitation(
1287
            array(
1288
                'limitationValues' => array('/mountain/forest/tree/42/'),
1289
            )
1290
        );
1291
1292
        // Create policy create struct and add limitation to it
1293
        $policyCreateStruct = $roleService->newPolicyCreateStruct('content', 'remove');
1294
        $policyCreateStruct->addLimitation($limitation);
1295
1296
        // This call will fail with an LimitationValidationException, because subtree
1297
        // "/mountain/forest/tree/42/" does not exist
1298
        $roleService->addPolicyByRoleDraft($roleDraft, $policyCreateStruct);
1299
        /* END: Use Case */
1300
    }
1301
1302
    /**
1303
     * Test for the createRole() method.