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
@@ 3418-3473 (lines=56) @@
3415
     * @see \eZ\Publish\API\Repository\ContentService::copyContent($contentInfo, $destinationLocationCreateStruct, $versionInfo)
3416
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCopyContent
3417
     */
3418
    public function testCopyContentWithGivenVersion()
3419
    {
3420
        $parentLocationId = $this->generateId('location', 56);
3421
3422
        $repository = $this->getRepository();
3423
3424
        $contentService = $repository->getContentService();
3425
        $locationService = $repository->getLocationService();
3426
3427
        /* BEGIN: Use Case */
3428
        $contentVersion2 = $this->createContentVersion2();
3429
3430
        // Configure new target location
3431
        $targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId);
3432
3433
        $targetLocationCreate->priority = 42;
3434
        $targetLocationCreate->hidden = true;
3435
        $targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789';
3436
        $targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID;
3437
        $targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC;
3438
3439
        // Copy only the initial version
3440
        $contentCopied = $contentService->copyContent(
3441
            $contentVersion2->contentInfo,
3442
            $targetLocationCreate,
3443
            $contentService->loadVersionInfo($contentVersion2->contentInfo, 1)
3444
        );
3445
        /* END: Use Case */
3446
3447
        $this->assertInstanceOf(
3448
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
3449
            $contentCopied
3450
        );
3451
3452
        $this->assertNotEquals(
3453
            $contentVersion2->contentInfo->remoteId,
3454
            $contentCopied->contentInfo->remoteId
3455
        );
3456
3457
        $this->assertNotEquals(
3458
            $contentVersion2->id,
3459
            $contentCopied->id
3460
        );
3461
3462
        $this->assertEquals(
3463
            1,
3464
            count($contentService->loadVersions($contentCopied->contentInfo))
3465
        );
3466
3467
        $this->assertEquals(1, $contentCopied->getVersionInfo()->versionNo);
3468
3469
        $this->assertNotNull(
3470
            $contentCopied->contentInfo->mainLocationId,
3471
            'Expected main location to be set given we provided a LocationCreateStruct'
3472
        );
3473
    }
3474
3475
    /**
3476
     * Test for the addRelation() method.