Code Duplication    Length = 40-44 lines in 3 locations

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

@@ 3888-3927 (lines=40) @@
3885
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft
3886
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
3887
     */
3888
    public function testCreateContentDraftInTransactionWithCommit()
3889
    {
3890
        $repository = $this->getRepository();
3891
3892
        $contentId = $this->generateId('object', 12);
3893
        /* BEGIN: Use Case */
3894
        // $contentId is the ID of the "Administrator users" user group
3895
3896
        // Get the content service
3897
        $contentService = $repository->getContentService();
3898
3899
        // Load the user group content object
3900
        $content = $contentService->loadContent($contentId);
3901
3902
        // Start a new transaction
3903
        $repository->beginTransaction();
3904
3905
        try {
3906
            // Create a new draft
3907
            $drafted = $contentService->createContentDraft($content->contentInfo);
3908
3909
            // Store version number for later reuse
3910
            $versionNo = $drafted->versionInfo->versionNo;
3911
3912
            // Commit all changes
3913
            $repository->commit();
3914
        } catch (Exception $e) {
3915
            // Cleanup hanging transaction on error
3916
            $repository->rollback();
3917
            throw $e;
3918
        }
3919
3920
        $content = $contentService->loadContent($contentId, null, $versionNo);
3921
        /* END: Use Case */
3922
3923
        $this->assertEquals(
3924
            $versionNo,
3925
            $content->getVersionInfo()->versionNo
3926
        );
3927
    }
3928
3929
    /**
3930
     * Test for the publishVersion() method.
@@ 3936-3979 (lines=44) @@
3933
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
3934
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
3935
     */
3936
    public function testPublishVersionInTransactionWithRollback()
3937
    {
3938
        $repository = $this->getRepository();
3939
3940
        $contentId = $this->generateId('object', 12);
3941
        /* BEGIN: Use Case */
3942
        // $contentId is the ID of the "Administrator users" user group
3943
3944
        // Get the content service
3945
        $contentService = $repository->getContentService();
3946
3947
        // Load the user group content object
3948
        $content = $contentService->loadContent($contentId);
3949
3950
        // Start a new transaction
3951
        $repository->beginTransaction();
3952
3953
        try {
3954
            $draftVersion = $contentService->createContentDraft($content->contentInfo)->getVersionInfo();
3955
3956
            // Publish a new version
3957
            $content = $contentService->publishVersion($draftVersion);
3958
3959
            // Store version number for later reuse
3960
            $versionNo = $content->versionInfo->versionNo;
3961
        } catch (Exception $e) {
3962
            // Cleanup hanging transaction on error
3963
            $repository->rollback();
3964
            throw $e;
3965
        }
3966
3967
        // Rollback
3968
        $repository->rollback();
3969
3970
        try {
3971
            // This call will fail with a "NotFoundException"
3972
            $contentService->loadContent($contentId, null, $versionNo);
3973
        } catch (NotFoundException $e) {
3974
            return;
3975
        }
3976
        /* END: Use Case */
3977
3978
        $this->fail('Can still load content draft after rollback');
3979
    }
3980
3981
    /**
3982
     * Test for the publishVersion() method.
@@ 3988-4027 (lines=40) @@
3985
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
3986
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo
3987
     */
3988
    public function testPublishVersionInTransactionWithCommit()
3989
    {
3990
        $repository = $this->getRepository();
3991
3992
        /* BEGIN: Use Case */
3993
        // ID of the "Administrator users" user group
3994
        $contentId = 12;
3995
3996
        // Get the content service
3997
        $contentService = $repository->getContentService();
3998
3999
        // Load the user group content object
4000
        $template = $contentService->loadContent($contentId);
4001
4002
        // Start a new transaction
4003
        $repository->beginTransaction();
4004
4005
        try {
4006
            // Publish a new version
4007
            $content = $contentService->publishVersion(
4008
                $contentService->createContentDraft($template->contentInfo)->getVersionInfo()
4009
            );
4010
4011
            // Store version number for later reuse
4012
            $versionNo = $content->versionInfo->versionNo;
4013
4014
            // Commit all changes
4015
            $repository->commit();
4016
        } catch (Exception $e) {
4017
            // Cleanup hanging transaction on error
4018
            $repository->rollback();
4019
            throw $e;
4020
        }
4021
4022
        // Load current version info
4023
        $versionInfo = $contentService->loadVersionInfo($content->contentInfo);
4024
        /* END: Use Case */
4025
4026
        $this->assertEquals($versionNo, $versionInfo->versionNo);
4027
    }
4028
4029
    /**
4030
     * Test for the updateContent() method.