Code Duplication    Length = 40-44 lines in 3 locations

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

@@ 4165-4204 (lines=40) @@
4162
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft
4163
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4164
     */
4165
    public function testCreateContentDraftInTransactionWithCommit()
4166
    {
4167
        $repository = $this->getRepository();
4168
4169
        $contentId = $this->generateId('object', 12);
4170
        /* BEGIN: Use Case */
4171
        // $contentId is the ID of the "Administrator users" user group
4172
4173
        // Get the content service
4174
        $contentService = $repository->getContentService();
4175
4176
        // Load the user group content object
4177
        $content = $contentService->loadContent($contentId);
4178
4179
        // Start a new transaction
4180
        $repository->beginTransaction();
4181
4182
        try {
4183
            // Create a new draft
4184
            $drafted = $contentService->createContentDraft($content->contentInfo);
4185
4186
            // Store version number for later reuse
4187
            $versionNo = $drafted->versionInfo->versionNo;
4188
4189
            // Commit all changes
4190
            $repository->commit();
4191
        } catch (Exception $e) {
4192
            // Cleanup hanging transaction on error
4193
            $repository->rollback();
4194
            throw $e;
4195
        }
4196
4197
        $content = $contentService->loadContent($contentId, null, $versionNo);
4198
        /* END: Use Case */
4199
4200
        $this->assertEquals(
4201
            $versionNo,
4202
            $content->getVersionInfo()->versionNo
4203
        );
4204
    }
4205
4206
    /**
4207
     * Test for the publishVersion() method.
@@ 4213-4256 (lines=44) @@
4210
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
4211
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4212
     */
4213
    public function testPublishVersionInTransactionWithRollback()
4214
    {
4215
        $repository = $this->getRepository();
4216
4217
        $contentId = $this->generateId('object', 12);
4218
        /* BEGIN: Use Case */
4219
        // $contentId is the ID of the "Administrator users" user group
4220
4221
        // Get the content service
4222
        $contentService = $repository->getContentService();
4223
4224
        // Load the user group content object
4225
        $content = $contentService->loadContent($contentId);
4226
4227
        // Start a new transaction
4228
        $repository->beginTransaction();
4229
4230
        try {
4231
            $draftVersion = $contentService->createContentDraft($content->contentInfo)->getVersionInfo();
4232
4233
            // Publish a new version
4234
            $content = $contentService->publishVersion($draftVersion);
4235
4236
            // Store version number for later reuse
4237
            $versionNo = $content->versionInfo->versionNo;
4238
        } catch (Exception $e) {
4239
            // Cleanup hanging transaction on error
4240
            $repository->rollback();
4241
            throw $e;
4242
        }
4243
4244
        // Rollback
4245
        $repository->rollback();
4246
4247
        try {
4248
            // This call will fail with a "NotFoundException"
4249
            $contentService->loadContent($contentId, null, $versionNo);
4250
        } catch (NotFoundException $e) {
4251
            return;
4252
        }
4253
        /* END: Use Case */
4254
4255
        $this->fail('Can still load content draft after rollback');
4256
    }
4257
4258
    /**
4259
     * Test for the publishVersion() method.
@@ 4265-4304 (lines=40) @@
4262
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
4263
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo
4264
     */
4265
    public function testPublishVersionInTransactionWithCommit()
4266
    {
4267
        $repository = $this->getRepository();
4268
4269
        /* BEGIN: Use Case */
4270
        // ID of the "Administrator users" user group
4271
        $contentId = 12;
4272
4273
        // Get the content service
4274
        $contentService = $repository->getContentService();
4275
4276
        // Load the user group content object
4277
        $template = $contentService->loadContent($contentId);
4278
4279
        // Start a new transaction
4280
        $repository->beginTransaction();
4281
4282
        try {
4283
            // Publish a new version
4284
            $content = $contentService->publishVersion(
4285
                $contentService->createContentDraft($template->contentInfo)->getVersionInfo()
4286
            );
4287
4288
            // Store version number for later reuse
4289
            $versionNo = $content->versionInfo->versionNo;
4290
4291
            // Commit all changes
4292
            $repository->commit();
4293
        } catch (Exception $e) {
4294
            // Cleanup hanging transaction on error
4295
            $repository->rollback();
4296
            throw $e;
4297
        }
4298
4299
        // Load current version info
4300
        $versionInfo = $contentService->loadVersionInfo($content->contentInfo);
4301
        /* END: Use Case */
4302
4303
        $this->assertEquals($versionNo, $versionInfo->versionNo);
4304
    }
4305
4306
    /**
4307
     * Test for the updateContent() method.