Code Duplication    Length = 47-47 lines in 2 locations

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

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