Code Duplication    Length = 45-45 lines in 2 locations

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

@@ 4109-4153 (lines=45) @@
4106
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4107
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4108
     */
4109
    public function testUpdateContentMetadataInTransactionWithRollback()
4110
    {
4111
        $repository = $this->getRepository();
4112
4113
        $contentId = $this->generateId('object', 12);
4114
        /* BEGIN: Use Case */
4115
        // $contentId is the ID of the "Administrator users" user group
4116
4117
        // Get the content service
4118
        $contentService = $repository->getContentService();
4119
4120
        // Load a ContentInfo object
4121
        $contentInfo = $contentService->loadContentInfo($contentId);
4122
4123
        // Store remoteId for later testing
4124
        $remoteId = $contentInfo->remoteId;
4125
4126
        // Start a transaction
4127
        $repository->beginTransaction();
4128
4129
        try {
4130
            // Get metadata update struct and change remoteId
4131
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4132
            $metadataUpdate->remoteId = md5(microtime(true));
4133
4134
            // Update the metadata of the published content object
4135
            $contentService->updateContentMetadata(
4136
                $contentInfo,
4137
                $metadataUpdate
4138
            );
4139
        } catch (Exception $e) {
4140
            // Cleanup hanging transaction on error
4141
            $repository->rollback();
4142
            throw $e;
4143
        }
4144
4145
        // Rollback all changes.
4146
        $repository->rollback();
4147
4148
        // Load current remoteId
4149
        $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4150
        /* END: Use Case */
4151
4152
        $this->assertEquals($remoteId, $remoteIdReloaded);
4153
    }
4154
4155
    /**
4156
     * Test for the updateContentMetadata() method.
@@ 4162-4206 (lines=45) @@
4159
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4160
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4161
     */
4162
    public function testUpdateContentMetadataInTransactionWithCommit()
4163
    {
4164
        $repository = $this->getRepository();
4165
4166
        $contentId = $this->generateId('object', 12);
4167
        /* BEGIN: Use Case */
4168
        // $contentId is the ID of the "Administrator users" user group
4169
4170
        // Get the content service
4171
        $contentService = $repository->getContentService();
4172
4173
        // Load a ContentInfo object
4174
        $contentInfo = $contentService->loadContentInfo($contentId);
4175
4176
        // Store remoteId for later testing
4177
        $remoteId = $contentInfo->remoteId;
4178
4179
        // Start a transaction
4180
        $repository->beginTransaction();
4181
4182
        try {
4183
            // Get metadata update struct and change remoteId
4184
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4185
            $metadataUpdate->remoteId = md5(microtime(true));
4186
4187
            // Update the metadata of the published content object
4188
            $contentService->updateContentMetadata(
4189
                $contentInfo,
4190
                $metadataUpdate
4191
            );
4192
4193
            // Commit all changes.
4194
            $repository->commit();
4195
        } catch (Exception $e) {
4196
            // Cleanup hanging transaction on error
4197
            $repository->rollback();
4198
            throw $e;
4199
        }
4200
4201
        // Load current remoteId
4202
        $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4203
        /* END: Use Case */
4204
4205
        $this->assertNotEquals($remoteId, $remoteIdReloaded);
4206
    }
4207
4208
    /**
4209
     * Test for the deleteVersion() method.