| @@ 3338-3447 (lines=110) @@ | ||
| 3335 | * @see \eZ\Publish\API\Repository\SearchService::findContent() |
|
| 3336 | * @group maplocation |
|
| 3337 | */ |
|
| 3338 | public function testMapLocationDistanceSortAscending() |
|
| 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 | $wellInVodice = 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 | $wellInVodice['latitude'], |
|
| 3413 | $wellInVodice['longitude'] |
|
| 3414 | ), |
|
| 3415 | ) |
|
| 3416 | ), |
|
| 3417 | 'offset' => 0, |
|
| 3418 | 'limit' => 10, |
|
| 3419 | 'sortClauses' => array( |
|
| 3420 | new SortClause\MapLocationDistance( |
|
| 3421 | 'testtype', |
|
| 3422 | 'maplocation', |
|
| 3423 | $wellInVodice['latitude'], |
|
| 3424 | $wellInVodice['longitude'], |
|
| 3425 | Query::SORT_ASC |
|
| 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[0]->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[2]->valueObject->id |
|
| 3446 | ); |
|
| 3447 | } |
|
| 3448 | ||
| 3449 | /** |
|
| 3450 | * Test for the findContent() method. |
|
| @@ 3455-3564 (lines=110) @@ | ||
| 3452 | * @see \eZ\Publish\API\Repository\SearchService::findContent() |
|
| 3453 | * @group maplocation |
|
| 3454 | */ |
|
| 3455 | public function testMapLocationDistanceSortDescending() |
|
| 3456 | { |
|
| 3457 | $contentType = $this->createTestPlaceContentType(); |
|
| 3458 | ||
| 3459 | // Create a draft to account for behaviour with ContentType in different states |
|
| 3460 | $repository = $this->getRepository(); |
|
| 3461 | $contentTypeService = $repository->getContentTypeService(); |
|
| 3462 | $contentService = $repository->getContentService(); |
|
| 3463 | $contentTypeService->createContentTypeDraft($contentType); |
|
| 3464 | ||
| 3465 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 3466 | $createStruct->alwaysAvailable = false; |
|
| 3467 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 3468 | $createStruct->setField( |
|
| 3469 | 'maplocation', |
|
| 3470 | array( |
|
| 3471 | 'latitude' => 45.894877, |
|
| 3472 | 'longitude' => 15.972699, |
|
| 3473 | 'address' => 'Here be wild boars', |
|
| 3474 | ), |
|
| 3475 | 'eng-GB' |
|
| 3476 | ); |
|
| 3477 | ||
| 3478 | $draft = $contentService->createContent($createStruct); |
|
| 3479 | $wildBoars = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 3480 | ||
| 3481 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 3482 | $createStruct->alwaysAvailable = false; |
|
| 3483 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 3484 | $createStruct->setField( |
|
| 3485 | 'maplocation', |
|
| 3486 | array( |
|
| 3487 | 'latitude' => 45.927334, |
|
| 3488 | 'longitude' => 15.934847, |
|
| 3489 | 'address' => 'A lone tree', |
|
| 3490 | ), |
|
| 3491 | 'eng-GB' |
|
| 3492 | ); |
|
| 3493 | ||
| 3494 | $draft = $contentService->createContent($createStruct); |
|
| 3495 | $tree = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 3496 | ||
| 3497 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 3498 | $createStruct->alwaysAvailable = false; |
|
| 3499 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 3500 | $createStruct->setField( |
|
| 3501 | 'maplocation', |
|
| 3502 | array( |
|
| 3503 | 'latitude' => 45.903777, |
|
| 3504 | 'longitude' => 15.958788, |
|
| 3505 | 'address' => 'Meadow with mushrooms', |
|
| 3506 | ), |
|
| 3507 | 'eng-GB' |
|
| 3508 | ); |
|
| 3509 | ||
| 3510 | $draft = $contentService->createContent($createStruct); |
|
| 3511 | $mushrooms = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 3512 | ||
| 3513 | $this->refreshSearch($repository); |
|
| 3514 | ||
| 3515 | $well = array( |
|
| 3516 | 'latitude' => 43.756825, |
|
| 3517 | 'longitude' => 15.775074, |
|
| 3518 | ); |
|
| 3519 | ||
| 3520 | $query = new Query( |
|
| 3521 | array( |
|
| 3522 | 'filter' => new Criterion\LogicalAnd( |
|
| 3523 | array( |
|
| 3524 | new Criterion\ContentTypeId($contentType->id), |
|
| 3525 | new Criterion\MapLocationDistance( |
|
| 3526 | 'maplocation', |
|
| 3527 | Criterion\Operator::GTE, |
|
| 3528 | 235, |
|
| 3529 | $well['latitude'], |
|
| 3530 | $well['longitude'] |
|
| 3531 | ), |
|
| 3532 | ) |
|
| 3533 | ), |
|
| 3534 | 'offset' => 0, |
|
| 3535 | 'limit' => 10, |
|
| 3536 | 'sortClauses' => array( |
|
| 3537 | new SortClause\MapLocationDistance( |
|
| 3538 | 'testtype', |
|
| 3539 | 'maplocation', |
|
| 3540 | $well['latitude'], |
|
| 3541 | $well['longitude'], |
|
| 3542 | Query::SORT_DESC |
|
| 3543 | ), |
|
| 3544 | ), |
|
| 3545 | ) |
|
| 3546 | ); |
|
| 3547 | ||
| 3548 | $searchService = $repository->getSearchService(); |
|
| 3549 | $result = $searchService->findContent($query); |
|
| 3550 | ||
| 3551 | $this->assertEquals(3, $result->totalCount); |
|
| 3552 | $this->assertEquals( |
|
| 3553 | $wildBoars->id, |
|
| 3554 | $result->searchHits[2]->valueObject->id |
|
| 3555 | ); |
|
| 3556 | $this->assertEquals( |
|
| 3557 | $mushrooms->id, |
|
| 3558 | $result->searchHits[1]->valueObject->id |
|
| 3559 | ); |
|
| 3560 | $this->assertEquals( |
|
| 3561 | $tree->id, |
|
| 3562 | $result->searchHits[0]->valueObject->id |
|
| 3563 | ); |
|
| 3564 | } |
|
| 3565 | ||
| 3566 | /** |
|
| 3567 | * Test for the findContent() method. |
|