Code Duplication    Length = 47-47 lines in 2 locations

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

@@ 4354-4400 (lines=47) @@
4351
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4352
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4353
     */
4354
    public function testUpdateContentInTransactionWithRollback()
4355
    {
4356
        $repository = $this->getRepository();
4357
4358
        $contentId = $this->generateId('object', 12);
4359
        /* BEGIN: Use Case */
4360
        // $contentId is the ID of the "Administrator users" user group
4361
4362
        // Load content service
4363
        $contentService = $repository->getContentService();
4364
4365
        // Create a new user group draft
4366
        $draft = $contentService->createContentDraft(
4367
            $contentService->loadContentInfo($contentId)
4368
        );
4369
4370
        // Get an update struct and change the group name
4371
        $contentUpdate = $contentService->newContentUpdateStruct();
4372
        $contentUpdate->setField('name', 'Administrators', 'eng-US');
4373
4374
        // Start a transaction
4375
        $repository->beginTransaction();
4376
4377
        try {
4378
            // Update the group name
4379
            $draft = $contentService->updateContent(
4380
                $draft->getVersionInfo(),
4381
                $contentUpdate
4382
            );
4383
4384
            // Publish updated version
4385
            $contentService->publishVersion($draft->getVersionInfo());
4386
        } catch (Exception $e) {
4387
            // Cleanup hanging transaction on error
4388
            $repository->rollback();
4389
            throw $e;
4390
        }
4391
4392
        // Rollback all changes.
4393
        $repository->rollback();
4394
4395
        // Name will still be "Administrator users"
4396
        $name = $contentService->loadContent($contentId)->getFieldValue('name');
4397
        /* END: Use Case */
4398
4399
        $this->assertEquals('Administrator users', $name);
4400
    }
4401
4402
    /**
4403
     * Test for the updateContent() method.
@@ 4410-4456 (lines=47) @@
4407
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4408
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4409
     */
4410
    public function testUpdateContentInTransactionWithCommit()
4411
    {
4412
        $repository = $this->getRepository();
4413
4414
        $contentId = $this->generateId('object', 12);
4415
        /* BEGIN: Use Case */
4416
        // $contentId is the ID of the "Administrator users" user group
4417
4418
        // Load content service
4419
        $contentService = $repository->getContentService();
4420
4421
        // Create a new user group draft
4422
        $draft = $contentService->createContentDraft(
4423
            $contentService->loadContentInfo($contentId)
4424
        );
4425
4426
        // Get an update struct and change the group name
4427
        $contentUpdate = $contentService->newContentUpdateStruct();
4428
        $contentUpdate->setField('name', 'Administrators', 'eng-US');
4429
4430
        // Start a transaction
4431
        $repository->beginTransaction();
4432
4433
        try {
4434
            // Update the group name
4435
            $draft = $contentService->updateContent(
4436
                $draft->getVersionInfo(),
4437
                $contentUpdate
4438
            );
4439
4440
            // Publish updated version
4441
            $contentService->publishVersion($draft->getVersionInfo());
4442
4443
            // Commit all changes.
4444
            $repository->commit();
4445
        } catch (Exception $e) {
4446
            // Cleanup hanging transaction on error
4447
            $repository->rollback();
4448
            throw $e;
4449
        }
4450
4451
        // Name is now "Administrators"
4452
        $name = $contentService->loadContent($contentId)->getFieldValue('name', 'eng-US');
4453
        /* END: Use Case */
4454
4455
        $this->assertEquals('Administrators', $name);
4456
    }
4457
4458
    /**
4459
     * Test for the updateContentMetadata() method.