Code Duplication    Length = 25-31 lines in 3 locations

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

@@ 247-274 (lines=28) @@
244
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
245
     * @depends eZ\Publish\API\Repository\Tests\ObjectStateServiceTest::testSetPriorityOfObjectState
246
     */
247
    public function testSetPriorityOfObjectStateThrowsUnauthorizedException()
248
    {
249
        $repository = $this->getRepository();
250
251
        $objectStateId = $this->generateId('objectstate', 2);
252
        $anonymousUserId = $this->generateId('user', 10);
253
        /* BEGIN: Use Case */
254
        // $anonymousUserId is the ID of the "Anonymous" user in a eZ
255
        // Publish demo installation.
256
        // Set anonymous user
257
        $userService = $repository->getUserService();
258
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
259
260
        // $objectStateId contains the ID of the "locked" state
261
        $objectStateService = $repository->getObjectStateService();
262
263
        $initiallyLoadedObjectState = $objectStateService->loadObjectState(
264
            $objectStateId
265
        );
266
267
        // Throws unauthorized exception, since the anonymous user must not
268
        // set priorities for object states
269
        $objectStateService->setPriorityOfObjectState(
270
            $initiallyLoadedObjectState,
271
            23
272
        );
273
        /* END: Use Case */
274
    }
275
276
    /**
277
     * Test for the deleteObjectState() method.

eZ/Publish/API/Repository/Tests/ObjectStateServiceTest.php 2 locations

@@ 1047-1077 (lines=31) @@
1044
     * @see \eZ\Publish\API\Repository\ObjectStateService::setPriorityOfObjectState()
1045
     * @depends testLoadObjectState
1046
     */
1047
    public function testSetPriorityOfObjectState()
1048
    {
1049
        $repository = $this->getRepository();
1050
1051
        $objectStateId = $this->generateId('objectstate', 1);
1052
        /* BEGIN: Use Case */
1053
        // $objectStateId contains the ID of the "not_locked" state
1054
        $objectStateService = $repository->getObjectStateService();
1055
1056
        $initiallyLoadedObjectState = $objectStateService->loadObjectState(
1057
            $objectStateId
1058
        );
1059
1060
        // Sets the given priority on $initiallyLoadedObjectState
1061
        $objectStateService->setPriorityOfObjectState(
1062
            $initiallyLoadedObjectState,
1063
            23
1064
        );
1065
        // $loadObjectState now has the priority 1, since object state
1066
        // priorities are always made sequential
1067
        $loadedObjectState = $objectStateService->loadObjectState(
1068
            $objectStateId
1069
        );
1070
        /* END: Use Case */
1071
1072
        $this->assertInstanceOf(
1073
            'eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectState',
1074
            $loadedObjectState
1075
        );
1076
        $this->assertEquals(1, $loadedObjectState->priority);
1077
    }
1078
1079
    /**
1080
     * Test for the getContentState() method.
@@ 1304-1328 (lines=25) @@
1301
     * @see \eZ\Publish\API\Repository\ObjectStateService::deleteObjectState()
1302
     * @depends testLoadObjectState
1303
     */
1304
    public function testDeleteObjectState()
1305
    {
1306
        $repository = $this->getRepository();
1307
1308
        $notLockedObjectStateId = $this->generateId('objectstate', 1);
1309
        $lockedObjectStateId = $this->generateId('objectstate', 2);
1310
        /* BEGIN: Use Case */
1311
        // $notLockedObjectStateId is the ID of the state "not_locked"
1312
        $objectStateService = $repository->getObjectStateService();
1313
1314
        $notLockedObjectState = $objectStateService->loadObjectState($notLockedObjectStateId);
1315
1316
        // Deletes the object state and sets all objects, which where in that
1317
        // state, to the first state of the same object state group
1318
        $objectStateService->deleteObjectState($notLockedObjectState);
1319
        /* END: Use Case */
1320
1321
        $lockedObjectState = $objectStateService->loadObjectState($lockedObjectStateId);
1322
1323
        // All objects transferred
1324
        $this->assertEquals(
1325
            18,
1326
            $objectStateService->getContentCount($lockedObjectState)
1327
        );
1328
    }
1329
1330
    /**
1331
     * Test for the deleteObjectStateGroup() method.