Code Duplication    Length = 26-40 lines in 9 locations

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

@@ 3815-3847 (lines=33) @@
3812
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentWithLocationCreateParameterDoesNotCreateLocationImmediately
3813
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentThrowsNotFoundException
3814
     */
3815
    public function testCreateContentWithLocationCreateParameterInTransactionWithRollback()
3816
    {
3817
        $repository = $this->getRepository();
3818
3819
        $contentService = $repository->getContentService();
3820
3821
        /* BEGIN: Use Case */
3822
        // Start a transaction
3823
        $repository->beginTransaction();
3824
3825
        try {
3826
            $draft = $this->createContentDraftVersion1();
3827
        } catch (Exception $e) {
3828
            // Cleanup hanging transaction on error
3829
            $repository->rollback();
3830
            throw $e;
3831
        }
3832
3833
        $contentId = $draft->id;
3834
3835
        // Roleback the transaction
3836
        $repository->rollback();
3837
3838
        try {
3839
            // This call will fail with a "NotFoundException"
3840
            $contentService->loadContent($contentId);
3841
        } catch (NotFoundException $e) {
3842
            return;
3843
        }
3844
        /* END: Use Case */
3845
3846
        $this->fail('Can still load content object after rollback.');
3847
    }
3848
3849
    /**
3850
     * Test for the createContent() method.
@@ 4443-4482 (lines=40) @@
4440
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteContent
4441
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4442
     */
4443
    public function testDeleteContentInTransactionWithCommit()
4444
    {
4445
        $repository = $this->getRepository();
4446
4447
        $contentId = $this->generateId('object', 11);
4448
        /* BEGIN: Use Case */
4449
        // $contentId is the ID of the "Members" user group in an eZ Publish
4450
        // demo installation
4451
4452
        // Get content service
4453
        $contentService = $repository->getContentService();
4454
4455
        // Load a ContentInfo instance
4456
        $contentInfo = $contentService->loadContentInfo($contentId);
4457
4458
        // Start a new transaction
4459
        $repository->beginTransaction();
4460
4461
        try {
4462
            // Delete content object
4463
            $contentService->deleteContent($contentInfo);
4464
4465
            // Commit all changes
4466
            $repository->commit();
4467
        } catch (Exception $e) {
4468
            // Cleanup hanging transaction on error
4469
            $repository->rollback();
4470
            throw $e;
4471
        }
4472
4473
        // Deleted content info is not found anymore
4474
        try {
4475
            $contentService->loadContentInfo($contentId);
4476
        } catch (NotFoundException $e) {
4477
            return;
4478
        }
4479
        /* END: Use Case */
4480
4481
        $this->fail('Can still load ContentInfo after commit.');
4482
    }
4483
4484
    /**
4485
     * Test for the copyContent() method.

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

@@ 522-547 (lines=26) @@
519
     * @see \eZ\Publish\API\Repository\ContentTypeService::deleteContentTypeGroup()
520
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeGroup
521
     */
522
    public function testDeleteContentTypeGroup()
523
    {
524
        $repository = $this->getRepository();
525
526
        /* BEGIN: Use Case */
527
        $contentTypeService = $repository->getContentTypeService();
528
529
        $groupCreate = $contentTypeService->newContentTypeGroupCreateStruct(
530
            'new-group'
531
        );
532
        $contentTypeService->createContentTypeGroup($groupCreate);
533
534
        // ...
535
536
        $group = $contentTypeService->loadContentTypeGroupByIdentifier('new-group');
537
538
        $contentTypeService->deleteContentTypeGroup($group);
539
        /* END: Use Case */
540
541
        try {
542
            $contentTypeService->loadContentTypeGroup($group->id);
543
            $this->fail('Content type group not deleted.');
544
        } catch (NotFoundException $e) {
545
            // All fine
546
        }
547
    }
548
549
    /**
550
     * Test for the newContentTypeCreateStruct() method.
@@ 2970-3007 (lines=38) @@
2967
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeGroup
2968
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testCreateContentTypeGroup
2969
     */
2970
    public function testCreateContentTypeGroupInTransactionWithRollback()
