Code Duplication    Length = 50-50 lines in 2 locations

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

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