Code Duplication    Length = 47-47 lines in 2 locations

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

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