Code Duplication    Length = 56-59 lines in 2 locations

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

@@ 3198-3256 (lines=59) @@
3195
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft
3196
     * @group field-type
3197
     */
3198
    public function testCopyContent()
3199
    {
3200
        $parentLocationId = $this->generateId('location', 56);
3201
3202
        $repository = $this->getRepository();
3203
3204
        $contentService = $repository->getContentService();
3205
        $locationService = $repository->getLocationService();
3206
3207
        /* BEGIN: Use Case */
3208
        $contentVersion2 = $this->createMultipleLanguageContentVersion2();
3209
3210
        // Configure new target location
3211
        $targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId);
3212
3213
        $targetLocationCreate->priority = 42;
3214
        $targetLocationCreate->hidden = true;
3215
        $targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789';
3216
        $targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID;
3217
        $targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC;
3218
3219
        // Copy content with all versions and drafts
3220
        $contentCopied = $contentService->copyContent(
3221
            $contentVersion2->contentInfo,
3222
            $targetLocationCreate
3223
        );
3224
        /* END: Use Case */
3225
3226
        $this->assertInstanceOf(
3227
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
3228
            $contentCopied
3229
        );
3230
3231
        $this->assertNotEquals(
3232
            $contentVersion2->contentInfo->remoteId,
3233
            $contentCopied->contentInfo->remoteId
3234
        );
3235
3236
        $this->assertNotEquals(
3237
            $contentVersion2->id,
3238
            $contentCopied->id
3239
        );
3240
3241
        $this->assertEquals(
3242
            2,
3243
            count($contentService->loadVersions($contentCopied->contentInfo))
3244
        );
3245
3246
        $this->assertEquals(2, $contentCopied->getVersionInfo()->versionNo);
3247
3248
        $this->assertAllFieldsEquals($contentCopied->getFields());
3249
3250
        $this->assertDefaultContentStates($contentCopied->contentInfo);
3251
3252
        $this->assertNotNull(
3253
            $contentCopied->contentInfo->mainLocationId,
3254
            'Expected main location to be set given we provided a LocationCreateStruct'
3255
        );
3256
    }
3257
3258
    /**
3259
     * Test for the copyContent() method.
@@ 3266-3321 (lines=56) @@
3263
     *
3264
     * @todo Fix to more descriptive name
3265
     */
3266
    public function testCopyContentWithThirdParameter()
3267
    {
3268
        $parentLocationId = $this->generateId('location', 56);
3269
3270
        $repository = $this->getRepository();
3271
3272
        $contentService = $repository->getContentService();
3273
        $locationService = $repository->getLocationService();
3274
3275
        /* BEGIN: Use Case */
3276
        $contentVersion2 = $this->createContentVersion2();
3277
3278
        // Configure new target location
3279
        $targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId);
3280
3281
        $targetLocationCreate->priority = 42;
3282
        $targetLocationCreate->hidden = true;
3283
        $targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789';
3284
        $targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID;
3285
        $targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC;
3286
3287
        // Copy only the initial version
3288
        $contentCopied = $contentService->copyContent(
3289
            $contentVersion2->contentInfo,
3290
            $targetLocationCreate,
3291
            $contentService->loadVersionInfo($contentVersion2->contentInfo, 1)
3292
        );
3293
        /* END: Use Case */
3294
3295
        $this->assertInstanceOf(
3296
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
3297
            $contentCopied
3298
        );
3299
3300
        $this->assertNotEquals(
3301
            $contentVersion2->contentInfo->remoteId,
3302
            $contentCopied->contentInfo->remoteId
3303
        );
3304
3305
        $this->assertNotEquals(
3306
            $contentVersion2->id,
3307
            $contentCopied->id
3308
        );
3309
3310
        $this->assertEquals(
3311
            1,
3312
            count($contentService->loadVersions($contentCopied->contentInfo))
3313
        );
3314
3315
        $this->assertEquals(1, $contentCopied->getVersionInfo()->versionNo);
3316
3317
        $this->assertNotNull(
3318
            $contentCopied->contentInfo->mainLocationId,
3319
            'Expected main location to be set given we provided a LocationCreateStruct'
3320
        );
3321
    }
3322
3323
    /**
3324
     * Test for the addRelation() method.