Code Duplication    Length = 34-37 lines in 3 locations

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

@@ 1192-1228 (lines=37) @@
1189
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
1190
     * @depends testLoadObjectState
1191
     */
1192
    public function testSetContentState()
1193
    {
1194
        $repository = $this->getRepository();
1195
1196
        $anonymousUserId = $this->generateId('user', 10);
1197
        $ezLockObjectStateGroupId = $this->generateId('objectstategroup', 2);
1198
        $lockedObjectStateId = $this->generateId('objectstate', 2);
1199
        /* BEGIN: Use Case */
1200
        // $anonymousUserId is the content ID of "Anonymous User"
1201
        // $ezLockObjectStateGroupId contains the ID of the "ez_lock" object
1202
        // state group
1203
        // $lockedObjectStateId is the ID of the state "locked"
1204
        $contentService = $repository->getContentService();
1205
        $objectStateService = $repository->getObjectStateService();
1206
1207
        $contentInfo = $contentService->loadContentInfo($anonymousUserId);
1208
1209
        $ezLockObjectStateGroup = $objectStateService->loadObjectStateGroup(
1210
            $ezLockObjectStateGroupId
1211
        );
1212
        $lockedObjectState = $objectStateService->loadObjectState($lockedObjectStateId);
1213
1214
        // Sets the state of $contentInfo from "not_locked" to "locked"
1215
        $objectStateService->setContentState(
1216
            $contentInfo,
1217
            $ezLockObjectStateGroup,
1218
            $lockedObjectState
1219
        );
1220
        /* END: Use Case */
1221
1222
        $ezLockObjectState = $objectStateService->getContentState(
1223
            $contentInfo,
1224
            $ezLockObjectStateGroup
1225
        );
1226
1227
        $this->assertEquals('locked', $ezLockObjectState->identifier);
1228
    }
1229
1230
    /**
1231
     * Test for the setContentState() method.

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

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