Code Duplication    Length = 47-47 lines in 2 locations

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

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