Code Duplication    Length = 36-36 lines in 3 locations

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

@@ 4310-4345 (lines=36) @@
4307
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4308
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentDrafts
4309
     */
4310
    public function testDeleteVersionInTransactionWithRollback()
4311
    {
4312
        $repository = $this->getRepository();
4313
4314
        $contentId = $this->generateId('object', 12);
4315
        /* BEGIN: Use Case */
4316
        // $contentId is the ID of the "Administrator users" user group
4317
4318
        // Get the content service
4319
        $contentService = $repository->getContentService();
4320
4321
        // Start a new transaction
4322
        $repository->beginTransaction();
4323
4324
        try {
4325
            // Create a new draft
4326
            $draft = $contentService->createContentDraft(
4327
                $contentService->loadContentInfo($contentId)
4328
            );
4329
4330
            $contentService->deleteVersion($draft->getVersionInfo());
4331
        } catch (Exception $e) {
4332
            // Cleanup hanging transaction on error
4333
            $repository->rollback();
4334
            throw $e;
4335
        }
4336
4337
        // Rollback all changes.
4338
        $repository->rollback();
4339
4340
        // This array will be empty
4341
        $drafts = $contentService->loadContentDrafts();
4342
        /* END: Use Case */
4343
4344
        $this->assertSame([], $drafts);
4345
    }
4346
4347
    /**
4348
     * Test for the deleteVersion() method.
@@ 4355-4390 (lines=36) @@
4352
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4353
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentDrafts
4354
     */
4355
    public function testDeleteVersionInTransactionWithCommit()
4356
    {
4357
        $repository = $this->getRepository();
4358
4359
        $contentId = $this->generateId('object', 12);
4360
        /* BEGIN: Use Case */
4361
        // $contentId is the ID of the "Administrator users" user group
4362
4363
        // Get the content service
4364
        $contentService = $repository->getContentService();
4365
4366
        // Start a new transaction
4367
        $repository->beginTransaction();
4368
4369
        try {
4370
            // Create a new draft
4371
            $draft = $contentService->createContentDraft(
4372
                $contentService->loadContentInfo($contentId)
4373
            );
4374
4375
            $contentService->deleteVersion($draft->getVersionInfo());
4376
4377
            // Commit all changes.
4378
            $repository->commit();
4379
        } catch (Exception $e) {
4380
            // Cleanup hanging transaction on error
4381
            $repository->rollback();
4382
            throw $e;
4383
        }
4384
4385
        // This array will contain no element
4386
        $drafts = $contentService->loadContentDrafts();
4387
        /* END: Use Case */
4388
4389
        $this->assertSame([], $drafts);
4390
    }
4391
4392
    /**
4393
     * Test for the deleteContent() method.
@@ 4399-4434 (lines=36) @@
4396
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteContent
4397
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4398
     */
4399
    public function testDeleteContentInTransactionWithRollback()
4400
    {
4401
        $repository = $this->getRepository();
4402
4403
        $contentId = $this->generateId('object', 11);
4404
        /* BEGIN: Use Case */
4405
        // $contentId is the ID of the "Members" user group in an eZ Publish
4406
        // demo installation
4407
4408
        // Get content service
4409
        $contentService = $repository->getContentService();
4410
4411
        // Load a ContentInfo instance
4412
        $contentInfo = $contentService->loadContentInfo($contentId);
4413
4414
        // Start a new transaction
4415
        $repository->beginTransaction();
4416
4417
        try {
4418
            // Delete content object
4419
            $contentService->deleteContent($contentInfo);
4420
        } catch (Exception $e) {
4421
            // Cleanup hanging transaction on error
4422
            $repository->rollback();
4423
            throw $e;
4424
        }
4425
4426
        // Rollback all changes
4427
        $repository->rollback();
4428
4429
        // This call will return the original content object
4430
        $contentInfo = $contentService->loadContentInfo($contentId);
4431
        /* END: Use Case */
4432
4433
        $this->assertEquals($contentId, $contentInfo->id);
4434
    }
4435
4436
    /**
4437
     * Test for the deleteContent() method.