Code Duplication    Length = 47-47 lines in 2 locations

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

@@ 4570-4616 (lines=47) @@
4567
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4568
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4569
     */
4570
    public function testUpdateContentInTransactionWithRollback()
4571
    {
4572
        $repository = $this->getRepository();
4573
4574
        $contentId = $this->generateId('object', 12);
4575
        /* BEGIN: Use Case */
4576
        // $contentId is the ID of the "Administrator users" user group
4577
4578
        // Load content service
4579
        $contentService = $repository->getContentService();
4580
4581
        // Create a new user group draft
4582
        $draft = $contentService->createContentDraft(
4583
            $contentService->loadContentInfo($contentId)
4584
        );
4585
4586
        // Get an update struct and change the group name
4587
        $contentUpdate = $contentService->newContentUpdateStruct();
4588
        $contentUpdate->setField('name', 'Administrators', 'eng-US');
4589
4590
        // Start a transaction
4591
        $repository->beginTransaction();
4592
4593
        try {
4594
            // Update the group name
4595
            $draft = $contentService->updateContent(
4596
                $draft->getVersionInfo(),
4597
                $contentUpdate
4598
            );
4599
4600
            // Publish updated version
4601
            $contentService->publishVersion($draft->getVersionInfo());
4602
        } catch (Exception $e) {
4603
            // Cleanup hanging transaction on error
4604
            $repository->rollback();
4605
            throw $e;
4606
        }
4607
4608
        // Rollback all changes.
4609
        $repository->rollback();
4610
4611
        // Name will still be "Administrator users"
4612
        $name = $contentService->loadContent($contentId)->getFieldValue('name');
4613
        /* END: Use Case */
4614
4615
        $this->assertEquals('Administrator users', $name);
4616
    }
4617
4618
    /**
4619
     * Test for the updateContent() method.
@@ 4626-4672 (lines=47) @@
4623
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4624
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4625
     */
4626
    public function testUpdateContentInTransactionWithCommit()
4627
    {
4628
        $repository = $this->getRepository();
4629
4630
        $contentId = $this->generateId('object', 12);
4631
        /* BEGIN: Use Case */
4632
        // $contentId is the ID of the "Administrator users" user group
4633
4634
        // Load content service
4635
        $contentService = $repository->getContentService();
4636
4637
        // Create a new user group draft
4638
        $draft = $contentService->createContentDraft(
4639
            $contentService->loadContentInfo($contentId)
4640
        );
4641
4642
        // Get an update struct and change the group name
4643
        $contentUpdate = $contentService->newContentUpdateStruct();
4644
        $contentUpdate->setField('name', 'Administrators', 'eng-US');
4645
4646
        // Start a transaction
4647
        $repository->beginTransaction();
4648
4649
        try {
4650
            // Update the group name
4651
            $draft = $contentService->updateContent(
4652
                $draft->getVersionInfo(),
4653
                $contentUpdate
4654
            );
4655
4656
            // Publish updated version
4657
            $contentService->publishVersion($draft->getVersionInfo());
4658
4659
            // Commit all changes.
4660
            $repository->commit();
4661
        } catch (Exception $e) {
4662
            // Cleanup hanging transaction on error
4663
            $repository->rollback();
4664
            throw $e;
4665
        }
4666
4667
        // Name is now "Administrators"
4668
        $name = $contentService->loadContent($contentId)->getFieldValue('name', 'eng-US');
4669
        /* END: Use Case */
4670
4671
        $this->assertEquals('Administrators', $name);
4672
    }
4673
4674
    /**
4675
     * Test for the updateContentMetadata() method.