2971
    {
2972
        $repository = $this->getRepository();
2973
2974
        /* BEGIN: Use Case */
2975
        $contentTypeService = $repository->getContentTypeService();
2976
2977
        // Get create struct and set language property
2978
        $groupCreate = $contentTypeService->newContentTypeGroupCreateStruct('new-group');
2979
        /* @todo uncomment when support for multilingual names and descriptions is added
2980
        $groupCreate->mainLanguageCode = 'eng-GB';
2981
        */
2982
2983
        // Start a new transaction
2984
        $repository->beginTransaction();
2985
2986
        try {
2987
            // Create the new content type group
2988
            $groupId = $contentTypeService->createContentTypeGroup($groupCreate)->id;
2989
        } catch (Exception $e) {
2990
            // Cleanup hanging transaction on error
2991
            $repository->rollback();
2992
            throw $e;
2993
        }
2994
2995
        // Rollback all changes
2996
        $repository->rollback();
2997
2998
        try {
2999
            // This call will fail with a "NotFoundException"
3000
            $contentTypeService->loadContentTypeGroup($groupId);
3001
        } catch (NotFoundException $e) {
3002
            return;
3003
        }
3004
        /* END: Use Case */
3005
3006
        $this->fail('Can still load content type group after rollback');
3007
    }
3008
3009
    /**
3010
     * Test for the createContentTypeGroup() method.
@@ 3146-3185 (lines=40) @@
3143
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testDeleteContentTypeGroup
3144
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeGroupByIdentifierThrowsNotFoundException
3145
     */
3146
    public function testDeleteContentTypeGroupWithRollback()
3147
    {
3148
        $repository = $this->getRepository();
3149
3150
        /* BEGIN: Use Case */
3151
        $contentTypeService = $repository->getContentTypeService();
3152
3153
        // Get a group create struct
3154
        $groupCreate = $contentTypeService->newContentTypeGroupCreateStruct(
3155
            'new-group'
3156
        );
3157
3158
        // Start a new transaction
3159
        $repository->beginTransaction();
3160
3161
        try {
3162
            // Create the new group
3163
            $group = $contentTypeService->createContentTypeGroup($groupCreate);
3164
3165
            // Delete the currently created group
3166
            $contentTypeService->deleteContentTypeGroup($group);
3167
        } catch (Exception $e) {
3168
            // Cleanup hanging transaction on error
3169
            $repository->rollback();
3170
            throw $e;
3171
        }
3172
3173
        // Rollback all changes
3174
        $repository->rollback();
3175
3176
        try {
3177
            // This call will fail with an "NotFoundException"
3178
            $contentTypeService->loadContentTypeGroupByIdentifier('new-group');
3179
        } catch (NotFoundException $e) {
3180
            // Expected error path
3181
        }
3182
        /* END: Use Case */
3183
3184
        $this->assertTrue(isset($e), 'Group not deleted after rollback');
3185
    }
3186
3187
    /**
3188
     * Test for the deleteContentTypeGroup() method.
@@ 3194-3233 (lines=40) @@
3191
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testDeleteContentTypeGroup
3192
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeGroupByIdentifierThrowsNotFoundException
3193
     */
3194
    public function testDeleteContentTypeGroupWithCommit()
3195
    {
3196
        $repository = $this->getRepository();
3197
3198
        /* BEGIN: Use Case */
3199
        $contentTypeService = $repository->getContentTypeService();
3200
3201
        // Get a group create struct
3202
        $groupCreate = $contentTypeService->newContentTypeGroupCreateStruct(
3203
            'new-group'
3204
        );
3205
3206
        // Start a new transaction
3207
        $repository->beginTransaction();
3208
3209
        try {
3210
            // Create the new group
3211
            $group = $contentTypeService->createContentTypeGroup($groupCreate);
3212
3213
            // Delete the currently created group
3214
            $contentTypeService->deleteContentTypeGroup($group);
3215
3216
            // Commit all changes
3217
            $repository->commit();
3218
        } catch (Exception $e) {
3219
            // Cleanup hanging transaction on error
3220
            $repository->rollback();
3221
            throw $e;
3222
        }
3223
3224
        try {
3225
            // This call will fail with an "NotFoundException"
3226
            $contentTypeService->loadContentTypeGroupByIdentifier('new-group');
3227
        } catch (NotFoundException $e) {
3228
            // Expected error path
3229
        }
3230
        /* END: Use Case */
3231
3232
        $this->assertTrue(isset($e), 'Group not deleted after commit.');
3233
    }
