Code Duplication    Length = 50-50 lines in 2 locations

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

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