| @@ 745-855 (lines=111) @@ | ||
| 742 | * @see \eZ\Publish\API\Repository\SearchService::findLocations() |
|
| 743 | * @group maplocation |
|
| 744 | */ |
|
| 745 | public function testMapLocationDistanceSortAscending() |
|
| 746 | { |
|
| 747 | $contentType = $this->createTestPlaceContentType(); |
|
| 748 | ||
| 749 | // Create a draft to account for behaviour with ContentType in different states |
|
| 750 | $repository = $this->getRepository(); |
|
| 751 | $contentTypeService = $repository->getContentTypeService(); |
|
| 752 | $contentService = $repository->getContentService(); |
|
| 753 | $contentTypeService->createContentTypeDraft($contentType); |
|
| 754 | $locationCreateStruct = $repository->getLocationService()->newLocationCreateStruct(2); |
|
| 755 | ||
| 756 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 757 | $createStruct->alwaysAvailable = false; |
|
| 758 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 759 | $createStruct->setField( |
|
| 760 | 'maplocation', |
|
| 761 | [ |
|
| 762 | 'latitude' => 45.894877, |
|
| 763 | 'longitude' => 15.972699, |
|
| 764 | 'address' => 'Here be wild boars', |
|
| 765 | ], |
|
| 766 | 'eng-GB' |
|
| 767 | ); |
|
| 768 | ||
| 769 | $draft = $contentService->createContent($createStruct, [$locationCreateStruct]); |
|
| 770 | $wildBoars = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 771 | ||
| 772 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 773 | $createStruct->alwaysAvailable = false; |
|
| 774 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 775 | $createStruct->setField( |
|
| 776 | 'maplocation', |
|
| 777 | [ |
|
| 778 | 'latitude' => 45.927334, |
|
| 779 | 'longitude' => 15.934847, |
|
| 780 | 'address' => 'A lone tree', |
|
| 781 | ], |
|
| 782 | 'eng-GB' |
|
| 783 | ); |
|
| 784 | ||
| 785 | $draft = $contentService->createContent($createStruct, [$locationCreateStruct]); |
|
| 786 | $tree = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 787 | ||
| 788 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 789 | $createStruct->alwaysAvailable = false; |
|
| 790 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 791 | $createStruct->setField( |
|
| 792 | 'maplocation', |
|
| 793 | [ |
|
| 794 | 'latitude' => 45.903777, |
|
| 795 | 'longitude' => 15.958788, |
|
| 796 | 'address' => 'Meadow with mushrooms', |
|
| 797 | ], |
|
| 798 | 'eng-GB' |
|
| 799 | ); |
|
| 800 | ||
| 801 | $draft = $contentService->createContent($createStruct, [$locationCreateStruct]); |
|
| 802 | $mushrooms = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 803 | ||
| 804 | $this->refreshSearch($repository); |
|
| 805 | ||
| 806 | $wellInVodice = [ |
|
| 807 | 'latitude' => 43.756825, |
|
| 808 | 'longitude' => 15.775074, |
|
| 809 | ]; |
|
| 810 | ||
| 811 | $query = new LocationQuery( |
|
| 812 | [ |
|
| 813 | 'filter' => new Criterion\LogicalAnd( |
|
| 814 | [ |
|
| 815 | new Criterion\ContentTypeId($contentType->id), |
|
| 816 | new Criterion\MapLocationDistance( |
|
| 817 | 'maplocation', |
|
| 818 | Criterion\Operator::GTE, |
|
| 819 | 235, |
|
| 820 | $wellInVodice['latitude'], |
|
| 821 | $wellInVodice['longitude'] |
|
| 822 | ), |
|
| 823 | ] |
|
| 824 | ), |
|
| 825 | 'offset' => 0, |
|
| 826 | 'limit' => 10, |
|
| 827 | 'sortClauses' => [ |
|
| 828 | new SortClause\MapLocationDistance( |
|
| 829 | 'testtype', |
|
| 830 | 'maplocation', |
|
| 831 | $wellInVodice['latitude'], |
|
| 832 | $wellInVodice['longitude'], |
|
| 833 | LocationQuery::SORT_ASC |
|
| 834 | ), |
|
| 835 | ], |
|
| 836 | ] |
|
| 837 | ); |
|
| 838 | ||
| 839 | $searchService = $repository->getSearchService(); |
|
| 840 | $result = $searchService->findLocations($query); |
|
| 841 | ||
| 842 | $this->assertEquals(3, $result->totalCount); |
|
| 843 | $this->assertEquals( |
|
| 844 | $wildBoars->contentInfo->mainLocationId, |
|
| 845 | $result->searchHits[0]->valueObject->id |
|
| 846 | ); |
|
| 847 | $this->assertEquals( |
|
| 848 | $mushrooms->contentInfo->mainLocationId, |
|
| 849 | $result->searchHits[1]->valueObject->id |
|
| 850 | ); |
|
| 851 | $this->assertEquals( |
|
| 852 | $tree->contentInfo->mainLocationId, |
|
| 853 | $result->searchHits[2]->valueObject->id |
|
| 854 | ); |
|
| 855 | } |
|
| 856 | ||
| 857 | /** |
|
| 858 | * Test for the findLocations() method. |
|
| @@ 863-973 (lines=111) @@ | ||
| 860 | * @see \eZ\Publish\API\Repository\SearchService::findLocations() |
|
| 861 | * @group maplocation |
|
| 862 | */ |
|
| 863 | public function testMapLocationDistanceSortDescending() |
|
| 864 | { |
|
| 865 | $contentType = $this->createTestPlaceContentType(); |
|
| 866 | ||
| 867 | // Create a draft to account for behaviour with ContentType in different states |
|
| 868 | $repository = $this->getRepository(); |
|
| 869 | $contentTypeService = $repository->getContentTypeService(); |
|
| 870 | $contentService = $repository->getContentService(); |
|
| 871 | $contentTypeService->createContentTypeDraft($contentType); |
|
| 872 | $locationCreateStruct = $repository->getLocationService()->newLocationCreateStruct(2); |
|
| 873 | ||
| 874 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 875 | $createStruct->alwaysAvailable = false; |
|
| 876 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 877 | $createStruct->setField( |
|
| 878 | 'maplocation', |
|
| 879 | [ |
|
| 880 | 'latitude' => 45.894877, |
|
| 881 | 'longitude' => 15.972699, |
|
| 882 | 'address' => 'Here be wild boars', |
|
| 883 | ], |
|
| 884 | 'eng-GB' |
|
| 885 | ); |
|
| 886 | ||
| 887 | $draft = $contentService->createContent($createStruct, [$locationCreateStruct]); |
|
| 888 | $wildBoars = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 889 | ||
| 890 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 891 | $createStruct->alwaysAvailable = false; |
|
| 892 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 893 | $createStruct->setField( |
|
| 894 | 'maplocation', |
|
| 895 | [ |
|
| 896 | 'latitude' => 45.927334, |
|
| 897 | 'longitude' => 15.934847, |
|
| 898 | 'address' => 'A lone tree', |
|
| 899 | ], |
|
| 900 | 'eng-GB' |
|
| 901 | ); |
|
| 902 | ||
| 903 | $draft = $contentService->createContent($createStruct, [$locationCreateStruct]); |
|
| 904 | $tree = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 905 | ||
| 906 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 907 | $createStruct->alwaysAvailable = false; |
|
| 908 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 909 | $createStruct->setField( |
|
| 910 | 'maplocation', |
|
| 911 | [ |
|
| 912 | 'latitude' => 45.903777, |
|
| 913 | 'longitude' => 15.958788, |
|
| 914 | 'address' => 'Meadow with mushrooms', |
|
| 915 | ], |
|
| 916 | 'eng-GB' |
|
| 917 | ); |
|
| 918 | ||
| 919 | $draft = $contentService->createContent($createStruct, [$locationCreateStruct]); |
|
| 920 | $mushrooms = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 921 | ||
| 922 | $this->refreshSearch($repository); |
|
| 923 | ||
| 924 | $well = [ |
|
| 925 | 'latitude' => 43.756825, |
|
| 926 | 'longitude' => 15.775074, |
|
| 927 | ]; |
|
| 928 | ||
| 929 | $query = new LocationQuery( |
|
| 930 | [ |
|
| 931 | 'filter' => new Criterion\LogicalAnd( |
|
| 932 | [ |
|
| 933 | new Criterion\ContentTypeId($contentType->id), |
|
| 934 | new Criterion\MapLocationDistance( |
|
| 935 | 'maplocation', |
|
| 936 | Criterion\Operator::GTE, |
|
| 937 | 235, |
|
| 938 | $well['latitude'], |
|
| 939 | $well['longitude'] |
|
| 940 | ), |
|
| 941 | ] |
|
| 942 | ), |
|
| 943 | 'offset' => 0, |
|
| 944 | 'limit' => 10, |
|
| 945 | 'sortClauses' => [ |
|
| 946 | new SortClause\MapLocationDistance( |
|
| 947 | 'testtype', |
|
| 948 | 'maplocation', |
|
| 949 | $well['latitude'], |
|
| 950 | $well['longitude'], |
|
| 951 | LocationQuery::SORT_DESC |
|
| 952 | ), |
|
| 953 | ], |
|
| 954 | ] |
|
| 955 | ); |
|
| 956 | ||
| 957 | $searchService = $repository->getSearchService(); |
|
| 958 | $result = $searchService->findLocations($query); |
|
| 959 | ||
| 960 | $this->assertEquals(3, $result->totalCount); |
|
| 961 | $this->assertEquals( |
|
| 962 | $wildBoars->contentInfo->mainLocationId, |
|
| 963 | $result->searchHits[2]->valueObject->id |
|
| 964 | ); |
|
| 965 | $this->assertEquals( |
|
| 966 | $mushrooms->contentInfo->mainLocationId, |
|
| 967 | $result->searchHits[1]->valueObject->id |
|
| 968 | ); |
|
| 969 | $this->assertEquals( |
|
| 970 | $tree->contentInfo->mainLocationId, |
|
| 971 | $result->searchHits[0]->valueObject->id |
|
| 972 | ); |
|
| 973 | } |
|
| 974 | ||
| 975 | /** |
|
| 976 | * Test for the findLocations() method. |
|