Code Duplication    Length = 45-45 lines in 2 locations

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

@@ 4425-4469 (lines=45) @@
4422
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4423
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4424
     */
4425
    public function testUpdateContentMetadataInTransactionWithRollback()
4426
    {
4427
        $repository = $this->getRepository();
4428
4429
        $contentId = $this->generateId('object', 12);
4430
        /* BEGIN: Use Case */
4431
        // $contentId is the ID of the "Administrator users" user group
4432
4433
        // Get the content service
4434
        $contentService = $repository->getContentService();
4435
4436
        // Load a ContentInfo object
4437
        $contentInfo = $contentService->loadContentInfo($contentId);
4438
4439
        // Store remoteId for later testing
4440
        $remoteId = $contentInfo->remoteId;
4441
4442
        // Start a transaction
4443
        $repository->beginTransaction();
4444
4445
        try {
4446
            // Get metadata update struct and change remoteId
4447
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4448
            $metadataUpdate->remoteId = md5(microtime(true));
4449
4450
            // Update the metadata of the published content object
4451
            $contentService->updateContentMetadata(
4452
                $contentInfo,
4453
                $metadataUpdate
4454
            );
4455
        } catch (Exception $e) {
4456
            // Cleanup hanging transaction on error
4457
            $repository->rollback();
4458
            throw $e;
4459
        }
4460
4461
        // Rollback all changes.
4462
        $repository->rollback();
4463
4464
        // Load current remoteId
4465
        $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4466
        /* END: Use Case */
4467
4468
        $this->assertEquals($remoteId, $remoteIdReloaded);
4469
    }
4470
4471
    /**
4472
     * Test for the updateContentMetadata() method.
@@ 4478-4522 (lines=45) @@
4475
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4476
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4477
     */
4478
    public function testUpdateContentMetadataInTransactionWithCommit()
4479
    {
4480
        $repository = $this->getRepository();
4481
4482
        $contentId = $this->generateId('object', 12);
4483
        /* BEGIN: Use Case */
4484
        // $contentId is the ID of the "Administrator users" user group
4485
4486
        // Get the content service
4487
        $contentService = $repository->getContentService();
4488
4489
        // Load a ContentInfo object
4490
        $contentInfo = $contentService->loadContentInfo($contentId);
4491
4492
        // Store remoteId for later testing
4493
        $remoteId = $contentInfo->remoteId;
4494
4495
        // Start a transaction
4496
        $repository->beginTransaction();
4497
4498
        try {
4499
            // Get metadata update struct and change remoteId
4500
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4501
            $metadataUpdate->remoteId = md5(microtime(true));
4502
4503
            // Update the metadata of the published content object
4504
            $contentService->updateContentMetadata(
4505
                $contentInfo,
4506
                $metadataUpdate
4507
            );
4508
4509
            // Commit all changes.
4510
            $repository->commit();
4511
        } catch (Exception $e) {
4512
            // Cleanup hanging transaction on error
4513
            $repository->rollback();
4514
            throw $e;
4515
        }
4516
4517
        // Load current remoteId
4518
        $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4519
        /* END: Use Case */
4520
4521
        $this->assertNotEquals($remoteId, $remoteIdReloaded);
4522
    }
4523
4524
    /**
4525
     * Test for the deleteVersion() method.