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

@@ 1212-1248 (lines=37) @@
1209
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
1210
     * @depends testLoadObjectState
1211
     */
1212
    public function testSetContentState()
1213
    {
1214
        $repository = $this->getRepository();
1215
1216
        $anonymousUserId = $this->generateId('user', 10);
1217
        $ezLockObjectStateGroupId = $this->generateId('objectstategroup', 2);
1218
        $lockedObjectStateId = $this->generateId('objectstate', 2);
1219
        /* BEGIN: Use Case */
1220
        // $anonymousUserId is the content ID of "Anonymous User"
1221
        // $ezLockObjectStateGroupId contains the ID of the "ez_lock" object
1222
        // state group
1223
        // $lockedObjectStateId is the ID of the state "locked"
1224
        $contentService = $repository->getContentService();
1225
        $objectStateService = $repository->getObjectStateService();
1226
1227
        $contentInfo = $contentService->loadContentInfo($anonymousUserId);
1228
1229
        $ezLockObjectStateGroup = $objectStateService->loadObjectStateGroup(
1230
            $ezLockObjectStateGroupId
1231
        );
1232
        $lockedObjectState = $objectStateService->loadObjectState($lockedObjectStateId);
1233
1234
        // Sets the state of $contentInfo from "not_locked" to "locked"
1235
        $objectStateService->setContentState(
1236
            $contentInfo,
1237
            $ezLockObjectStateGroup,
1238
            $lockedObjectState
1239
        );
1240
        /* END: Use Case */
1241
1242
        $ezLockObjectState = $objectStateService->getContentState(
1243
            $contentInfo,
1244
            $ezLockObjectStateGroup
1245
        );
1246
1247
        $this->assertEquals('locked', $ezLockObjectState->identifier);
1248
    }
1249
1250
    /**
1251
     * Test for the setContentState() method.

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

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