Code Duplication    Length = 30-32 lines in 2 locations

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

@@ 304-335 (lines=32) @@
301
     * @see \eZ\Publish\API\Repository\RoleService::createRole()
302
     * @expectedException \eZ\Publish\API\Repository\Exceptions\LimitationValidationException
303
     */
304
    public function testCreateRoleThrowsLimitationValidationException()
305
    {
306
        $repository = $this->getRepository();
307
308
        /* BEGIN: Use Case */
309
        $roleService = $repository->getRoleService();
310
311
        // Create new role create struct
312
        $roleCreate = $roleService->newRoleCreateStruct('Lumberjack');
313
314
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
315
        // $roleCreate->mainLanguageCode = 'eng-US';
316
317
        // Create new subtree limitation
318
        $limitation = new SubtreeLimitation(
319
            array(
320
                'limitationValues' => array('/mountain/forest/tree/42/'),
321
            )
322
        );
323
324
        // Create policy create struct and add limitation to it
325
        $policyCreate = $roleService->newPolicyCreateStruct('content', 'remove');
326
        $policyCreate->addLimitation($limitation);
327
328
        // Add policy create struct to role create struct
329
        $roleCreate->addPolicy($policyCreate);
330
331
        // This call will fail with an LimitationValidationException, because subtree
332
        // "/mountain/forest/tree/42/" does not exist
333
        $roleService->createRole($roleCreate);
334
        /* END: Use Case */
335
    }
336
337
    /**
338
     * Test for the createRole() method.
@@ 1200-1229 (lines=30) @@
1197
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewPolicyCreateStruct
1198
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleDraft
1199
     */
1200
    public function testAddPolicyByRoleDraftThrowsLimitationValidationException()
1201
    {
1202
        $repository = $this->getRepository();
1203
1204
        /* BEGIN: Use Case */
1205
        $roleService = $repository->getRoleService();
1206
1207
        $roleCreate = $roleService->newRoleCreateStruct('Lumberjack');
1208
1209
        // @todo uncomment when support for multilingual names and descriptions is added EZP-24776
1210
        // $roleCreate->mainLanguageCode = 'eng-US';
1211
1212
        $roleDraft = $roleService->createRole($roleCreate);
1213
1214
        // Create new subtree limitation
1215
        $limitation = new SubtreeLimitation(
1216
            array(
1217
                'limitationValues' => array('/mountain/forest/tree/42/'),
1218
            )
1219
        );
1220
1221
        // Create policy create struct and add limitation to it
1222
        $policyCreateStruct = $roleService->newPolicyCreateStruct('content', 'remove');
1223
        $policyCreateStruct->addLimitation($limitation);
1224
1225
        // This call will fail with an LimitationValidationException, because subtree
1226
        // "/mountain/forest/tree/42/" does not exist
1227
        $roleService->addPolicyByRoleDraft($roleDraft, $policyCreateStruct);
1228
        /* END: Use Case */
1229
    }
1230
1231
    /**
1232
     * Test for the createRole() method.