Code Duplication    Length = 47-47 lines in 2 locations

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

@@ 4037-4083 (lines=47) @@
4034
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4035
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4036
     */
4037
    public function testUpdateContentInTransactionWithRollback()
4038
    {
4039
        $repository = $this->getRepository();
4040
4041
        $contentId = $this->generateId('object', 12);
4042
        /* BEGIN: Use Case */
4043
        // $contentId is the ID of the "Administrator users" user group
4044
4045
        // Load content service
4046
        $contentService = $repository->getContentService();
4047
4048
        // Create a new user group draft
4049
        $draft = $contentService->createContentDraft(
4050
            $contentService->loadContentInfo($contentId)
4051
        );
4052
4053
        // Get an update struct and change the group name
4054
        $contentUpdate = $contentService->newContentUpdateStruct();
4055
        $contentUpdate->setField('name', 'Administrators', 'eng-US');
4056
4057
        // Start a transaction
4058
        $repository->beginTransaction();
4059
4060
        try {
4061
            // Update the group name
4062
            $draft = $contentService->updateContent(
4063
                $draft->getVersionInfo(),
4064
                $contentUpdate
4065
            );
4066
4067
            // Publish updated version
4068
            $contentService->publishVersion($draft->getVersionInfo());
4069
        } catch (Exception $e) {
4070
            // Cleanup hanging transaction on error
4071
            $repository->rollback();
4072
            throw $e;
4073
        }
4074
4075
        // Rollback all changes.
4076
        $repository->rollback();
4077
4078
        // Name will still be "Administrator users"
4079
        $name = $contentService->loadContent($contentId)->getFieldValue('name');
4080
        /* END: Use Case */
4081
4082
        $this->assertEquals('Administrator users', $name);
4083
    }
4084
4085
    /**
4086
     * Test for the updateContent() method.
@@ 4093-4139 (lines=47) @@
4090
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4091
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4092
     */
4093
    public function testUpdateContentInTransactionWithCommit()
4094
    {
4095
        $repository = $this->getRepository();
4096
4097
        $contentId = $this->generateId('object', 12);
4098
        /* BEGIN: Use Case */
4099
        // $contentId is the ID of the "Administrator users" user group
4100
4101
        // Load content service
4102
        $contentService = $repository->getContentService();
4103
4104
        // Create a new user group draft
4105
        $draft = $contentService->createContentDraft(
4106
            $contentService->loadContentInfo($contentId)
4107
        );
4108
4109
        // Get an update struct and change the group name
4110
        $contentUpdate = $contentService->newContentUpdateStruct();
4111
        $contentUpdate->setField('name', 'Administrators', 'eng-US');
4112
4113
        // Start a transaction
4114
        $repository->beginTransaction();
4115
4116
        try {
4117
            // Update the group name
4118
            $draft = $contentService->updateContent(
4119
                $draft->getVersionInfo(),
4120
                $contentUpdate
4121
            );
4122
4123
            // Publish updated version
4124
            $contentService->publishVersion($draft->getVersionInfo());
4125
4126
            // Commit all changes.
4127
            $repository->commit();
4128
        } catch (Exception $e) {
4129
            // Cleanup hanging transaction on error
4130
            $repository->rollback();
4131
            throw $e;
4132
        }
4133
4134
        // Name is now "Administrators"
4135
        $name = $contentService->loadContent($contentId)->getFieldValue('name', 'eng-US');
4136
        /* END: Use Case */
4137
4138
        $this->assertEquals('Administrators', $name);
4139
    }
4140
4141
    /**
4142
     * Test for the updateContentMetadata() method.