Code Duplication    Length = 40-44 lines in 3 locations

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

@@ 4250-4289 (lines=40) @@
4247
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft
4248
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4249
     */
4250
    public function testCreateContentDraftInTransactionWithCommit()
4251
    {
4252
        $repository = $this->getRepository();
4253
4254
        $contentId = $this->generateId('object', 12);
4255
        /* BEGIN: Use Case */
4256
        // $contentId is the ID of the "Administrator users" user group
4257
4258
        // Get the content service
4259
        $contentService = $repository->getContentService();
4260
4261
        // Load the user group content object
4262
        $content = $contentService->loadContent($contentId);
4263
4264
        // Start a new transaction
4265
        $repository->beginTransaction();
4266
4267
        try {
4268
            // Create a new draft
4269
            $drafted = $contentService->createContentDraft($content->contentInfo);
4270
4271
            // Store version number for later reuse
4272
            $versionNo = $drafted->versionInfo->versionNo;
4273
4274
            // Commit all changes
4275
            $repository->commit();
4276
        } catch (Exception $e) {
4277
            // Cleanup hanging transaction on error
4278
            $repository->rollback();
4279
            throw $e;
4280
        }
4281
4282
        $content = $contentService->loadContent($contentId, null, $versionNo);
4283
        /* END: Use Case */
4284
4285
        $this->assertEquals(
4286
            $versionNo,
4287
            $content->getVersionInfo()->versionNo
4288
        );
4289
    }
4290
4291
    /**
4292
     * Test for the publishVersion() method.
@@ 4298-4341 (lines=44) @@
4295
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
4296
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4297
     */
4298
    public function testPublishVersionInTransactionWithRollback()
4299
    {
4300
        $repository = $this->getRepository();
4301
4302
        $contentId = $this->generateId('object', 12);
4303
        /* BEGIN: Use Case */
4304
        // $contentId is the ID of the "Administrator users" user group
4305
4306
        // Get the content service
4307
        $contentService = $repository->getContentService();
4308
4309
        // Load the user group content object
4310
        $content = $contentService->loadContent($contentId);
4311
4312
        // Start a new transaction
4313
        $repository->beginTransaction();
4314
4315
        try {
4316
            $draftVersion = $contentService->createContentDraft($content->contentInfo)->getVersionInfo();
4317
4318
            // Publish a new version
4319
            $content = $contentService->publishVersion($draftVersion);
4320
4321
            // Store version number for later reuse
4322
            $versionNo = $content->versionInfo->versionNo;
4323
        } catch (Exception $e) {
4324
            // Cleanup hanging transaction on error
4325
            $repository->rollback();
4326
            throw $e;
4327
        }
4328
4329
        // Rollback
4330
        $repository->rollback();
4331
4332
        try {
4333
            // This call will fail with a "NotFoundException"
4334
            $contentService->loadContent($contentId, null, $versionNo);
4335
        } catch (NotFoundException $e) {
4336
            return;
4337
        }
4338
        /* END: Use Case */
4339
4340
        $this->fail('Can still load content draft after rollback');
4341
    }
4342
4343
    /**
4344
     * Test for the publishVersion() method.
@@ 4350-4389 (lines=40) @@
4347
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
4348
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo
4349
     */
4350
    public function testPublishVersionInTransactionWithCommit()
4351
    {
4352
        $repository = $this->getRepository();
4353
4354
        /* BEGIN: Use Case */
4355
        // ID of the "Administrator users" user group
4356
        $contentId = 12;
4357
4358
        // Get the content service
4359
        $contentService = $repository->getContentService();
4360
4361
        // Load the user group content object
4362
        $template = $contentService->loadContent($contentId);
4363
4364
        // Start a new transaction
4365
        $repository->beginTransaction();
4366
4367
        try {
4368
            // Publish a new version
4369
            $content = $contentService->publishVersion(
4370
                $contentService->createContentDraft($template->contentInfo)->getVersionInfo()
4371
            );
4372
4373
            // Store version number for later reuse
4374
            $versionNo = $content->versionInfo->versionNo;
4375
4376
            // Commit all changes
4377
            $repository->commit();
4378
        } catch (Exception $e) {
4379
            // Cleanup hanging transaction on error
4380
            $repository->rollback();
4381
            throw $e;
4382
        }
4383
4384
        // Load current version info
4385
        $versionInfo = $contentService->loadVersionInfo($content->contentInfo);
4386
        /* END: Use Case */
4387
4388
        $this->assertEquals($versionNo, $versionInfo->versionNo);
4389
    }
4390
4391
    /**
4392
     * Test for the updateContent() method.