Code Duplication    Length = 32-34 lines in 2 locations

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

@@ 27-60 (lines=34) @@
24
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
25
     * @depends eZ\Publish\API\Repository\Tests\ObjectStateServiceTest::testCreateObjectStateGroup
26
     */
27
    public function testCreateObjectStateGroupThrowsUnauthorizedException()
28
    {
29
        $repository = $this->getRepository();
30
31
        $anonymousUserId = $this->generateId('user', 10);
32
        /* BEGIN: Use Case */
33
        // $anonymousUserId is the ID of the "Anonymous" user in a eZ
34
        // Publish demo installation.
35
        // Set anonymous user
36
        $userService = $repository->getUserService();
37
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
38
39
        $objectStateService = $repository->getObjectStateService();
40
41
        $objectStateGroupCreate = $objectStateService->newObjectStateGroupCreateStruct(
42
            'publishing'
43
        );
44
        $objectStateGroupCreate->defaultLanguageCode = 'eng-US';
45
        $objectStateGroupCreate->names = array(
46
            'eng-US' => 'Publishing',
47
            'eng-GB' => 'Sindelfingen',
48
        );
49
        $objectStateGroupCreate->descriptions = array(
50
            'eng-US' => 'Put something online',
51
            'eng-GB' => 'Put something ton Sindelfingen.',
52
        );
53
54
        // Throws unauthorized exception, since the anonymous user must not
55
        // create object state groups
56
        $createdObjectStateGroup = $objectStateService->createObjectStateGroup(
57
            $objectStateGroupCreate
58
        );
59
        /* END: Use Case */
60
    }
61
62
    /**
63
     * Test for the updateObjectStateGroup() method.

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

@@ 1309-1340 (lines=32) @@
1306
     * @see \eZ\Publish\API\Repository\ObjectStateService::updateObjectState()
1307
     * @depends testUpdateObjectState
1308
     */
1309
    public function testUpdateObjectStateThrowsInvalidArgumentException()
1310
    {
1311
        $repository = $this->getRepository();
1312
1313
        $objectStateId = $this->generateId('objectstate', 2);
1314
        // $objectStateId contains the ID of the "locked" state
1315
        $objectStateService = $repository->getObjectStateService();
1316
1317
        $loadedObjectState = $objectStateService->loadObjectState(
1318
            $objectStateId
1319
        );
1320
1321
        $updateStateStruct = $objectStateService->newObjectStateUpdateStruct();
1322
        // 'not_locked' is the identifier of already existing state
1323
        $updateStateStruct->identifier = 'not_locked';
1324
        $updateStateStruct->defaultLanguageCode = 'ger-DE';
1325
        $updateStateStruct->names = array(
1326
            'eng-US' => 'Somehow locked',
1327
            'ger-DE' => 'Irgendwie gelockt',
1328
        );
1329
        $updateStateStruct->descriptions = array(
1330
            'eng-US' => 'The object is somehow locked',
1331
            'ger-DE' => 'Sindelfingen',
1332
        );
1333
1334
        // This call will fail because state with
1335
        // 'not_locked' identifier already exists
1336
        $objectStateService->updateObjectState(
1337
            $loadedObjectState,
1338
            $updateStateStruct
1339
        );
1340
    }
1341
1342
    /**
1343
     * testUpdateObjectStateStructValues.