Code Duplication    Length = 47-47 lines in 2 locations

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

@@ 4395-4441 (lines=47) @@
4392
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4393
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4394
     */
4395
    public function testUpdateContentInTransactionWithRollback()
4396
    {
4397
        $repository = $this->getRepository();
4398
4399
        $contentId = $this->generateId('object', 12);
4400
        /* BEGIN: Use Case */
4401
        // $contentId is the ID of the "Administrator users" user group
4402
4403
        // Load content service
4404
        $contentService = $repository->getContentService();
4405
4406
        // Create a new user group draft
4407
        $draft = $contentService->createContentDraft(
4408
            $contentService->loadContentInfo($contentId)
4409
        );
4410
4411
        // Get an update struct and change the group name
4412
        $contentUpdate = $contentService->newContentUpdateStruct();
4413
        $contentUpdate->setField('name', 'Administrators', 'eng-US');
4414
4415
        // Start a transaction
4416
        $repository->beginTransaction();
4417
4418
        try {
4419
            // Update the group name
4420
            $draft = $contentService->updateContent(
4421
                $draft->getVersionInfo(),
4422
                $contentUpdate
4423
            );
4424
4425
            // Publish updated version
4426
            $contentService->publishVersion($draft->getVersionInfo());
4427
        } catch (Exception $e) {
4428
            // Cleanup hanging transaction on error
4429
            $repository->rollback();
4430
            throw $e;
4431
        }
4432
4433
        // Rollback all changes.
4434
        $repository->rollback();
4435
4436
        // Name will still be "Administrator users"
4437
        $name = $contentService->loadContent($contentId)->getFieldValue('name');
4438
        /* END: Use Case */
4439
4440
        $this->assertEquals('Administrator users', $name);
4441
    }
4442
4443
    /**
4444
     * Test for the updateContent() method.
@@ 4451-4497 (lines=47) @@
4448
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4449
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4450
     */
4451
    public function testUpdateContentInTransactionWithCommit()
4452
    {
4453
        $repository = $this->getRepository();
4454
4455
        $contentId = $this->generateId('object', 12);
4456
        /* BEGIN: Use Case */
4457
        // $contentId is the ID of the "Administrator users" user group
4458
4459
        // Load content service
4460
        $contentService = $repository->getContentService();
4461
4462
        // Create a new user group draft
4463
        $draft = $contentService->createContentDraft(
4464
            $contentService->loadContentInfo($contentId)
4465
        );
4466
4467
        // Get an update struct and change the group name
4468
        $contentUpdate = $contentService->newContentUpdateStruct();
4469
        $contentUpdate->setField('name', 'Administrators', 'eng-US');
4470
4471
        // Start a transaction
4472
        $repository->beginTransaction();
4473
4474
        try {
4475
            // Update the group name
4476
            $draft = $contentService->updateContent(
4477
                $draft->getVersionInfo(),
4478
                $contentUpdate
4479
            );
4480
4481
            // Publish updated version
4482
            $contentService->publishVersion($draft->getVersionInfo());
4483
4484
            // Commit all changes.
4485
            $repository->commit();
4486
        } catch (Exception $e) {
4487
            // Cleanup hanging transaction on error
4488
            $repository->rollback();
4489
            throw $e;
4490
        }
4491
4492
        // Name is now "Administrators"
4493
        $name = $contentService->loadContent($contentId)->getFieldValue('name', 'eng-US');
4494
        /* END: Use Case */
4495
4496
        $this->assertEquals('Administrators', $name);
4497
    }
4498
4499
    /**
4500
     * Test for the updateContentMetadata() method.