Code Duplication    Length = 31-40 lines in 8 locations

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

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

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.