Code Duplication    Length = 47-47 lines in 2 locations

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

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