Code Duplication    Length = 40-44 lines in 3 locations

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

@@ 4161-4200 (lines=40) @@
4158
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft
4159
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4160
     */
4161
    public function testCreateContentDraftInTransactionWithCommit()
4162
    {
4163
        $repository = $this->getRepository();
4164
4165
        $contentId = $this->generateId('object', 12);
4166
        /* BEGIN: Use Case */
4167
        // $contentId is the ID of the "Administrator users" user group
4168
4169
        // Get the content service
4170
        $contentService = $repository->getContentService();
4171
4172
        // Load the user group content object
4173
        $content = $contentService->loadContent($contentId);
4174
4175
        // Start a new transaction
4176
        $repository->beginTransaction();
4177
4178
        try {
4179
            // Create a new draft
4180
            $drafted = $contentService->createContentDraft($content->contentInfo);
4181
4182
            // Store version number for later reuse
4183
            $versionNo = $drafted->versionInfo->versionNo;
4184
4185
            // Commit all changes
4186
            $repository->commit();
4187
        } catch (Exception $e) {
4188
            // Cleanup hanging transaction on error
4189
            $repository->rollback();
4190
            throw $e;
4191
        }
4192
4193
        $content = $contentService->loadContent($contentId, null, $versionNo);
4194
        /* END: Use Case */
4195
4196
        $this->assertEquals(
4197
            $versionNo,
4198
            $content->getVersionInfo()->versionNo
4199
        );
4200
    }
4201
4202
    /**
4203
     * Test for the publishVersion() method.
@@ 4209-4252 (lines=44) @@
4206
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
4207
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent
4208
     */
4209
    public function testPublishVersionInTransactionWithRollback()
4210
    {
4211
        $repository = $this->getRepository();
4212
4213
        $contentId = $this->generateId('object', 12);
4214
        /* BEGIN: Use Case */
4215
        // $contentId is the ID of the "Administrator users" user group
4216
4217
        // Get the content service
4218
        $contentService = $repository->getContentService();
4219
4220
        // Load the user group content object
4221
        $content = $contentService->loadContent($contentId);
4222
4223
        // Start a new transaction
4224
        $repository->beginTransaction();
4225
4226
        try {
4227
            $draftVersion = $contentService->createContentDraft($content->contentInfo)->getVersionInfo();
4228
4229
            // Publish a new version
4230
            $content = $contentService->publishVersion($draftVersion);
4231
4232
            // Store version number for later reuse
4233
            $versionNo = $content->versionInfo->versionNo;
4234
        } catch (Exception $e) {
4235
            // Cleanup hanging transaction on error
4236
            $repository->rollback();
4237
            throw $e;
4238
        }
4239
4240
        // Rollback
4241
        $repository->rollback();
4242
4243
        try {
4244
            // This call will fail with a "NotFoundException"
4245
            $contentService->loadContent($contentId, null, $versionNo);
4246
        } catch (NotFoundException $e) {
4247
            return;
4248
        }
4249
        /* END: Use Case */
4250
4251
        $this->fail('Can still load content draft after rollback');
4252
    }
4253
4254
    /**
4255
     * Test for the publishVersion() method.
@@ 4261-4300 (lines=40) @@
4258
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion
4259
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo
4260
     */
4261
    public function testPublishVersionInTransactionWithCommit()
4262
    {
4263
        $repository = $this->getRepository();
4264
4265
        /* BEGIN: Use Case */
4266
        // ID of the "Administrator users" user group
4267
        $contentId = 12;
4268
4269
        // Get the content service
4270
        $contentService = $repository->getContentService();
4271
4272
        // Load the user group content object
4273
        $template = $contentService->loadContent($contentId);
4274
4275
        // Start a new transaction
4276
        $repository->beginTransaction();
4277
4278
        try {
4279
            // Publish a new version
4280
            $content = $contentService->publishVersion(
4281
                $contentService->createContentDraft($template->contentInfo)->getVersionInfo()
4282
            );
4283
4284
            // Store version number for later reuse
4285
            $versionNo = $content->versionInfo->versionNo;
4286
4287
            // Commit all changes
4288
            $repository->commit();
4289
        } catch (Exception $e) {
4290
            // Cleanup hanging transaction on error
4291
            $repository->rollback();
4292
            throw $e;
4293
        }
4294
4295
        // Load current version info
4296
        $versionInfo = $contentService->loadVersionInfo($content->contentInfo);
4297
        /* END: Use Case */
4298
4299
        $this->assertEquals($versionNo, $versionInfo->versionNo);
4300
    }
4301
4302
    /**
4303
     * Test for the updateContent() method.