Code Duplication    Length = 40-44 lines in 3 locations

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

@@ 4246-4285 (lines=40) @@
4243
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft
4244
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4245
     */
4246
    public function testCreateContentDraftInTransactionWithCommit()
4247
    {
4248
        $repository = $this->getRepository();
4249
4250
        $contentId = $this->generateId('object', 12);
4251
        /* BEGIN: Use Case */
4252
        // $contentId is the ID of the "Administrator users" user group
4253
4254
        // Get the content service
4255
        $contentService = $repository->getContentService();
4256
4257
        // Load the user group content object
4258
        $content = $contentService->loadContent($contentId);
4259
4260
        // Start a new transaction
4261
        $repository->beginTransaction();
4262
4263
        try {
4264
            // Create a new draft
4265
            $drafted = $contentService->createContentDraft($content->contentInfo);
4266
4267
            // Store version number for later reuse
4268
            $versionNo = $drafted->versionInfo->versionNo;
4269
4270
            // Commit all changes
4271
            $repository->commit();
4272
        } catch (Exception $e) {
4273
            // Cleanup hanging transaction on error
4274
            $repository->rollback();
4275
            throw $e;
4276
        }
4277
4278
        $content = $contentService->loadContent($contentId, null, $versionNo);
4279
        /* END: Use Case */
4280
4281
        $this->assertEquals(
4282
            $versionNo,
4283
            $content->getVersionInfo()->versionNo
4284
        );
4285
    }
4286
4287
    /**
4288
     * Test for the publishVersion() method.
@@ 4294-4337 (lines=44) @@
4291
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
4292
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4293
     */
4294
    public function testPublishVersionInTransactionWithRollback()
4295
    {
4296
        $repository = $this->getRepository();
4297
4298
        $contentId = $this->generateId('object', 12);
4299
        /* BEGIN: Use Case */
4300
        // $contentId is the ID of the "Administrator users" user group
4301
4302
        // Get the content service
4303
        $contentService = $repository->getContentService();
4304
4305
        // Load the user group content object
4306
        $content = $contentService->loadContent($contentId);
4307
4308
        // Start a new transaction
4309
        $repository->beginTransaction();
4310
4311
        try {
4312
            $draftVersion = $contentService->createContentDraft($content->contentInfo)->getVersionInfo();
4313
4314
            // Publish a new version
4315
            $content = $contentService->publishVersion($draftVersion);
4316
4317
            // Store version number for later reuse
4318
            $versionNo = $content->versionInfo->versionNo;
4319
        } catch (Exception $e) {
4320
            // Cleanup hanging transaction on error
4321
            $repository->rollback();
4322
            throw $e;
4323
        }
4324
4325
        // Rollback
4326
        $repository->rollback();
4327
4328
        try {
4329
            // This call will fail with a "NotFoundException"
4330
            $contentService->loadContent($contentId, null, $versionNo);
4331
        } catch (NotFoundException $e) {
4332
            return;
4333
        }
4334
        /* END: Use Case */
4335
4336
        $this->fail('Can still load content draft after rollback');
4337
    }
4338
4339
    /**
4340
     * Test for the publishVersion() method.
@@ 4346-4385 (lines=40) @@
4343
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
4344
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo
4345
     */
4346
    public function testPublishVersionInTransactionWithCommit()
4347
    {
4348
        $repository = $this->getRepository();
4349
4350
        /* BEGIN: Use Case */
4351
        // ID of the "Administrator users" user group
4352
        $contentId = 12;
4353
4354
        // Get the content service
4355
        $contentService = $repository->getContentService();
4356
4357
        // Load the user group content object
4358
        $template = $contentService->loadContent($contentId);
4359
4360
        // Start a new transaction
4361
        $repository->beginTransaction();
4362
4363
        try {
4364
            // Publish a new version
4365
            $content = $contentService->publishVersion(
4366
                $contentService->createContentDraft($template->contentInfo)->getVersionInfo()
4367
            );
4368
4369
            // Store version number for later reuse
4370
            $versionNo = $content->versionInfo->versionNo;
4371
4372
            // Commit all changes
4373
            $repository->commit();
4374
        } catch (Exception $e) {
4375
            // Cleanup hanging transaction on error
4376
            $repository->rollback();
4377
            throw $e;
4378
        }
4379
4380
        // Load current version info
4381
        $versionInfo = $contentService->loadVersionInfo($content->contentInfo);
4382
        /* END: Use Case */
4383
4384
        $this->assertEquals($versionNo, $versionInfo->versionNo);
4385
    }
4386
4387
    /**
4388
     * Test for the updateContent() method.