Code Duplication    Length = 47-47 lines in 2 locations

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

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