Code Duplication    Length = 47-47 lines in 2 locations

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

@@ 3990-4036 (lines=47) @@
3987
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
3988
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
3989
     */
3990
    public function testUpdateContentInTransactionWithRollback()
3991
    {
3992
        $repository = $this->getRepository();
3993
3994
        $contentId = $this->generateId('object', 12);
3995
        /* BEGIN: Use Case */
3996
        // $contentId is the ID of the "Administrator users" user group
3997
3998
        // Load content service
3999
        $contentService = $repository->getContentService();
4000
4001
        // Create a new user group draft
4002
        $draft = $contentService->createContentDraft(
4003
            $contentService->loadContentInfo($contentId)
4004
        );
4005
4006
        // Get an update struct and change the group name
4007
        $contentUpdate = $contentService->newContentUpdateStruct();
4008
        $contentUpdate->setField('name', 'Administrators', 'eng-US');
4009
4010
        // Start a transaction
4011
        $repository->beginTransaction();
4012
4013
        try {
4014
            // Update the group name
4015
            $draft = $contentService->updateContent(
4016
                $draft->getVersionInfo(),
4017
                $contentUpdate
4018
            );
4019
4020
            // Publish updated version
4021
            $contentService->publishVersion($draft->getVersionInfo());
4022
        } catch (Exception $e) {
4023
            // Cleanup hanging transaction on error
4024
            $repository->rollback();
4025
            throw $e;
4026
        }
4027
4028
        // Rollback all changes.
4029
        $repository->rollback();
4030
4031
        // Name will still be "Administrator users"
4032
        $name = $contentService->loadContent($contentId)->getFieldValue('name');
4033
        /* END: Use Case */
4034
4035
        $this->assertEquals('Administrator users', $name);
4036
    }
4037
4038
    /**
4039
     * Test for the updateContent() method.
@@ 4046-4092 (lines=47) @@
4043
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4044
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4045
     */
4046
    public function testUpdateContentInTransactionWithCommit()
4047
    {
4048
        $repository = $this->getRepository();
4049
4050
        $contentId = $this->generateId('object', 12);
4051
        /* BEGIN: Use Case */
4052
        // $contentId is the ID of the "Administrator users" user group
4053
4054
        // Load content service
4055
        $contentService = $repository->getContentService();
4056
4057
        // Create a new user group draft
4058
        $draft = $contentService->createContentDraft(
4059
            $contentService->loadContentInfo($contentId)
4060
        );
4061
4062
        // Get an update struct and change the group name
4063
        $contentUpdate = $contentService->newContentUpdateStruct();
4064
        $contentUpdate->setField('name', 'Administrators', 'eng-US');
4065
4066
        // Start a transaction
4067
        $repository->beginTransaction();
4068
4069
        try {
4070
            // Update the group name
4071
            $draft = $contentService->updateContent(
4072
                $draft->getVersionInfo(),
4073
                $contentUpdate
4074
            );
4075
4076
            // Publish updated version
4077
            $contentService->publishVersion($draft->getVersionInfo());
4078
4079
            // Commit all changes.
4080
            $repository->commit();
4081
        } catch (Exception $e) {
4082
            // Cleanup hanging transaction on error
4083
            $repository->rollback();
4084
            throw $e;
4085
        }
4086
4087
        // Name is now "Administrators"
4088
        $name = $contentService->loadContent($contentId)->getFieldValue('name', 'eng-US');
4089
        /* END: Use Case */
4090
4091
        $this->assertEquals('Administrators', $name);
4092
    }
4093
4094
    /**
4095
     * Test for the updateContentMetadata() method.