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.
@@ 3265-3320 (lines=56) @@
3262
     *
3263
     * @todo Fix to more descriptive name
3264
     */
3265
    public function testCopyContentWithThirdParameter()
3266
    {
3267
        $parentLocationId = $this->generateId('location', 56);
3268
3269
        $repository = $this->getRepository();
3270
3271
        $contentService = $repository->getContentService();
3272
        $locationService = $repository->getLocationService();
3273
3274
        /* BEGIN: Use Case */
3275
        $contentVersion2 = $this->createContentVersion2();
3276
3277
        // Configure new target location
3278
        $targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId);
3279
3280
        $targetLocationCreate->priority = 42;
3281
        $targetLocationCreate->hidden = true;
3282
        $targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789';
3283
        $targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID;
3284
        $targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC;
3285
3286
        // Copy only the initial version
3287
        $contentCopied = $contentService->copyContent(
3288
            $contentVersion2->contentInfo,
3289
            $targetLocationCreate,
3290
            $contentService->loadVersionInfo($contentVersion2->contentInfo, 1)
3291
        );
3292
        /* END: Use Case */
3293
3294
        $this->assertInstanceOf(
3295
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
3296
            $contentCopied
3297
        );
3298
3299
        $this->assertNotEquals(
3300
            $contentVersion2->contentInfo->remoteId,
3301
            $contentCopied->contentInfo->remoteId
3302
        );
3303
3304
        $this->assertNotEquals(
3305
            $contentVersion2->id,
3306
            $contentCopied->id
3307
        );
3308
3309
        $this->assertEquals(
3310
            1,
3311
            count($contentService->loadVersions($contentCopied->contentInfo))
3312
        );
3313
3314
        $this->assertEquals(1, $contentCopied->getVersionInfo()->versionNo);
3315
3316
        $this->assertNotNull(
3317
            $contentCopied->contentInfo->mainLocationId,
3318
            'Expected main location to be set given we provided a LocationCreateStruct'
3319
        );
3320
    }
3321
3322
    /**
3323
     * Test for the addRelation() method.