Code Duplication    Length = 56-59 lines in 2 locations

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

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