Code Duplication    Length = 34-37 lines in 3 locations

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

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

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

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

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.