Code Duplication    Length = 40-44 lines in 3 locations

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

@@ 3770-3809 (lines=40) @@
3767
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft
3768
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
3769
     */
3770
    public function testCreateContentDraftInTransactionWithCommit()
3771
    {
3772
        $repository = $this->getRepository();
3773
3774
        $contentId = $this->generateId('object', 12);
3775
        /* BEGIN: Use Case */
3776
        // $contentId is the ID of the "Administrator users" user group
3777
3778
        // Get the content service
3779
        $contentService = $repository->getContentService();
3780
3781
        // Load the user group content object
3782
        $content = $contentService->loadContent($contentId);
3783
3784
        // Start a new transaction
3785
        $repository->beginTransaction();
3786
3787
        try {
3788
            // Create a new draft
3789
            $drafted = $contentService->createContentDraft($content->contentInfo);
3790
3791
            // Store version number for later reuse
3792
            $versionNo = $drafted->versionInfo->versionNo;
3793
3794
            // Commit all changes
3795
            $repository->commit();
3796
        } catch (Exception $e) {
3797
            // Cleanup hanging transaction on error
3798
            $repository->rollback();
3799
            throw $e;
3800
        }
3801
3802
        $content = $contentService->loadContent($contentId, null, $versionNo);
3803
        /* END: Use Case */
3804
3805
        $this->assertEquals(
3806
            $versionNo,
3807
            $content->getVersionInfo()->versionNo
3808
        );
3809
    }
3810
3811
    /**
3812
     * Test for the publishVersion() method.
@@ 3818-3861 (lines=44) @@
3815
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
3816
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
3817
     */
3818
    public function testPublishVersionInTransactionWithRollback()
3819
    {
3820
        $repository = $this->getRepository();
3821
3822
        $contentId = $this->generateId('object', 12);
3823
        /* BEGIN: Use Case */
3824
        // $contentId is the ID of the "Administrator users" user group
3825
3826
        // Get the content service
3827
        $contentService = $repository->getContentService();
3828
3829
        // Load the user group content object
3830
        $content = $contentService->loadContent($contentId);
3831
3832
        // Start a new transaction
3833
        $repository->beginTransaction();
3834
3835
        try {
3836
            $draftVersion = $contentService->createContentDraft($content->contentInfo)->getVersionInfo();
3837
3838
            // Publish a new version
3839
            $content = $contentService->publishVersion($draftVersion);
3840
3841
            // Store version number for later reuse
3842
            $versionNo = $content->versionInfo->versionNo;
3843
        } catch (Exception $e) {
3844
            // Cleanup hanging transaction on error
3845
            $repository->rollback();
3846
            throw $e;
3847
        }
3848
3849
        // Rollback
3850
        $repository->rollback();
3851
3852
        try {
3853
            // This call will fail with a "NotFoundException"
3854
            $contentService->loadContent($contentId, null, $versionNo);
3855
        } catch (NotFoundException $e) {
3856
            return;
3857
        }
3858
        /* END: Use Case */
3859
3860
        $this->fail('Can still load content draft after rollback');
3861
    }
3862
3863
    /**
3864
     * Test for the publishVersion() method.
@@ 3870-3909 (lines=40) @@
3867
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
3868
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo
3869
     */
3870
    public function testPublishVersionInTransactionWithCommit()
3871
    {
3872
        $repository = $this->getRepository();
3873
3874
        /* BEGIN: Use Case */
3875
        // ID of the "Administrator users" user group
3876
        $contentId = 12;
3877
3878
        // Get the content service
3879
        $contentService = $repository->getContentService();
3880
3881
        // Load the user group content object
3882
        $template = $contentService->loadContent($contentId);
3883
3884
        // Start a new transaction
3885
        $repository->beginTransaction();
3886
3887
        try {
3888
            // Publish a new version
3889
            $content = $contentService->publishVersion(
3890
                $contentService->createContentDraft($template->contentInfo)->getVersionInfo()
3891
            );
3892
3893
            // Store version number for later reuse
3894
            $versionNo = $content->versionInfo->versionNo;
3895
3896
            // Commit all changes
3897
            $repository->commit();
3898
        } catch (Exception $e) {
3899
            // Cleanup hanging transaction on error
3900
            $repository->rollback();
3901
            throw $e;
3902
        }
3903
3904
        // Load current version info
3905
        $versionInfo = $contentService->loadVersionInfo($content->contentInfo);
3906
        /* END: Use Case */
3907
3908
        $this->assertEquals($versionNo, $versionInfo->versionNo);
3909
    }
3910
3911
    /**
3912
     * Test for the updateContent() method.