Code Duplication    Length = 47-47 lines in 2 locations

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

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