Code Duplication    Length = 110-110 lines in 2 locations

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

@@ 3272-3381 (lines=110) @@
3269
     * @see \eZ\Publish\API\Repository\SearchService::findContent()
3270
     * @group maplocation
3271
     */
3272
    public function testMapLocationDistanceSortAscending()
3273
    {
3274
        $contentType = $this->createTestPlaceContentType();
3275
3276
        // Create a draft to account for behaviour with ContentType in different states
3277
        $repository = $this->getRepository();
3278
        $contentTypeService = $repository->getContentTypeService();
3279
        $contentService = $repository->getContentService();
3280
        $contentTypeService->createContentTypeDraft($contentType);
3281
3282
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
3283
        $createStruct->alwaysAvailable = false;
3284
        $createStruct->mainLanguageCode = 'eng-GB';
3285
        $createStruct->setField(
3286
            'maplocation',
3287
            array(
3288
                'latitude' => 45.894877,
3289
                'longitude' => 15.972699,
3290
                'address' => 'Here be wild boars',
3291
            ),
3292
            'eng-GB'
3293
        );
3294
3295
        $draft = $contentService->createContent($createStruct);
3296
        $wildBoars = $contentService->publishVersion($draft->getVersionInfo());
3297
3298
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
3299
        $createStruct->alwaysAvailable = false;
3300
        $createStruct->mainLanguageCode = 'eng-GB';
3301
        $createStruct->setField(
3302
            'maplocation',
3303
            array(
3304
                'latitude' => 45.927334,
3305
                'longitude' => 15.934847,
3306
                'address' => 'A lone tree',
3307
            ),
3308
            'eng-GB'
3309
        );
3310
3311
        $draft = $contentService->createContent($createStruct);
3312
        $tree = $contentService->publishVersion($draft->getVersionInfo());
3313
3314
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
3315
        $createStruct->alwaysAvailable = false;
3316
        $createStruct->mainLanguageCode = 'eng-GB';
3317
        $createStruct->setField(
3318
            'maplocation',
3319
            array(
3320
                'latitude' => 45.903777,
3321
                'longitude' => 15.958788,
3322
                'address' => 'Meadow with mushrooms',
3323
            ),
3324
            'eng-GB'
3325
        );
3326
3327
        $draft = $contentService->createContent($createStruct);
3328
        $mushrooms = $contentService->publishVersion($draft->getVersionInfo());
3329
3330
        $this->refreshSearch($repository);
3331
3332
        $wellInVodice = array(
3333
            'latitude' => 43.756825,
3334
            'longitude' => 15.775074,
3335
        );
3336
3337
        $query = new Query(
3338
            array(
3339
                'filter' => new Criterion\LogicalAnd(
3340
                    array(
3341
                        new Criterion\ContentTypeId($contentType->id),
3342
                        new Criterion\MapLocationDistance(
3343
                            'maplocation',
3344
                            Criterion\Operator::GTE,
3345
                            235,
3346
                            $wellInVodice['latitude'],
3347
                            $wellInVodice['longitude']
3348
                        ),
3349
                    )
3350
                ),
3351
                'offset' => 0,
3352
                'limit' => 10,
3353
                'sortClauses' => array(
3354
                    new SortClause\MapLocationDistance(
3355
                        'testtype',
3356
                        'maplocation',
3357
                        $wellInVodice['latitude'],
3358
                        $wellInVodice['longitude'],
3359
                        Query::SORT_ASC
3360
                    ),
3361
                ),
3362
            )
3363
        );
3364
3365
        $searchService = $repository->getSearchService();
3366
        $result = $searchService->findContent($query);
3367
3368
        $this->assertEquals(3, $result->totalCount);
3369
        $this->assertEquals(
3370
            $wildBoars->id,
3371
            $result->searchHits[0]->valueObject->id
3372
        );
3373
        $this->assertEquals(
3374
            $mushrooms->id,
3375
            $result->searchHits[1]->valueObject->id
3376
        );
3377
        $this->assertEquals(
3378
            $tree->id,
3379
            $result->searchHits[2]->valueObject->id
3380
        );
3381
    }
