Code Duplication    Length = 47-47 lines in 2 locations

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

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