Code Duplication    Length = 30-31 lines in 3 locations

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

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

eZ/Publish/API/Repository/Tests/ContentServiceAuthorizationTest.php 1 location

@@ 1427-1456 (lines=30) @@
1424
     *
1425
     * @return \eZ\Publish\API\Repository\Values\User\User
1426
     */
1427
    private function createAnonymousWithEditorRole()
1428
    {
1429
        $repository = $this->getRepository();
1430
1431
        $anonymousUserId = $this->generateId('user', 10);
1432
        /* BEGIN: Use Case */
1433
        // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish
1434
        // demo installation
1435
        $roleService = $repository->getRoleService();
1436
        $userService = $repository->getUserService();
1437
1438
        $user = $userService->loadUser($anonymousUserId);
1439
        $role = $roleService->loadRoleByIdentifier('Editor');
1440
1441
        // Assign "Editor" role with limitation to "Media/Images"
1442
        $roleService->assignRoleToUser(
1443
            $role,
1444
            $user,
1445
            new \eZ\Publish\API\Repository\Values\User\Limitation\SubtreeLimitation(
1446
                [
1447
                    'limitationValues' => ['/1/43/51/'],
1448
                ]
1449
            )
1450
        );
1451
1452
        $pseudoEditor = $userService->loadUser($user->id);
1453
        /* END: Inline */
1454
1455
        return $pseudoEditor;
1456
    }
1457
1458
    /**
1459
     * Test that for an user that doesn't have access (read permissions) to an