Code Duplication    Length = 40-44 lines in 3 locations

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

@@ 4305-4344 (lines=40) @@
4302
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft
4303
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4304
     */
4305
    public function testCreateContentDraftInTransactionWithCommit()
4306
    {
4307
        $repository = $this->getRepository();
4308
4309
        $contentId = $this->generateId('object', 12);
4310
        /* BEGIN: Use Case */
4311
        // $contentId is the ID of the "Administrator users" user group
4312
4313
        // Get the content service
4314
        $contentService = $repository->getContentService();
4315
4316
        // Load the user group content object
4317
        $content = $contentService->loadContent($contentId);
4318
4319
        // Start a new transaction
4320
        $repository->beginTransaction();
4321
4322
        try {
4323
            // Create a new draft
4324
            $drafted = $contentService->createContentDraft($content->contentInfo);
4325
4326
            // Store version number for later reuse
4327
            $versionNo = $drafted->versionInfo->versionNo;
4328
4329
            // Commit all changes
4330
            $repository->commit();
4331
        } catch (Exception $e) {
4332
            // Cleanup hanging transaction on error
4333
            $repository->rollback();
4334
            throw $e;
4335
        }
4336
4337
        $content = $contentService->loadContent($contentId, null, $versionNo);
4338
        /* END: Use Case */
4339
4340
        $this->assertEquals(
4341
            $versionNo,
4342
            $content->getVersionInfo()->versionNo
4343
        );
4344
    }
4345
4346
    /**
4347
     * Test for the publishVersion() method.
@@ 4353-4396 (lines=44) @@
4350
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
4351
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4352
     */
4353
    public function testPublishVersionInTransactionWithRollback()
4354
    {
4355
        $repository = $this->getRepository();
4356
4357
        $contentId = $this->generateId('object', 12);
4358
        /* BEGIN: Use Case */
4359
        // $contentId is the ID of the "Administrator users" user group
4360
4361
        // Get the content service
4362
        $contentService = $repository->getContentService();
4363
4364
        // Load the user group content object
4365
        $content = $contentService->loadContent($contentId);
4366
4367
        // Start a new transaction
4368
        $repository->beginTransaction();
4369
4370
        try {
4371
            $draftVersion = $contentService->createContentDraft($content->contentInfo)->getVersionInfo();
4372
4373
            // Publish a new version
4374
            $content = $contentService->publishVersion($draftVersion);
4375
4376
            // Store version number for later reuse
4377
            $versionNo = $content->versionInfo->versionNo;
4378
        } catch (Exception $e) {
4379
            // Cleanup hanging transaction on error
4380
            $repository->rollback();
4381
            throw $e;
4382
        }
4383
4384
        // Rollback
4385
        $repository->rollback();
4386
4387
        try {
4388
            // This call will fail with a "NotFoundException"
4389
            $contentService->loadContent($contentId, null, $versionNo);
4390
        } catch (NotFoundException $e) {
4391
            return;
4392
        }
4393
        /* END: Use Case */
4394
4395
        $this->fail('Can still load content draft after rollback');
4396
    }
4397
4398
    /**
4399
     * Test for the publishVersion() method.
@@ 4405-4444 (lines=40) @@
4402
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
4403
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo
4404
     */
4405
    public function testPublishVersionInTransactionWithCommit()
4406
    {
4407
        $repository = $this->getRepository();
4408
4409
        /* BEGIN: Use Case */
4410
        // ID of the "Administrator users" user group
4411
        $contentId = 12;
4412
4413
        // Get the content service
4414
        $contentService = $repository->getContentService();
4415
4416
        // Load the user group content object
4417
        $template = $contentService->loadContent($contentId);
4418
4419
        // Start a new transaction
4420
        $repository->beginTransaction();
4421
4422
        try {
4423
            // Publish a new version
4424
            $content = $contentService->publishVersion(
4425
                $contentService->createContentDraft($template->contentInfo)->getVersionInfo()
4426
            );
4427
4428
            // Store version number for later reuse
4429
            $versionNo = $content->versionInfo->versionNo;
4430
4431
            // Commit all changes
4432
            $repository->commit();
4433
        } catch (Exception $e) {
4434
            // Cleanup hanging transaction on error
4435
            $repository->rollback();
4436
            throw $e;
4437
        }
4438
4439
        // Load current version info
4440
        $versionInfo = $contentService->loadVersionInfo($content->contentInfo);
4441
        /* END: Use Case */
4442
4443
        $this->assertEquals($versionNo, $versionInfo->versionNo);
4444
    }
4445
4446
    /**
4447
     * Test for the updateContent() method.