Code Duplication    Length = 31-40 lines in 8 locations

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

@@ 3316-3353 (lines=38) @@
3313
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeGroup
3314
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testCreateContentTypeGroup
3315
     */
3316
    public function testCreateContentTypeGroupInTransactionWithRollback()
3317
    {
3318
        $repository = $this->getRepository();
3319
3320
        /* BEGIN: Use Case */
3321
        $contentTypeService = $repository->getContentTypeService();
3322
3323
        // Get create struct and set language property
3324
        $groupCreate = $contentTypeService->newContentTypeGroupCreateStruct('new-group');
3325
        /* @todo uncomment when support for multilingual names and descriptions is added
3326
        $groupCreate->mainLanguageCode = 'eng-GB';
3327
        */
3328
3329
        // Start a new transaction
3330
        $repository->beginTransaction();
3331
3332
        try {
3333
            // Create the new content type group
3334
            $groupId = $contentTypeService->createContentTypeGroup($groupCreate)->id;
3335
        } catch (Exception $e) {
3336
            // Cleanup hanging transaction on error
3337
            $repository->rollback();
3338
            throw $e;
3339
        }
3340
3341
        // Rollback all changes
3342
        $repository->rollback();
3343
3344
        try {
3345
            // This call will fail with a "NotFoundException"
3346
            $contentTypeService->loadContentTypeGroup($groupId);
3347
        } catch (NotFoundException $e) {
3348
            return;
3349
        }
3350
        /* END: Use Case */
3351
3352
        $this->fail('Can still load content type group after rollback');
3353
    }
3354
3355
    /**
3356
     * Test for the createContentTypeGroup() method.
@@ 3492-3531 (lines=40) @@
3489
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testDeleteContentTypeGroup
3490
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeGroupByIdentifierThrowsNotFoundException
3491
     */
3492
    public function testDeleteContentTypeGroupWithRollback()
3493
    {
3494
        $repository = $this->getRepository();
3495
3496
        /* BEGIN: Use Case */
3497
        $contentTypeService = $repository->getContentTypeService();
3498
3499
        // Get a group create struct
3500
        $groupCreate = $contentTypeService->newContentTypeGroupCreateStruct(
3501
            'new-group'
3502
        );
3503
3504
        // Start a new transaction
3505
        $repository->beginTransaction();
3506
3507
        try {
3508
            // Create the new group
3509
            $group = $contentTypeService->createContentTypeGroup($groupCreate);
3510
3511
            // Delete the currently created group
3512
            $contentTypeService->deleteContentTypeGroup($group);
3513
        } catch (Exception $e) {
3514
            // Cleanup hanging transaction on error
3515
            $repository->rollback();
3516
            throw $e;
3517
        }
3518
3519
        // Rollback all changes
3520
        $repository->rollback();
3521
3522
        try {
3523
            // This call will fail with an "NotFoundException"
3524
            $contentTypeService->loadContentTypeGroupByIdentifier('new-group');
3525
        } catch (NotFoundException $e) {
3526
            // Expected error path
3527
        }
3528
        /* END: Use Case */
3529
3530
        $this->assertTrue(isset($e), 'Group not deleted after rollback');
3531
    }
3532
3533
    /**
3534
     * Test for the deleteContentTypeGroup() method.
@@ 3540-3579 (lines=40) @@
3537
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testDeleteContentTypeGroup
3538
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeGroupByIdentifierThrowsNotFoundException
3539
     */
3540
    public function testDeleteContentTypeGroupWithCommit()
