Code Duplication    Length = 47-47 lines in 2 locations

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

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