Code Duplication    Length = 40-44 lines in 3 locations

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

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