Code Duplication    Length = 56-59 lines in 2 locations

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

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