|
@@ 570-643 (lines=74) @@
|
| 567 |
|
* @see \eZ\Publish\API\Repository\SearchService::findLocations() |
| 568 |
|
* @group maplocation |
| 569 |
|
*/ |
| 570 |
|
public function testMapLocationDistanceLessThanOrEqual() |
| 571 |
|
{ |
| 572 |
|
$contentType = $this->createTestPlaceContentType(); |
| 573 |
|
|
| 574 |
|
// Create a draft to account for behaviour with ContentType in different states |
| 575 |
|
$repository = $this->getRepository(); |
| 576 |
|
$contentTypeService = $repository->getContentTypeService(); |
| 577 |
|
$contentService = $repository->getContentService(); |
| 578 |
|
$contentTypeService->createContentTypeDraft($contentType); |
| 579 |
|
$locationCreateStruct = $repository->getLocationService()->newLocationCreateStruct(2); |
| 580 |
|
|
| 581 |
|
$createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
| 582 |
|
$createStruct->alwaysAvailable = false; |
| 583 |
|
$createStruct->mainLanguageCode = 'eng-GB'; |
| 584 |
|
$createStruct->setField( |
| 585 |
|
'maplocation', |
| 586 |
|
[ |
| 587 |
|
'latitude' => 45.894877, |
| 588 |
|
'longitude' => 15.972699, |
| 589 |
|
'address' => 'Here be wild boars', |
| 590 |
|
], |
| 591 |
|
'eng-GB' |
| 592 |
|
); |
| 593 |
|
|
| 594 |
|
$draft = $contentService->createContent($createStruct, [$locationCreateStruct]); |
| 595 |
|
$wildBoars = $contentService->publishVersion($draft->getVersionInfo()); |
| 596 |
|
|
| 597 |
|
$createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
| 598 |
|
$createStruct->alwaysAvailable = false; |
| 599 |
|
$createStruct->mainLanguageCode = 'eng-GB'; |
| 600 |
|
$createStruct->setField( |
| 601 |
|
'maplocation', |
| 602 |
|
[ |
| 603 |
|
'latitude' => 45.927334, |
| 604 |
|
'longitude' => 15.934847, |
| 605 |
|
'address' => 'A lone tree', |
| 606 |
|
], |
| 607 |
|
'eng-GB' |
| 608 |
|
); |
| 609 |
|
|
| 610 |
|
$draft = $contentService->createContent($createStruct, [$locationCreateStruct]); |
| 611 |
|
$tree = $contentService->publishVersion($draft->getVersionInfo()); |
| 612 |
|
|
| 613 |
|
$this->refreshSearch($repository); |
| 614 |
|
|
| 615 |
|
$query = new LocationQuery( |
| 616 |
|
[ |
| 617 |
|
'filter' => new Criterion\LogicalAnd( |
| 618 |
|
[ |
| 619 |
|
new Criterion\ContentTypeId($contentType->id), |
| 620 |
|
new Criterion\MapLocationDistance( |
| 621 |
|
'maplocation', |
| 622 |
|
Criterion\Operator::LTE, |
| 623 |
|
240, |
| 624 |
|
43.756825, |
| 625 |
|
15.775074 |
| 626 |
|
), |
| 627 |
|
] |
| 628 |
|
), |
| 629 |
|
'offset' => 0, |
| 630 |
|
'limit' => 10, |
| 631 |
|
'sortClauses' => [], |
| 632 |
|
] |
| 633 |
|
); |
| 634 |
|
|
| 635 |
|
$searchService = $repository->getSearchService(); |
| 636 |
|
$result = $searchService->findLocations($query); |
| 637 |
|
|
| 638 |
|
$this->assertEquals(1, $result->totalCount); |
| 639 |
|
$this->assertEquals( |
| 640 |
|
$wildBoars->contentInfo->mainLocationId, |
| 641 |
|
$result->searchHits[0]->valueObject->id |
| 642 |
|
); |
| 643 |
|
} |
| 644 |
|
|
| 645 |
|
/** |
| 646 |
|
* Test for the findLocations() method. |
|
@@ 651-724 (lines=74) @@
|
| 648 |
|
* @see \eZ\Publish\API\Repository\SearchService::findLocations() |
| 649 |
|
* @group maplocation |
| 650 |
|
*/ |
| 651 |
|
public function testMapLocationDistanceGreaterThanOrEqual() |
| 652 |
|
{ |
| 653 |
|
$contentType = $this->createTestPlaceContentType(); |
| 654 |
|
|
| 655 |
|
// Create a draft to account for behaviour with ContentType in different states |
| 656 |
|
$repository = $this->getRepository(); |
| 657 |
|
$contentTypeService = $repository->getContentTypeService(); |
| 658 |
|
$contentService = $repository->getContentService(); |
| 659 |
|
$contentTypeService->createContentTypeDraft($contentType); |
| 660 |
|
$locationCreateStruct = $repository->getLocationService()->newLocationCreateStruct(2); |
| 661 |
|
|
| 662 |
|
$createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
| 663 |
|
$createStruct->alwaysAvailable = false; |
| 664 |
|
$createStruct->mainLanguageCode = 'eng-GB'; |
| 665 |
|
$createStruct->setField( |
| 666 |
|
'maplocation', |
| 667 |
|
[ |
| 668 |
|
'latitude' => 45.894877, |
| 669 |
|
'longitude' => 15.972699, |
| 670 |
|
'address' => 'Here be wild boars', |
| 671 |
|
], |
| 672 |
|
'eng-GB' |
| 673 |
|
); |
| 674 |
|
|
| 675 |
|
$draft = $contentService->createContent($createStruct, [$locationCreateStruct]); |
| 676 |
|
$wildBoars = $contentService->publishVersion($draft->getVersionInfo()); |
| 677 |
|
|
| 678 |
|
$createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
| 679 |
|
$createStruct->alwaysAvailable = false; |
| 680 |
|
$createStruct->mainLanguageCode = 'eng-GB'; |
| 681 |
|
$createStruct->setField( |
| 682 |
|
'maplocation', |
| 683 |
|
[ |
| 684 |
|
'latitude' => 45.927334, |
| 685 |
|
'longitude' => 15.934847, |
| 686 |
|
'address' => 'A lone tree', |
| 687 |
|
], |
| 688 |
|
'eng-GB' |
| 689 |
|
); |
| 690 |
|
|
| 691 |
|
$draft = $contentService->createContent($createStruct, [$locationCreateStruct]); |
| 692 |
|
$tree = $contentService->publishVersion($draft->getVersionInfo()); |
| 693 |
|
|
| 694 |
|
$this->refreshSearch($repository); |
| 695 |
|
|
| 696 |
|
$query = new LocationQuery( |
| 697 |
|
[ |
| 698 |
|
'filter' => new Criterion\LogicalAnd( |
| 699 |
|
[ |
| 700 |
|
new Criterion\ContentTypeId($contentType->id), |
| 701 |
|
new Criterion\MapLocationDistance( |
| 702 |
|
'maplocation', |
| 703 |
|
Criterion\Operator::GTE, |
| 704 |
|
240, |
| 705 |
|
43.756825, |
| 706 |
|
15.775074 |
| 707 |
|
), |
| 708 |
|
] |
| 709 |
|
), |
| 710 |
|
'offset' => 0, |
| 711 |
|
'limit' => 10, |
| 712 |
|
'sortClauses' => [], |
| 713 |
|
] |
| 714 |
|
); |
| 715 |
|
|
| 716 |
|
$searchService = $repository->getSearchService(); |
| 717 |
|
$result = $searchService->findLocations($query); |
| 718 |
|
|
| 719 |
|
$this->assertEquals(1, $result->totalCount); |
| 720 |
|
$this->assertEquals( |
| 721 |
|
$tree->contentInfo->mainLocationId, |
| 722 |
|
$result->searchHits[0]->valueObject->id |
| 723 |
|
); |
| 724 |
|
} |
| 725 |
|
|
| 726 |
|
/** |
| 727 |
|
* Test for the findLocations() method. |