Code Duplication    Length = 50-50 lines in 2 locations

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

@@ 5009-5058 (lines=50) @@
5006
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren
5007
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
5008
     */
5009
    public function testCopyContentInTransactionWithRollback()
5010
    {
5011
        $repository = $this->getRepository();
5012
5013
        $contentId = $this->generateId('object', 11);
5014
        $locationId = $this->generateId('location', 13);
5015
        /* BEGIN: Use Case */
5016
        // $contentId is the ID of the "Members" user group in an eZ Publish
5017
        // demo installation
5018
5019
        // $locationId is the ID of the "Administrator users" group location
5020
5021
        // Get services
5022
        $contentService = $repository->getContentService();
5023
        $locationService = $repository->getLocationService();
5024
5025
        // Load content object to copy
5026
        $content = $contentService->loadContent($contentId);
5027
5028
        // Create new target location
5029
        $locationCreate = $locationService->newLocationCreateStruct($locationId);
5030
5031
        // Start a new transaction
5032
        $repository->beginTransaction();
5033
5034
        try {
5035
            // Copy content with all versions and drafts
5036
            $contentService->copyContent(
5037
                $content->contentInfo,
5038
                $locationCreate
5039
            );
5040
        } catch (Exception $e) {
5041
            // Cleanup hanging transaction on error
5042
            $repository->rollback();
5043
            throw $e;
5044
        }
5045
5046
        // Rollback all changes
5047
        $repository->rollback();
5048
5049
        $this->refreshSearch($repository);
5050
5051
        // This array will only contain a single admin user object
5052
        $locations = $locationService->loadLocationChildren(
5053
            $locationService->loadLocation($locationId)
5054
        )->locations;
5055
        /* END: Use Case */
5056
5057
        $this->assertEquals(1, count($locations));
5058
    }
5059
5060
    /**
5061
     * Test for the copyContent() method.
@@ 5069-5118 (lines=50) @@
5066
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren
5067
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
5068
     */
5069
    public function testCopyContentInTransactionWithCommit()
5070
    {
5071
        $repository = $this->getRepository();
5072
5073
        $contentId = $this->generateId('object', 11);
5074
        $locationId = $this->generateId('location', 13);
5075
        /* BEGIN: Use Case */
5076
        // $contentId is the ID of the "Members" user group in an eZ Publish
5077
        // demo installation
5078
5079
        // $locationId is the ID of the "Administrator users" group location
5080
5081
        // Get services
5082
        $contentService = $repository->getContentService();
5083
        $locationService = $repository->getLocationService();
5084
5085
        // Load content object to copy
5086
        $content = $contentService->loadContent($contentId);
5087
5088
        // Create new target location
5089
        $locationCreate = $locationService->newLocationCreateStruct($locationId);
5090
5091
        // Start a new transaction
5092
        $repository->beginTransaction();
5093
5094
        try {
5095
            // Copy content with all versions and drafts
5096
            $contentCopied = $contentService->copyContent(
5097
                $content->contentInfo,
5098
                $locationCreate
5099
            );
5100
5101
            // Commit all changes
5102
            $repository->commit();
5103
        } catch (Exception $e) {
5104
            // Cleanup hanging transaction on error
5105
            $repository->rollback();
5106
            throw $e;
5107
        }
5108
5109
        $this->refreshSearch($repository);
5110
5111
        // This will contain the admin user and the new child location
5112
        $locations = $locationService->loadLocationChildren(
5113
            $locationService->loadLocation($locationId)
5114
        )->locations;
5115
        /* END: Use Case */
5116
5117
        $this->assertEquals(2, count($locations));
5118
    }
5119
5120
    public function testURLAliasesCreatedForNewContent()
5121
    {