Code Duplication    Length = 110-110 lines in 2 locations

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

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