Code Duplication    Length = 47-47 lines in 2 locations

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

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