Code Duplication    Length = 34-37 lines in 3 locations

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

@@ 304-337 (lines=34) @@
301
     * @depends eZ\Publish\API\Repository\Tests\PermissionResolverTest::testHasAccessForCurrentUserYes
302
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
303
     */
304
    public function testCanUserForAdministratorUser()
305
    {
306
        $repository = $this->getRepository();
307
308
        $administratorUserId = $this->generateId('user', 14);
309
        $homeId = $this->generateId('object', 57);
310
311
        /* BEGIN: Use Case */
312
        // $administratorUserId contains the ID of the administrator user
313
        // $homeId contains the ID of the "Home" frontpage
314
315
        $contentService = $repository->getContentService();
316
        $userService = $repository->getUserService();
317
        $permissionResolver = $repository->getPermissionResolver();
318
319
        // Load administrator user
320
        $administratorUser = $userService->loadUser($administratorUserId);
321
322
        // Set administrator user as current user reference
323
        $permissionResolver->setCurrentUserReference($administratorUser);
324
325
        // Load the ContentInfo for "Home" frontpage
326
        $contentInfo = $contentService->loadContentInfo($homeId);
327
328
        // This call will return true
329
        $canUser = $permissionResolver->canUser('content', 'remove', $contentInfo);
330
331
        // Performing an action having necessary permissions will succeed
332
        $contentService->deleteContent($contentInfo);
333
        /* END: Use Case */
334
335
        $this->assertTrue($canUser);
336
        $contentService->loadContent($homeId);
337
    }
338
339
    /**
340
     * Test for the canUser() method.

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

@@ 315-351 (lines=37) @@
312
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
313
     * @depends eZ\Publish\API\Repository\Tests\ObjectStateServiceTest::testSetContentState
314
     */
315
    public function testSetContentStateThrowsUnauthorizedException()
316
    {
317
        $repository = $this->getRepository();
318
319
        $anonymousUserId = $this->generateId('user', 10);
320
        $ezLockObjectStateGroupId = $this->generateId('objectstategroup', 2);
321
        $lockedObjectStateId = $this->generateId('objectstate', 2);
322
        /* BEGIN: Use Case */
323
        // $anonymousUserId is the ID of the "Anonymous" user in a eZ
324
        // Publish demo installation.
325
        // Set anonymous user
326
        $userService = $repository->getUserService();
327
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
328
329
        // $anonymousUserId is the content ID of "Anonymous User"
330
        // $ezLockObjectStateGroupId contains the ID of the "ez_lock" object
331
        // state group
332
        // $lockedObjectStateId is the ID of the state "locked"
333
        $contentService = $repository->getContentService();
334
        $objectStateService = $repository->getObjectStateService();
335
336
        $contentInfo = $contentService->loadContentInfo($anonymousUserId);
337
338
        $ezLockObjectStateGroup = $objectStateService->loadObjectStateGroup(
339
            $ezLockObjectStateGroupId
340
        );
341
        $lockedObjectState = $objectStateService->loadObjectState($lockedObjectStateId);
342
343
        // Throws unauthorized exception, since the anonymous user must not
344
        // set object state
345
        $objectStateService->setContentState(
346
            $contentInfo,
347
            $ezLockObjectStateGroup,
348
            $lockedObjectState
349
        );
350
        /* END: Use Case */
351
    }
352
}
353

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

@@ 1342-1378 (lines=37) @@
1339
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
1340
     * @depends testLoadObjectState
1341
     */
1342
    public function testSetContentState()
1343
    {
1344
        $repository = $this->getRepository();
1345
1346
        $anonymousUserId = $this->generateId('user', 10);
1347
        $ezLockObjectStateGroupId = $this->generateId('objectstategroup', 2);
1348
        $lockedObjectStateId = $this->generateId('objectstate', 2);
1349
        /* BEGIN: Use Case */
1350
        // $anonymousUserId is the content ID of "Anonymous User"
1351
        // $ezLockObjectStateGroupId contains the ID of the "ez_lock" object
1352
        // state group
1353
        // $lockedObjectStateId is the ID of the state "locked"
1354
        $contentService = $repository->getContentService();
1355
        $objectStateService = $repository->getObjectStateService();
1356
1357
        $contentInfo = $contentService->loadContentInfo($anonymousUserId);
1358
1359
        $ezLockObjectStateGroup = $objectStateService->loadObjectStateGroup(
1360
            $ezLockObjectStateGroupId
1361
        );
1362
        $lockedObjectState = $objectStateService->loadObjectState($lockedObjectStateId);
1363
1364
        // Sets the state of $contentInfo from "not_locked" to "locked"
1365
        $objectStateService->setContentState(
1366
            $contentInfo,
1367
            $ezLockObjectStateGroup,
1368
            $lockedObjectState
1369
        );
1370
        /* END: Use Case */
1371
1372
        $ezLockObjectState = $objectStateService->getContentState(
1373
            $contentInfo,
1374
            $ezLockObjectStateGroup
1375
        );
1376
1377
        $this->assertEquals('locked', $ezLockObjectState->identifier);
1378
    }
1379
1380
    /**
1381
     * Test for the setContentState() method.