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

@@ 1197-1227 (lines=31) @@
1194
     * @see \eZ\Publish\API\Repository\ObjectStateService::setPriorityOfObjectState()
1195
     * @depends testLoadObjectState
1196
     */
1197
    public function testSetPriorityOfObjectState()
1198
    {
1199
        $repository = $this->getRepository();
1200
1201
        $objectStateId = $this->generateId('objectstate', 1);
1202
        /* BEGIN: Use Case */
1203
        // $objectStateId contains the ID of the "not_locked" state
1204
        $objectStateService = $repository->getObjectStateService();
1205
1206
        $initiallyLoadedObjectState = $objectStateService->loadObjectState(
1207
            $objectStateId
1208
        );
1209
1210
        // Sets the given priority on $initiallyLoadedObjectState
1211
        $objectStateService->setPriorityOfObjectState(
1212
            $initiallyLoadedObjectState,
1213
            23
1214
        );
1215
        // $loadObjectState now has the priority 1, since object state
1216
        // priorities are always made sequential
1217
        $loadedObjectState = $objectStateService->loadObjectState(
1218
            $objectStateId
1219
        );
1220
        /* END: Use Case */
1221
1222
        $this->assertInstanceOf(
1223
            'eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectState',
1224
            $loadedObjectState
1225
        );
1226
        $this->assertEquals(1, $loadedObjectState->priority);
1227
    }
1228
1229
    /**
1230
     * Test for the getContentState() method.
@@ 1453-1477 (lines=25) @@
1450
     * @see \eZ\Publish\API\Repository\ObjectStateService::deleteObjectState()
1451
     * @depends testLoadObjectState
1452
     */
1453
    public function testDeleteObjectState()
1454
    {
1455
        $repository = $this->getRepository();
1456
1457
        $notLockedObjectStateId = $this->generateId('objectstate', 1);
1458
        $lockedObjectStateId = $this->generateId('objectstate', 2);
1459
        /* BEGIN: Use Case */
1460
        // $notLockedObjectStateId is the ID of the state "not_locked"
1461
        $objectStateService = $repository->getObjectStateService();
1462
1463
        $notLockedObjectState = $objectStateService->loadObjectState($notLockedObjectStateId);
1464
1465
        // Deletes the object state and sets all objects, which where in that
1466
        // state, to the first state of the same object state group
1467
        $objectStateService->deleteObjectState($notLockedObjectState);
1468
        /* END: Use Case */
1469
1470
        $lockedObjectState = $objectStateService->loadObjectState($lockedObjectStateId);
1471
1472
        // All objects transferred
1473
        $this->assertEquals(
1474
            18,
1475
            $objectStateService->getContentCount($lockedObjectState)
1476
        );
1477
    }
1478
1479
    /**
1480
     * Test for the deleteObjectStateGroup() method.