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.
@@ 356-385 (lines=30) @@
353
     * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup
354
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser
355
     */
356
    public function testAssignRoleToUserGroupThrowsUnauthorizedExceptionWithRoleLimitationParameter()
357
    {
358
        $repository = $this->getRepository();
359
        $userService = $repository->getUserService();
360
        $roleService = $repository->getRoleService();
361
362
        $editorsGroupId = $this->generateId('group', 13);
363
364
        /* BEGIN: Use Case */
365
        $user = $this->createUserVersion1();
366
367
        $role = $this->createRole();
368
369
        // Load the "Editors" user group
370
        $userGroup = $userService->loadUserGroup($editorsGroupId);
371
372
        // Set "Editor" user as current user.
373
        $repository->setCurrentUser($user);
374
375
        // Create a subtree role limitation
376
        $limitation = new SubtreeLimitation(
377
            array(
378
                'limitationValues' => array('/1/2/'),
379
            )
380
        );
381
382
        // This call will fail with an "UnauthorizedException"
383
        $roleService->assignRoleToUserGroup($role, $userGroup, $limitation);
384
        /* END: Use Case */
385
    }
386
387
    /**
388
     * Test for the unassignRoleFromUserGroup() method.