Code Duplication    Length = 56-59 lines in 2 locations

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

@@ 3193-3251 (lines=59) @@
3190
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft
3191
     * @group field-type
3192
     */
3193
    public function testCopyContent()
3194
    {
3195
        $parentLocationId = $this->generateId('location', 56);
3196
3197
        $repository = $this->getRepository();
3198
3199
        $contentService = $repository->getContentService();
3200
        $locationService = $repository->getLocationService();
3201
3202
        /* BEGIN: Use Case */
3203
        $contentVersion2 = $this->createMultipleLanguageContentVersion2();
3204
3205
        // Configure new target location
3206
        $targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId);
3207
3208
        $targetLocationCreate->priority = 42;
3209
        $targetLocationCreate->hidden = true;
3210
        $targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789';
3211
        $targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID;
3212
        $targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC;
3213
3214
        // Copy content with all versions and drafts
3215
        $contentCopied = $contentService->copyContent(
3216
            $contentVersion2->contentInfo,
3217
            $targetLocationCreate
3218
        );
3219
        /* END: Use Case */
3220
3221
        $this->assertInstanceOf(
3222
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
3223
            $contentCopied
3224
        );
3225
3226
        $this->assertNotEquals(
3227
            $contentVersion2->contentInfo->remoteId,
3228
            $contentCopied->contentInfo->remoteId
3229
        );
3230
3231
        $this->assertNotEquals(
3232
            $contentVersion2->id,
3233
            $contentCopied->id
3234
        );
3235
3236
        $this->assertEquals(
3237
            2,
3238
            count($contentService->loadVersions($contentCopied->contentInfo))
3239
        );
3240
3241
        $this->assertEquals(2, $contentCopied->getVersionInfo()->versionNo);
3242
3243
        $this->assertAllFieldsEquals($contentCopied->getFields());
3244
3245
        $this->assertDefaultContentStates($contentCopied->contentInfo);
3246
3247
        $this->assertNotNull(
3248
            $contentCopied->contentInfo->mainLocationId,
3249
            'Expected main location to be set given we provided a LocationCreateStruct'
3250
        );
3251
    }
3252
3253
    /**
3254
     * Test for the copyContent() method.
@@ 3261-3316 (lines=56) @@
3258
     *
3259
     * @todo Fix to more descriptive name
3260
     */
3261
    public function testCopyContentWithThirdParameter()
3262
    {
3263
        $parentLocationId = $this->generateId('location', 56);
3264
3265
        $repository = $this->getRepository();
3266
3267
        $contentService = $repository->getContentService();
3268
        $locationService = $repository->getLocationService();
3269
3270
        /* BEGIN: Use Case */
3271
        $contentVersion2 = $this->createContentVersion2();
3272
3273
        // Configure new target location
3274
        $targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId);
3275
3276
        $targetLocationCreate->priority = 42;
3277
        $targetLocationCreate->hidden = true;
3278
        $targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789';
3279
        $targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID;
3280
        $targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC;
3281
3282
        // Copy only the initial version
3283
        $contentCopied = $contentService->copyContent(
3284
            $contentVersion2->contentInfo,
3285
            $targetLocationCreate,
3286
            $contentService->loadVersionInfo($contentVersion2->contentInfo, 1)
3287
        );
3288
        /* END: Use Case */
3289
3290
        $this->assertInstanceOf(
3291
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
3292
            $contentCopied
3293
        );
3294
3295
        $this->assertNotEquals(
3296
            $contentVersion2->contentInfo->remoteId,
3297
            $contentCopied->contentInfo->remoteId
3298
        );
3299
3300
        $this->assertNotEquals(
3301
            $contentVersion2->id,
3302
            $contentCopied->id
3303
        );
3304
3305
        $this->assertEquals(
3306
            1,
3307
            count($contentService->loadVersions($contentCopied->contentInfo))
3308
        );
3309
3310
        $this->assertEquals(1, $contentCopied->getVersionInfo()->versionNo);
3311
3312
        $this->assertNotNull(
3313
            $contentCopied->contentInfo->mainLocationId,
3314
            'Expected main location to be set given we provided a LocationCreateStruct'
3315
        );
3316
    }
3317
3318
    /**
3319
     * Test for the addRelation() method.