Code Duplication    Length = 110-110 lines in 2 locations

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

@@ 3150-3259 (lines=110) @@
3147
     * @see \eZ\Publish\API\Repository\SearchService::findContent()
3148
     * @group maplocation
3149
     */
3150
    public function testMapLocationDistanceSortAscending()
3151
    {
3152
        $contentType = $this->createTestPlaceContentType();
3153
3154
        // Create a draft to account for behaviour with ContentType in different states
3155
        $repository = $this->getRepository();
3156
        $contentTypeService = $repository->getContentTypeService();
3157
        $contentService = $repository->getContentService();
3158
        $contentTypeService->createContentTypeDraft($contentType);
3159
3160
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
3161
        $createStruct->alwaysAvailable = false;
3162
        $createStruct->mainLanguageCode = 'eng-GB';
3163
        $createStruct->setField(
3164
            'maplocation',
3165
            [
3166
                'latitude' => 45.894877,
3167
                'longitude' => 15.972699,
3168
                'address' => 'Here be wild boars',
3169
            ],
3170
            'eng-GB'
3171
        );
3172
3173
        $draft = $contentService->createContent($createStruct);
3174
        $wildBoars = $contentService->publishVersion($draft->getVersionInfo());
3175
3176
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
3177
        $createStruct->alwaysAvailable = false;
3178
        $createStruct->mainLanguageCode = 'eng-GB';
3179
        $createStruct->setField(
3180
            'maplocation',
3181
            [
3182
                'latitude' => 45.927334,
3183
                'longitude' => 15.934847,
3184
                'address' => 'A lone tree',
3185
            ],
3186
            'eng-GB'
3187
        );
3188
3189
        $draft = $contentService->createContent($createStruct);
3190
        $tree = $contentService->publishVersion($draft->getVersionInfo());
3191
3192
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
3193
        $createStruct->alwaysAvailable = false;
3194
        $createStruct->mainLanguageCode = 'eng-GB';
3195
        $createStruct->setField(
3196
            'maplocation',
3197
            [
3198
                'latitude' => 45.903777,
3199
                'longitude' => 15.958788,
3200
                'address' => 'Meadow with mushrooms',
3201
            ],
3202
            'eng-GB'
3203
        );
3204
3205
        $draft = $contentService->createContent($createStruct);
3206
        $mushrooms = $contentService->publishVersion($draft->getVersionInfo());
3207
3208
        $this->refreshSearch($repository);
3209
3210
        $wellInVodice = [
3211
            'latitude' => 43.756825,
3212
            'longitude' => 15.775074,
3213
        ];
3214
3215
        $query = new Query(
3216
            [
3217
                'filter' => new Criterion\LogicalAnd(
3218
                    [
3219
                        new Criterion\ContentTypeId($contentType->id),
3220
                        new Criterion\MapLocationDistance(
3221
                            'maplocation',
3222
                            Criterion\Operator::GTE,
3223
                            235,
3224
                            $wellInVodice['latitude'],
3225
                            $wellInVodice['longitude']
3226
                        ),
3227
                    ]
3228
                ),
3229
                'offset' => 0,
3230
                'limit' => 10,
3231
                'sortClauses' => [
3232
                    new SortClause\MapLocationDistance(
3233
                        'testtype',
3234
                        'maplocation',
3235
                        $wellInVodice['latitude'],
3236
                        $wellInVodice['longitude'],
3237
                        Query::SORT_ASC
3238
                    ),
3239
                ],
3240
            ]
3241
        );
3242
3243
        $searchService = $repository->getSearchService();
3244
        $result = $searchService->findContent($query);
3245
3246
        $this->assertEquals(3, $result->totalCount);
3247
        $this->assertEquals(
3248
            $wildBoars->id,
3249
            $result->searchHits[0]->valueObject->id
3250
        );
3251
        $this->assertEquals(
3252
            $mushrooms->id,
3253
            $result->searchHits[1]->valueObject->id
3254
        );
3255
        $this->assertEquals(
3256
            $tree->id,
3257
            $result->searchHits[2]->valueObject->id
3258
        );
3259
    }
