Code Duplication    Length = 30-31 lines in 2 locations

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

@@ 224-254 (lines=31) @@
221
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testUpdatePolicy
222
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser
223
     */
224
    public function testUpdatePolicyThrowsUnauthorizedException()
225
    {
226
        $repository = $this->getRepository();
227
        $roleService = $repository->getRoleService();
228
229
        /* BEGIN: Use Case */
230
        $user = $this->createUserVersion1();
231
232
        $role = $this->createRole();
233
234
        // Get first role policy
235
        $policies = $role->getPolicies();
236
        $policy = reset($policies);
237
238
        // Set "Editor" user as current user.
239
        $repository->setCurrentUser($user);
240
241
        // Get a policy update struct and add a limitation
242
        $policyUpdate = $roleService->newPolicyUpdateStruct();
243
        $policyUpdate->addLimitation(
244
            new SubtreeLimitation(
245
                array(
246
                    'limitationValues' => array('/1/'),
247
                )
248
            )
249
        );
250
251
        // This call will fail with an "UnauthorizedException"
252
        $roleService->updatePolicy($policy, $policyUpdate);
253
        /* END: Use Case */
254
    }
255
256
    /**
257
     * Test for the removePolicy() method.
@@ 366-395 (lines=30) @@
363
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup
364
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser
365
     */
366
    public function testAssignRoleToUserGroupThrowsUnauthorizedExceptionWithRoleLimitationParameter()
367
    {
368
        $repository = $this->getRepository();
369
        $userService = $repository->getUserService();
370
        $roleService = $repository->getRoleService();
371
372
        $editorsGroupId = $this->generateId('group', 13);
373
374
        /* BEGIN: Use Case */
375
        $user = $this->createUserVersion1();
376
377
        $role = $this->createRole();
378
379
        // Load the "Editors" user group
380
        $userGroup = $userService->loadUserGroup($editorsGroupId);
381
382
        // Set "Editor" user as current user.
383
        $repository->setCurrentUser($user);
384
385
        // Create a subtree role limitation
386
        $limitation = new SubtreeLimitation(
387
            array(
388
                'limitationValues' => array('/1/2/'),
389
            )
390
        );
391
392
        // This call will fail with an "UnauthorizedException"
393
        $roleService->assignRoleToUserGroup($role, $userGroup, $limitation);
394
        /* END: Use Case */
395
    }
396
397
    /**
398
     * Test for the unassignRoleFromUserGroup() method.