Code Duplication    Length = 56-59 lines in 2 locations

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

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