Code Duplication    Length = 44-44 lines in 2 locations

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

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