Code Duplication    Length = 47-47 lines in 2 locations

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

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