Code Duplication    Length = 28-30 lines in 4 locations

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

@@ 1107-1136 (lines=30) @@
1104
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
1105
     * @depends testLoadObjectState
1106
     */
1107
    public function testGetContentState()
1108
    {
1109
        $repository = $this->getRepository();
1110
1111
        $anonymousUserId = $this->generateId('user', 10);
1112
        $ezLockObjectStateGroupId = $this->generateId('objectstategroup', 2);
1113
        /* BEGIN: Use Case */
1114
        // $anonymousUserId is the content ID of "Anonymous User"
1115
        $contentService = $repository->getContentService();
1116
        $objectStateService = $repository->getObjectStateService();
1117
1118
        $contentInfo = $contentService->loadContentInfo($anonymousUserId);
1119
1120
        $ezLockObjectStateGroup = $objectStateService->loadObjectStateGroup(
1121
            $ezLockObjectStateGroupId
1122
        );
1123
1124
        // Loads the state of $contentInfo in the "ez_lock" object state group
1125
        $ezLockObjectState = $objectStateService->getContentState(
1126
            $contentInfo,
1127
            $ezLockObjectStateGroup
1128
        );
1129
        /* END: Use Case */
1130
1131
        $this->assertInstanceOf(
1132
            'eZ\\Publish\\API\\Repository\\Values\\ObjectState\\ObjectState',
1133
            $ezLockObjectState
1134
        );
1135
        $this->assertEquals('not_locked', $ezLockObjectState->identifier);
1136
    }
1137
1138
    /**
1139
     * testGetInitialObjectState.

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

@@ 90-117 (lines=28) @@
87
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
88
     * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testUpdateSection
89
     */
90
    public function testUpdateSectionThrowsUnauthorizedException()
91
    {
92
        $repository = $this->getRepository();
93
94
        $standardSectionId = $this->generateId('section', 1);
95
        $anonymousUserId = $this->generateId('user', 10);
96
        /* BEGIN: Use Case */
97
        // $anonymousUserId is the ID of the "Anonymous" user in a eZ
98
        // Publish demo installation.
99
        // $standardSectionId is the ID of the "Standard" section in a eZ
100
        // Publish demo installation.
101
102
        $userService = $repository->getUserService();
103
        $sectionService = $repository->getSectionService();
104
105
        $section = $sectionService->loadSection($standardSectionId);
106
107
        $sectionUpdate = $sectionService->newSectionUpdateStruct();
108
        $sectionUpdate->name = 'New section name';
109
        $sectionUpdate->identifier = 'newUniqueKey';
110
111
        // Set anonymous user
112
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
113
114
        // This call will fail with a "UnauthorizedException"
115
        $sectionService->updateSection($section, $sectionUpdate);
116
        /* END: Use Case */
117
    }
118
119
    /**
120
     * Test for the loadSections() method.

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

@@ 200-227 (lines=28) @@
197
     * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testLoadSection
198
     * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testNewSectionUpdateStruct
199
     */
200
    public function testUpdateSection()
201
    {
202
        $repository = $this->getRepository();
203
204
        $standardSectionId = $this->generateId('section', 1);
205
        /* BEGIN: Use Case */
206
        // $standardSectionId contains the ID of the "Standard" section in a eZ
207
        // Publish demo installation.
208
209
        $sectionService = $repository->getSectionService();
210
211
        $section = $sectionService->loadSection($standardSectionId);
212
213
        $sectionUpdate = $sectionService->newSectionUpdateStruct();
214
        $sectionUpdate->name = 'New section name';
215
        $sectionUpdate->identifier = 'newUniqueKey';
216
217
        $updatedSection = $sectionService->updateSection($section, $sectionUpdate);
218
        /* END: Use Case */
219
220
        // Verify that service returns an instance of Section
221
        $this->assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Section', $updatedSection);
222
223
        // Verify that the service also persists the changes
224
        $updatedSection = $sectionService->loadSection($standardSectionId);
225
226
        $this->assertEquals('New section name', $updatedSection->name);
227
    }
228
229
    /**
230
     * Test for the updateSection() method.
@@ 321-348 (lines=28) @@
318
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
319
     * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testUpdateSection
320
     */
321
    public function testUpdateSectionThrowsInvalidArgumentException()
322
    {
323
        $repository = $this->getRepository();
324
325
        $standardSectionId = $this->generateId('section', 1);
326
        /* BEGIN: Use Case */
327
        // $standardSectionId contains the ID of the "Standard" section in a eZ
328
        // Publish demo installation.
329
330
        $sectionService = $repository->getSectionService();
331
332
        // Create section with conflict identifier
333
        $sectionCreate = $sectionService->newSectionCreateStruct();
334
        $sectionCreate->name = 'Conflict section';
335
        $sectionCreate->identifier = 'conflictKey';
336
337
        $sectionService->createSection($sectionCreate);
338
339
        // Load an existing section and update to an existing identifier
340
        $section = $sectionService->loadSection($standardSectionId);
341
342
        $sectionUpdate = $sectionService->newSectionUpdateStruct();
343
        $sectionUpdate->identifier = 'conflictKey';
344
345
        // This call should fail with an InvalidArgumentException
346
        $sectionService->updateSection($section, $sectionUpdate);
347
        /* END: Use Case */
348
    }
349
350
    /**
351
     * Test for the loadSections() method.