Code Duplication    Length = 45-45 lines in 2 locations

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

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