Code Duplication    Length = 40-44 lines in 3 locations

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

@@ 4491-4530 (lines=40) @@
4488
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft
4489
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4490
     */
4491
    public function testCreateContentDraftInTransactionWithCommit()
4492
    {
4493
        $repository = $this->getRepository();
4494
4495
        $contentId = $this->generateId('object', 12);
4496
        /* BEGIN: Use Case */
4497
        // $contentId is the ID of the "Administrator users" user group
4498
4499
        // Get the content service
4500
        $contentService = $repository->getContentService();
4501
4502
        // Load the user group content object
4503
        $content = $contentService->loadContent($contentId);
4504
4505
        // Start a new transaction
4506
        $repository->beginTransaction();
4507
4508
        try {
4509
            // Create a new draft
4510
            $drafted = $contentService->createContentDraft($content->contentInfo);
4511
4512
            // Store version number for later reuse
4513
            $versionNo = $drafted->versionInfo->versionNo;
4514
4515
            // Commit all changes
4516
            $repository->commit();
4517
        } catch (Exception $e) {
4518
            // Cleanup hanging transaction on error
4519
            $repository->rollback();
4520
            throw $e;
4521
        }
4522
4523
        $content = $contentService->loadContent($contentId, null, $versionNo);
4524
        /* END: Use Case */
4525
4526
        $this->assertEquals(
4527
            $versionNo,
4528
            $content->getVersionInfo()->versionNo
4529
        );
4530
    }
4531
4532
    /**
4533
     * Test for the publishVersion() method.
@@ 4539-4582 (lines=44) @@
4536
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
4537
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4538
     */
4539
    public function testPublishVersionInTransactionWithRollback()
4540
    {
4541
        $repository = $this->getRepository();
4542
4543
        $contentId = $this->generateId('object', 12);
4544
        /* BEGIN: Use Case */
4545
        // $contentId is the ID of the "Administrator users" user group
4546
4547
        // Get the content service
4548
        $contentService = $repository->getContentService();
4549
4550
        // Load the user group content object
4551
        $content = $contentService->loadContent($contentId);
4552
4553
        // Start a new transaction
4554
        $repository->beginTransaction();
4555
4556
        try {
4557
            $draftVersion = $contentService->createContentDraft($content->contentInfo)->getVersionInfo();
4558
4559
            // Publish a new version
4560
            $content = $contentService->publishVersion($draftVersion);
4561
4562
            // Store version number for later reuse
4563
            $versionNo = $content->versionInfo->versionNo;
4564
        } catch (Exception $e) {
4565
            // Cleanup hanging transaction on error
4566
            $repository->rollback();
4567
            throw $e;
4568
        }
4569
4570
        // Rollback
4571
        $repository->rollback();
4572
4573
        try {
4574
            // This call will fail with a "NotFoundException"
4575
            $contentService->loadContent($contentId, null, $versionNo);
4576
        } catch (NotFoundException $e) {
4577
            return;
4578
        }
4579
        /* END: Use Case */
4580
4581
        $this->fail('Can still load content draft after rollback');
4582
    }
4583
4584
    /**
4585
     * Test for the publishVersion() method.
@@ 4591-4630 (lines=40) @@
4588
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
4589
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo
4590
     */
4591
    public function testPublishVersionInTransactionWithCommit()
4592
    {
4593
        $repository = $this->getRepository();
4594
4595
        /* BEGIN: Use Case */
4596
        // ID of the "Administrator users" user group
4597
        $contentId = 12;
4598
4599
        // Get the content service
4600
        $contentService = $repository->getContentService();
4601
4602
        // Load the user group content object
4603
        $template = $contentService->loadContent($contentId);
4604
4605
        // Start a new transaction
4606
        $repository->beginTransaction();
4607
4608
        try {
4609
            // Publish a new version
4610
            $content = $contentService->publishVersion(
4611
                $contentService->createContentDraft($template->contentInfo)->getVersionInfo()
4612
            );
4613
4614
            // Store version number for later reuse
4615
            $versionNo = $content->versionInfo->versionNo;
4616
4617
            // Commit all changes
4618
            $repository->commit();
4619
        } catch (Exception $e) {
4620
            // Cleanup hanging transaction on error
4621
            $repository->rollback();
4622
            throw $e;
4623
        }
4624
4625
        // Load current version info
4626
        $versionInfo = $contentService->loadVersionInfo($content->contentInfo);
4627
        /* END: Use Case */
4628
4629
        $this->assertEquals($versionNo, $versionInfo->versionNo);
4630
    }
4631
4632
    /**
4633
     * Test for the updateContent() method.