Code Duplication    Length = 31-40 lines in 8 locations

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

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

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

@@ 3516-3553 (lines=38) @@
3513
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeGroup
3514
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testCreateContentTypeGroup
3515
     */
3516
    public function testCreateContentTypeGroupInTransactionWithRollback()
3517
    {
3518
        $repository = $this->getRepository();
3519
3520
        /* BEGIN: Use Case */
3521
        $contentTypeService = $repository->getContentTypeService();
3522
3523
        // Get create struct and set language property
3524
        $groupCreate = $contentTypeService->newContentTypeGroupCreateStruct('new-group');
3525
        /* @todo uncomment when support for multilingual names and descriptions is added
3526
        $groupCreate->mainLanguageCode = 'eng-GB';
3527
        */
3528
3529
        // Start a new transaction
3530
        $repository->beginTransaction();
3531
3532
        try {
3533
            // Create the new content type group
3534
            $groupId = $contentTypeService->createContentTypeGroup($groupCreate)->id;
3535
        } catch (Exception $e) {
3536
            // Cleanup hanging transaction on error
3537
            $repository->rollback();
3538
            throw $e;
3539
        }
3540
3541
        // Rollback all changes
3542
        $repository->rollback();
3543
3544
        try {
3545
            // This call will fail with a "NotFoundException"
3546
            $contentTypeService->loadContentTypeGroup($groupId);
3547
        } catch (NotFoundException $e) {
3548
            return;
3549
        }
3550
        /* END: Use Case */
3551
3552
        $this->fail('Can still load content type group after rollback');
3553
    }
3554
3555
    /**
3556
     * Test for the createContentTypeGroup() method.
@@ 3692-3731 (lines=40) @@
3689
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testDeleteContentTypeGroup
3690
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeGroupByIdentifierThrowsNotFoundException
3691
     */
3692
    public function testDeleteContentTypeGroupWithRollback()
3693
    {
3694
        $repository = $this->getRepository();
3695
3696
        /* BEGIN: Use Case */
3697
        $contentTypeService = $repository->getContentTypeService();
3698
3699
        // Get a group create struct
3700
        $groupCreate = $contentTypeService->newContentTypeGroupCreateStruct(
3701
            'new-group'
3702
        );
3703
3704
        // Start a new transaction
3705
        $repository->beginTransaction();
3706
3707
        try {
3708
            // Create the new group
3709
            $group = $contentTypeService->createContentTypeGroup($groupCreate);
3710
3711
            // Delete the currently created group
3712
            $contentTypeService->deleteContentTypeGroup($group);
3713
        } catch (Exception $e) {
3714
            // Cleanup hanging transaction on error
3715
            $repository->rollback();
3716
            throw $e;
3717
        }
3718
3719
        // Rollback all changes
3720
        $repository->rollback();
3721
3722
        try {
3723
            // This call will fail with an "NotFoundException"
3724
            $contentTypeService->loadContentTypeGroupByIdentifier('new-group');
3725
        } catch (NotFoundException $e) {
3726
            // Expected error path
3727
        }
3728
        /* END: Use Case */
3729
3730
        $this->assertTrue(isset($e), 'Group not deleted after rollback');
3731
    }
3732
3733
    /**
3734
     * Test for the deleteContentTypeGroup() method.
@@ 3740-3779 (lines=40) @@
3737
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testDeleteContentTypeGroup
3738
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeGroupByIdentifierThrowsNotFoundException
3739
     */
3740
    public function testDeleteContentTypeGroupWithCommit()
3741
    {
3742
        $repository = $this->getRepository();
3743
3744
        /* BEGIN: Use Case */
3745
        $contentTypeService = $repository->getContentTypeService();
3746
3747
        // Get a group create struct
3748
        $groupCreate = $contentTypeService->newContentTypeGroupCreateStruct(
3749
            'new-group'
3750
        );
3751
3752
        // Start a new transaction
3753
        $repository->beginTransaction();
3754
3755
        try {
3756
            // Create the new group
3757
            $group = $contentTypeService->createContentTypeGroup($groupCreate);
3758
3759
            // Delete the currently created group
3760
            $contentTypeService->deleteContentTypeGroup($group);
3761
3762
            // Commit all changes
3763
            $repository->commit();
3764
        } catch (Exception $e) {
3765
            // Cleanup hanging transaction on error
3766
            $repository->rollback();
3767
            throw $e;
3768
        }
3769
3770
        try {
3771
            // This call will fail with an "NotFoundException"
3772
            $contentTypeService->loadContentTypeGroupByIdentifier('new-group');
3773
        } catch (NotFoundException $e) {
3774
            // Expected error path
3775
        }
3776
        /* END: Use Case */
3777
3778
        $this->assertTrue(isset($e), 'Group not deleted after commit.');
3779
    }
3780
3781
    /**
3782
     * Test for the createContentType() method.
@@ 3905-3939 (lines=35) @@
3902
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeByIdentifier
3903
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeThrowsNotFoundException
3904
     */
3905
    public function testCopyContentTypeInTransactionWithRollback()
