Code Duplication    Length = 47-47 lines in 2 locations

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

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