Code Duplication    Length = 47-47 lines in 2 locations

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

@@ 4455-4501 (lines=47) @@
4452
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4453
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4454
     */
4455
    public function testUpdateContentInTransactionWithRollback()
4456
    {
4457
        $repository = $this->getRepository();
4458
4459
        $contentId = $this->generateId('object', 12);
4460
        /* BEGIN: Use Case */
4461
        // $contentId is the ID of the "Administrator users" user group
4462
4463
        // Load content service
4464
        $contentService = $repository->getContentService();
4465
4466
        // Create a new user group draft
4467
        $draft = $contentService->createContentDraft(
4468
            $contentService->loadContentInfo($contentId)
4469
        );
4470
4471
        // Get an update struct and change the group name
4472
        $contentUpdate = $contentService->newContentUpdateStruct();
4473
        $contentUpdate->setField('name', 'Administrators', 'eng-US');
4474
4475
        // Start a transaction
4476
        $repository->beginTransaction();
4477
4478
        try {
4479
            // Update the group name
4480
            $draft = $contentService->updateContent(
4481
                $draft->getVersionInfo(),
4482
                $contentUpdate
4483
            );
4484
4485
            // Publish updated version
4486
            $contentService->publishVersion($draft->getVersionInfo());
4487
        } catch (Exception $e) {
4488
            // Cleanup hanging transaction on error
4489
            $repository->rollback();
4490
            throw $e;
4491
        }
4492
4493
        // Rollback all changes.
4494
        $repository->rollback();
4495
4496
        // Name will still be "Administrator users"
4497
        $name = $contentService->loadContent($contentId)->getFieldValue('name');
4498
        /* END: Use Case */
4499
4500
        $this->assertEquals('Administrator users', $name);
4501
    }
4502
4503
    /**
4504
     * Test for the updateContent() method.
@@ 4511-4557 (lines=47) @@
4508
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4509
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4510
     */
4511
    public function testUpdateContentInTransactionWithCommit()
4512
    {
4513
        $repository = $this->getRepository();
4514
4515
        $contentId = $this->generateId('object', 12);
4516
        /* BEGIN: Use Case */
4517
        // $contentId is the ID of the "Administrator users" user group
4518
4519
        // Load content service
4520
        $contentService = $repository->getContentService();
4521
4522
        // Create a new user group draft
4523
        $draft = $contentService->createContentDraft(
4524
            $contentService->loadContentInfo($contentId)
4525
        );
4526
4527
        // Get an update struct and change the group name
4528
        $contentUpdate = $contentService->newContentUpdateStruct();
4529
        $contentUpdate->setField('name', 'Administrators', 'eng-US');
4530
4531
        // Start a transaction
4532
        $repository->beginTransaction();
4533
4534
        try {
4535
            // Update the group name
4536
            $draft = $contentService->updateContent(
4537
                $draft->getVersionInfo(),
4538
                $contentUpdate
4539
            );
4540
4541
            // Publish updated version
4542
            $contentService->publishVersion($draft->getVersionInfo());
4543
4544
            // Commit all changes.
4545
            $repository->commit();
4546
        } catch (Exception $e) {
4547
            // Cleanup hanging transaction on error
4548
            $repository->rollback();
4549
            throw $e;
4550
        }
4551
4552
        // Name is now "Administrators"
4553
        $name = $contentService->loadContent($contentId)->getFieldValue('name', 'eng-US');
4554
        /* END: Use Case */
4555
4556
        $this->assertEquals('Administrators', $name);
4557
    }
4558
4559
    /**
4560
     * Test for the updateContentMetadata() method.