Code Duplication    Length = 47-47 lines in 2 locations

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

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