3541
    {
3542
        $repository = $this->getRepository();
3543
3544
        /* BEGIN: Use Case */
3545
        $contentTypeService = $repository->getContentTypeService();
3546
3547
        // Get a group create struct
3548
        $groupCreate = $contentTypeService->newContentTypeGroupCreateStruct(
3549
            'new-group'
3550
        );
3551
3552
        // Start a new transaction
3553
        $repository->beginTransaction();
3554
3555
        try {
3556
            // Create the new group
3557
            $group = $contentTypeService->createContentTypeGroup($groupCreate);
3558
3559
            // Delete the currently created group
3560
            $contentTypeService->deleteContentTypeGroup($group);
3561
3562
            // Commit all changes
3563
            $repository->commit();
3564
        } catch (Exception $e) {
3565
            // Cleanup hanging transaction on error
3566
            $repository->rollback();
3567
            throw $e;
3568
        }
3569
3570
        try {
3571
            // This call will fail with an "NotFoundException"
3572
            $contentTypeService->loadContentTypeGroupByIdentifier('new-group');
3573
        } catch (NotFoundException $e) {
3574
            // Expected error path
3575
        }
3576
        /* END: Use Case */
3577
3578
        $this->assertTrue(isset($e), 'Group not deleted after commit.');
3579
    }
3580
3581
    /**
3582
     * Test for the createContentType() method.
@@ 3705-3739 (lines=35) @@
3702
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeByIdentifier
3703
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeThrowsNotFoundException
3704
     */
3705
    public function testCopyContentTypeInTransactionWithRollback()
3706
    {
3707
        $repository = $this->getRepository();
3708
3709
        /* BEGIN: Use Case */
3710
        $contentTypeService = $repository->getContentTypeService();
3711
3712
        // Load content type to copy
3713
        $contentType = $contentTypeService->loadContentTypeByIdentifier('comment');
3714
3715
        // Start a new transaction
3716
        $repository->beginTransaction();
3717
3718
        try {
3719
            // Complete copy of the content type
3720
            $copiedType = $contentTypeService->copyContentType($contentType);
3721
        } catch (Exception $e) {
3722
            // Cleanup hanging transaction on error
3723
            $repository->rollback();
3724
            throw $e;
3725
        }
3726
3727
        // Rollback all changes
3728
        $repository->rollback();
3729
3730
        try {
3731
            // This call will fail with a "NotFoundException"
3732
            $contentTypeService->loadContentType($copiedType->id);
3733
        } catch (NotFoundException $e) {
3734
            // Expected execution path
3735
        }
3736
        /* END: Use Case */
3737
3738
        $this->assertTrue(isset($e), 'Can still load copied content type after rollback.');
3739
    }
3740
3741
    /**
3742
     * Test for the copyContentType() method.
@@ 3827-3861 (lines=35) @@
3824
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testCopyContentType
3825
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeByIdentifierThrowsNotFoundException
3826
     */
3827
    public function testDeleteContentTypeInTransactionWithCommit()
3828
    {
3829
        $repository = $this->getRepository();
3830
3831
        /* BEGIN: Use Case */
3832
        $contentTypeService = $repository->getContentTypeService();
3833
3834
        // Load content type to copy
3835
        $contentType = $contentTypeService->loadContentTypeByIdentifier('comment');
3836
3837
        // Start a new transaction
3838
        $repository->beginTransaction();
3839
3840
        try {
3841
            // Delete the "comment" content type.
3842
            $contentTypeService->deleteContentType($contentType);
3843
3844
            // Commit all changes
3845
            $repository->commit();
3846
        } catch (Exception $e) {
3847
            // Cleanup hanging transaction on error
3848
            $repository->rollback();
3849
            throw $e;
3850
        }
3851
3852
        try {
3853
            // This call will fail with a "NotFoundException"
3854
            $contentTypeService->loadContentTypeByIdentifier('comment');
3855
        } catch (NotFoundException $e) {
3856
            // Expected execution path
3857
        }
3858
        /* END: Use Case */
3859
3860
        $this->assertTrue(isset($e), 'Can still load content type after rollback.');
3861
    }
