Code Duplication    Length = 40-44 lines in 3 locations

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

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