Code Duplication    Length = 47-47 lines in 2 locations

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

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