Code Duplication    Length = 45-45 lines in 2 locations

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

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