Code Duplication    Length = 45-45 lines in 2 locations

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

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