Code Duplication    Length = 47-47 lines in 2 locations

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

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