Code Duplication    Length = 47-47 lines in 2 locations

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

@@ 3917-3963 (lines=47) @@
3914
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
3915
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
3916
     */
3917
    public function testUpdateContentInTransactionWithRollback()
3918
    {
3919
        $repository = $this->getRepository();
3920
3921
        $contentId = $this->generateId('object', 12);
3922
        /* BEGIN: Use Case */
3923
        // $contentId is the ID of the "Administrator users" user group
3924
3925
        // Load content service
3926
        $contentService = $repository->getContentService();
3927
3928
        // Create a new user group draft
3929
        $draft = $contentService->createContentDraft(
3930
            $contentService->loadContentInfo($contentId)
3931
        );
3932
3933
        // Get an update struct and change the group name
3934
        $contentUpdate = $contentService->newContentUpdateStruct();
3935
        $contentUpdate->setField('name', 'Administrators', 'eng-US');
3936
3937
        // Start a transaction
3938
        $repository->beginTransaction();
3939
3940
        try {
3941
            // Update the group name
3942
            $draft = $contentService->updateContent(
3943
                $draft->getVersionInfo(),
3944
                $contentUpdate
3945
            );
3946
3947
            // Publish updated version
3948
            $contentService->publishVersion($draft->getVersionInfo());
3949
        } catch (Exception $e) {
3950
            // Cleanup hanging transaction on error
3951
            $repository->rollback();
3952
            throw $e;
3953
        }
3954
3955
        // Rollback all changes.
3956
        $repository->rollback();
3957
3958
        // Name will still be "Administrator users"
3959
        $name = $contentService->loadContent($contentId)->getFieldValue('name');
3960
        /* END: Use Case */
3961
3962
        $this->assertEquals('Administrator users', $name);
3963
    }
3964
3965
    /**
3966
     * Test for the updateContent() method.
@@ 3973-4019 (lines=47) @@
3970
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
3971
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
3972
     */
3973
    public function testUpdateContentInTransactionWithCommit()
3974
    {
3975
        $repository = $this->getRepository();
3976
3977
        $contentId = $this->generateId('object', 12);
3978
        /* BEGIN: Use Case */
3979
        // $contentId is the ID of the "Administrator users" user group
3980
3981
        // Load content service
3982
        $contentService = $repository->getContentService();
3983
3984
        // Create a new user group draft
3985
        $draft = $contentService->createContentDraft(
3986
            $contentService->loadContentInfo($contentId)
3987
        );
3988
3989
        // Get an update struct and change the group name
3990
        $contentUpdate = $contentService->newContentUpdateStruct();
3991
        $contentUpdate->setField('name', 'Administrators', 'eng-US');
3992
3993
        // Start a transaction
3994
        $repository->beginTransaction();
3995
3996
        try {
3997
            // Update the group name
3998
            $draft = $contentService->updateContent(
3999
                $draft->getVersionInfo(),
4000
                $contentUpdate
4001
            );
4002
4003
            // Publish updated version
4004
            $contentService->publishVersion($draft->getVersionInfo());
4005
4006
            // Commit all changes.
4007
            $repository->commit();
4008
        } catch (Exception $e) {
4009
            // Cleanup hanging transaction on error
4010
            $repository->rollback();
4011
            throw $e;
4012
        }
4013
4014
        // Name is now "Administrators"
4015
        $name = $contentService->loadContent($contentId)->getFieldValue('name', 'eng-US');
4016
        /* END: Use Case */
4017
4018
        $this->assertEquals('Administrators', $name);
4019
    }
4020
4021
    /**
4022
     * Test for the updateContentMetadata() method.