Code Duplication    Length = 110-110 lines in 2 locations

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

@@ 3219-3328 (lines=110) @@
3216
     * @see \eZ\Publish\API\Repository\SearchService::findContent()
3217
     * @group maplocation
3218
     */
3219
    public function testMapLocationDistanceSortAscending()
3220
    {
3221
        $contentType = $this->createTestPlaceContentType();
3222
3223
        // Create a draft to account for behaviour with ContentType in different states
3224
        $repository = $this->getRepository();
3225
        $contentTypeService = $repository->getContentTypeService();
3226
        $contentService = $repository->getContentService();
3227
        $contentTypeService->createContentTypeDraft($contentType);
3228
3229
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
3230
        $createStruct->alwaysAvailable = false;
3231
        $createStruct->mainLanguageCode = 'eng-GB';
3232
        $createStruct->setField(
3233
            'maplocation',
3234
            [
3235
                'latitude' => 45.894877,
3236
                'longitude' => 15.972699,
3237
                'address' => 'Here be wild boars',
3238
            ],
3239
            'eng-GB'
3240
        );
3241
3242
        $draft = $contentService->createContent($createStruct);
3243
        $wildBoars = $contentService->publishVersion($draft->getVersionInfo());
3244
3245
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
3246
        $createStruct->alwaysAvailable = false;
3247
        $createStruct->mainLanguageCode = 'eng-GB';
3248
        $createStruct->setField(
3249
            'maplocation',
3250
            [
3251
                'latitude' => 45.927334,
3252
                'longitude' => 15.934847,
3253
                'address' => 'A lone tree',
3254
            ],
3255
            'eng-GB'
3256
        );
3257
3258
        $draft = $contentService->createContent($createStruct);
3259
        $tree = $contentService->publishVersion($draft->getVersionInfo());
3260
3261
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
3262
        $createStruct->alwaysAvailable = false;
3263
        $createStruct->mainLanguageCode = 'eng-GB';
3264
        $createStruct->setField(
3265
            'maplocation',
3266
            [
3267
                'latitude' => 45.903777,
3268
                'longitude' => 15.958788,
3269
                'address' => 'Meadow with mushrooms',
3270
            ],
3271
            'eng-GB'
3272
        );
3273
3274
        $draft = $contentService->createContent($createStruct);
3275
        $mushrooms = $contentService->publishVersion($draft->getVersionInfo());
3276
3277
        $this->refreshSearch($repository);
3278
3279
        $wellInVodice = [
3280
            'latitude' => 43.756825,
3281
            'longitude' => 15.775074,
3282
        ];
3283
3284
        $query = new Query(
3285
            [
3286
                'filter' => new Criterion\LogicalAnd(
3287
                    [
3288
                        new Criterion\ContentTypeId($contentType->id),
3289
                        new Criterion\MapLocationDistance(
3290
                            'maplocation',
3291
                            Criterion\Operator::GTE,
3292
                            235,
3293
                            $wellInVodice['latitude'],
3294
                            $wellInVodice['longitude']
3295
                        ),
3296
                    ]
3297
                ),
3298
                'offset' => 0,
3299
                'limit' => 10,
3300
                'sortClauses' => [
3301
                    new SortClause\MapLocationDistance(
3302
                        'testtype',
3303
                        'maplocation',
3304
                        $wellInVodice['latitude'],
3305
                        $wellInVodice['longitude'],
3306
                        Query::SORT_ASC
3307
                    ),
3308
                ],
3309
            ]
3310
        );
3311
3312
        $searchService = $repository->getSearchService();
3313
        $result = $searchService->findContent($query);
3314
3315
        $this->assertEquals(3, $result->totalCount);
3316
        $this->assertEquals(
3317
            $wildBoars->id,
3318
            $result->searchHits[0]->valueObject->id
3319
        );
3320
        $this->assertEquals(
3321
            $mushrooms->id,
3322
            $result->searchHits[1]->valueObject->id
3323
        );
3324
        $this->assertEquals(
3325
            $tree->id,
3326
            $result->searchHits[2]->valueObject->id
3327
        );
3328
    }
