Code Duplication    Length = 44-44 lines in 2 locations

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

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