Code Duplication    Length = 47-47 lines in 2 locations

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

@@ 4512-4558 (lines=47) @@
4509
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4510
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4511
     */
4512
    public function testUpdateContentInTransactionWithRollback()
4513
    {
4514
        $repository = $this->getRepository();
4515
4516
        $contentId = $this->generateId('object', 12);
4517
        /* BEGIN: Use Case */
4518
        // $contentId is the ID of the "Administrator users" user group
4519
4520
        // Load content service
4521
        $contentService = $repository->getContentService();
4522
4523
        // Create a new user group draft
4524
        $draft = $contentService->createContentDraft(
4525
            $contentService->loadContentInfo($contentId)
4526
        );
4527
4528
        // Get an update struct and change the group name
4529
        $contentUpdate = $contentService->newContentUpdateStruct();
4530
        $contentUpdate->setField('name', 'Administrators', 'eng-US');
4531
4532
        // Start a transaction
4533
        $repository->beginTransaction();
4534
4535
        try {
4536
            // Update the group name
4537
            $draft = $contentService->updateContent(
4538
                $draft->getVersionInfo(),
4539
                $contentUpdate
4540
            );
4541
4542
            // Publish updated version
4543
            $contentService->publishVersion($draft->getVersionInfo());
4544
        } catch (Exception $e) {
4545
            // Cleanup hanging transaction on error
4546
            $repository->rollback();
4547
            throw $e;
4548
        }
4549
4550
        // Rollback all changes.
4551
        $repository->rollback();
4552
4553
        // Name will still be "Administrator users"
4554
        $name = $contentService->loadContent($contentId)->getFieldValue('name');
4555
        /* END: Use Case */
4556
4557
        $this->assertEquals('Administrator users', $name);
4558
    }
4559
4560
    /**
4561
     * Test for the updateContent() method.
@@ 4568-4614 (lines=47) @@
4565
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4566
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4567
     */
4568
    public function testUpdateContentInTransactionWithCommit()
4569
    {
4570
        $repository = $this->getRepository();
4571
4572
        $contentId = $this->generateId('object', 12);
4573
        /* BEGIN: Use Case */
4574
        // $contentId is the ID of the "Administrator users" user group
4575
4576
        // Load content service
4577
        $contentService = $repository->getContentService();
4578
4579
        // Create a new user group draft
4580
        $draft = $contentService->createContentDraft(
4581
            $contentService->loadContentInfo($contentId)
4582
        );
4583
4584
        // Get an update struct and change the group name
4585
        $contentUpdate = $contentService->newContentUpdateStruct();
4586
        $contentUpdate->setField('name', 'Administrators', 'eng-US');
4587
4588
        // Start a transaction
4589
        $repository->beginTransaction();
4590
4591
        try {
4592
            // Update the group name
4593
            $draft = $contentService->updateContent(
4594
                $draft->getVersionInfo(),
4595
                $contentUpdate
4596
            );
4597
4598
            // Publish updated version
4599
            $contentService->publishVersion($draft->getVersionInfo());
4600
4601
            // Commit all changes.
4602
            $repository->commit();
4603
        } catch (Exception $e) {
4604
            // Cleanup hanging transaction on error
4605
            $repository->rollback();
4606
            throw $e;
4607
        }
4608
4609
        // Name is now "Administrators"
4610
        $name = $contentService->loadContent($contentId)->getFieldValue('name', 'eng-US');
4611
        /* END: Use Case */
4612
4613
        $this->assertEquals('Administrators', $name);
4614
    }
4615
4616
    /**
4617
     * Test for the updateContentMetadata() method.