Code Duplication    Length = 56-59 lines in 2 locations

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

@@ 3142-3200 (lines=59) @@
3139
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft
3140
     * @group field-type
3141
     */
3142
    public function testCopyContent()
3143
    {
3144
        $parentLocationId = $this->generateId('location', 56);
3145
3146
        $repository = $this->getRepository();
3147
3148
        $contentService = $repository->getContentService();
3149
        $locationService = $repository->getLocationService();
3150
3151
        /* BEGIN: Use Case */
3152
        $contentVersion2 = $this->createMultipleLanguageContentVersion2();
3153
3154
        // Configure new target location
3155
        $targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId);
3156
3157
        $targetLocationCreate->priority = 42;
3158
        $targetLocationCreate->hidden = true;
3159
        $targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789';
3160
        $targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID;
3161
        $targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC;
3162
3163
        // Copy content with all versions and drafts
3164
        $contentCopied = $contentService->copyContent(
3165
            $contentVersion2->contentInfo,
3166
            $targetLocationCreate
3167
        );
3168
        /* END: Use Case */
3169
3170
        $this->assertInstanceOf(
3171
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
3172
            $contentCopied
3173
        );
3174
3175
        $this->assertNotEquals(
3176
            $contentVersion2->contentInfo->remoteId,
3177
            $contentCopied->contentInfo->remoteId
3178
        );
3179
3180
        $this->assertNotEquals(
3181
            $contentVersion2->id,
3182
            $contentCopied->id
3183
        );
3184
3185
        $this->assertEquals(
3186
            2,
3187
            count($contentService->loadVersions($contentCopied->contentInfo))
3188
        );
3189
3190
        $this->assertEquals(2, $contentCopied->getVersionInfo()->versionNo);
3191
3192
        $this->assertAllFieldsEquals($contentCopied->getFields());
3193
3194
        $this->assertDefaultContentStates($contentCopied->contentInfo);
3195
3196
        $this->assertNotNull(
3197
            $contentCopied->contentInfo->mainLocationId,
3198
            'Expected main location to be set given we provided a LocationCreateStruct'
3199
        );
3200
    }
3201
3202
    /**
3203
     * Test for the copyContent() method.
@@ 3210-3265 (lines=56) @@
3207
     *
3208
     * @todo Fix to more descriptive name
3209
     */
3210
    public function testCopyContentWithThirdParameter()
3211
    {
3212
        $parentLocationId = $this->generateId('location', 56);
3213
3214
        $repository = $this->getRepository();
3215
3216
        $contentService = $repository->getContentService();
3217
        $locationService = $repository->getLocationService();
3218
3219
        /* BEGIN: Use Case */
3220
        $contentVersion2 = $this->createContentVersion2();
3221
3222
        // Configure new target location
3223
        $targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId);
3224
3225
        $targetLocationCreate->priority = 42;
3226
        $targetLocationCreate->hidden = true;
3227
        $targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789';
3228
        $targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID;
3229
        $targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC;
3230
3231
        // Copy only the initial version
3232
        $contentCopied = $contentService->copyContent(
3233
            $contentVersion2->contentInfo,
3234
            $targetLocationCreate,
3235
            $contentService->loadVersionInfo($contentVersion2->contentInfo, 1)
3236
        );
3237
        /* END: Use Case */
3238
3239
        $this->assertInstanceOf(
3240
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
3241
            $contentCopied
3242
        );
3243
3244
        $this->assertNotEquals(
3245
            $contentVersion2->contentInfo->remoteId,
3246
            $contentCopied->contentInfo->remoteId
3247
        );
3248
3249
        $this->assertNotEquals(
3250
            $contentVersion2->id,
3251
            $contentCopied->id
3252
        );
3253
3254
        $this->assertEquals(
3255
            1,
3256
            count($contentService->loadVersions($contentCopied->contentInfo))
3257
        );
3258
3259
        $this->assertEquals(1, $contentCopied->getVersionInfo()->versionNo);
3260
3261
        $this->assertNotNull(
3262
            $contentCopied->contentInfo->mainLocationId,
3263
            'Expected main location to be set given we provided a LocationCreateStruct'
3264
        );
3265
    }
3266
3267
    /**
3268
     * Test for the addRelation() method.