Code Duplication    Length = 47-47 lines in 2 locations

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

@@ 4314-4360 (lines=47) @@
4311
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4312
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4313
     */
4314
    public function testUpdateContentInTransactionWithRollback()
4315
    {
4316
        $repository = $this->getRepository();
4317
4318
        $contentId = $this->generateId('object', 12);
4319
        /* BEGIN: Use Case */
4320
        // $contentId is the ID of the "Administrator users" user group
4321
4322
        // Load content service
4323
        $contentService = $repository->getContentService();
4324
4325
        // Create a new user group draft
4326
        $draft = $contentService->createContentDraft(
4327
            $contentService->loadContentInfo($contentId)
4328
        );
4329
4330
        // Get an update struct and change the group name
4331
        $contentUpdate = $contentService->newContentUpdateStruct();
4332
        $contentUpdate->setField('name', 'Administrators', 'eng-US');
4333
4334
        // Start a transaction
4335
        $repository->beginTransaction();
4336
4337
        try {
4338
            // Update the group name
4339
            $draft = $contentService->updateContent(
4340
                $draft->getVersionInfo(),
4341
                $contentUpdate
4342
            );
4343
4344
            // Publish updated version
4345
            $contentService->publishVersion($draft->getVersionInfo());
4346
        } catch (Exception $e) {
4347
            // Cleanup hanging transaction on error
4348
            $repository->rollback();
4349
            throw $e;
4350
        }
4351
4352
        // Rollback all changes.
4353
        $repository->rollback();
4354
4355
        // Name will still be "Administrator users"
4356
        $name = $contentService->loadContent($contentId)->getFieldValue('name');
4357
        /* END: Use Case */
4358
4359
        $this->assertEquals('Administrator users', $name);
4360
    }
4361
4362
    /**
4363
     * Test for the updateContent() method.
@@ 4370-4416 (lines=47) @@
4367
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4368
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4369
     */
4370
    public function testUpdateContentInTransactionWithCommit()
4371
    {
4372
        $repository = $this->getRepository();
4373
4374
        $contentId = $this->generateId('object', 12);
4375
        /* BEGIN: Use Case */
4376
        // $contentId is the ID of the "Administrator users" user group
4377
4378
        // Load content service
4379
        $contentService = $repository->getContentService();
4380
4381
        // Create a new user group draft
4382
        $draft = $contentService->createContentDraft(
4383
            $contentService->loadContentInfo($contentId)
4384
        );
4385
4386
        // Get an update struct and change the group name
4387
        $contentUpdate = $contentService->newContentUpdateStruct();
4388
        $contentUpdate->setField('name', 'Administrators', 'eng-US');
4389
4390
        // Start a transaction
4391
        $repository->beginTransaction();
4392
4393
        try {
4394
            // Update the group name
4395
            $draft = $contentService->updateContent(
4396
                $draft->getVersionInfo(),
4397
                $contentUpdate
4398
            );
4399
4400
            // Publish updated version
4401
            $contentService->publishVersion($draft->getVersionInfo());
4402
4403
            // Commit all changes.
4404
            $repository->commit();
4405
        } catch (Exception $e) {
4406
            // Cleanup hanging transaction on error
4407
            $repository->rollback();
4408
            throw $e;
4409
        }
4410
4411
        // Name is now "Administrators"
4412
        $name = $contentService->loadContent($contentId)->getFieldValue('name', 'eng-US');
4413
        /* END: Use Case */
4414
4415
        $this->assertEquals('Administrators', $name);
4416
    }
4417
4418
    /**
4419
     * Test for the updateContentMetadata() method.