Code Duplication    Length = 47-47 lines in 2 locations

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

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