Code Duplication    Length = 50-50 lines in 2 locations

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

@@ 4913-4962 (lines=50) @@
4910
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren
4911
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
4912
     */
4913
    public function testCopyContentInTransactionWithRollback()
4914
    {
4915
        $repository = $this->getRepository();
4916
4917
        $contentId = $this->generateId('object', 11);
4918
        $locationId = $this->generateId('location', 13);
4919
        /* BEGIN: Use Case */
4920
        // $contentId is the ID of the "Members" user group in an eZ Publish
4921
        // demo installation
4922
4923
        // $locationId is the ID of the "Administrator users" group location
4924
4925
        // Get services
4926
        $contentService = $repository->getContentService();
4927
        $locationService = $repository->getLocationService();
4928
4929
        // Load content object to copy
4930
        $content = $contentService->loadContent($contentId);
4931
4932
        // Create new target location
4933
        $locationCreate = $locationService->newLocationCreateStruct($locationId);
4934
4935
        // Start a new transaction
4936
        $repository->beginTransaction();
4937
4938
        try {
4939
            // Copy content with all versions and drafts
4940
            $contentService->copyContent(
4941
                $content->contentInfo,
4942
                $locationCreate
4943
            );
4944
        } catch (Exception $e) {
4945
            // Cleanup hanging transaction on error
4946
            $repository->rollback();
4947
            throw $e;
4948
        }
4949
4950
        // Rollback all changes
4951
        $repository->rollback();
4952
4953
        $this->refreshSearch($repository);
4954
4955
        // This array will only contain a single admin user object
4956
        $locations = $locationService->loadLocationChildren(
4957
            $locationService->loadLocation($locationId)
4958
        )->locations;
4959
        /* END: Use Case */
4960
4961
        $this->assertEquals(1, count($locations));
4962
    }
4963
4964
    /**
4965
     * Test for the copyContent() method.
@@ 4973-5022 (lines=50) @@
4970
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren
4971
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
4972
     */
4973
    public function testCopyContentInTransactionWithCommit()
4974
    {
4975
        $repository = $this->getRepository();
4976
4977
        $contentId = $this->generateId('object', 11);
4978
        $locationId = $this->generateId('location', 13);
4979
        /* BEGIN: Use Case */
4980
        // $contentId is the ID of the "Members" user group in an eZ Publish
4981
        // demo installation
4982
4983
        // $locationId is the ID of the "Administrator users" group location
4984
4985
        // Get services
4986
        $contentService = $repository->getContentService();
4987
        $locationService = $repository->getLocationService();
4988
4989
        // Load content object to copy
4990
        $content = $contentService->loadContent($contentId);
4991
4992
        // Create new target location
4993
        $locationCreate = $locationService->newLocationCreateStruct($locationId);
4994
4995
        // Start a new transaction
4996
        $repository->beginTransaction();
4997
4998
        try {
4999
            // Copy content with all versions and drafts
5000
            $contentCopied = $contentService->copyContent(
5001
                $content->contentInfo,
5002
                $locationCreate
5003
            );
5004
5005
            // Commit all changes
5006
            $repository->commit();
5007
        } catch (Exception $e) {
5008
            // Cleanup hanging transaction on error
5009
            $repository->rollback();
5010
            throw $e;
5011
        }
5012
5013
        $this->refreshSearch($repository);
5014
5015
        // This will contain the admin user and the new child location
5016
        $locations = $locationService->loadLocationChildren(
5017
            $locationService->loadLocation($locationId)
5018
        )->locations;
5019
        /* END: Use Case */
5020
5021
        $this->assertEquals(2, count($locations));
5022
    }
5023
5024
    public function testURLAliasesCreatedForNewContent()
5025
    {