Code Duplication    Length = 42-42 lines in 2 locations

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

@@ 4449-4490 (lines=42) @@
4446
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4447
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4448
     */
4449
    public function testUpdateContentMetadataInTransactionWithRollback()
4450
    {
4451
        $repository = $this->getRepository();
4452
4453
        $contentId = $this->generateId('object', 12);
4454
        /* BEGIN: Use Case */
4455
        // $contentId is the ID of the "Administrator users" user group
4456
4457
        // Load a ContentInfo object
4458
        $contentInfo = $this->contentService->loadContentInfo($contentId);
4459
4460
        // Store remoteId for later testing
4461
        $remoteId = $contentInfo->remoteId;
4462
4463
        // Start a transaction
4464
        $repository->beginTransaction();
4465
4466
        try {
4467
            // Get metadata update struct and change remoteId
4468
            $metadataUpdate = $this->contentService->newContentMetadataUpdateStruct();
4469
            $metadataUpdate->remoteId = md5(microtime(true));
4470
4471
            // Update the metadata of the published content object
4472
            $this->contentService->updateContentMetadata(
4473
                $contentInfo,
4474
                $metadataUpdate
4475
            );
4476
        } catch (Exception $e) {
4477
            // Cleanup hanging transaction on error
4478
            $repository->rollback();
4479
            throw $e;
4480
        }
4481
4482
        // Rollback all changes.
4483
        $repository->rollback();
4484
4485
        // Load current remoteId
4486
        $remoteIdReloaded = $this->contentService->loadContentInfo($contentId)->remoteId;
4487
        /* END: Use Case */
4488
4489
        $this->assertEquals($remoteId, $remoteIdReloaded);
4490
    }
4491
4492
    /**
4493
     * Test for the updateContentMetadata() method.
@@ 4499-4540 (lines=42) @@
4496
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4497
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4498
     */
4499
    public function testUpdateContentMetadataInTransactionWithCommit()
4500
    {
4501
        $repository = $this->getRepository();
4502
4503
        $contentId = $this->generateId('object', 12);
4504
        /* BEGIN: Use Case */
4505
        // $contentId is the ID of the "Administrator users" user group
4506
4507
        // Load a ContentInfo object
4508
        $contentInfo = $this->contentService->loadContentInfo($contentId);
4509
4510
        // Store remoteId for later testing
4511
        $remoteId = $contentInfo->remoteId;
4512
4513
        // Start a transaction
4514
        $repository->beginTransaction();
4515
4516
        try {
4517
            // Get metadata update struct and change remoteId
4518
            $metadataUpdate = $this->contentService->newContentMetadataUpdateStruct();
4519
            $metadataUpdate->remoteId = md5(microtime(true));
4520
4521
            // Update the metadata of the published content object
4522
            $this->contentService->updateContentMetadata(
4523
                $contentInfo,
4524
                $metadataUpdate
4525
            );
4526
4527
            // Commit all changes.
4528
            $repository->commit();
4529
        } catch (Exception $e) {
4530
            // Cleanup hanging transaction on error
4531
            $repository->rollback();
4532
            throw $e;
4533
        }
4534
4535
        // Load current remoteId
4536
        $remoteIdReloaded = $this->contentService->loadContentInfo($contentId)->remoteId;
4537
        /* END: Use Case */
4538
4539
        $this->assertNotEquals($remoteId, $remoteIdReloaded);
4540
    }
4541
4542
    /**
4543
     * Test for the deleteVersion() method.