Code Duplication    Length = 38-45 lines in 3 locations

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

@@ 4619-4663 (lines=45) @@
4616
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4617
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4618
     */
4619
    public function testUpdateContentMetadataInTransactionWithRollback()
4620
    {
4621
        $repository = $this->getRepository();
4622
4623
        $contentId = $this->generateId('object', 12);
4624
        /* BEGIN: Use Case */
4625
        // $contentId is the ID of the "Administrator users" user group
4626
4627
        // Get the content service
4628
        $contentService = $repository->getContentService();
4629
4630
        // Load a ContentInfo object
4631
        $contentInfo = $contentService->loadContentInfo($contentId);
4632
4633
        // Store remoteId for later testing
4634
        $remoteId = $contentInfo->remoteId;
4635
4636
        // Start a transaction
4637
        $repository->beginTransaction();
4638
4639
        try {
4640
            // Get metadata update struct and change remoteId
4641
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4642
            $metadataUpdate->remoteId = md5(microtime(true));
4643
4644
            // Update the metadata of the published content object
4645
            $contentService->updateContentMetadata(
4646
                $contentInfo,
4647
                $metadataUpdate
4648
            );
4649
        } catch (Exception $e) {
4650
            // Cleanup hanging transaction on error
4651
            $repository->rollback();
4652
            throw $e;
4653
        }
4654
4655
        // Rollback all changes.
4656
        $repository->rollback();
4657
4658
        // Load current remoteId
4659
        $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4660
        /* END: Use Case */
4661
4662
        $this->assertEquals($remoteId, $remoteIdReloaded);
4663
    }
4664
4665
    /**
4666
     * Test for the updateContentMetadata() method.
@@ 4672-4716 (lines=45) @@
4669
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4670
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4671
     */
4672
    public function testUpdateContentMetadataInTransactionWithCommit()
4673
    {
4674
        $repository = $this->getRepository();
4675
4676
        $contentId = $this->generateId('object', 12);
4677
        /* BEGIN: Use Case */
4678
        // $contentId is the ID of the "Administrator users" user group
4679
4680
        // Get the content service
4681
        $contentService = $repository->getContentService();
4682
4683
        // Load a ContentInfo object
4684
        $contentInfo = $contentService->loadContentInfo($contentId);
4685
4686
        // Store remoteId for later testing
4687
        $remoteId = $contentInfo->remoteId;
4688
4689
        // Start a transaction
4690
        $repository->beginTransaction();
4691
4692
        try {
4693
            // Get metadata update struct and change remoteId
4694
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4695
            $metadataUpdate->remoteId = md5(microtime(true));
4696
4697
            // Update the metadata of the published content object
4698
            $contentService->updateContentMetadata(
4699
                $contentInfo,
4700
                $metadataUpdate
4701
            );
4702
4703
            // Commit all changes.
4704
            $repository->commit();
4705
        } catch (Exception $e) {
4706
            // Cleanup hanging transaction on error
4707
            $repository->rollback();
4708
            throw $e;
4709
        }
4710
4711
        // Load current remoteId
4712
        $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4713
        /* END: Use Case */
4714
4715
        $this->assertNotEquals($remoteId, $remoteIdReloaded);
4716
    }
4717
4718
    /**
4719
     * Test for the updateContentMetadata() method, and how cache + transactions play together.
@@ 4725-4762 (lines=38) @@
4722
     * @depends testUpdateContentMetadata
4723
     * @depends testLoadContentInfo
4724
     */
4725
    public function testUpdateContentMetadataCheckWithinTransaction()
4726
    {
4727
        $repository = $this->getRepository();
4728
        $contentService = $repository->getContentService();
4729
        $contentId = $this->generateId('object', 12);
4730
4731
        // Load a ContentInfo object, and warmup cache
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
4751
            // Check that it's been updated
4752
            $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4753
            $this->assertNotEquals($remoteId, $remoteIdReloaded);
4754
4755
            // Commit all changes.
4756
            $repository->commit();
4757
        } catch (Exception $e) {
4758
            // Cleanup hanging transaction on error
4759
            $repository->rollback();
4760
            throw $e;
4761
        }
4762
    }
4763
4764
    /**
4765
     * Test for the deleteVersion() method.