Code Duplication    Length = 40-44 lines in 3 locations

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

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