Code Duplication    Length = 110-110 lines in 2 locations

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

@@ 3094-3203 (lines=110) @@
3091
     * @see \eZ\Publish\API\Repository\SearchService::findContent()
3092
     * @group maplocation
3093
     */
3094
    public function testMapLocationDistanceSortAscending()
3095
    {
3096
        $contentType = $this->createTestPlaceContentType();
3097
3098
        // Create a draft to account for behaviour with ContentType in different states
3099
        $repository = $this->getRepository();
3100
        $contentTypeService = $repository->getContentTypeService();
3101
        $contentService = $repository->getContentService();
3102
        $contentTypeService->createContentTypeDraft($contentType);
3103
3104
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
3105
        $createStruct->alwaysAvailable = false;
3106
        $createStruct->mainLanguageCode = 'eng-GB';
3107
        $createStruct->setField(
3108
            'maplocation',
3109
            array(
3110
                'latitude' => 45.894877,
3111
                'longitude' => 15.972699,
3112
                'address' => 'Here be wild boars',
3113
            ),
3114
            'eng-GB'
3115
        );
3116
3117
        $draft = $contentService->createContent($createStruct);
3118
        $wildBoars = $contentService->publishVersion($draft->getVersionInfo());
3119
3120
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
3121
        $createStruct->alwaysAvailable = false;
3122
        $createStruct->mainLanguageCode = 'eng-GB';
3123
        $createStruct->setField(
3124
            'maplocation',
3125
            array(
3126
                'latitude' => 45.927334,
3127
                'longitude' => 15.934847,
3128
                'address' => 'A lone tree',
3129
            ),
3130
            'eng-GB'
3131
        );
3132
3133
        $draft = $contentService->createContent($createStruct);
3134
        $tree = $contentService->publishVersion($draft->getVersionInfo());
3135
3136
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
3137
        $createStruct->alwaysAvailable = false;
3138
        $createStruct->mainLanguageCode = 'eng-GB';
3139
        $createStruct->setField(
3140
            'maplocation',
3141
            array(
3142
                'latitude' => 45.903777,
3143
                'longitude' => 15.958788,
3144
                'address' => 'Meadow with mushrooms',
3145
            ),
3146
            'eng-GB'
3147
        );
3148
3149
        $draft = $contentService->createContent($createStruct);
3150
        $mushrooms = $contentService->publishVersion($draft->getVersionInfo());
3151
3152
        $this->refreshSearch($repository);
3153
3154
        $wellInVodice = array(
3155
            'latitude' => 43.756825,
3156
            'longitude' => 15.775074,
3157
        );
3158
3159
        $query = new Query(
3160
            array(
3161
                'filter' => new Criterion\LogicalAnd(
3162
                    array(
3163
                        new Criterion\ContentTypeId($contentType->id),
3164
                        new Criterion\MapLocationDistance(
3165
                            'maplocation',
3166
                            Criterion\Operator::GTE,
3167
                            235,
3168
                            $wellInVodice['latitude'],
3169
                            $wellInVodice['longitude']
3170
                        ),
3171
                    )
3172
                ),
3173
                'offset' => 0,
3174
                'limit' => 10,
3175
                'sortClauses' => array(
3176
                    new SortClause\MapLocationDistance(
3177
                        'testtype',
3178
                        'maplocation',
3179
                        $wellInVodice['latitude'],
3180
                        $wellInVodice['longitude'],
3181
                        Query::SORT_ASC
3182
                    ),
3183
                ),
3184
            )
3185
        );
3186
3187
        $searchService = $repository->getSearchService();
3188
        $result = $searchService->findContent($query);
3189
3190
        $this->assertEquals(3, $result->totalCount);
3191
        $this->assertEquals(
3192
            $wildBoars->id,
3193
            $result->searchHits[0]->valueObject->id
3194
        );
3195
        $this->assertEquals(
3196
            $mushrooms->id,
3197
            $result->searchHits[1]->valueObject->id
3198
        );
3199
        $this->assertEquals(
3200
            $tree->id,
3201
            $result->searchHits[2]->valueObject->id
3202
        );
3203
    }
