Code Duplication    Length = 40-44 lines in 3 locations

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

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