Code Duplication    Length = 40-44 lines in 3 locations

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

@@ 4363-4402 (lines=40) @@
4360
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft
4361
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4362
     */
4363
    public function testCreateContentDraftInTransactionWithCommit()
4364
    {
4365
        $repository = $this->getRepository();
4366
4367
        $contentId = $this->generateId('object', 12);
4368
        /* BEGIN: Use Case */
4369
        // $contentId is the ID of the "Administrator users" user group
4370
4371
        // Get the content service
4372
        $contentService = $repository->getContentService();
4373
4374
        // Load the user group content object
4375
        $content = $contentService->loadContent($contentId);
4376
4377
        // Start a new transaction
4378
        $repository->beginTransaction();
4379
4380
        try {
4381
            // Create a new draft
4382
            $drafted = $contentService->createContentDraft($content->contentInfo);
4383
4384
            // Store version number for later reuse
4385
            $versionNo = $drafted->versionInfo->versionNo;
4386
4387
            // Commit all changes
4388
            $repository->commit();
4389
        } catch (Exception $e) {
4390
            // Cleanup hanging transaction on error
4391
            $repository->rollback();
4392
            throw $e;
4393
        }
4394
4395
        $content = $contentService->loadContent($contentId, null, $versionNo);
4396
        /* END: Use Case */
4397
4398
        $this->assertEquals(
4399
            $versionNo,
4400
            $content->getVersionInfo()->versionNo
4401
        );
4402
    }
4403
4404
    /**
4405
     * Test for the publishVersion() method.
@@ 4411-4454 (lines=44) @@
4408
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
4409
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4410
     */
4411
    public function testPublishVersionInTransactionWithRollback()
4412
    {
4413
        $repository = $this->getRepository();
4414
4415
        $contentId = $this->generateId('object', 12);
4416
        /* BEGIN: Use Case */
4417
        // $contentId is the ID of the "Administrator users" user group
4418
4419
        // Get the content service
4420
        $contentService = $repository->getContentService();
4421
4422
        // Load the user group content object
4423
        $content = $contentService->loadContent($contentId);
4424
4425
        // Start a new transaction
4426
        $repository->beginTransaction();
4427
4428
        try {
4429
            $draftVersion = $contentService->createContentDraft($content->contentInfo)->getVersionInfo();
4430
4431
            // Publish a new version
4432
            $content = $contentService->publishVersion($draftVersion);
4433
4434
            // Store version number for later reuse
4435
            $versionNo = $content->versionInfo->versionNo;
4436
        } catch (Exception $e) {
4437
            // Cleanup hanging transaction on error
4438
            $repository->rollback();
4439
            throw $e;
4440
        }
4441
4442
        // Rollback
4443
        $repository->rollback();
4444
4445
        try {
4446
            // This call will fail with a "NotFoundException"
4447
            $contentService->loadContent($contentId, null, $versionNo);
4448
        } catch (NotFoundException $e) {
4449
            return;
4450
        }
4451
        /* END: Use Case */
4452
4453
        $this->fail('Can still load content draft after rollback');
4454
    }
4455
4456
    /**
4457
     * Test for the publishVersion() method.
@@ 4463-4502 (lines=40) @@
4460
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
4461
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo
4462
     */
4463
    public function testPublishVersionInTransactionWithCommit()
4464
    {
4465
        $repository = $this->getRepository();
4466
4467
        /* BEGIN: Use Case */
4468
        // ID of the "Administrator users" user group
4469
        $contentId = 12;
4470
4471
        // Get the content service
4472
        $contentService = $repository->getContentService();
4473
4474
        // Load the user group content object
4475
        $template = $contentService->loadContent($contentId);
4476
4477
        // Start a new transaction
4478
        $repository->beginTransaction();
4479
4480
        try {
4481
            // Publish a new version
4482
            $content = $contentService->publishVersion(
4483
                $contentService->createContentDraft($template->contentInfo)->getVersionInfo()
4484
            );
4485
4486
            // Store version number for later reuse
4487
            $versionNo = $content->versionInfo->versionNo;
4488
4489
            // Commit all changes
4490
            $repository->commit();
4491
        } catch (Exception $e) {
4492
            // Cleanup hanging transaction on error
4493
            $repository->rollback();
4494
            throw $e;
4495
        }
4496
4497
        // Load current version info
4498
        $versionInfo = $contentService->loadVersionInfo($content->contentInfo);
4499
        /* END: Use Case */
4500
4501
        $this->assertEquals($versionNo, $versionInfo->versionNo);
4502
    }
4503
4504
    /**
4505
     * Test for the updateContent() method.