Code Duplication    Length = 45-45 lines in 2 locations

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

@@ 4203-4247 (lines=45) @@
4200
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4201
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4202
     */
4203
    public function testUpdateContentMetadataInTransactionWithRollback()
4204
    {
4205
        $repository = $this->getRepository();
4206
4207
        $contentId = $this->generateId('object', 12);
4208
        /* BEGIN: Use Case */
4209
        // $contentId is the ID of the "Administrator users" user group
4210
4211
        // Get the content service
4212
        $contentService = $repository->getContentService();
4213
4214
        // Load a ContentInfo object
4215
        $contentInfo = $contentService->loadContentInfo($contentId);
4216
4217
        // Store remoteId for later testing
4218
        $remoteId = $contentInfo->remoteId;
4219
4220
        // Start a transaction
4221
        $repository->beginTransaction();
4222
4223
        try {
4224
            // Get metadata update struct and change remoteId
4225
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4226
            $metadataUpdate->remoteId = md5(microtime(true));
4227
4228
            // Update the metadata of the published content object
4229
            $contentService->updateContentMetadata(
4230
                $contentInfo,
4231
                $metadataUpdate
4232
            );
4233
        } catch (Exception $e) {
4234
            // Cleanup hanging transaction on error
4235
            $repository->rollback();
4236
            throw $e;
4237
        }
4238
4239
        // Rollback all changes.
4240
        $repository->rollback();
4241
4242
        // Load current remoteId
4243
        $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4244
        /* END: Use Case */
4245
4246
        $this->assertEquals($remoteId, $remoteIdReloaded);
4247
    }
4248
4249
    /**
4250
     * Test for the updateContentMetadata() method.
@@ 4256-4300 (lines=45) @@
4253
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4254
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4255
     */
4256
    public function testUpdateContentMetadataInTransactionWithCommit()
4257
    {
4258
        $repository = $this->getRepository();
4259
4260
        $contentId = $this->generateId('object', 12);
4261
        /* BEGIN: Use Case */
4262
        // $contentId is the ID of the "Administrator users" user group
4263
4264
        // Get the content service
4265
        $contentService = $repository->getContentService();
4266
4267
        // Load a ContentInfo object
4268
        $contentInfo = $contentService->loadContentInfo($contentId);
4269
4270
        // Store remoteId for later testing
4271
        $remoteId = $contentInfo->remoteId;
4272
4273
        // Start a transaction
4274
        $repository->beginTransaction();
4275
4276
        try {
4277
            // Get metadata update struct and change remoteId
4278
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4279
            $metadataUpdate->remoteId = md5(microtime(true));
4280
4281
            // Update the metadata of the published content object
4282
            $contentService->updateContentMetadata(
4283
                $contentInfo,
4284
                $metadataUpdate
4285
            );
4286
4287
            // Commit all changes.
4288
            $repository->commit();
4289
        } catch (Exception $e) {
4290
            // Cleanup hanging transaction on error
4291
            $repository->rollback();
4292
            throw $e;
4293
        }
4294
4295
        // Load current remoteId
4296
        $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4297
        /* END: Use Case */
4298
4299
        $this->assertNotEquals($remoteId, $remoteIdReloaded);
4300
    }
4301
4302
    /**
4303
     * Test for the deleteVersion() method.