Code Duplication    Length = 50-50 lines in 2 locations

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

@@ 5041-5090 (lines=50) @@
5038
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren
5039
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
5040
     */
5041
    public function testCopyContentInTransactionWithRollback()
5042
    {
5043
        $repository = $this->getRepository();
5044
5045
        $contentId = $this->generateId('object', 11);
5046
        $locationId = $this->generateId('location', 13);
5047
        /* BEGIN: Use Case */
5048
        // $contentId is the ID of the "Members" user group in an eZ Publish
5049
        // demo installation
5050
5051
        // $locationId is the ID of the "Administrator users" group location
5052
5053
        // Get services
5054
        $contentService = $repository->getContentService();
5055
        $locationService = $repository->getLocationService();
5056
5057
        // Load content object to copy
5058
        $content = $contentService->loadContent($contentId);
5059
5060
        // Create new target location
5061
        $locationCreate = $locationService->newLocationCreateStruct($locationId);
5062
5063
        // Start a new transaction
5064
        $repository->beginTransaction();
5065
5066
        try {
5067
            // Copy content with all versions and drafts
5068
            $contentService->copyContent(
5069
                $content->contentInfo,
5070
                $locationCreate
5071
            );
5072
        } catch (Exception $e) {
5073
            // Cleanup hanging transaction on error
5074
            $repository->rollback();
5075
            throw $e;
5076
        }
5077
5078
        // Rollback all changes
5079
        $repository->rollback();
5080
5081
        $this->refreshSearch($repository);
5082
5083
        // This array will only contain a single admin user object
5084
        $locations = $locationService->loadLocationChildren(
5085
            $locationService->loadLocation($locationId)
5086
        )->locations;
5087
        /* END: Use Case */
5088
5089
        $this->assertEquals(1, count($locations));
5090
    }
5091
5092
    /**
5093
     * Test for the copyContent() method.
@@ 5101-5150 (lines=50) @@
5098
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren
5099
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
5100
     */
5101
    public function testCopyContentInTransactionWithCommit()
5102
    {
5103
        $repository = $this->getRepository();
5104
5105
        $contentId = $this->generateId('object', 11);
5106
        $locationId = $this->generateId('location', 13);
5107
        /* BEGIN: Use Case */
5108
        // $contentId is the ID of the "Members" user group in an eZ Publish
5109
        // demo installation
5110
5111
        // $locationId is the ID of the "Administrator users" group location
5112
5113
        // Get services
5114
        $contentService = $repository->getContentService();
5115
        $locationService = $repository->getLocationService();
5116
5117
        // Load content object to copy
5118
        $content = $contentService->loadContent($contentId);
5119
5120
        // Create new target location
5121
        $locationCreate = $locationService->newLocationCreateStruct($locationId);
5122
5123
        // Start a new transaction
5124
        $repository->beginTransaction();
5125
5126
        try {
5127
            // Copy content with all versions and drafts
5128
            $contentCopied = $contentService->copyContent(
5129
                $content->contentInfo,
5130
                $locationCreate
5131
            );
5132
5133
            // Commit all changes
5134
            $repository->commit();
5135
        } catch (Exception $e) {
5136
            // Cleanup hanging transaction on error
5137
            $repository->rollback();
5138
            throw $e;
5139
        }
5140
5141
        $this->refreshSearch($repository);
5142
5143
        // This will contain the admin user and the new child location
5144
        $locations = $locationService->loadLocationChildren(
5145
            $locationService->loadLocation($locationId)
5146
        )->locations;
5147
        /* END: Use Case */
5148
5149
        $this->assertEquals(2, count($locations));
5150
    }
5151
5152
    public function testURLAliasesCreatedForNewContent()
5153
    {