Code Duplication    Length = 56-59 lines in 2 locations

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

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