Code Duplication    Length = 40-44 lines in 3 locations

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

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