|
@@ 487-560 (lines=74) @@
|
| 484 |
|
* @see \eZ\Publish\API\Repository\SearchService::findLocations() |
| 485 |
|
* @group maplocation |
| 486 |
|
*/ |
| 487 |
|
public function testMapLocationDistanceLessThanOrEqual() |
| 488 |
|
{ |
| 489 |
|
$contentType = $this->createTestPlaceContentType(); |
| 490 |
|
|
| 491 |
|
// Create a draft to account for behaviour with ContentType in different states |
| 492 |
|
$repository = $this->getRepository(); |
| 493 |
|
$contentTypeService = $repository->getContentTypeService(); |
| 494 |
|
$contentService = $repository->getContentService(); |
| 495 |
|
$contentTypeService->createContentTypeDraft($contentType); |
| 496 |
|
$locationCreateStruct = $repository->getLocationService()->newLocationCreateStruct(2); |
| 497 |
|
|
| 498 |
|
$createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
| 499 |
|
$createStruct->alwaysAvailable = false; |
| 500 |
|
$createStruct->mainLanguageCode = 'eng-GB'; |
| 501 |
|
$createStruct->setField( |
| 502 |
|
'maplocation', |
| 503 |
|
[ |
| 504 |
|
'latitude' => 45.894877, |
| 505 |
|
'longitude' => 15.972699, |
| 506 |
|
'address' => 'Here be wild boars', |
| 507 |
|
], |
| 508 |
|
'eng-GB' |
| 509 |
|
); |
| 510 |
|
|
| 511 |
|
$draft = $contentService->createContent($createStruct, [$locationCreateStruct]); |
| 512 |
|
$wildBoars = $contentService->publishVersion($draft->getVersionInfo()); |
| 513 |
|
|
| 514 |
|
$createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
| 515 |
|
$createStruct->alwaysAvailable = false; |
| 516 |
|
$createStruct->mainLanguageCode = 'eng-GB'; |
| 517 |
|
$createStruct->setField( |
| 518 |
|
'maplocation', |
| 519 |
|
[ |
| 520 |
|
'latitude' => 45.927334, |
| 521 |
|
'longitude' => 15.934847, |
| 522 |
|
'address' => 'A lone tree', |
| 523 |
|
], |
| 524 |
|
'eng-GB' |
| 525 |
|
); |
| 526 |
|
|
| 527 |
|
$draft = $contentService->createContent($createStruct, [$locationCreateStruct]); |
| 528 |
|
$tree = $contentService->publishVersion($draft->getVersionInfo()); |
| 529 |
|
|
| 530 |
|
$this->refreshSearch($repository); |
| 531 |
|
|
| 532 |
|
$query = new LocationQuery( |
| 533 |
|
[ |
| 534 |
|
'filter' => new Criterion\LogicalAnd( |
| 535 |
|
[ |
| 536 |
|
new Criterion\ContentTypeId($contentType->id), |
| 537 |
|
new Criterion\MapLocationDistance( |
| 538 |
|
'maplocation', |
| 539 |
|
Criterion\Operator::LTE, |
| 540 |
|
240, |
| 541 |
|
43.756825, |
| 542 |
|
15.775074 |
| 543 |
|
), |
| 544 |
|
] |
| 545 |
|
), |
| 546 |
|
'offset' => 0, |
| 547 |
|
'limit' => 10, |
| 548 |
|
'sortClauses' => [], |
| 549 |
|
] |
| 550 |
|
); |
| 551 |
|
|
| 552 |
|
$searchService = $repository->getSearchService(); |
| 553 |
|
$result = $searchService->findLocations($query); |
| 554 |
|
|
| 555 |
|
$this->assertEquals(1, $result->totalCount); |
| 556 |
|
$this->assertEquals( |
| 557 |
|
$wildBoars->contentInfo->mainLocationId, |
| 558 |
|
$result->searchHits[0]->valueObject->id |
| 559 |
|
); |
| 560 |
|
} |
| 561 |
|
|
| 562 |
|
/** |
| 563 |
|
* Test for the findLocations() method. |
|
@@ 568-641 (lines=74) @@
|
| 565 |
|
* @see \eZ\Publish\API\Repository\SearchService::findLocations() |
| 566 |
|
* @group maplocation |
| 567 |
|
*/ |
| 568 |
|
public function testMapLocationDistanceGreaterThanOrEqual() |
| 569 |
|
{ |
| 570 |
|
$contentType = $this->createTestPlaceContentType(); |
| 571 |
|
|
| 572 |
|
// Create a draft to account for behaviour with ContentType in different states |
| 573 |
|
$repository = $this->getRepository(); |
| 574 |
|
$contentTypeService = $repository->getContentTypeService(); |
| 575 |
|
$contentService = $repository->getContentService(); |
| 576 |
|
$contentTypeService->createContentTypeDraft($contentType); |
| 577 |
|
$locationCreateStruct = $repository->getLocationService()->newLocationCreateStruct(2); |
| 578 |
|
|
| 579 |
|
$createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
| 580 |
|
$createStruct->alwaysAvailable = false; |
| 581 |
|
$createStruct->mainLanguageCode = 'eng-GB'; |
| 582 |
|
$createStruct->setField( |
| 583 |
|
'maplocation', |
| 584 |
|
[ |
| 585 |
|
'latitude' => 45.894877, |
| 586 |
|
'longitude' => 15.972699, |
| 587 |
|
'address' => 'Here be wild boars', |
| 588 |
|
], |
| 589 |
|
'eng-GB' |
| 590 |
|
); |
| 591 |
|
|
| 592 |
|
$draft = $contentService->createContent($createStruct, [$locationCreateStruct]); |
| 593 |
|
$wildBoars = $contentService->publishVersion($draft->getVersionInfo()); |
| 594 |
|
|
| 595 |
|
$createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
| 596 |
|
$createStruct->alwaysAvailable = false; |
| 597 |
|
$createStruct->mainLanguageCode = 'eng-GB'; |
| 598 |
|
$createStruct->setField( |
| 599 |
|
'maplocation', |
| 600 |
|
[ |
| 601 |
|
'latitude' => 45.927334, |
| 602 |
|
'longitude' => 15.934847, |
| 603 |
|
'address' => 'A lone tree', |
| 604 |
|
], |
| 605 |
|
'eng-GB' |
| 606 |
|
); |
| 607 |
|
|
| 608 |
|
$draft = $contentService->createContent($createStruct, [$locationCreateStruct]); |
| 609 |
|
$tree = $contentService->publishVersion($draft->getVersionInfo()); |
| 610 |
|
|
| 611 |
|
$this->refreshSearch($repository); |
| 612 |
|
|
| 613 |
|
$query = new LocationQuery( |
| 614 |
|
[ |
| 615 |
|
'filter' => new Criterion\LogicalAnd( |
| 616 |
|
[ |
| 617 |
|
new Criterion\ContentTypeId($contentType->id), |
| 618 |
|
new Criterion\MapLocationDistance( |
| 619 |
|
'maplocation', |
| 620 |
|
Criterion\Operator::GTE, |
| 621 |
|
240, |
| 622 |
|
43.756825, |
| 623 |
|
15.775074 |
| 624 |
|
), |
| 625 |
|
] |
| 626 |
|
), |
| 627 |
|
'offset' => 0, |
| 628 |
|
'limit' => 10, |
| 629 |
|
'sortClauses' => [], |
| 630 |
|
] |
| 631 |
|
); |
| 632 |
|
|
| 633 |
|
$searchService = $repository->getSearchService(); |
| 634 |
|
$result = $searchService->findLocations($query); |
| 635 |
|
|
| 636 |
|
$this->assertEquals(1, $result->totalCount); |
| 637 |
|
$this->assertEquals( |
| 638 |
|
$tree->contentInfo->mainLocationId, |
| 639 |
|
$result->searchHits[0]->valueObject->id |
| 640 |
|
); |
| 641 |
|
} |
| 642 |
|
|
| 643 |
|
/** |
| 644 |
|
* Test for the findLocations() method. |