Code Duplication    Length = 38-45 lines in 3 locations

eZ/Publish/API/Repository/Tests/ContentServiceTest.php 3 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 updateContentMetadata() method, and how cache + transactions play together.
@@ 4826-4863 (lines=38) @@
4823
     * @depends testUpdateContentMetadata
4824
     * @depends testLoadContentInfo
4825
     */
4826
    public function testUpdateContentMetadataCheckWithinTransaction()
4827
    {
4828
        $repository = $this->getRepository();
4829
        $contentService = $repository->getContentService();
4830
        $contentId = $this->generateId('object', 12);
4831
4832
        // Load a ContentInfo object, and warmup cache
4833
        $contentInfo = $contentService->loadContentInfo($contentId);
4834
4835
        // Store remoteId for later testing
4836
        $remoteId = $contentInfo->remoteId;
4837
4838
        // Start a transaction
4839
        $repository->beginTransaction();
4840
4841
        try {
4842
            // Get metadata update struct and change remoteId
4843
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4844
            $metadataUpdate->remoteId = md5(microtime(true));
4845
4846
            // Update the metadata of the published content object
4847
            $contentService->updateContentMetadata(
4848
                $contentInfo,
4849
                $metadataUpdate
4850
            );
4851
4852
            // Check that it's been updated
4853
            $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4854
            $this->assertNotEquals($remoteId, $remoteIdReloaded);
4855
4856
            // Commit all changes.
4857
            $repository->commit();
4858
        } catch (Exception $e) {
4859
            // Cleanup hanging transaction on error
4860
            $repository->rollback();
4861
            throw $e;
4862
        }
4863
    }
4864
4865
    /**
4866
     * Test for the deleteVersion() method.