Code Duplication    Length = 29-34 lines in 3 locations

eZ/Publish/API/Repository/Tests/ContentServiceTest.php 1 location

@@ 4219-4247 (lines=29) @@
4216
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentWithLocationCreateParameterDoesNotCreateLocationImmediately
4217
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentThrowsNotFoundException
4218
     */
4219
    public function testCreateContentWithLocationCreateParameterInTransactionWithCommit()
4220
    {
4221
        $repository = $this->getRepository();
4222
4223
        $contentService = $repository->getContentService();
4224
4225
        /* BEGIN: Use Case */
4226
        // Start a transaction
4227
        $repository->beginTransaction();
4228
4229
        try {
4230
            $draft = $this->createContentDraftVersion1();
4231
4232
            $contentId = $draft->id;
4233
4234
            // Roleback the transaction
4235
            $repository->commit();
4236
        } catch (Exception $e) {
4237
            // Cleanup hanging transaction on error
4238
            $repository->rollback();
4239
            throw $e;
4240
        }
4241
4242
        // Load the new content object
4243
        $content = $contentService->loadContent($contentId);
4244
        /* END: Use Case */
4245
4246
        $this->assertEquals($contentId, $content->id);
4247
    }
4248
4249
    /**
4250
     * Test for the createContentDraft() method.

eZ/Publish/API/Repository/Tests/ContentTypeServiceTest.php 2 locations

@@ 3383-3416 (lines=34) @@
3380
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeGroup
3381
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testCreateContentTypeGroup
3382
     */
3383
    public function testCreateContentTypeGroupInTransactionWithCommit()
3384
    {
3385
        $repository = $this->getRepository();
3386
3387
        /* BEGIN: Use Case */
3388
        $contentTypeService = $repository->getContentTypeService();
3389
3390
        // Get create struct and set language property
3391
        $groupCreate = $contentTypeService->newContentTypeGroupCreateStruct('new-group');
3392
        /* @todo uncomment when support for multilingual names and descriptions is added
3393
        $groupCreate->mainLanguageCode = 'eng-GB';
3394
        */
3395
3396
        // Start a new transaction
3397
        $repository->beginTransaction();
3398
3399
        try {
3400
            // Create the new content type group
3401
            $groupId = $contentTypeService->createContentTypeGroup($groupCreate)->id;
3402
3403
            // Rollback all changes
3404
            $repository->commit();
3405
        } catch (Exception $e) {
3406
            // Cleanup hanging transaction on error
3407
            $repository->rollback();
3408
            throw $e;
3409
        }
3410
3411
        // Load created content type group
3412
        $group = $contentTypeService->loadContentTypeGroup($groupId);
3413
        /* END: Use Case */
3414
3415
        $this->assertEquals($groupId, $group->id);
3416
    }
3417
3418
    /**
3419
     * Test for the updateContentTypeGroup() method.
@@ 3770-3800 (lines=31) @@
3767
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeByIdentifier
3768
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeThrowsNotFoundException
3769
     */
3770
    public function testCopyContentTypeInTransactionWithCommit()
3771
    {
3772
        $repository = $this->getRepository();
3773
3774
        /* BEGIN: Use Case */
3775
        $contentTypeService = $repository->getContentTypeService();
3776
3777
        // Load content type to copy
3778
        $contentType = $contentTypeService->loadContentTypeByIdentifier('comment');
3779
3780
        // Start a new transaction
3781
        $repository->beginTransaction();
3782
3783
        try {
3784
            // Complete copy of the content type
3785
            $contentTypeId = $contentTypeService->copyContentType($contentType)->id;
3786
3787
            // Commit all changes
3788
            $repository->commit();
3789
        } catch (Exception $e) {
3790
            // Cleanup hanging transaction on error
3791
            $repository->rollback();
3792
            throw $e;
3793
        }
3794
3795
        // Load the new content type copy.
3796
        $copiedContentType = $contentTypeService->loadContentType($contentTypeId);
3797
        /* END: Use Case */
3798
3799
        $this->assertEquals($contentTypeId, $copiedContentType->id);
3800
    }
3801
3802
    /**
3803
     * Test for the deleteContentType() method.