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

@@ 1549-1585 (lines=37) @@
1546
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
1547
     * @depends testLoadObjectState
1548
     */
1549
    public function testSetContentState()
1550
    {
1551
        $repository = $this->getRepository();
1552
1553
        $anonymousUserId = $this->generateId('user', 10);
1554
        $ezLockObjectStateGroupId = $this->generateId('objectstategroup', 2);
1555
        $lockedObjectStateId = $this->generateId('objectstate', 2);
1556
        /* BEGIN: Use Case */
1557
        // $anonymousUserId is the content ID of "Anonymous User"
1558
        // $ezLockObjectStateGroupId contains the ID of the "ez_lock" object
1559
        // state group
1560
        // $lockedObjectStateId is the ID of the state "locked"
1561
        $contentService = $repository->getContentService();
1562
        $objectStateService = $repository->getObjectStateService();
1563
1564
        $contentInfo = $contentService->loadContentInfo($anonymousUserId);
1565
1566
        $ezLockObjectStateGroup = $objectStateService->loadObjectStateGroup(
1567
            $ezLockObjectStateGroupId
1568
        );
1569
        $lockedObjectState = $objectStateService->loadObjectState($lockedObjectStateId);
1570
1571
        // Sets the state of $contentInfo from "not_locked" to "locked"
1572
        $objectStateService->setContentState(
1573
            $contentInfo,
1574
            $ezLockObjectStateGroup,
1575
            $lockedObjectState
1576
        );
1577
        /* END: Use Case */
1578
1579
        $ezLockObjectState = $objectStateService->getContentState(
1580
            $contentInfo,
1581
            $ezLockObjectStateGroup
1582
        );
1583
1584
        $this->assertEquals('locked', $ezLockObjectState->identifier);
1585
    }
1586
1587
    /**
1588
     * 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.