3329
3330
    /**
3331
     * Test for the findContent() method.
@@ 3336-3445 (lines=110) @@
3333
     * @see \eZ\Publish\API\Repository\SearchService::findContent()
3334
     * @group maplocation
3335
     */
3336
    public function testMapLocationDistanceSortDescending()
3337
    {
3338
        $contentType = $this->createTestPlaceContentType();
3339
3340
        // Create a draft to account for behaviour with ContentType in different states
3341
        $repository = $this->getRepository();
3342
        $contentTypeService = $repository->getContentTypeService();
3343
        $contentService = $repository->getContentService();
3344
        $contentTypeService->createContentTypeDraft($contentType);
3345
3346
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
3347
        $createStruct->alwaysAvailable = false;
3348
        $createStruct->mainLanguageCode = 'eng-GB';
3349
        $createStruct->setField(
3350
            'maplocation',
3351
            [
3352
                'latitude' => 45.894877,
3353
                'longitude' => 15.972699,
3354
                'address' => 'Here be wild boars',
3355
            ],
3356
            'eng-GB'
3357
        );
3358
3359
        $draft = $contentService->createContent($createStruct);
3360
        $wildBoars = $contentService->publishVersion($draft->getVersionInfo());
3361
3362
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
3363
        $createStruct->alwaysAvailable = false;
3364
        $createStruct->mainLanguageCode = 'eng-GB';
3365
        $createStruct->setField(
3366
            'maplocation',
3367
            [
3368
                'latitude' => 45.927334,
3369
                'longitude' => 15.934847,
3370
                'address' => 'A lone tree',
3371
            ],
3372
            'eng-GB'
3373
        );
3374
3375
        $draft = $contentService->createContent($createStruct);
3376
        $tree = $contentService->publishVersion($draft->getVersionInfo());
3377
3378
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
3379
        $createStruct->alwaysAvailable = false;
3380
        $createStruct->mainLanguageCode = 'eng-GB';
3381
        $createStruct->setField(
3382
            'maplocation',
3383
            [
3384
                'latitude' => 45.903777,
3385
                'longitude' => 15.958788,
3386
                'address' => 'Meadow with mushrooms',
3387
            ],
3388
            'eng-GB'
3389
        );
3390
3391
        $draft = $contentService->createContent($createStruct);
3392
        $mushrooms = $contentService->publishVersion($draft->getVersionInfo());
3393
3394
        $this->refreshSearch($repository);
3395
3396
        $well = [
3397
            'latitude' => 43.756825,
3398
            'longitude' => 15.775074,
3399
        ];
3400
3401
        $query = new Query(
3402
            [
3403
                'filter' => new Criterion\LogicalAnd(
3404
                    [
3405
                        new Criterion\ContentTypeId($contentType->id),
3406
                        new Criterion\MapLocationDistance(
3407
                            'maplocation',
3408
                            Criterion\Operator::GTE,
3409
                            235,
3410
                            $well['latitude'],
3411
                            $well['longitude']
3412
                        ),
3413
                    ]
3414
                ),
3415
                'offset' => 0,
3416
                'limit' => 10,
3417
                'sortClauses' => [
3418
                    new SortClause\MapLocationDistance(
3419
                        'testtype',
3420
                        'maplocation',
3421
                        $well['latitude'],
3422
                        $well['longitude'],
3423
                        Query::SORT_DESC
3424
                    ),
3425
                ],
3426
            ]
3427
        );
3428
3429
        $searchService = $repository->getSearchService();
3430
        $result = $searchService->findContent($query);
3431
3432
        $this->assertEquals(3, $result->totalCount);
3433
        $this->assertEquals(
3434
            $wildBoars->id,
3435
            $result->searchHits[2]->valueObject->id
3436
        );
3437
        $this->assertEquals(
3438
            $mushrooms->id,
3439
            $result->searchHits[1]->valueObject->id
3440
        );
3441
        $this->assertEquals(
3442
            $tree->id,
3443
            $result->searchHits[0]->valueObject->id
3444
        );
3445
    }
3446
3447
    /**
3448
     * Test for the findContent() method.