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

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