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

@@ 1325-1356 (lines=32) @@
1322
     * @see \eZ\Publish\API\Repository\ObjectStateService::updateObjectState()
1323
     * @depends testUpdateObjectState
1324
     */
1325
    public function testUpdateObjectStateThrowsInvalidArgumentException()
1326
    {
1327
        $repository = $this->getRepository();
1328
1329
        $objectStateId = $this->generateId('objectstate', 2);
1330
        // $objectStateId contains the ID of the "locked" state
1331
        $objectStateService = $repository->getObjectStateService();
1332
1333
        $loadedObjectState = $objectStateService->loadObjectState(
1334
            $objectStateId
1335
        );
1336
1337
        $updateStateStruct = $objectStateService->newObjectStateUpdateStruct();
1338
        // 'not_locked' is the identifier of already existing state
1339
        $updateStateStruct->identifier = 'not_locked';
1340
        $updateStateStruct->defaultLanguageCode = 'ger-DE';
1341
        $updateStateStruct->names = array(
1342
            'eng-US' => 'Somehow locked',
1343
            'ger-DE' => 'Irgendwie gelockt',
1344
        );
1345
        $updateStateStruct->descriptions = array(
1346
            'eng-US' => 'The object is somehow locked',
1347
            'ger-DE' => 'Sindelfingen',
1348
        );
1349
1350
        // This call will fail because state with
1351
        // 'not_locked' identifier already exists
1352
        $objectStateService->updateObjectState(
1353
            $loadedObjectState,
1354
            $updateStateStruct
1355
        );
1356
    }
1357
1358
    /**
1359
     * testUpdateObjectStateStructValues.