Code Duplication    Length = 37-41 lines in 3 locations

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

@@ 4204-4240 (lines=37) @@
4201
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft
4202
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4203
     */
4204
    public function testCreateContentDraftInTransactionWithCommit()
4205
    {
4206
        $repository = $this->getRepository();
4207
4208
        $contentId = $this->generateId('object', 12);
4209
        /* BEGIN: Use Case */
4210
        // $contentId is the ID of the "Administrator users" user group
4211
4212
        // Load the user group content object
4213
        $content = $this->contentService->loadContent($contentId);
4214
4215
        // Start a new transaction
4216
        $repository->beginTransaction();
4217
4218
        try {
4219
            // Create a new draft
4220
            $drafted = $this->contentService->createContentDraft($content->contentInfo);
4221
4222
            // Store version number for later reuse
4223
            $versionNo = $drafted->versionInfo->versionNo;
4224
4225
            // Commit all changes
4226
            $repository->commit();
4227
        } catch (Exception $e) {
4228
            // Cleanup hanging transaction on error
4229
            $repository->rollback();
4230
            throw $e;
4231
        }
4232
4233
        $content = $this->contentService->loadContent($contentId, null, $versionNo);
4234
        /* END: Use Case */
4235
4236
        $this->assertEquals(
4237
            $versionNo,
4238
            $content->getVersionInfo()->versionNo
4239
        );
4240
    }
4241
4242
    /**
4243
     * Test for the publishVersion() method.
@@ 4249-4289 (lines=41) @@
4246
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
4247
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4248
     */
4249
    public function testPublishVersionInTransactionWithRollback()
4250
    {
4251
        $repository = $this->getRepository();
4252
4253
        $contentId = $this->generateId('object', 12);
4254
        /* BEGIN: Use Case */
4255
        // $contentId is the ID of the "Administrator users" user group
4256
4257
        // Load the user group content object
4258
        $content = $this->contentService->loadContent($contentId);
4259
4260
        // Start a new transaction
4261
        $repository->beginTransaction();
4262
4263
        try {
4264
            $draftVersion = $this->contentService->createContentDraft($content->contentInfo)->getVersionInfo();
4265
4266
            // Publish a new version
4267
            $content = $this->contentService->publishVersion($draftVersion);
4268
4269
            // Store version number for later reuse
4270
            $versionNo = $content->versionInfo->versionNo;
4271
        } catch (Exception $e) {
4272
            // Cleanup hanging transaction on error
4273
            $repository->rollback();
4274
            throw $e;
4275
        }
4276
4277
        // Rollback
4278
        $repository->rollback();
4279
4280
        try {
4281
            // This call will fail with a "NotFoundException"
4282
            $this->contentService->loadContent($contentId, null, $versionNo);
4283
        } catch (NotFoundException $e) {
4284
            return;
4285
        }
4286
        /* END: Use Case */
4287
4288
        $this->fail('Can still load content draft after rollback');
4289
    }
4290
4291
    /**
4292
     * Test for the publishVersion() method.
@@ 4298-4334 (lines=37) @@
4295
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
4296
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo
4297
     */
4298
    public function testPublishVersionInTransactionWithCommit()
4299
    {
4300
        $repository = $this->getRepository();
4301
4302
        /* BEGIN: Use Case */
4303
        // ID of the "Administrator users" user group
4304
        $contentId = 12;
4305
4306
        // Load the user group content object
4307
        $template = $this->contentService->loadContent($contentId);
4308
4309
        // Start a new transaction
4310
        $repository->beginTransaction();
4311
4312
        try {
4313
            // Publish a new version
4314
            $content = $this->contentService->publishVersion(
4315
                $this->contentService->createContentDraft($template->contentInfo)->getVersionInfo()
4316
            );
4317
4318
            // Store version number for later reuse
4319
            $versionNo = $content->versionInfo->versionNo;
4320
4321
            // Commit all changes
4322
            $repository->commit();
4323
        } catch (Exception $e) {
4324
            // Cleanup hanging transaction on error
4325
            $repository->rollback();
4326
            throw $e;
4327
        }
4328
4329
        // Load current version info
4330
        $versionInfo = $this->contentService->loadVersionInfo($content->contentInfo);
4331
        /* END: Use Case */
4332
4333
        $this->assertEquals($versionNo, $versionInfo->versionNo);
4334
    }
4335
4336
    /**
4337
     * Test for the updateContent() method.