Code Duplication    Length = 38-45 lines in 3 locations

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

@@ 4712-4756 (lines=45) @@
4709
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4710
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4711
     */
4712
    public function testUpdateContentMetadataInTransactionWithRollback()
4713
    {
4714
        $repository = $this->getRepository();
4715
4716
        $contentId = $this->generateId('object', 12);
4717
        /* BEGIN: Use Case */
4718
        // $contentId is the ID of the "Administrator users" user group
4719
4720
        // Get the content service
4721
        $contentService = $repository->getContentService();
4722
4723
        // Load a ContentInfo object
4724
        $contentInfo = $contentService->loadContentInfo($contentId);
4725
4726
        // Store remoteId for later testing
4727
        $remoteId = $contentInfo->remoteId;
4728
4729
        // Start a transaction
4730
        $repository->beginTransaction();
4731
4732
        try {
4733
            // Get metadata update struct and change remoteId
4734
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4735
            $metadataUpdate->remoteId = md5(microtime(true));
4736
4737
            // Update the metadata of the published content object
4738
            $contentService->updateContentMetadata(
4739
                $contentInfo,
4740
                $metadataUpdate
4741
            );
4742
        } catch (Exception $e) {
4743
            // Cleanup hanging transaction on error
4744
            $repository->rollback();
4745
            throw $e;
4746
        }
4747
4748
        // Rollback all changes.
4749
        $repository->rollback();
4750
4751
        // Load current remoteId
4752
        $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4753
        /* END: Use Case */
4754
4755
        $this->assertEquals($remoteId, $remoteIdReloaded);
4756
    }
4757
4758
    /**
4759
     * Test for the updateContentMetadata() method.
@@ 4765-4809 (lines=45) @@
4762
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4763
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4764
     */
4765
    public function testUpdateContentMetadataInTransactionWithCommit()
4766
    {
4767
        $repository = $this->getRepository();
4768
4769
        $contentId = $this->generateId('object', 12);
4770
        /* BEGIN: Use Case */
4771
        // $contentId is the ID of the "Administrator users" user group
4772
4773
        // Get the content service
4774
        $contentService = $repository->getContentService();
4775
4776
        // Load a ContentInfo object
4777
        $contentInfo = $contentService->loadContentInfo($contentId);
4778
4779
        // Store remoteId for later testing
4780
        $remoteId = $contentInfo->remoteId;
4781
4782
        // Start a transaction
4783
        $repository->beginTransaction();
4784
4785
        try {
4786
            // Get metadata update struct and change remoteId
4787
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4788
            $metadataUpdate->remoteId = md5(microtime(true));
4789
4790
            // Update the metadata of the published content object
4791
            $contentService->updateContentMetadata(
4792
                $contentInfo,
4793
                $metadataUpdate
4794
            );
4795
4796
            // Commit all changes.
4797
            $repository->commit();
4798
        } catch (Exception $e) {
4799
            // Cleanup hanging transaction on error
4800
            $repository->rollback();
4801
            throw $e;
4802
        }
4803
4804
        // Load current remoteId
4805
        $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4806
        /* END: Use Case */
4807
4808
        $this->assertNotEquals($remoteId, $remoteIdReloaded);
4809
    }
4810
4811
    /**
4812
     * Test for the updateContentMetadata() method, and how cache + transactions play together.
@@ 4818-4855 (lines=38) @@
4815
     * @depends testUpdateContentMetadata
4816
     * @depends testLoadContentInfo
4817
     */
4818
    public function testUpdateContentMetadataCheckWithinTransaction()
4819
    {
4820
        $repository = $this->getRepository();
4821
        $contentService = $repository->getContentService();
4822
        $contentId = $this->generateId('object', 12);
4823
4824
        // Load a ContentInfo object, and warmup cache
4825
        $contentInfo = $contentService->loadContentInfo($contentId);
4826
4827
        // Store remoteId for later testing
4828
        $remoteId = $contentInfo->remoteId;
4829
4830
        // Start a transaction
4831
        $repository->beginTransaction();
4832
4833
        try {
4834
            // Get metadata update struct and change remoteId
4835
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4836
            $metadataUpdate->remoteId = md5(microtime(true));
4837
4838
            // Update the metadata of the published content object
4839
            $contentService->updateContentMetadata(
4840
                $contentInfo,
4841
                $metadataUpdate
4842
            );
4843
4844
            // Check that it's been updated
4845
            $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4846
            $this->assertNotEquals($remoteId, $remoteIdReloaded);
4847
4848
            // Commit all changes.
4849
            $repository->commit();
4850
        } catch (Exception $e) {
4851
            // Cleanup hanging transaction on error
4852
            $repository->rollback();
4853
            throw $e;
4854
        }
4855
    }
4856
4857
    /**
4858
     * Test for the deleteVersion() method.