Code Duplication    Length = 56-59 lines in 2 locations

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

@@ 3057-3115 (lines=59) @@
3054
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft
3055
     * @group field-type
3056
     */
3057
    public function testCopyContent()
3058
    {
3059
        $parentLocationId = $this->generateId('location', 56);
3060
3061
        $repository = $this->getRepository();
3062
3063
        $contentService = $repository->getContentService();
3064
        $locationService = $repository->getLocationService();
3065
3066
        /* BEGIN: Use Case */
3067
        $contentVersion2 = $this->createMultipleLanguageContentVersion2();
3068
3069
        // Configure new target location
3070
        $targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId);
3071
3072
        $targetLocationCreate->priority = 42;
3073
        $targetLocationCreate->hidden = true;
3074
        $targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789';
3075
        $targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID;
3076
        $targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC;
3077
3078
        // Copy content with all versions and drafts
3079
        $contentCopied = $contentService->copyContent(
3080
            $contentVersion2->contentInfo,
3081
            $targetLocationCreate
3082
        );
3083
        /* END: Use Case */
3084
3085
        $this->assertInstanceOf(
3086
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
3087
            $contentCopied
3088
        );
3089
3090
        $this->assertNotEquals(
3091
            $contentVersion2->contentInfo->remoteId,
3092
            $contentCopied->contentInfo->remoteId
3093
        );
3094
3095
        $this->assertNotEquals(
3096
            $contentVersion2->id,
3097
            $contentCopied->id
3098
        );
3099
3100
        $this->assertEquals(
3101
            2,
3102
            count($contentService->loadVersions($contentCopied->contentInfo))
3103
        );
3104
3105
        $this->assertEquals(2, $contentCopied->getVersionInfo()->versionNo);
3106
3107
        $this->assertAllFieldsEquals($contentCopied->getFields());
3108
3109
        $this->assertDefaultContentStates($contentCopied->contentInfo);
3110
3111
        $this->assertNotNull(
3112
            $contentCopied->contentInfo->mainLocationId,
3113
            'Expected main location to be set given we provided a LocationCreateStruct'
3114
        );
3115
    }
3116
3117
    /**
3118
     * Test for the copyContent() method.
@@ 3125-3180 (lines=56) @@
3122
     *
3123
     * @todo Fix to more descriptive name
3124
     */
3125
    public function testCopyContentWithThirdParameter()
3126
    {
3127
        $parentLocationId = $this->generateId('location', 56);
3128
3129
        $repository = $this->getRepository();
3130
3131
        $contentService = $repository->getContentService();
3132
        $locationService = $repository->getLocationService();
3133
3134
        /* BEGIN: Use Case */
3135
        $contentVersion2 = $this->createContentVersion2();
3136
3137
        // Configure new target location
3138
        $targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId);
3139
3140
        $targetLocationCreate->priority = 42;
3141
        $targetLocationCreate->hidden = true;
3142
        $targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789';
3143
        $targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID;
3144
        $targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC;
3145
3146
        // Copy only the initial version
3147
        $contentCopied = $contentService->copyContent(
3148
            $contentVersion2->contentInfo,
3149
            $targetLocationCreate,
3150
            $contentService->loadVersionInfo($contentVersion2->contentInfo, 1)
3151
        );
3152
        /* END: Use Case */
3153
3154
        $this->assertInstanceOf(
3155
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
3156
            $contentCopied
3157
        );
3158
3159
        $this->assertNotEquals(
3160
            $contentVersion2->contentInfo->remoteId,
3161
            $contentCopied->contentInfo->remoteId
3162
        );
3163
3164
        $this->assertNotEquals(
3165
            $contentVersion2->id,
3166
            $contentCopied->id
3167
        );
3168
3169
        $this->assertEquals(
3170
            1,
3171
            count($contentService->loadVersions($contentCopied->contentInfo))
3172
        );
3173
3174
        $this->assertEquals(1, $contentCopied->getVersionInfo()->versionNo);
3175
3176
        $this->assertNotNull(
3177
            $contentCopied->contentInfo->mainLocationId,
3178
            'Expected main location to be set given we provided a LocationCreateStruct'
3179
        );
3180
    }
3181
3182
    /**
3183
     * Test for the addRelation() method.