Code Duplication    Length = 40-44 lines in 3 locations

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

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