Code Duplication    Length = 40-44 lines in 3 locations

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

@@ 4452-4491 (lines=40) @@
4449
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft
4450
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4451
     */
4452
    public function testCreateContentDraftInTransactionWithCommit()
4453
    {
4454
        $repository = $this->getRepository();
4455
4456
        $contentId = $this->generateId('object', 12);
4457
        /* BEGIN: Use Case */
4458
        // $contentId is the ID of the "Administrator users" user group
4459
4460
        // Get the content service
4461
        $contentService = $repository->getContentService();
4462
4463
        // Load the user group content object
4464
        $content = $contentService->loadContent($contentId);
4465
4466
        // Start a new transaction
4467
        $repository->beginTransaction();
4468
4469
        try {
4470
            // Create a new draft
4471
            $drafted = $contentService->createContentDraft($content->contentInfo);
4472
4473
            // Store version number for later reuse
4474
            $versionNo = $drafted->versionInfo->versionNo;
4475
4476
            // Commit all changes
4477
            $repository->commit();
4478
        } catch (Exception $e) {
4479
            // Cleanup hanging transaction on error
4480
            $repository->rollback();
4481
            throw $e;
4482
        }
4483
4484
        $content = $contentService->loadContent($contentId, null, $versionNo);
4485
        /* END: Use Case */
4486
4487
        $this->assertEquals(
4488
            $versionNo,
4489
            $content->getVersionInfo()->versionNo
4490
        );
4491
    }
4492
4493
    /**
4494
     * Test for the publishVersion() method.
@@ 4500-4543 (lines=44) @@
4497
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
4498
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4499
     */
4500
    public function testPublishVersionInTransactionWithRollback()
4501
    {
4502
        $repository = $this->getRepository();
4503
4504
        $contentId = $this->generateId('object', 12);
4505
        /* BEGIN: Use Case */
4506
        // $contentId is the ID of the "Administrator users" user group
4507
4508
        // Get the content service
4509
        $contentService = $repository->getContentService();
4510
4511
        // Load the user group content object
4512
        $content = $contentService->loadContent($contentId);
4513
4514
        // Start a new transaction
4515
        $repository->beginTransaction();
4516
4517
        try {
4518
            $draftVersion = $contentService->createContentDraft($content->contentInfo)->getVersionInfo();
4519
4520
            // Publish a new version
4521
            $content = $contentService->publishVersion($draftVersion);
4522
4523
            // Store version number for later reuse
4524
            $versionNo = $content->versionInfo->versionNo;
4525
        } catch (Exception $e) {
4526
            // Cleanup hanging transaction on error
4527
            $repository->rollback();
4528
            throw $e;
4529
        }
4530
4531
        // Rollback
4532
        $repository->rollback();
4533
4534
        try {
4535
            // This call will fail with a "NotFoundException"
4536
            $contentService->loadContent($contentId, null, $versionNo);
4537
        } catch (NotFoundException $e) {
4538
            return;
4539
        }
4540
        /* END: Use Case */
4541
4542
        $this->fail('Can still load content draft after rollback');
4543
    }
4544
4545
    /**
4546
     * Test for the publishVersion() method.
@@ 4552-4591 (lines=40) @@
4549
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
4550
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo
4551
     */
4552
    public function testPublishVersionInTransactionWithCommit()
4553
    {
4554
        $repository = $this->getRepository();
4555
4556
        /* BEGIN: Use Case */
4557
        // ID of the "Administrator users" user group
4558
        $contentId = 12;
4559
4560
        // Get the content service
4561
        $contentService = $repository->getContentService();
4562
4563
        // Load the user group content object
4564
        $template = $contentService->loadContent($contentId);
4565
4566
        // Start a new transaction
4567
        $repository->beginTransaction();
4568
4569
        try {
4570
            // Publish a new version
4571
            $content = $contentService->publishVersion(
4572
                $contentService->createContentDraft($template->contentInfo)->getVersionInfo()
4573
            );
4574
4575
            // Store version number for later reuse
4576
            $versionNo = $content->versionInfo->versionNo;
4577
4578
            // Commit all changes
4579
            $repository->commit();
4580
        } catch (Exception $e) {
4581
            // Cleanup hanging transaction on error
4582
            $repository->rollback();
4583
            throw $e;
4584
        }
4585
4586
        // Load current version info
4587
        $versionInfo = $contentService->loadVersionInfo($content->contentInfo);
4588
        /* END: Use Case */
4589
4590
        $this->assertEquals($versionNo, $versionInfo->versionNo);
4591
    }
4592
4593
    /**
4594
     * Test for the updateContent() method.