Code Duplication    Length = 56-59 lines in 2 locations

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

@@ 3197-3255 (lines=59) @@
3194
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft
3195
     * @group field-type
3196
     */
3197
    public function testCopyContent()
3198
    {
3199
        $parentLocationId = $this->generateId('location', 56);
3200
3201
        $repository = $this->getRepository();
3202
3203
        $contentService = $repository->getContentService();
3204
        $locationService = $repository->getLocationService();
3205
3206
        /* BEGIN: Use Case */
3207
        $contentVersion2 = $this->createMultipleLanguageContentVersion2();
3208
3209
        // Configure new target location
3210
        $targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId);
3211
3212
        $targetLocationCreate->priority = 42;
3213
        $targetLocationCreate->hidden = true;
3214
        $targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789';
3215
        $targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID;
3216
        $targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC;
3217
3218
        // Copy content with all versions and drafts
3219
        $contentCopied = $contentService->copyContent(
3220
            $contentVersion2->contentInfo,
3221
            $targetLocationCreate
3222
        );
3223
        /* END: Use Case */
3224
3225
        $this->assertInstanceOf(
3226
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
3227
            $contentCopied
3228
        );
3229
3230
        $this->assertNotEquals(
3231
            $contentVersion2->contentInfo->remoteId,
3232
            $contentCopied->contentInfo->remoteId
3233
        );
3234
3235
        $this->assertNotEquals(
3236
            $contentVersion2->id,
3237
            $contentCopied->id
3238
        );
3239
3240
        $this->assertEquals(
3241
            2,
3242
            count($contentService->loadVersions($contentCopied->contentInfo))
3243
        );
3244
3245
        $this->assertEquals(2, $contentCopied->getVersionInfo()->versionNo);
3246
3247
        $this->assertAllFieldsEquals($contentCopied->getFields());
3248
3249
        $this->assertDefaultContentStates($contentCopied->contentInfo);
3250
3251
        $this->assertNotNull(
3252
            $contentCopied->contentInfo->mainLocationId,
3253
            'Expected main location to be set given we provided a LocationCreateStruct'
3254
        );
3255
    }
3256
3257
    /**
3258
     * Test for the copyContent() method with ezsettings.default.content.retain_owner_on_copy set to false
@@ 3319-3374 (lines=56) @@
3316
     *
3317
     * @todo Fix to more descriptive name
3318
     */
3319
    public function testCopyContentWithThirdParameter()
3320
    {
3321
        $parentLocationId = $this->generateId('location', 56);
3322
3323
        $repository = $this->getRepository();
3324
3325
        $contentService = $repository->getContentService();
3326
        $locationService = $repository->getLocationService();
3327
3328
        /* BEGIN: Use Case */
3329
        $contentVersion2 = $this->createContentVersion2();
3330
3331
        // Configure new target location
3332
        $targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId);
3333
3334
        $targetLocationCreate->priority = 42;
3335
        $targetLocationCreate->hidden = true;
3336
        $targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789';
3337
        $targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID;
3338
        $targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC;
3339
3340
        // Copy only the initial version
3341
        $contentCopied = $contentService->copyContent(
3342
            $contentVersion2->contentInfo,
3343
            $targetLocationCreate,
3344
            $contentService->loadVersionInfo($contentVersion2->contentInfo, 1)
3345
        );
3346
        /* END: Use Case */
3347
3348
        $this->assertInstanceOf(
3349
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
3350
            $contentCopied
3351
        );
3352
3353
        $this->assertNotEquals(
3354
            $contentVersion2->contentInfo->remoteId,
3355
            $contentCopied->contentInfo->remoteId
3356
        );
3357
3358
        $this->assertNotEquals(
3359
            $contentVersion2->id,
3360
            $contentCopied->id
3361
        );
3362
3363
        $this->assertEquals(
3364
            1,
3365
            count($contentService->loadVersions($contentCopied->contentInfo))
3366
        );
3367
3368
        $this->assertEquals(1, $contentCopied->getVersionInfo()->versionNo);
3369
3370
        $this->assertNotNull(
3371
            $contentCopied->contentInfo->mainLocationId,
3372
            'Expected main location to be set given we provided a LocationCreateStruct'
3373
        );
3374
    }
3375
3376
    /**
3377
     * Test for the addRelation() method.