Code Duplication    Length = 47-47 lines in 2 locations

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

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