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.
@@ 1267-1296 (lines=30) @@
1264
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewPolicyCreateStruct
1265
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleDraft
1266
     */
1267
    public function testAddPolicyByRoleDraftThrowsLimitationValidationException()
1268
    {
1269
        $repository = $this->getRepository();
1270
1271
        /* BEGIN: Use Case */
1272
        $roleService = $repository->getRoleService();
1273
1274
        $roleCreate = $roleService->newRoleCreateStruct('Lumberjack');
1275
1276
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
1277
        // $roleCreate->mainLanguageCode = 'eng-US';
1278
1279
        $roleDraft = $roleService->createRole($roleCreate);
1280
1281
        // Create new subtree limitation
1282
        $limitation = new SubtreeLimitation(
1283
            array(
1284
                'limitationValues' => array('/mountain/forest/tree/42/'),
1285
            )
1286
        );
1287
1288
        // Create policy create struct and add limitation to it
1289
        $policyCreateStruct = $roleService->newPolicyCreateStruct('content', 'remove');
1290
        $policyCreateStruct->addLimitation($limitation);
1291
1292
        // This call will fail with an LimitationValidationException, because subtree
1293
        // "/mountain/forest/tree/42/" does not exist
1294
        $roleService->addPolicyByRoleDraft($roleDraft, $policyCreateStruct);
1295
        /* END: Use Case */
1296
    }
1297
1298
    /**
1299
     * Test for the createRole() method.