Code Duplication    Length = 50-50 lines in 2 locations

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

@@ 4955-5004 (lines=50) @@
4952
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren
4953
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
4954
     */
4955
    public function testCopyContentInTransactionWithRollback()
4956
    {
4957
        $repository = $this->getRepository();
4958
4959
        $contentId = $this->generateId('object', 11);
4960
        $locationId = $this->generateId('location', 13);
4961
        /* BEGIN: Use Case */
4962
        // $contentId is the ID of the "Members" user group in an eZ Publish
4963
        // demo installation
4964
4965
        // $locationId is the ID of the "Administrator users" group location
4966
4967
        // Get services
4968
        $contentService = $repository->getContentService();
4969
        $locationService = $repository->getLocationService();
4970
4971
        // Load content object to copy
4972
        $content = $contentService->loadContent($contentId);
4973
4974
        // Create new target location
4975
        $locationCreate = $locationService->newLocationCreateStruct($locationId);
4976
4977
        // Start a new transaction
4978
        $repository->beginTransaction();
4979
4980
        try {
4981
            // Copy content with all versions and drafts
4982
            $contentService->copyContent(
4983
                $content->contentInfo,
4984
                $locationCreate
4985
            );
4986
        } catch (Exception $e) {
4987
            // Cleanup hanging transaction on error
4988
            $repository->rollback();
4989
            throw $e;
4990
        }
4991
4992
        // Rollback all changes
4993
        $repository->rollback();
4994
4995
        $this->refreshSearch($repository);
4996
4997
        // This array will only contain a single admin user object
4998
        $locations = $locationService->loadLocationChildren(
4999
            $locationService->loadLocation($locationId)
5000
        )->locations;
5001
        /* END: Use Case */
5002
5003
        $this->assertEquals(1, count($locations));
5004
    }
5005
5006
    /**
5007
     * Test for the copyContent() method.
@@ 5015-5064 (lines=50) @@
5012
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren
5013
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
5014
     */
5015
    public function testCopyContentInTransactionWithCommit()
5016
    {
5017
        $repository = $this->getRepository();
5018
5019
        $contentId = $this->generateId('object', 11);
5020
        $locationId = $this->generateId('location', 13);
5021
        /* BEGIN: Use Case */
5022
        // $contentId is the ID of the "Members" user group in an eZ Publish
5023
        // demo installation
5024
5025
        // $locationId is the ID of the "Administrator users" group location
5026
5027
        // Get services
5028
        $contentService = $repository->getContentService();
5029
        $locationService = $repository->getLocationService();
5030
5031
        // Load content object to copy
5032
        $content = $contentService->loadContent($contentId);
5033
5034
        // Create new target location
5035
        $locationCreate = $locationService->newLocationCreateStruct($locationId);
5036
5037
        // Start a new transaction
5038
        $repository->beginTransaction();
5039
5040
        try {
5041
            // Copy content with all versions and drafts
5042
            $contentCopied = $contentService->copyContent(
5043
                $content->contentInfo,
5044
                $locationCreate
5045
            );
5046
5047
            // Commit all changes
5048
            $repository->commit();
5049
        } catch (Exception $e) {
5050
            // Cleanup hanging transaction on error
5051
            $repository->rollback();
5052
            throw $e;
5053
        }
5054
5055
        $this->refreshSearch($repository);
5056
5057
        // This will contain the admin user and the new child location
5058
        $locations = $locationService->loadLocationChildren(
5059
            $locationService->loadLocation($locationId)
5060
        )->locations;
5061
        /* END: Use Case */
5062
5063
        $this->assertEquals(2, count($locations));
5064
    }
5065
5066
    public function testURLAliasesCreatedForNewContent()
5067
    {