Code Duplication    Length = 56-59 lines in 2 locations

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

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