Code Duplication    Length = 37-41 lines in 3 locations

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

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