Code Duplication    Length = 40-44 lines in 3 locations

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

@@ 3943-3982 (lines=40) @@
3940
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft
3941
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
3942
     */
3943
    public function testCreateContentDraftInTransactionWithCommit()
3944
    {
3945
        $repository = $this->getRepository();
3946
3947
        $contentId = $this->generateId('object', 12);
3948
        /* BEGIN: Use Case */
3949
        // $contentId is the ID of the "Administrator users" user group
3950
3951
        // Get the content service
3952
        $contentService = $repository->getContentService();
3953
3954
        // Load the user group content object
3955
        $content = $contentService->loadContent($contentId);
3956
3957
        // Start a new transaction
3958
        $repository->beginTransaction();
3959
3960
        try {
3961
            // Create a new draft
3962
            $drafted = $contentService->createContentDraft($content->contentInfo);
3963
3964
            // Store version number for later reuse
3965
            $versionNo = $drafted->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
        $content = $contentService->loadContent($contentId, null, $versionNo);
3976
        /* END: Use Case */
3977
3978
        $this->assertEquals(
3979
            $versionNo,
3980
            $content->getVersionInfo()->versionNo
3981
        );
3982
    }
3983
3984
    /**
3985
     * Test for the publishVersion() method.
@@ 3991-4034 (lines=44) @@
3988
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
3989
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
3990
     */
3991
    public function testPublishVersionInTransactionWithRollback()
3992
    {
3993
        $repository = $this->getRepository();
3994
3995
        $contentId = $this->generateId('object', 12);
3996
        /* BEGIN: Use Case */
3997
        // $contentId is the ID of the "Administrator users" user group
3998
3999
        // Get the content service
4000
        $contentService = $repository->getContentService();
4001
4002
        // Load the user group content object
4003
        $content = $contentService->loadContent($contentId);
4004
4005
        // Start a new transaction
4006
        $repository->beginTransaction();
4007
4008
        try {
4009
            $draftVersion = $contentService->createContentDraft($content->contentInfo)->getVersionInfo();
4010
4011
            // Publish a new version
4012
            $content = $contentService->publishVersion($draftVersion);
4013
4014
            // Store version number for later reuse
4015
            $versionNo = $content->versionInfo->versionNo;
4016
        } catch (Exception $e) {
4017
            // Cleanup hanging transaction on error
4018
            $repository->rollback();
4019
            throw $e;
4020
        }
4021
4022
        // Rollback
4023
        $repository->rollback();
4024
4025
        try {
4026
            // This call will fail with a "NotFoundException"
4027
            $contentService->loadContent($contentId, null, $versionNo);
4028
        } catch (NotFoundException $e) {
4029
            return;
4030
        }
4031
        /* END: Use Case */
4032
4033
        $this->fail('Can still load content draft after rollback');
4034
    }
4035
4036
    /**
4037
     * Test for the publishVersion() method.
@@ 4043-4082 (lines=40) @@
4040
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
4041
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo
4042
     */
4043
    public function testPublishVersionInTransactionWithCommit()
4044
    {
4045
        $repository = $this->getRepository();
4046
4047
        /* BEGIN: Use Case */
4048
        // ID of the "Administrator users" user group
4049
        $contentId = 12;
4050
4051
        // Get the content service
4052
        $contentService = $repository->getContentService();
4053
4054
        // Load the user group content object
4055
        $template = $contentService->loadContent($contentId);
4056
4057
        // Start a new transaction
4058
        $repository->beginTransaction();
4059
4060
        try {
4061
            // Publish a new version
4062
            $content = $contentService->publishVersion(
4063
                $contentService->createContentDraft($template->contentInfo)->getVersionInfo()
4064
            );
4065
4066
            // Store version number for later reuse
4067
            $versionNo = $content->versionInfo->versionNo;
4068
4069
            // Commit all changes
4070
            $repository->commit();
4071
        } catch (Exception $e) {
4072
            // Cleanup hanging transaction on error
4073
            $repository->rollback();
4074
            throw $e;
4075
        }
4076
4077
        // Load current version info
4078
        $versionInfo = $contentService->loadVersionInfo($content->contentInfo);
4079
        /* END: Use Case */
4080
4081
        $this->assertEquals($versionNo, $versionInfo->versionNo);
4082
    }
4083
4084
    /**
4085
     * Test for the updateContent() method.