3862
3863
    /**
3864
     * Test for the assignContentTypeGroup() method.

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

@@ 701-731 (lines=31) @@
698
     * @covers \eZ\Publish\API\Repository\LanguageService::updateLanguageName
699
     * @depends eZ\Publish\API\Repository\Tests\LanguageServiceTest::testUpdateLanguageName
700
     */
701
    public function testUpdateLanguageNameInTransactionWithCommit()
702
    {
703
        $repository = $this->getRepository();
704
705
        /* BEGIN: Use Case */
706
        $languageService = $repository->getContentLanguageService();
707
708
        // Start a new transaction
709
        $repository->beginTransaction();
710
711
        try {
712
            // Load an existing language
713
            $language = $languageService->loadLanguage('eng-US');
714
715
            // Update the language name
716
            $languageService->updateLanguageName($language, 'My English');
717
718
            // Commit all changes
719
            $repository->commit();
720
        } catch (Exception $e) {
721
            // Cleanup hanging transaction on error
722
            $repository->rollback();
723
            throw $e;
724
        }
725
726
        // Load updated version, name will be "My English"
727
        $updatedLanguage = $languageService->loadLanguage('eng-US');
728
        /* END: Use Case */
729
730
        $this->assertEquals('My English', $updatedLanguage->name);
731
    }
732
}
733

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

@@ 4324-4356 (lines=33) @@
4321
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentWithLocationCreateParameterDoesNotCreateLocationImmediately
4322
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentThrowsNotFoundException
4323
     */
4324
    public function testCreateContentWithLocationCreateParameterInTransactionWithRollback()
4325
    {
4326
        $repository = $this->getRepository();
4327
4328
        $contentService = $repository->getContentService();
4329
4330
        /* BEGIN: Use Case */
4331
        // Start a transaction
4332
        $repository->beginTransaction();
4333
4334
        try {
4335
            $draft = $this->createContentDraftVersion1();
4336
        } catch (Exception $e) {
4337
            // Cleanup hanging transaction on error
4338
            $repository->rollback();
4339
            throw $e;
4340
        }
4341
4342
        $contentId = $draft->id;
4343
4344
        // Roleback the transaction
4345
        $repository->rollback();
4346
4347
        try {
4348
            // This call will fail with a "NotFoundException"
4349
            $contentService->loadContent($contentId);
4350
        } catch (NotFoundException $e) {
4351
            return;
4352
        }
4353
        /* END: Use Case */
4354
4355
        $this->fail('Can still load content object after rollback.');
4356
    }
4357
4358
    /**
4359
     * Test for the createContent() method.
@@ 4998-5037 (lines=40) @@
4995
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteContent
4996
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4997
     */
4998
    public function testDeleteContentInTransactionWithCommit()
4999
    {
5000
        $repository = $this->getRepository();
5001
5002
        $contentId = $this->generateId('object', 11);
5003
        /* BEGIN: Use Case */
5004
        // $contentId is the ID of the "Members" user group in an eZ Publish
5005
        // demo installation
5006
5007
        // Get content service
5008
        $contentService = $repository->getContentService();
5009
5010
        // Load a ContentInfo instance
5011
        $contentInfo = $contentService->loadContentInfo($contentId);
5012
5013
        // Start a new transaction
5014
        $repository->beginTransaction();
5015
5016
        try {
5017
            // Delete content object
5018
            $contentService->deleteContent($contentInfo);
5019
5020
            // Commit all changes
5021
            $repository->commit();
5022
        } catch (Exception $e) {
5023
            // Cleanup hanging transaction on error
5024
            $repository->rollback();
5025
            throw $e;
5026
        }
5027
5028
        // Deleted content info is not found anymore
5029
        try {
5030
            $contentService->loadContentInfo($contentId);
5031
        } catch (NotFoundException $e) {
5032
            return;
5033
        }
5034
        /* END: Use Case */
5035
5036
        $this->fail('Can still load ContentInfo after commit.');
5037
    }
5038
5039
    /**
5040
     * Test for the copyContent() method.