3204
3205
    /**
3206
     * Test for the findContent() method.
@@ 3211-3320 (lines=110) @@
3208
     * @see \eZ\Publish\API\Repository\SearchService::findContent()
3209
     * @group maplocation
3210
     */
3211
    public function testMapLocationDistanceSortDescending()
3212
    {
3213
        $contentType = $this->createTestPlaceContentType();
3214
3215
        // Create a draft to account for behaviour with ContentType in different states
3216
        $repository = $this->getRepository();
3217
        $contentTypeService = $repository->getContentTypeService();
3218
        $contentService = $repository->getContentService();
3219
        $contentTypeService->createContentTypeDraft($contentType);
3220
3221
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
3222
        $createStruct->alwaysAvailable = false;
3223
        $createStruct->mainLanguageCode = 'eng-GB';
3224
        $createStruct->setField(
3225
            'maplocation',
3226
            array(
3227
                'latitude' => 45.894877,
3228
                'longitude' => 15.972699,
3229
                'address' => 'Here be wild boars',
3230
            ),
3231
            'eng-GB'
3232
        );
3233
3234
        $draft = $contentService->createContent($createStruct);
3235
        $wildBoars = $contentService->publishVersion($draft->getVersionInfo());
3236
3237
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
3238
        $createStruct->alwaysAvailable = false;
3239
        $createStruct->mainLanguageCode = 'eng-GB';
3240
        $createStruct->setField(
3241
            'maplocation',
3242
            array(
3243
                'latitude' => 45.927334,
3244
                'longitude' => 15.934847,
3245
                'address' => 'A lone tree',
3246
            ),
3247
            'eng-GB'
3248
        );
3249
3250
        $draft = $contentService->createContent($createStruct);
3251
        $tree = $contentService->publishVersion($draft->getVersionInfo());
3252
3253
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
3254
        $createStruct->alwaysAvailable = false;
3255
        $createStruct->mainLanguageCode = 'eng-GB';
3256
        $createStruct->setField(
3257
            'maplocation',
3258
            array(
3259
                'latitude' => 45.903777,
3260
                'longitude' => 15.958788,
3261
                'address' => 'Meadow with mushrooms',
3262
            ),
3263
            'eng-GB'
3264
        );
3265
3266
        $draft = $contentService->createContent($createStruct);
3267
        $mushrooms = $contentService->publishVersion($draft->getVersionInfo());
3268
3269
        $this->refreshSearch($repository);
3270
3271
        $well = array(
3272
            'latitude' => 43.756825,
3273
            'longitude' => 15.775074,
3274
        );
3275
3276
        $query = new Query(
3277
            array(
3278
                'filter' => new Criterion\LogicalAnd(
3279
                    array(
3280
                        new Criterion\ContentTypeId($contentType->id),
3281
                        new Criterion\MapLocationDistance(
3282
                            'maplocation',
3283
                            Criterion\Operator::GTE,
3284
                            235,
3285
                            $well['latitude'],
3286
                            $well['longitude']
3287
                        ),
3288
                    )
3289
                ),
3290
                'offset' => 0,
3291
                'limit' => 10,
3292
                'sortClauses' => array(
3293
                    new SortClause\MapLocationDistance(
3294
                        'testtype',
3295
                        'maplocation',
3296
                        $well['latitude'],
3297
                        $well['longitude'],
3298
                        Query::SORT_DESC
3299
                    ),
3300
                ),
3301
            )
3302
        );
3303
3304
        $searchService = $repository->getSearchService();
3305
        $result = $searchService->findContent($query);
3306
3307
        $this->assertEquals(3, $result->totalCount);
3308
        $this->assertEquals(
3309
            $wildBoars->id,
3310
            $result->searchHits[2]->valueObject->id
3311
        );
3312
        $this->assertEquals(
3313
            $mushrooms->id,
3314
            $result->searchHits[1]->valueObject->id
3315
        );
3316
        $this->assertEquals(
3317
            $tree->id,
3318
            $result->searchHits[0]->valueObject->id
3319
        );
3320
    }
3321
3322
    /**
3323
     * Test for the findContent() method.