Code Duplication    Length = 31-40 lines in 6 locations

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

@@ 3550-3587 (lines=38) @@
3547
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeGroup
3548
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testCreateContentTypeGroup
3549
     */
3550
    public function testCreateContentTypeGroupInTransactionWithRollback()
3551
    {
3552
        $repository = $this->getRepository();
3553
3554
        /* BEGIN: Use Case */
3555
        $contentTypeService = $repository->getContentTypeService();
3556
3557
        // Get create struct and set language property
3558
        $groupCreate = $contentTypeService->newContentTypeGroupCreateStruct('new-group');
3559
        /* @todo uncomment when support for multilingual names and descriptions is added
3560
        $groupCreate->mainLanguageCode = 'eng-GB';
3561
        */
3562
3563
        // Start a new transaction
3564
        $repository->beginTransaction();
3565
3566
        try {
3567
            // Create the new content type group
3568
            $groupId = $contentTypeService->createContentTypeGroup($groupCreate)->id;
3569
        } catch (Exception $e) {
3570
            // Cleanup hanging transaction on error
3571
            $repository->rollback();
3572
            throw $e;
3573
        }
3574
3575
        // Rollback all changes
3576
        $repository->rollback();
3577
3578
        try {
3579
            // This call will fail with a "NotFoundException"
3580
            $contentTypeService->loadContentTypeGroup($groupId);
3581
        } catch (NotFoundException $e) {
3582
            return;
3583
        }
3584
        /* END: Use Case */
3585
3586
        $this->fail('Can still load content type group after rollback');
3587
    }
3588
3589
    /**
3590
     * Test for the createContentTypeGroup() method.
@@ 3726-3765 (lines=40) @@
3723
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testDeleteContentTypeGroup
3724
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeGroupByIdentifierThrowsNotFoundException
3725
     */
3726
    public function testDeleteContentTypeGroupWithRollback()
3727
    {
3728
        $repository = $this->getRepository();
3729
3730
        /* BEGIN: Use Case */
3731
        $contentTypeService = $repository->getContentTypeService();
3732
3733
        // Get a group create struct
3734
        $groupCreate = $contentTypeService->newContentTypeGroupCreateStruct(
3735
            'new-group'
3736
        );
3737
3738
        // Start a new transaction
3739
        $repository->beginTransaction();
3740
3741
        try {
3742
            // Create the new group
3743
            $group = $contentTypeService->createContentTypeGroup($groupCreate);
3744
3745
            // Delete the currently created group
3746
            $contentTypeService->deleteContentTypeGroup($group);
3747
        } catch (Exception $e) {
3748
            // Cleanup hanging transaction on error
3749
            $repository->rollback();
3750
            throw $e;
3751
        }
3752
3753
        // Rollback all changes
3754
        $repository->rollback();
3755
3756
        try {
3757
            // This call will fail with an "NotFoundException"
3758
            $contentTypeService->loadContentTypeGroupByIdentifier('new-group');
3759
        } catch (NotFoundException $e) {
3760
            // Expected error path
3761
        }
3762
        /* END: Use Case */
3763
3764
        $this->assertTrue(isset($e), 'Group not deleted after rollback');
3765
    }
3766
3767
    /**
3768
     * Test for the deleteContentTypeGroup() method.
@@ 3774-3813 (lines=40) @@
3771
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testDeleteContentTypeGroup
3772
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeGroupByIdentifierThrowsNotFoundException
3773
     */
3774
    public function testDeleteContentTypeGroupWithCommit()
3775
    {
3776
        $repository = $this->getRepository();
3777
3778
        /* BEGIN: Use Case */
3779
        $contentTypeService = $repository->getContentTypeService();
3780
3781
        // Get a group create struct
3782
        $groupCreate = $contentTypeService->newContentTypeGroupCreateStruct(
3783
            'new-group'
3784
        );
3785
3786
        // Start a new transaction
3787
        $repository->beginTransaction();
3788
3789
        try {
3790
            // Create the new group
3791
            $group = $contentTypeService->createContentTypeGroup($groupCreate);
3792
3793
            // Delete the currently created group
3794
            $contentTypeService->deleteContentTypeGroup($group);
3795
3796
            // Commit all changes
3797
            $repository->commit();
3798
        } catch (Exception $e) {
3799
            // Cleanup hanging transaction on error
3800
            $repository->rollback();
3801
            throw $e;
3802
        }
3803
3804
        try {
3805
            // This call will fail with an "NotFoundException"
3806
            $contentTypeService->loadContentTypeGroupByIdentifier('new-group');
3807
        } catch (NotFoundException $e) {
3808
            // Expected error path
3809
        }
3810
        /* END: Use Case */
3811
3812
        $this->assertTrue(isset($e), 'Group not deleted after commit.');
3813
    }
