Code Duplication    Length = 45-45 lines in 2 locations

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

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