Code Duplication    Length = 40-44 lines in 3 locations

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

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