Code Duplication    Length = 56-59 lines in 2 locations

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

@@ 3097-3155 (lines=59) @@
3094
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft
3095
     * @group field-type
3096
     */
3097
    public function testCopyContent()
3098
    {
3099
        $parentLocationId = $this->generateId('location', 56);
3100
3101
        $repository = $this->getRepository();
3102
3103
        $contentService = $repository->getContentService();
3104
        $locationService = $repository->getLocationService();
3105
3106
        /* BEGIN: Use Case */
3107
        $contentVersion2 = $this->createMultipleLanguageContentVersion2();
3108
3109
        // Configure new target location
3110
        $targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId);
3111
3112
        $targetLocationCreate->priority = 42;
3113
        $targetLocationCreate->hidden = true;
3114
        $targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789';
3115
        $targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID;
3116
        $targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC;
3117
3118
        // Copy content with all versions and drafts
3119
        $contentCopied = $contentService->copyContent(
3120
            $contentVersion2->contentInfo,
3121
            $targetLocationCreate
3122
        );
3123
        /* END: Use Case */
3124
3125
        $this->assertInstanceOf(
3126
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
3127
            $contentCopied
3128
        );
3129
3130
        $this->assertNotEquals(
3131
            $contentVersion2->contentInfo->remoteId,
3132
            $contentCopied->contentInfo->remoteId
3133
        );
3134
3135
        $this->assertNotEquals(
3136
            $contentVersion2->id,
3137
            $contentCopied->id
3138
        );
3139
3140
        $this->assertEquals(
3141
            2,
3142
            count($contentService->loadVersions($contentCopied->contentInfo))
3143
        );
3144
3145
        $this->assertEquals(2, $contentCopied->getVersionInfo()->versionNo);
3146
3147
        $this->assertAllFieldsEquals($contentCopied->getFields());
3148
3149
        $this->assertDefaultContentStates($contentCopied->contentInfo);
3150
3151
        $this->assertNotNull(
3152
            $contentCopied->contentInfo->mainLocationId,
3153
            'Expected main location to be set given we provided a LocationCreateStruct'
3154
        );
3155
    }
3156
3157
    /**
3158
     * Test for the copyContent() method.
@@ 3165-3220 (lines=56) @@
3162
     *
3163
     * @todo Fix to more descriptive name
3164
     */
3165
    public function testCopyContentWithThirdParameter()
3166
    {
3167
        $parentLocationId = $this->generateId('location', 56);
3168
3169
        $repository = $this->getRepository();
3170
3171
        $contentService = $repository->getContentService();
3172
        $locationService = $repository->getLocationService();
3173
3174
        /* BEGIN: Use Case */
3175
        $contentVersion2 = $this->createContentVersion2();
3176
3177
        // Configure new target location
3178
        $targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId);
3179
3180
        $targetLocationCreate->priority = 42;
3181
        $targetLocationCreate->hidden = true;
3182
        $targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789';
3183
        $targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID;
3184
        $targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC;
3185
3186
        // Copy only the initial version
3187
        $contentCopied = $contentService->copyContent(
3188
            $contentVersion2->contentInfo,
3189
            $targetLocationCreate,
3190
            $contentService->loadVersionInfo($contentVersion2->contentInfo, 1)
3191
        );
3192
        /* END: Use Case */
3193
3194
        $this->assertInstanceOf(
3195
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
3196
            $contentCopied
3197
        );
3198
3199
        $this->assertNotEquals(
3200
            $contentVersion2->contentInfo->remoteId,
3201
            $contentCopied->contentInfo->remoteId
3202
        );
3203
3204
        $this->assertNotEquals(
3205
            $contentVersion2->id,
3206
            $contentCopied->id
3207
        );
3208
3209
        $this->assertEquals(
3210
            1,
3211
            count($contentService->loadVersions($contentCopied->contentInfo))
3212
        );
3213
3214
        $this->assertEquals(1, $contentCopied->getVersionInfo()->versionNo);
3215
3216
        $this->assertNotNull(
3217
            $contentCopied->contentInfo->mainLocationId,
3218
            'Expected main location to be set given we provided a LocationCreateStruct'
3219
        );
3220
    }
3221
3222
    /**
3223
     * Test for the addRelation() method.