Code Duplication    Length = 47-47 lines in 2 locations

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

@@ 4608-4654 (lines=47) @@
4605
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4606
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4607
     */
4608
    public function testUpdateContentInTransactionWithRollback()
4609
    {
4610
        $repository = $this->getRepository();
4611
4612
        $contentId = $this->generateId('object', 12);
4613
        /* BEGIN: Use Case */
4614
        // $contentId is the ID of the "Administrator users" user group
4615
4616
        // Load content service
4617
        $contentService = $repository->getContentService();
4618
4619
        // Create a new user group draft
4620
        $draft = $contentService->createContentDraft(
4621
            $contentService->loadContentInfo($contentId)
4622
        );
4623
4624
        // Get an update struct and change the group name
4625
        $contentUpdate = $contentService->newContentUpdateStruct();
4626
        $contentUpdate->setField('name', 'Administrators', 'eng-US');
4627
4628
        // Start a transaction
4629
        $repository->beginTransaction();
4630
4631
        try {
4632
            // Update the group name
4633
            $draft = $contentService->updateContent(
4634
                $draft->getVersionInfo(),
4635
                $contentUpdate
4636
            );
4637
4638
            // Publish updated version
4639
            $contentService->publishVersion($draft->getVersionInfo());
4640
        } catch (Exception $e) {
4641
            // Cleanup hanging transaction on error
4642
            $repository->rollback();
4643
            throw $e;
4644
        }
4645
4646
        // Rollback all changes.
4647
        $repository->rollback();
4648
4649
        // Name will still be "Administrator users"
4650
        $name = $contentService->loadContent($contentId)->getFieldValue('name');
4651
        /* END: Use Case */
4652
4653
        $this->assertEquals('Administrator users', $name);
4654
    }
4655
4656
    /**
4657
     * Test for the updateContent() method.
@@ 4664-4710 (lines=47) @@
4661
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4662
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4663
     */
4664
    public function testUpdateContentInTransactionWithCommit()
4665
    {
4666
        $repository = $this->getRepository();
4667
4668
        $contentId = $this->generateId('object', 12);
4669
        /* BEGIN: Use Case */
4670
        // $contentId is the ID of the "Administrator users" user group
4671
4672
        // Load content service
4673
        $contentService = $repository->getContentService();
4674
4675
        // Create a new user group draft
4676
        $draft = $contentService->createContentDraft(
4677
            $contentService->loadContentInfo($contentId)
4678
        );
4679
4680
        // Get an update struct and change the group name
4681
        $contentUpdate = $contentService->newContentUpdateStruct();
4682
        $contentUpdate->setField('name', 'Administrators', 'eng-US');
4683
4684
        // Start a transaction
4685
        $repository->beginTransaction();
4686
4687
        try {
4688
            // Update the group name
4689
            $draft = $contentService->updateContent(
4690
                $draft->getVersionInfo(),
4691
                $contentUpdate
4692
            );
4693
4694
            // Publish updated version
4695
            $contentService->publishVersion($draft->getVersionInfo());
4696
4697
            // Commit all changes.
4698
            $repository->commit();
4699
        } catch (Exception $e) {
4700
            // Cleanup hanging transaction on error
4701
            $repository->rollback();
4702
            throw $e;
4703
        }
4704
4705
        // Name is now "Administrators"
4706
        $name = $contentService->loadContent($contentId)->getFieldValue('name', 'eng-US');
4707
        /* END: Use Case */
4708
4709
        $this->assertEquals('Administrators', $name);
4710
    }
4711
4712
    /**
4713
     * Test for the updateContentMetadata() method.