Code Duplication    Length = 40-44 lines in 3 locations

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

@@ 4301-4340 (lines=40) @@
4298
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft
4299
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4300
     */
4301
    public function testCreateContentDraftInTransactionWithCommit()
4302
    {
4303
        $repository = $this->getRepository();
4304
4305
        $contentId = $this->generateId('object', 12);
4306
        /* BEGIN: Use Case */
4307
        // $contentId is the ID of the "Administrator users" user group
4308
4309
        // Get the content service
4310
        $contentService = $repository->getContentService();
4311
4312
        // Load the user group content object
4313
        $content = $contentService->loadContent($contentId);
4314
4315
        // Start a new transaction
4316
        $repository->beginTransaction();
4317
4318
        try {
4319
            // Create a new draft
4320
            $drafted = $contentService->createContentDraft($content->contentInfo);
4321
4322
            // Store version number for later reuse
4323
            $versionNo = $drafted->versionInfo->versionNo;
4324
4325
            // Commit all changes
4326
            $repository->commit();
4327
        } catch (Exception $e) {
4328
            // Cleanup hanging transaction on error
4329
            $repository->rollback();
4330
            throw $e;
4331
        }
4332
4333
        $content = $contentService->loadContent($contentId, null, $versionNo);
4334
        /* END: Use Case */
4335
4336
        $this->assertEquals(
4337
            $versionNo,
4338
            $content->getVersionInfo()->versionNo
4339
        );
4340
    }
4341
4342
    /**
4343
     * Test for the publishVersion() method.
@@ 4349-4392 (lines=44) @@
4346
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
4347
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4348
     */
4349
    public function testPublishVersionInTransactionWithRollback()
4350
    {
4351
        $repository = $this->getRepository();
4352
4353
        $contentId = $this->generateId('object', 12);
4354
        /* BEGIN: Use Case */
4355
        // $contentId is the ID of the "Administrator users" user group
4356
4357
        // Get the content service
4358
        $contentService = $repository->getContentService();
4359
4360
        // Load the user group content object
4361
        $content = $contentService->loadContent($contentId);
4362
4363
        // Start a new transaction
4364
        $repository->beginTransaction();
4365
4366
        try {
4367
            $draftVersion = $contentService->createContentDraft($content->contentInfo)->getVersionInfo();
4368
4369
            // Publish a new version
4370
            $content = $contentService->publishVersion($draftVersion);
4371
4372
            // Store version number for later reuse
4373
            $versionNo = $content->versionInfo->versionNo;
4374
        } catch (Exception $e) {
4375
            // Cleanup hanging transaction on error
4376
            $repository->rollback();
4377
            throw $e;
4378
        }
4379
4380
        // Rollback
4381
        $repository->rollback();
4382
4383
        try {
4384
            // This call will fail with a "NotFoundException"
4385
            $contentService->loadContent($contentId, null, $versionNo);
4386
        } catch (NotFoundException $e) {
4387
            return;
4388
        }
4389
        /* END: Use Case */
4390
4391
        $this->fail('Can still load content draft after rollback');
4392
    }
4393
4394
    /**
4395
     * Test for the publishVersion() method.
@@ 4401-4440 (lines=40) @@
4398
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
4399
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo
4400
     */
4401
    public function testPublishVersionInTransactionWithCommit()
4402
    {
4403
        $repository = $this->getRepository();
4404
4405
        /* BEGIN: Use Case */
4406
        // ID of the "Administrator users" user group
4407
        $contentId = 12;
4408
4409
        // Get the content service
4410
        $contentService = $repository->getContentService();
4411
4412
        // Load the user group content object
4413
        $template = $contentService->loadContent($contentId);
4414
4415
        // Start a new transaction
4416
        $repository->beginTransaction();
4417
4418
        try {
4419
            // Publish a new version
4420
            $content = $contentService->publishVersion(
4421
                $contentService->createContentDraft($template->contentInfo)->getVersionInfo()
4422
            );
4423
4424
            // Store version number for later reuse
4425
            $versionNo = $content->versionInfo->versionNo;
4426
4427
            // Commit all changes
4428
            $repository->commit();
4429
        } catch (Exception $e) {
4430
            // Cleanup hanging transaction on error
4431
            $repository->rollback();
4432
            throw $e;
4433
        }
4434
4435
        // Load current version info
4436
        $versionInfo = $contentService->loadVersionInfo($content->contentInfo);
4437
        /* END: Use Case */
4438
4439
        $this->assertEquals($versionNo, $versionInfo->versionNo);
4440
    }
4441
4442
    /**
4443
     * Test for the updateContent() method.