Code Duplication    Length = 32-33 lines in 2 locations

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

@@ 255-287 (lines=33) @@
252
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testUpdatePolicy
253
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser
254
     */
255
    public function testUpdatePolicyThrowsUnauthorizedException()
256
    {
257
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\UnauthorizedException::class);
258
259
        $repository = $this->getRepository();
260
        $roleService = $repository->getRoleService();
261
262
        /* BEGIN: Use Case */
263
        $user = $this->createUserVersion1();
264
265
        $role = $this->createRole();
266
267
        // Get first role policy
268
        $policies = $role->getPolicies();
269
        $policy = reset($policies);
270
271
        // Set "Editor" user as current user.
272
        $repository->setCurrentUser($user);
273
274
        // Get a policy update struct and add a limitation
275
        $policyUpdate = $roleService->newPolicyUpdateStruct();
276
        $policyUpdate->addLimitation(
277
            new SubtreeLimitation(
278
                [
279
                    'limitationValues' => ['/1/'],
280
                ]
281
            )
282
        );
283
284
        // This call will fail with an "UnauthorizedException"
285
        $roleService->updatePolicy($policy, $policyUpdate);
286
        /* END: Use Case */
287
    }
288
289
    /**
290
     * Test for the removePolicy() method.
@@ 401-432 (lines=32) @@
398
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup
399
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser
400
     */
401
    public function testAssignRoleToUserGroupThrowsUnauthorizedExceptionWithRoleLimitationParameter()
402
    {
403
        $this->expectException(\eZ\Publish\API\Repository\Exceptions\UnauthorizedException::class);
404
405
        $repository = $this->getRepository();
406
        $userService = $repository->getUserService();
407
        $roleService = $repository->getRoleService();
408
409
        $editorsGroupId = $this->generateId('group', 13);
410
411
        /* BEGIN: Use Case */
412
        $user = $this->createUserVersion1();
413
414
        $role = $this->createRole();
415
416
        // Load the "Editors" user group
417
        $userGroup = $userService->loadUserGroup($editorsGroupId);
418
419
        // Set "Editor" user as current user.
420
        $repository->setCurrentUser($user);
421
422
        // Create a subtree role limitation
423
        $limitation = new SubtreeLimitation(
424
            [
425
                'limitationValues' => ['/1/2/'],
426
            ]
427
        );
428
429
        // This call will fail with an "UnauthorizedException"
430
        $roleService->assignRoleToUserGroup($role, $userGroup, $limitation);
431
        /* END: Use Case */
432
    }
433
434
    /**
435
     * Test for the unassignRoleFromUserGroup() method.