3260
3261
    /**
3262
     * Test for the findContent() method.
@@ 3267-3376 (lines=110) @@
3264
     * @see \eZ\Publish\API\Repository\SearchService::findContent()
3265
     * @group maplocation
3266
     */
3267
    public function testMapLocationDistanceSortDescending()
3268
    {
3269
        $contentType = $this->createTestPlaceContentType();
3270
3271
        // Create a draft to account for behaviour with ContentType in different states
3272
        $repository = $this->getRepository();
3273
        $contentTypeService = $repository->getContentTypeService();
3274
        $contentService = $repository->getContentService();
3275
        $contentTypeService->createContentTypeDraft($contentType);
3276
3277
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
3278
        $createStruct->alwaysAvailable = false;
3279
        $createStruct->mainLanguageCode = 'eng-GB';
3280
        $createStruct->setField(
3281
            'maplocation',
3282
            [
3283
                'latitude' => 45.894877,
3284
                'longitude' => 15.972699,
3285
                'address' => 'Here be wild boars',
3286
            ],
3287
            'eng-GB'
3288
        );
3289
3290
        $draft = $contentService->createContent($createStruct);
3291
        $wildBoars = $contentService->publishVersion($draft->getVersionInfo());
3292
3293
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
3294
        $createStruct->alwaysAvailable = false;
3295
        $createStruct->mainLanguageCode = 'eng-GB';
3296
        $createStruct->setField(
3297
            'maplocation',
3298
            [
3299
                'latitude' => 45.927334,
3300
                'longitude' => 15.934847,
3301
                'address' => 'A lone tree',
3302
            ],
3303
            'eng-GB'
3304
        );
3305
3306
        $draft = $contentService->createContent($createStruct);
3307
        $tree = $contentService->publishVersion($draft->getVersionInfo());
3308
3309
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
3310
        $createStruct->alwaysAvailable = false;
3311
        $createStruct->mainLanguageCode = 'eng-GB';
3312
        $createStruct->setField(
3313
            'maplocation',
3314
            [
3315
                'latitude' => 45.903777,
3316
                'longitude' => 15.958788,
3317
                'address' => 'Meadow with mushrooms',
3318
            ],
3319
            'eng-GB'
3320
        );
3321
3322
        $draft = $contentService->createContent($createStruct);
3323
        $mushrooms = $contentService->publishVersion($draft->getVersionInfo());
3324
3325
        $this->refreshSearch($repository);
3326
3327
        $well = [
3328
            'latitude' => 43.756825,
3329
            'longitude' => 15.775074,
3330
        ];
3331
3332
        $query = new Query(
3333
            [
3334
                'filter' => new Criterion\LogicalAnd(
3335
                    [
3336
                        new Criterion\ContentTypeId($contentType->id),
3337
                        new Criterion\MapLocationDistance(
3338
                            'maplocation',
3339
                            Criterion\Operator::GTE,
3340
                            235,
3341
                            $well['latitude'],
3342
                            $well['longitude']
3343
                        ),
3344
                    ]
3345
                ),
3346
                'offset' => 0,
3347
                'limit' => 10,
3348
                'sortClauses' => [
3349
                    new SortClause\MapLocationDistance(
3350
                        'testtype',
3351
                        'maplocation',
3352
                        $well['latitude'],
3353
                        $well['longitude'],
3354
                        Query::SORT_DESC
3355
                    ),
3356
                ],
3357
            ]
3358
        );
3359
3360
        $searchService = $repository->getSearchService();
3361
        $result = $searchService->findContent($query);
3362
3363
        $this->assertEquals(3, $result->totalCount);
3364
        $this->assertEquals(
3365
            $wildBoars->id,
3366
            $result->searchHits[2]->valueObject->id
3367
        );
3368
        $this->assertEquals(
3369
            $mushrooms->id,
3370
            $result->searchHits[1]->valueObject->id
3371
        );
3372
        $this->assertEquals(
3373
            $tree->id,
3374
            $result->searchHits[0]->valueObject->id
3375
        );
3376
    }
3377
3378
    /**
3379
     * Test for the findContent() method.