Code Duplication    Length = 50-50 lines in 2 locations

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

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