Code Duplication    Length = 40-44 lines in 3 locations

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

@@ 3841-3880 (lines=40) @@
3838
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft
3839
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
3840
     */
3841
    public function testCreateContentDraftInTransactionWithCommit()
3842
    {
3843
        $repository = $this->getRepository();
3844
3845
        $contentId = $this->generateId('object', 12);
3846
        /* BEGIN: Use Case */
3847
        // $contentId is the ID of the "Administrator users" user group
3848
3849
        // Get the content service
3850
        $contentService = $repository->getContentService();
3851
3852
        // Load the user group content object
3853
        $content = $contentService->loadContent($contentId);
3854
3855
        // Start a new transaction
3856
        $repository->beginTransaction();
3857
3858
        try {
3859
            // Create a new draft
3860
            $drafted = $contentService->createContentDraft($content->contentInfo);
3861
3862
            // Store version number for later reuse
3863
            $versionNo = $drafted->versionInfo->versionNo;
3864
3865
            // Commit all changes
3866
            $repository->commit();
3867
        } catch (Exception $e) {
3868
            // Cleanup hanging transaction on error
3869
            $repository->rollback();
3870
            throw $e;
3871
        }
3872
3873
        $content = $contentService->loadContent($contentId, null, $versionNo);
3874
        /* END: Use Case */
3875
3876
        $this->assertEquals(
3877
            $versionNo,
3878
            $content->getVersionInfo()->versionNo
3879
        );
3880
    }
3881
3882
    /**
3883
     * Test for the publishVersion() method.
@@ 3889-3932 (lines=44) @@
3886
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
3887
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
3888
     */
3889
    public function testPublishVersionInTransactionWithRollback()
3890
    {
3891
        $repository = $this->getRepository();
3892
3893
        $contentId = $this->generateId('object', 12);
3894
        /* BEGIN: Use Case */
3895
        // $contentId is the ID of the "Administrator users" user group
3896
3897
        // Get the content service
3898
        $contentService = $repository->getContentService();
3899
3900
        // Load the user group content object
3901
        $content = $contentService->loadContent($contentId);
3902
3903
        // Start a new transaction
3904
        $repository->beginTransaction();
3905
3906
        try {
3907
            $draftVersion = $contentService->createContentDraft($content->contentInfo)->getVersionInfo();
3908
3909
            // Publish a new version
3910
            $content = $contentService->publishVersion($draftVersion);
3911
3912
            // Store version number for later reuse
3913
            $versionNo = $content->versionInfo->versionNo;
3914
        } catch (Exception $e) {
3915
            // Cleanup hanging transaction on error
3916
            $repository->rollback();
3917
            throw $e;
3918
        }
3919
3920
        // Rollback
3921
        $repository->rollback();
3922
3923
        try {
3924
            // This call will fail with a "NotFoundException"
3925
            $contentService->loadContent($contentId, null, $versionNo);
3926
        } catch (NotFoundException $e) {
3927
            return;
3928
        }
3929
        /* END: Use Case */
3930
3931
        $this->fail('Can still load content draft after rollback');
3932
    }
3933
3934
    /**
3935
     * Test for the publishVersion() method.
@@ 3941-3980 (lines=40) @@
3938
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
3939
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo
3940
     */
3941
    public function testPublishVersionInTransactionWithCommit()
3942
    {
3943
        $repository = $this->getRepository();
3944
3945
        /* BEGIN: Use Case */
3946
        // ID of the "Administrator users" user group
3947
        $contentId = 12;
3948
3949
        // Get the content service
3950
        $contentService = $repository->getContentService();
3951
3952
        // Load the user group content object
3953
        $template = $contentService->loadContent($contentId);
3954
3955
        // Start a new transaction
3956
        $repository->beginTransaction();
3957
3958
        try {
3959
            // Publish a new version
3960
            $content = $contentService->publishVersion(
3961
                $contentService->createContentDraft($template->contentInfo)->getVersionInfo()
3962
            );
3963
3964
            // Store version number for later reuse
3965
            $versionNo = $content->versionInfo->versionNo;
3966
3967
            // Commit all changes
3968
            $repository->commit();
3969
        } catch (Exception $e) {
3970
            // Cleanup hanging transaction on error
3971
            $repository->rollback();
3972
            throw $e;
3973
        }
3974
3975
        // Load current version info
3976
        $versionInfo = $contentService->loadVersionInfo($content->contentInfo);
3977
        /* END: Use Case */
3978
3979
        $this->assertEquals($versionNo, $versionInfo->versionNo);
3980
    }
3981
3982
    /**
3983
     * Test for the updateContent() method.