Code Duplication    Length = 40-44 lines in 3 locations

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

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