3906
    {
3907
        $repository = $this->getRepository();
3908
3909
        /* BEGIN: Use Case */
3910
        $contentTypeService = $repository->getContentTypeService();
3911
3912
        // Load content type to copy
3913
        $contentType = $contentTypeService->loadContentTypeByIdentifier('comment');
3914
3915
        // Start a new transaction
3916
        $repository->beginTransaction();
3917
3918
        try {
3919
            // Complete copy of the content type
3920
            $copiedType = $contentTypeService->copyContentType($contentType);
3921
        } catch (Exception $e) {
3922
            // Cleanup hanging transaction on error
3923
            $repository->rollback();
3924
            throw $e;
3925
        }
3926
3927
        // Rollback all changes
3928
        $repository->rollback();
3929
3930
        try {
3931
            // This call will fail with a "NotFoundException"
3932
            $contentTypeService->loadContentType($copiedType->id);
3933
        } catch (NotFoundException $e) {
3934
            // Expected execution path
3935
        }
3936
        /* END: Use Case */
3937
3938
        $this->assertTrue(isset($e), 'Can still load copied content type after rollback.');
3939
    }
3940
3941
    /**
3942
     * Test for the copyContentType() method.
@@ 4027-4061 (lines=35) @@
4024
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testCopyContentType
4025
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeByIdentifierThrowsNotFoundException
4026
     */
4027
    public function testDeleteContentTypeInTransactionWithCommit()
4028
    {
4029
        $repository = $this->getRepository();
4030
4031
        /* BEGIN: Use Case */
4032
        $contentTypeService = $repository->getContentTypeService();
4033
4034
        // Load content type to copy
4035
        $contentType = $contentTypeService->loadContentTypeByIdentifier('comment');
4036
4037
        // Start a new transaction
4038
        $repository->beginTransaction();
4039
4040
        try {
4041
            // Delete the "comment" content type.
4042
            $contentTypeService->deleteContentType($contentType);
4043
4044
            // Commit all changes
4045
            $repository->commit();
4046
        } catch (Exception $e) {
4047
            // Cleanup hanging transaction on error
4048
            $repository->rollback();
4049
            throw $e;
4050
        }
4051
4052
        try {
4053
            // This call will fail with a "NotFoundException"
4054
            $contentTypeService->loadContentTypeByIdentifier('comment');
4055
        } catch (NotFoundException $e) {
4056
            // Expected execution path
4057
        }
4058
        /* END: Use Case */
4059
4060
        $this->assertTrue(isset($e), 'Can still load content type after rollback.');
4061
    }
4062
4063
    /**
4064
     * Test for the assignContentTypeGroup() method.

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

@@ 4330-4362 (lines=33) @@
4327
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentWithLocationCreateParameterDoesNotCreateLocationImmediately
4328
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentThrowsNotFoundException
4329
     */
4330
    public function testCreateContentWithLocationCreateParameterInTransactionWithRollback()
4331
    {
4332
        $repository = $this->getRepository();
4333
4334
        $contentService = $repository->getContentService();
4335
4336
        /* BEGIN: Use Case */
4337
        // Start a transaction
4338
        $repository->beginTransaction();
4339
4340
        try {
4341
            $draft = $this->createContentDraftVersion1();
4342
        } catch (Exception $e) {
4343
            // Cleanup hanging transaction on error
4344
            $repository->rollback();
4345
            throw $e;
4346
        }
4347
4348
        $contentId = $draft->id;
4349
4350
        // Roleback the transaction
4351
        $repository->rollback();
4352
4353
        try {
4354
            // This call will fail with a "NotFoundException"
4355
            $contentService->loadContent($contentId);
4356
        } catch (NotFoundException $e) {
4357
            return;
4358
        }
4359
        /* END: Use Case */
4360
4361
        $this->fail('Can still load content object after rollback.');
4362
    }
4363
4364
    /**
4365
     * Test for the createContent() method.
@@ 4958-4997 (lines=40) @@
4955
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteContent
4956
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4957
     */
4958
    public function testDeleteContentInTransactionWithCommit()
4959
    {
4960
        $repository = $this->getRepository();
4961
4962
        $contentId = $this->generateId('object', 11);
4963
        /* BEGIN: Use Case */
4964
        // $contentId is the ID of the "Members" user group in an eZ Publish
4965
        // demo installation
4966
4967
        // Get content service
4968
        $contentService = $repository->getContentService();
4969
4970
        // Load a ContentInfo instance
4971
        $contentInfo = $contentService->loadContentInfo($contentId);
4972
4973
        // Start a new transaction
4974
        $repository->beginTransaction();
4975
4976
        try {
4977
            // Delete content object
4978
            $contentService->deleteContent($contentInfo);
4979
4980
            // Commit all changes
4981
            $repository->commit();
4982
        } catch (Exception $e) {
4983
            // Cleanup hanging transaction on error
4984
            $repository->rollback();
4985
            throw $e;
4986
        }
4987
4988
        // Deleted content info is not found anymore
4989
        try {
4990
            $contentService->loadContentInfo($contentId);
4991
        } catch (NotFoundException $e) {
4992
            return;
4993
        }
4994
        /* END: Use Case */
4995
4996
        $this->fail('Can still load ContentInfo after commit.');
4997
    }
4998
4999
    /**
5000
     * Test for the copyContent() method.