Code Duplication    Length = 45-45 lines in 2 locations

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

@@ 4720-4764 (lines=45) @@
4717
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4718
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4719
     */
4720
    public function testUpdateContentMetadataInTransactionWithRollback()
4721
    {
4722
        $repository = $this->getRepository();
4723
4724
        $contentId = $this->generateId('object', 12);
4725
        /* BEGIN: Use Case */
4726
        // $contentId is the ID of the "Administrator users" user group
4727
4728
        // Get the content service
4729
        $contentService = $repository->getContentService();
4730
4731
        // Load a ContentInfo object
4732
        $contentInfo = $contentService->loadContentInfo($contentId);
4733
4734
        // Store remoteId for later testing
4735
        $remoteId = $contentInfo->remoteId;
4736
4737
        // Start a transaction
4738
        $repository->beginTransaction();
4739
4740
        try {
4741
            // Get metadata update struct and change remoteId
4742
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4743
            $metadataUpdate->remoteId = md5(microtime(true));
4744
4745
            // Update the metadata of the published content object
4746
            $contentService->updateContentMetadata(
4747
                $contentInfo,
4748
                $metadataUpdate
4749
            );
4750
        } catch (Exception $e) {
4751
            // Cleanup hanging transaction on error
4752
            $repository->rollback();
4753
            throw $e;
4754
        }
4755
4756
        // Rollback all changes.
4757
        $repository->rollback();
4758
4759
        // Load current remoteId
4760
        $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4761
        /* END: Use Case */
4762
4763
        $this->assertEquals($remoteId, $remoteIdReloaded);
4764
    }
4765
4766
    /**
4767
     * Test for the updateContentMetadata() method.
@@ 4773-4817 (lines=45) @@
4770
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4771
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4772
     */
4773
    public function testUpdateContentMetadataInTransactionWithCommit()
4774
    {
4775
        $repository = $this->getRepository();
4776
4777
        $contentId = $this->generateId('object', 12);
4778
        /* BEGIN: Use Case */
4779
        // $contentId is the ID of the "Administrator users" user group
4780
4781
        // Get the content service
4782
        $contentService = $repository->getContentService();
4783
4784
        // Load a ContentInfo object
4785
        $contentInfo = $contentService->loadContentInfo($contentId);
4786
4787
        // Store remoteId for later testing
4788
        $remoteId = $contentInfo->remoteId;
4789
4790
        // Start a transaction
4791
        $repository->beginTransaction();
4792
4793
        try {
4794
            // Get metadata update struct and change remoteId
4795
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4796
            $metadataUpdate->remoteId = md5(microtime(true));
4797
4798
            // Update the metadata of the published content object
4799
            $contentService->updateContentMetadata(
4800
                $contentInfo,
4801
                $metadataUpdate
4802
            );
4803
4804
            // Commit all changes.
4805
            $repository->commit();
4806
        } catch (Exception $e) {
4807
            // Cleanup hanging transaction on error
4808
            $repository->rollback();
4809
            throw $e;
4810
        }
4811
4812
        // Load current remoteId
4813
        $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4814
        /* END: Use Case */
4815
4816
        $this->assertNotEquals($remoteId, $remoteIdReloaded);
4817
    }
4818
4819
    /**
4820
     * Test for the deleteVersion() method.