Code Duplication    Length = 47-47 lines in 2 locations

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

@@ 4640-4686 (lines=47) @@
4637
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4638
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4639
     */
4640
    public function testUpdateContentInTransactionWithRollback()
4641
    {
4642
        $repository = $this->getRepository();
4643
4644
        $contentId = $this->generateId('object', 12);
4645
        /* BEGIN: Use Case */
4646
        // $contentId is the ID of the "Administrator users" user group
4647
4648
        // Load content service
4649
        $contentService = $repository->getContentService();
4650
4651
        // Create a new user group draft
4652
        $draft = $contentService->createContentDraft(
4653
            $contentService->loadContentInfo($contentId)
4654
        );
4655
4656
        // Get an update struct and change the group name
4657
        $contentUpdate = $contentService->newContentUpdateStruct();
4658
        $contentUpdate->setField('name', 'Administrators', 'eng-US');
4659
4660
        // Start a transaction
4661
        $repository->beginTransaction();
4662
4663
        try {
4664
            // Update the group name
4665
            $draft = $contentService->updateContent(
4666
                $draft->getVersionInfo(),
4667
                $contentUpdate
4668
            );
4669
4670
            // Publish updated version
4671
            $contentService->publishVersion($draft->getVersionInfo());
4672
        } catch (Exception $e) {
4673
            // Cleanup hanging transaction on error
4674
            $repository->rollback();
4675
            throw $e;
4676
        }
4677
4678
        // Rollback all changes.
4679
        $repository->rollback();
4680
4681
        // Name will still be "Administrator users"
4682
        $name = $contentService->loadContent($contentId)->getFieldValue('name');
4683
        /* END: Use Case */
4684
4685
        $this->assertEquals('Administrator users', $name);
4686
    }
4687
4688
    /**
4689
     * Test for the updateContent() method.
@@ 4696-4742 (lines=47) @@
4693
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4694
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4695
     */
4696
    public function testUpdateContentInTransactionWithCommit()
4697
    {
4698
        $repository = $this->getRepository();
4699
4700
        $contentId = $this->generateId('object', 12);
4701
        /* BEGIN: Use Case */
4702
        // $contentId is the ID of the "Administrator users" user group
4703
4704
        // Load content service
4705
        $contentService = $repository->getContentService();
4706
4707
        // Create a new user group draft
4708
        $draft = $contentService->createContentDraft(
4709
            $contentService->loadContentInfo($contentId)
4710
        );
4711
4712
        // Get an update struct and change the group name
4713
        $contentUpdate = $contentService->newContentUpdateStruct();
4714
        $contentUpdate->setField('name', 'Administrators', 'eng-US');
4715
4716
        // Start a transaction
4717
        $repository->beginTransaction();
4718
4719
        try {
4720
            // Update the group name
4721
            $draft = $contentService->updateContent(
4722
                $draft->getVersionInfo(),
4723
                $contentUpdate
4724
            );
4725
4726
            // Publish updated version
4727
            $contentService->publishVersion($draft->getVersionInfo());
4728
4729
            // Commit all changes.
4730
            $repository->commit();
4731
        } catch (Exception $e) {
4732
            // Cleanup hanging transaction on error
4733
            $repository->rollback();
4734
            throw $e;
4735
        }
4736
4737
        // Name is now "Administrators"
4738
        $name = $contentService->loadContent($contentId)->getFieldValue('name', 'eng-US');
4739
        /* END: Use Case */
4740
4741
        $this->assertEquals('Administrators', $name);
4742
    }
4743
4744
    /**
4745
     * Test for the updateContentMetadata() method.