Code Duplication    Length = 50-50 lines in 2 locations

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

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