3814
3815
    /**
3816
     * Test for the createContentType() method.
@@ 3939-3973 (lines=35) @@
3936
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeByIdentifier
3937
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeThrowsNotFoundException
3938
     */
3939
    public function testCopyContentTypeInTransactionWithRollback()
3940
    {
3941
        $repository = $this->getRepository();
3942
3943
        /* BEGIN: Use Case */
3944
        $contentTypeService = $repository->getContentTypeService();
3945
3946
        // Load content type to copy
3947
        $contentType = $contentTypeService->loadContentTypeByIdentifier('comment');
3948
3949
        // Start a new transaction
3950
        $repository->beginTransaction();
3951
3952
        try {
3953
            // Complete copy of the content type
3954
            $copiedType = $contentTypeService->copyContentType($contentType);
3955
        } catch (Exception $e) {
3956
            // Cleanup hanging transaction on error
3957
            $repository->rollback();
3958
            throw $e;
3959
        }
3960
3961
        // Rollback all changes
3962
        $repository->rollback();
3963
3964
        try {
3965
            // This call will fail with a "NotFoundException"
3966
            $contentTypeService->loadContentType($copiedType->id);
3967
        } catch (NotFoundException $e) {
3968
            // Expected execution path
3969
        }
3970
        /* END: Use Case */
3971
3972
        $this->assertTrue(isset($e), 'Can still load copied content type after rollback.');
3973
    }
3974
3975
    /**
3976
     * Test for the copyContentType() method.
@@ 4061-4095 (lines=35) @@
4058
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testCopyContentType
4059
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeByIdentifierThrowsNotFoundException
4060
     */
4061
    public function testDeleteContentTypeInTransactionWithCommit()
4062
    {
4063
        $repository = $this->getRepository();
4064
4065
        /* BEGIN: Use Case */
4066
        $contentTypeService = $repository->getContentTypeService();
4067
4068
        // Load content type to copy
4069
        $contentType = $contentTypeService->loadContentTypeByIdentifier('comment');
4070
4071
        // Start a new transaction
4072
        $repository->beginTransaction();
4073
4074
        try {
4075
            // Delete the "comment" content type.
4076
            $contentTypeService->deleteContentType($contentType);
4077
4078
            // Commit all changes
4079
            $repository->commit();
4080
        } catch (Exception $e) {
4081
            // Cleanup hanging transaction on error
4082
            $repository->rollback();
4083
            throw $e;
4084
        }
4085
4086
        try {
4087
            // This call will fail with a "NotFoundException"
4088
            $contentTypeService->loadContentTypeByIdentifier('comment');
4089
        } catch (NotFoundException $e) {
4090
            // Expected execution path
4091
        }
4092
        /* END: Use Case */
4093
4094
        $this->assertTrue(isset($e), 'Can still load content type after rollback.');
4095
    }
4096
4097
    /**
4098
     * Test for the assignContentTypeGroup() method.

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

@@ 685-715 (lines=31) @@
682
     * @covers \eZ\Publish\API\Repository\LanguageService::updateLanguageName
683
     * @depends eZ\Publish\API\Repository\Tests\LanguageServiceTest::testUpdateLanguageName
684
     */
685
    public function testUpdateLanguageNameInTransactionWithCommit()
686
    {
687
        $repository = $this->getRepository();
688
689
        /* BEGIN: Use Case */
690
        $languageService = $repository->getContentLanguageService();
691
692
        // Start a new transaction
693
        $repository->beginTransaction();
694
695
        try {
696
            // Load an existing language
697
            $language = $languageService->loadLanguage('eng-US');
698
699
            // Update the language name
700
            $languageService->updateLanguageName($language, 'My English');
701
702
            // Commit all changes
703
            $repository->commit();
704
        } catch (Exception $e) {
705
            // Cleanup hanging transaction on error
706
            $repository->rollback();
707
            throw $e;
708
        }
709
710
        // Load updated version, name will be "My English"
711
        $updatedLanguage = $languageService->loadLanguage('eng-US');
712
        /* END: Use Case */
713
714
        $this->assertEquals('My English', $updatedLanguage->name);
715
    }
716
}
717