Code Duplication    Length = 40-44 lines in 3 locations

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

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