Code Duplication    Length = 47-47 lines in 2 locations

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

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