Code Duplication    Length = 110-110 lines in 2 locations

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

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