Code Duplication    Length = 45-45 lines in 2 locations

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

@@ 4751-4795 (lines=45) @@
4748
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4749
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4750
     */
4751
    public function testUpdateContentMetadataInTransactionWithRollback()
4752
    {
4753
        $repository = $this->getRepository();
4754
4755
        $contentId = $this->generateId('object', 12);
4756
        /* BEGIN: Use Case */
4757
        // $contentId is the ID of the "Administrator users" user group
4758
4759
        // Get the content service
4760
        $contentService = $repository->getContentService();
4761
4762
        // Load a ContentInfo object
4763
        $contentInfo = $contentService->loadContentInfo($contentId);
4764
4765
        // Store remoteId for later testing
4766
        $remoteId = $contentInfo->remoteId;
4767
4768
        // Start a transaction
4769
        $repository->beginTransaction();
4770
4771
        try {
4772
            // Get metadata update struct and change remoteId
4773
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4774
            $metadataUpdate->remoteId = md5(microtime(true));
4775
4776
            // Update the metadata of the published content object
4777
            $contentService->updateContentMetadata(
4778
                $contentInfo,
4779
                $metadataUpdate
4780
            );
4781
        } catch (Exception $e) {
4782
            // Cleanup hanging transaction on error
4783
            $repository->rollback();
4784
            throw $e;
4785
        }
4786
4787
        // Rollback all changes.
4788
        $repository->rollback();
4789
4790
        // Load current remoteId
4791
        $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4792
        /* END: Use Case */
4793
4794
        $this->assertEquals($remoteId, $remoteIdReloaded);
4795
    }
4796
4797
    /**
4798
     * Test for the updateContentMetadata() method.
@@ 4804-4848 (lines=45) @@
4801
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4802
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4803
     */
4804
    public function testUpdateContentMetadataInTransactionWithCommit()
4805
    {
4806
        $repository = $this->getRepository();
4807
4808
        $contentId = $this->generateId('object', 12);
4809
        /* BEGIN: Use Case */
4810
        // $contentId is the ID of the "Administrator users" user group
4811
4812
        // Get the content service
4813
        $contentService = $repository->getContentService();
4814
4815
        // Load a ContentInfo object
4816
        $contentInfo = $contentService->loadContentInfo($contentId);
4817
4818
        // Store remoteId for later testing
4819
        $remoteId = $contentInfo->remoteId;
4820
4821
        // Start a transaction
4822
        $repository->beginTransaction();
4823
4824
        try {
4825
            // Get metadata update struct and change remoteId
4826
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4827
            $metadataUpdate->remoteId = md5(microtime(true));
4828
4829
            // Update the metadata of the published content object
4830
            $contentService->updateContentMetadata(
4831
                $contentInfo,
4832
                $metadataUpdate
4833
            );
4834
4835
            // Commit all changes.
4836
            $repository->commit();
4837
        } catch (Exception $e) {
4838
            // Cleanup hanging transaction on error
4839
            $repository->rollback();
4840
            throw $e;
4841
        }
4842
4843
        // Load current remoteId
4844
        $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4845
        /* END: Use Case */
4846
4847
        $this->assertNotEquals($remoteId, $remoteIdReloaded);
4848
    }
4849
4850
    /**
4851
     * Test for the deleteVersion() method.