Code Duplication    Length = 45-45 lines in 2 locations

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

@@ 4623-4667 (lines=45) @@
4620
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4621
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4622
     */
4623
    public function testUpdateContentMetadataInTransactionWithRollback()
4624
    {
4625
        $repository = $this->getRepository();
4626
4627
        $contentId = $this->generateId('object', 12);
4628
        /* BEGIN: Use Case */
4629
        // $contentId is the ID of the "Administrator users" user group
4630
4631
        // Get the content service
4632
        $contentService = $repository->getContentService();
4633
4634
        // Load a ContentInfo object
4635
        $contentInfo = $contentService->loadContentInfo($contentId);
4636
4637
        // Store remoteId for later testing
4638
        $remoteId = $contentInfo->remoteId;
4639
4640
        // Start a transaction
4641
        $repository->beginTransaction();
4642
4643
        try {
4644
            // Get metadata update struct and change remoteId
4645
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4646
            $metadataUpdate->remoteId = md5(microtime(true));
4647
4648
            // Update the metadata of the published content object
4649
            $contentService->updateContentMetadata(
4650
                $contentInfo,
4651
                $metadataUpdate
4652
            );
4653
        } catch (Exception $e) {
4654
            // Cleanup hanging transaction on error
4655
            $repository->rollback();
4656
            throw $e;
4657
        }
4658
4659
        // Rollback all changes.
4660
        $repository->rollback();
4661
4662
        // Load current remoteId
4663
        $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4664
        /* END: Use Case */
4665
4666
        $this->assertEquals($remoteId, $remoteIdReloaded);
4667
    }
4668
4669
    /**
4670
     * Test for the updateContentMetadata() method.
@@ 4676-4720 (lines=45) @@
4673
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4674
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4675
     */
4676
    public function testUpdateContentMetadataInTransactionWithCommit()
4677
    {
4678
        $repository = $this->getRepository();
4679
4680
        $contentId = $this->generateId('object', 12);
4681
        /* BEGIN: Use Case */
4682
        // $contentId is the ID of the "Administrator users" user group
4683
4684
        // Get the content service
4685
        $contentService = $repository->getContentService();
4686
4687
        // Load a ContentInfo object
4688
        $contentInfo = $contentService->loadContentInfo($contentId);
4689
4690
        // Store remoteId for later testing
4691
        $remoteId = $contentInfo->remoteId;
4692
4693
        // Start a transaction
4694
        $repository->beginTransaction();
4695
4696
        try {
4697
            // Get metadata update struct and change remoteId
4698
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4699
            $metadataUpdate->remoteId = md5(microtime(true));
4700
4701
            // Update the metadata of the published content object
4702
            $contentService->updateContentMetadata(
4703
                $contentInfo,
4704
                $metadataUpdate
4705
            );
4706
4707
            // Commit all changes.
4708
            $repository->commit();
4709
        } catch (Exception $e) {
4710
            // Cleanup hanging transaction on error
4711
            $repository->rollback();
4712
            throw $e;
4713
        }
4714
4715
        // Load current remoteId
4716
        $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4717
        /* END: Use Case */
4718
4719
        $this->assertNotEquals($remoteId, $remoteIdReloaded);
4720
    }
4721
4722
    /**
4723
     * Test for the deleteVersion() method.