3234
3235
    /**
3236
     * Test for the createContentType() method.
@@ 3359-3393 (lines=35) @@
3356
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeByIdentifier
3357
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeThrowsNotFoundException
3358
     */
3359
    public function testCopyContentTypeInTransactionWithRollback()
3360
    {
3361
        $repository = $this->getRepository();
3362
3363
        /* BEGIN: Use Case */
3364
        $contentTypeService = $repository->getContentTypeService();
3365
3366
        // Load content type to copy
3367
        $contentType = $contentTypeService->loadContentTypeByIdentifier('comment');
3368
3369
        // Start a new transaction
3370
        $repository->beginTransaction();
3371
3372
        try {
3373
            // Complete copy of the content type
3374
            $copiedType = $contentTypeService->copyContentType($contentType);
3375
        } catch (Exception $e) {
3376
            // Cleanup hanging transaction on error
3377
            $repository->rollback();
3378
            throw $e;
3379
        }
3380
3381
        // Rollback all changes
3382
        $repository->rollback();
3383
3384
        try {
3385
            // This call will fail with a "NotFoundException"
3386
            $contentTypeService->loadContentType($copiedType->id);
3387
        } catch (NotFoundException $e) {
3388
            // Expected execution path
3389
        }
3390
        /* END: Use Case */
3391
3392
        $this->assertTrue(isset($e), 'Can still load copied content type after rollback.');
3393
    }
3394
3395
    /**
3396
     * Test for the copyContentType() method.
@@ 3481-3515 (lines=35) @@
3478
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testCopyContentType
3479
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeByIdentifierThrowsNotFoundException
3480
     */
3481
    public function testDeleteContentTypeInTransactionWithCommit()
3482
    {
3483
        $repository = $this->getRepository();
3484
3485
        /* BEGIN: Use Case */
3486
        $contentTypeService = $repository->getContentTypeService();
3487
3488
        // Load content type to copy
3489
        $contentType = $contentTypeService->loadContentTypeByIdentifier('comment');
3490
3491
        // Start a new transaction
3492
        $repository->beginTransaction();
3493
3494
        try {
3495
            // Delete the "comment" content type.
3496
            $contentTypeService->deleteContentType($contentType);
3497
3498
            // Commit all changes
3499
            $repository->commit();
3500
        } catch (Exception $e) {
3501
            // Cleanup hanging transaction on error
3502
            $repository->rollback();
3503
            throw $e;
3504
        }
3505
3506
        try {
3507
            // This call will fail with a "NotFoundException"
3508
            $contentTypeService->loadContentTypeByIdentifier('comment');
3509
        } catch (NotFoundException $e) {
3510
            // Expected execution path
3511
        }
3512
        /* END: Use Case */
3513
3514
        $this->assertTrue(isset($e), 'Can still load content type after rollback.');
3515
    }
3516
3517
    /**
3518
     * Test for the assignContentTypeGroup() method.

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

@@ 631-661 (lines=31) @@
628
     * @see \eZ\Publish\API\Repository\LanguageService::updateLanguageName()
629
     * @depends eZ\Publish\API\Repository\Tests\LanguageServiceTest::testUpdateLanguageName
630
     */
631
    public function testUpdateLanguageNameInTransactionWithCommit()
632
    {
633
        $repository = $this->getRepository();
634
635
        /* BEGIN: Use Case */
636
        $languageService = $repository->getContentLanguageService();
637
638
        // Start a new transaction
639
        $repository->beginTransaction();
640
641
        try {
642
            // Load an existing language
643
            $language = $languageService->loadLanguage('eng-US');
644
645
            // Update the language name
646
            $languageService->updateLanguageName($language, 'My English');
647
648
            // Commit all changes
649
            $repository->commit();
650
        } catch (Exception $e) {
651
            // Cleanup hanging transaction on error
652
            $repository->rollback();
653
            throw $e;
654
        }
655
656
        // Load updated version, name will be "My English"
657
        $updatedLanguage = $languageService->loadLanguage('eng-US');
658
        /* END: Use Case */
659
660
        $this->assertEquals('My English', $updatedLanguage->name);
661
    }
662
}
663