Code Duplication    Length = 40-44 lines in 3 locations

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

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