Code Duplication    Length = 45-45 lines in 2 locations

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

@@ 4148-4192 (lines=45) @@
4145
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4146
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4147
     */
4148
    public function testUpdateContentMetadataInTransactionWithRollback()
4149
    {
4150
        $repository = $this->getRepository();
4151
4152
        $contentId = $this->generateId('object', 12);
4153
        /* BEGIN: Use Case */
4154
        // $contentId is the ID of the "Administrator users" user group
4155
4156
        // Get the content service
4157
        $contentService = $repository->getContentService();
4158
4159
        // Load a ContentInfo object
4160
        $contentInfo = $contentService->loadContentInfo($contentId);
4161
4162
        // Store remoteId for later testing
4163
        $remoteId = $contentInfo->remoteId;
4164
4165
        // Start a transaction
4166
        $repository->beginTransaction();
4167
4168
        try {
4169
            // Get metadata update struct and change remoteId
4170
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4171
            $metadataUpdate->remoteId = md5(microtime(true));
4172
4173
            // Update the metadata of the published content object
4174
            $contentService->updateContentMetadata(
4175
                $contentInfo,
4176
                $metadataUpdate
4177
            );
4178
        } catch (Exception $e) {
4179
            // Cleanup hanging transaction on error
4180
            $repository->rollback();
4181
            throw $e;
4182
        }
4183
4184
        // Rollback all changes.
4185
        $repository->rollback();
4186
4187
        // Load current remoteId
4188
        $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4189
        /* END: Use Case */
4190
4191
        $this->assertEquals($remoteId, $remoteIdReloaded);
4192
    }
4193
4194
    /**
4195
     * Test for the updateContentMetadata() method.
@@ 4201-4245 (lines=45) @@
4198
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4199
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4200
     */
4201
    public function testUpdateContentMetadataInTransactionWithCommit()
4202
    {
4203
        $repository = $this->getRepository();
4204
4205
        $contentId = $this->generateId('object', 12);
4206
        /* BEGIN: Use Case */
4207
        // $contentId is the ID of the "Administrator users" user group
4208
4209
        // Get the content service
4210
        $contentService = $repository->getContentService();
4211
4212
        // Load a ContentInfo object
4213
        $contentInfo = $contentService->loadContentInfo($contentId);
4214
4215
        // Store remoteId for later testing
4216
        $remoteId = $contentInfo->remoteId;
4217
4218
        // Start a transaction
4219
        $repository->beginTransaction();
4220
4221
        try {
4222
            // Get metadata update struct and change remoteId
4223
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4224
            $metadataUpdate->remoteId = md5(microtime(true));
4225
4226
            // Update the metadata of the published content object
4227
            $contentService->updateContentMetadata(
4228
                $contentInfo,
4229
                $metadataUpdate
4230
            );
4231
4232
            // Commit all changes.
4233
            $repository->commit();
4234
        } catch (Exception $e) {
4235
            // Cleanup hanging transaction on error
4236
            $repository->rollback();
4237
            throw $e;
4238
        }
4239
4240
        // Load current remoteId
4241
        $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4242
        /* END: Use Case */
4243
4244
        $this->assertNotEquals($remoteId, $remoteIdReloaded);
4245
    }
4246
4247
    /**
4248
     * Test for the deleteVersion() method.