Code Duplication    Length = 56-59 lines in 2 locations

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

@@ 3290-3348 (lines=59) @@
3287
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft
3288
     * @group field-type
3289
     */
3290
    public function testCopyContent()
3291
    {
3292
        $parentLocationId = $this->generateId('location', 56);
3293
3294
        $repository = $this->getRepository();
3295
3296
        $contentService = $repository->getContentService();
3297
        $locationService = $repository->getLocationService();
3298
3299
        /* BEGIN: Use Case */
3300
        $contentVersion2 = $this->createMultipleLanguageContentVersion2();
3301
3302
        // Configure new target location
3303
        $targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId);
3304
3305
        $targetLocationCreate->priority = 42;
3306
        $targetLocationCreate->hidden = true;
3307
        $targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789';
3308
        $targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID;
3309
        $targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC;
3310
3311
        // Copy content with all versions and drafts
3312
        $contentCopied = $contentService->copyContent(
3313
            $contentVersion2->contentInfo,
3314
            $targetLocationCreate
3315
        );
3316
        /* END: Use Case */
3317
3318
        $this->assertInstanceOf(
3319
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
3320
            $contentCopied
3321
        );
3322
3323
        $this->assertNotEquals(
3324
            $contentVersion2->contentInfo->remoteId,
3325
            $contentCopied->contentInfo->remoteId
3326
        );
3327
3328
        $this->assertNotEquals(
3329
            $contentVersion2->id,
3330
            $contentCopied->id
3331
        );
3332
3333
        $this->assertEquals(
3334
            2,
3335
            count($contentService->loadVersions($contentCopied->contentInfo))
3336
        );
3337
3338
        $this->assertEquals(2, $contentCopied->getVersionInfo()->versionNo);
3339
3340
        $this->assertAllFieldsEquals($contentCopied->getFields());
3341
3342
        $this->assertDefaultContentStates($contentCopied->contentInfo);
3343
3344
        $this->assertNotNull(
3345
            $contentCopied->contentInfo->mainLocationId,
3346
            'Expected main location to be set given we provided a LocationCreateStruct'
3347
        );
3348
    }
3349
3350
    /**
3351
     * Test for the copyContent() method with ezsettings.default.content.retain_owner_on_copy set to false
@@ 3412-3467 (lines=56) @@
3409
     *
3410
     * @todo Fix to more descriptive name
3411
     */
3412
    public function testCopyContentWithThirdParameter()
3413
    {
3414
        $parentLocationId = $this->generateId('location', 56);
3415
3416
        $repository = $this->getRepository();
3417
3418
        $contentService = $repository->getContentService();
3419
        $locationService = $repository->getLocationService();
3420
3421
        /* BEGIN: Use Case */
3422
        $contentVersion2 = $this->createContentVersion2();
3423
3424
        // Configure new target location
3425
        $targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId);
3426
3427
        $targetLocationCreate->priority = 42;
3428
        $targetLocationCreate->hidden = true;
3429
        $targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789';
3430
        $targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID;
3431
        $targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC;
3432
3433
        // Copy only the initial version
3434
        $contentCopied = $contentService->copyContent(
3435
            $contentVersion2->contentInfo,
3436
            $targetLocationCreate,
3437
            $contentService->loadVersionInfo($contentVersion2->contentInfo, 1)
3438
        );
3439
        /* END: Use Case */
3440
3441
        $this->assertInstanceOf(
3442
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
3443
            $contentCopied
3444
        );
3445
3446
        $this->assertNotEquals(
3447
            $contentVersion2->contentInfo->remoteId,
3448
            $contentCopied->contentInfo->remoteId
3449
        );
3450
3451
        $this->assertNotEquals(
3452
            $contentVersion2->id,
3453
            $contentCopied->id
3454
        );
3455
3456
        $this->assertEquals(
3457
            1,
3458
            count($contentService->loadVersions($contentCopied->contentInfo))
3459
        );
3460
3461
        $this->assertEquals(1, $contentCopied->getVersionInfo()->versionNo);
3462
3463
        $this->assertNotNull(
3464
            $contentCopied->contentInfo->mainLocationId,
3465
            'Expected main location to be set given we provided a LocationCreateStruct'
3466
        );
3467
    }
3468
3469
    /**
3470
     * Test for the addRelation() method.