Code Duplication    Length = 50-50 lines in 2 locations

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

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