3382
3383
    /**
3384
     * Test for the findContent() method.
@@ 3389-3498 (lines=110) @@
3386
     * @see \eZ\Publish\API\Repository\SearchService::findContent()
3387
     * @group maplocation
3388
     */
3389
    public function testMapLocationDistanceSortDescending()
3390
    {
3391
        $contentType = $this->createTestPlaceContentType();
3392
3393
        // Create a draft to account for behaviour with ContentType in different states
3394
        $repository = $this->getRepository();
3395
        $contentTypeService = $repository->getContentTypeService();
3396
        $contentService = $repository->getContentService();
3397
        $contentTypeService->createContentTypeDraft($contentType);
3398
3399
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
3400
        $createStruct->alwaysAvailable = false;
3401
        $createStruct->mainLanguageCode = 'eng-GB';
3402
        $createStruct->setField(
3403
            'maplocation',
3404
            array(
3405
                'latitude' => 45.894877,
3406
                'longitude' => 15.972699,
3407
                'address' => 'Here be wild boars',
3408
            ),
3409
            'eng-GB'
3410
        );
3411
3412
        $draft = $contentService->createContent($createStruct);
3413
        $wildBoars = $contentService->publishVersion($draft->getVersionInfo());
3414
3415
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
3416
        $createStruct->alwaysAvailable = false;
3417
        $createStruct->mainLanguageCode = 'eng-GB';
3418
        $createStruct->setField(
3419
            'maplocation',
3420
            array(
3421
                'latitude' => 45.927334,
3422
                'longitude' => 15.934847,
3423
                'address' => 'A lone tree',
3424
            ),
3425
            'eng-GB'
3426
        );
3427
3428
        $draft = $contentService->createContent($createStruct);
3429
        $tree = $contentService->publishVersion($draft->getVersionInfo());
3430
3431
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
3432
        $createStruct->alwaysAvailable = false;
3433
        $createStruct->mainLanguageCode = 'eng-GB';
3434
        $createStruct->setField(
3435
            'maplocation',
3436
            array(
3437
                'latitude' => 45.903777,
3438
                'longitude' => 15.958788,
3439
                'address' => 'Meadow with mushrooms',
3440
            ),
3441
            'eng-GB'
3442
        );
3443
3444
        $draft = $contentService->createContent($createStruct);
3445
        $mushrooms = $contentService->publishVersion($draft->getVersionInfo());
3446
3447
        $this->refreshSearch($repository);
3448
3449
        $well = array(
3450
            'latitude' => 43.756825,
3451
            'longitude' => 15.775074,
3452
        );
3453
3454
        $query = new Query(
3455
            array(
3456
                'filter' => new Criterion\LogicalAnd(
3457
                    array(
3458
                        new Criterion\ContentTypeId($contentType->id),
3459
                        new Criterion\MapLocationDistance(
3460
                            'maplocation',
3461
                            Criterion\Operator::GTE,
3462
                            235,
3463
                            $well['latitude'],
3464
                            $well['longitude']
3465
                        ),
3466
                    )
3467
                ),
3468
                'offset' => 0,
3469
                'limit' => 10,
3470
                'sortClauses' => array(
3471
                    new SortClause\MapLocationDistance(
3472
                        'testtype',
3473
                        'maplocation',
3474
                        $well['latitude'],
3475
                        $well['longitude'],
3476
                        Query::SORT_DESC
3477
                    ),
3478
                ),
3479
            )
3480
        );
3481
3482
        $searchService = $repository->getSearchService();
3483
        $result = $searchService->findContent($query);
3484
3485
        $this->assertEquals(3, $result->totalCount);
3486
        $this->assertEquals(
3487
            $wildBoars->id,
3488
            $result->searchHits[2]->valueObject->id
3489
        );
3490
        $this->assertEquals(
3491
            $mushrooms->id,
3492
            $result->searchHits[1]->valueObject->id
3493
        );
3494
        $this->assertEquals(
3495
            $tree->id,
3496
            $result->searchHits[0]->valueObject->id
3497
        );
3498
    }
3499
3500
    /**
3501
     * Test for the findContent() method.