Code Duplication    Length = 40-44 lines in 3 locations

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

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