Code Duplication    Length = 40-44 lines in 3 locations

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

@@ 3768-3807 (lines=40) @@
3765
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft
3766
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
3767
     */
3768
    public function testCreateContentDraftInTransactionWithCommit()
3769
    {
3770
        $repository = $this->getRepository();
3771
3772
        $contentId = $this->generateId('object', 12);
3773
        /* BEGIN: Use Case */
3774
        // $contentId is the ID of the "Administrator users" user group
3775
3776
        // Get the content service
3777
        $contentService = $repository->getContentService();
3778
3779
        // Load the user group content object
3780
        $content = $contentService->loadContent($contentId);
3781
3782
        // Start a new transaction
3783
        $repository->beginTransaction();
3784
3785
        try {
3786
            // Create a new draft
3787
            $drafted = $contentService->createContentDraft($content->contentInfo);
3788
3789
            // Store version number for later reuse
3790
            $versionNo = $drafted->versionInfo->versionNo;
3791
3792
            // Commit all changes
3793
            $repository->commit();
3794
        } catch (Exception $e) {
3795
            // Cleanup hanging transaction on error
3796
            $repository->rollback();
3797
            throw $e;
3798
        }
3799
3800
        $content = $contentService->loadContent($contentId, null, $versionNo);
3801
        /* END: Use Case */
3802
3803
        $this->assertEquals(
3804
            $versionNo,
3805
            $content->getVersionInfo()->versionNo
3806
        );
3807
    }
3808
3809
    /**
3810
     * Test for the publishVersion() method.
@@ 3816-3859 (lines=44) @@
3813
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
3814
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
3815
     */
3816
    public function testPublishVersionInTransactionWithRollback()
3817
    {
3818
        $repository = $this->getRepository();
3819
3820
        $contentId = $this->generateId('object', 12);
3821
        /* BEGIN: Use Case */
3822
        // $contentId is the ID of the "Administrator users" user group
3823
3824
        // Get the content service
3825
        $contentService = $repository->getContentService();
3826
3827
        // Load the user group content object
3828
        $content = $contentService->loadContent($contentId);
3829
3830
        // Start a new transaction
3831
        $repository->beginTransaction();
3832
3833
        try {
3834
            $draftVersion = $contentService->createContentDraft($content->contentInfo)->getVersionInfo();
3835
3836
            // Publish a new version
3837
            $content = $contentService->publishVersion($draftVersion);
3838
3839
            // Store version number for later reuse
3840
            $versionNo = $content->versionInfo->versionNo;
3841
        } catch (Exception $e) {
3842
            // Cleanup hanging transaction on error
3843
            $repository->rollback();
3844
            throw $e;
3845
        }
3846
3847
        // Rollback
3848
        $repository->rollback();
3849
3850
        try {
3851
            // This call will fail with a "NotFoundException"
3852
            $contentService->loadContent($contentId, null, $versionNo);
3853
        } catch (NotFoundException $e) {
3854
            return;
3855
        }
3856
        /* END: Use Case */
3857
3858
        $this->fail('Can still load content draft after rollback');
3859
    }
3860
3861
    /**
3862
     * Test for the publishVersion() method.
@@ 3868-3907 (lines=40) @@
3865
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
3866
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo
3867
     */
3868
    public function testPublishVersionInTransactionWithCommit()
3869
    {
3870
        $repository = $this->getRepository();
3871
3872
        /* BEGIN: Use Case */
3873
        // ID of the "Administrator users" user group
3874
        $contentId = 12;
3875
3876
        // Get the content service
3877
        $contentService = $repository->getContentService();
3878
3879
        // Load the user group content object
3880
        $template = $contentService->loadContent($contentId);
3881
3882
        // Start a new transaction
3883
        $repository->beginTransaction();
3884
3885
        try {
3886
            // Publish a new version
3887
            $content = $contentService->publishVersion(
3888
                $contentService->createContentDraft($template->contentInfo)->getVersionInfo()
3889
            );
3890
3891
            // Store version number for later reuse
3892
            $versionNo = $content->versionInfo->versionNo;
3893
3894
            // Commit all changes
3895
            $repository->commit();
3896
        } catch (Exception $e) {
3897
            // Cleanup hanging transaction on error
3898
            $repository->rollback();
3899
            throw $e;
3900
        }
3901
3902
        // Load current version info
3903
        $versionInfo = $contentService->loadVersionInfo($content->contentInfo);
3904
        /* END: Use Case */
3905
3906
        $this->assertEquals($versionNo, $versionInfo->versionNo);
3907
    }
3908
3909
    /**
3910
     * Test for the updateContent() method.