Code Duplication    Length = 40-44 lines in 3 locations

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

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