Code Duplication    Length = 56-59 lines in 2 locations

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

@@ 3143-3201 (lines=59) @@
3140
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft
3141
     * @group field-type
3142
     */
3143
    public function testCopyContent()
3144
    {
3145
        $parentLocationId = $this->generateId('location', 56);
3146
3147
        $repository = $this->getRepository();
3148
3149
        $contentService = $repository->getContentService();
3150
        $locationService = $repository->getLocationService();
3151
3152
        /* BEGIN: Use Case */
3153
        $contentVersion2 = $this->createMultipleLanguageContentVersion2();
3154
3155
        // Configure new target location
3156
        $targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId);
3157
3158
        $targetLocationCreate->priority = 42;
3159
        $targetLocationCreate->hidden = true;
3160
        $targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789';
3161
        $targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID;
3162
        $targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC;
3163
3164
        // Copy content with all versions and drafts
3165
        $contentCopied = $contentService->copyContent(
3166
            $contentVersion2->contentInfo,
3167
            $targetLocationCreate
3168
        );
3169
        /* END: Use Case */
3170
3171
        $this->assertInstanceOf(
3172
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
3173
            $contentCopied
3174
        );
3175
3176
        $this->assertNotEquals(
3177
            $contentVersion2->contentInfo->remoteId,
3178
            $contentCopied->contentInfo->remoteId
3179
        );
3180
3181
        $this->assertNotEquals(
3182
            $contentVersion2->id,
3183
            $contentCopied->id
3184
        );
3185
3186
        $this->assertEquals(
3187
            2,
3188
            count($contentService->loadVersions($contentCopied->contentInfo))
3189
        );
3190
3191
        $this->assertEquals(2, $contentCopied->getVersionInfo()->versionNo);
3192
3193
        $this->assertAllFieldsEquals($contentCopied->getFields());
3194
3195
        $this->assertDefaultContentStates($contentCopied->contentInfo);
3196
3197
        $this->assertNotNull(
3198
            $contentCopied->contentInfo->mainLocationId,
3199
            'Expected main location to be set given we provided a LocationCreateStruct'
3200
        );
3201
    }
3202
3203
    /**
3204
     * Test for the copyContent() method.
@@ 3211-3266 (lines=56) @@
3208
     *
3209
     * @todo Fix to more descriptive name
3210
     */
3211
    public function testCopyContentWithThirdParameter()
3212
    {
3213
        $parentLocationId = $this->generateId('location', 56);
3214
3215
        $repository = $this->getRepository();
3216
3217
        $contentService = $repository->getContentService();
3218
        $locationService = $repository->getLocationService();
3219
3220
        /* BEGIN: Use Case */
3221
        $contentVersion2 = $this->createContentVersion2();
3222
3223
        // Configure new target location
3224
        $targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId);
3225
3226
        $targetLocationCreate->priority = 42;
3227
        $targetLocationCreate->hidden = true;
3228
        $targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789';
3229
        $targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID;
3230
        $targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC;
3231
3232
        // Copy only the initial version
3233
        $contentCopied = $contentService->copyContent(
3234
            $contentVersion2->contentInfo,
3235
            $targetLocationCreate,
3236
            $contentService->loadVersionInfo($contentVersion2->contentInfo, 1)
3237
        );
3238
        /* END: Use Case */
3239
3240
        $this->assertInstanceOf(
3241
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
3242
            $contentCopied
3243
        );
3244
3245
        $this->assertNotEquals(
3246
            $contentVersion2->contentInfo->remoteId,
3247
            $contentCopied->contentInfo->remoteId
3248
        );
3249
3250
        $this->assertNotEquals(
3251
            $contentVersion2->id,
3252
            $contentCopied->id
3253
        );
3254
3255
        $this->assertEquals(
3256
            1,
3257
            count($contentService->loadVersions($contentCopied->contentInfo))
3258
        );
3259
3260
        $this->assertEquals(1, $contentCopied->getVersionInfo()->versionNo);
3261
3262
        $this->assertNotNull(
3263
            $contentCopied->contentInfo->mainLocationId,
3264
            'Expected main location to be set given we provided a LocationCreateStruct'
3265
        );
3266
    }
3267
3268
    /**
3269
     * Test for the addRelation() method.