@@ 829-939 (lines=111) @@ | ||
826 | * @see \eZ\Publish\API\Repository\SearchService::findLocations() |
|
827 | * @group maplocation |
|
828 | */ |
|
829 | public function testMapLocationDistanceSortAscending() |
|
830 | { |
|
831 | $contentType = $this->createTestPlaceContentType(); |
|
832 | ||
833 | // Create a draft to account for behaviour with ContentType in different states |
|
834 | $repository = $this->getRepository(); |
|
835 | $contentTypeService = $repository->getContentTypeService(); |
|
836 | $contentService = $repository->getContentService(); |
|
837 | $contentTypeService->createContentTypeDraft($contentType); |
|
838 | $locationCreateStruct = $repository->getLocationService()->newLocationCreateStruct(2); |
|
839 | ||
840 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
841 | $createStruct->alwaysAvailable = false; |
|
842 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
843 | $createStruct->setField( |
|
844 | 'maplocation', |
|
845 | [ |
|
846 | 'latitude' => 45.894877, |
|
847 | 'longitude' => 15.972699, |
|
848 | 'address' => 'Here be wild boars', |
|
849 | ], |
|
850 | 'eng-GB' |
|
851 | ); |
|
852 | ||
853 | $draft = $contentService->createContent($createStruct, [$locationCreateStruct]); |
|
854 | $wildBoars = $contentService->publishVersion($draft->getVersionInfo()); |
|
855 | ||
856 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
857 | $createStruct->alwaysAvailable = false; |
|
858 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
859 | $createStruct->setField( |
|
860 | 'maplocation', |
|
861 | [ |
|
862 | 'latitude' => 45.927334, |
|
863 | 'longitude' => 15.934847, |
|
864 | 'address' => 'A lone tree', |
|
865 | ], |
|
866 | 'eng-GB' |
|
867 | ); |
|
868 | ||
869 | $draft = $contentService->createContent($createStruct, [$locationCreateStruct]); |
|
870 | $tree = $contentService->publishVersion($draft->getVersionInfo()); |
|
871 | ||
872 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
873 | $createStruct->alwaysAvailable = false; |
|
874 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
875 | $createStruct->setField( |
|
876 | 'maplocation', |
|
877 | [ |
|
878 | 'latitude' => 45.903777, |
|
879 | 'longitude' => 15.958788, |
|
880 | 'address' => 'Meadow with mushrooms', |
|
881 | ], |
|
882 | 'eng-GB' |
|
883 | ); |
|
884 | ||
885 | $draft = $contentService->createContent($createStruct, [$locationCreateStruct]); |
|
886 | $mushrooms = $contentService->publishVersion($draft->getVersionInfo()); |
|
887 | ||
888 | $this->refreshSearch($repository); |
|
889 | ||
890 | $wellInVodice = [ |
|
891 | 'latitude' => 43.756825, |
|
892 | 'longitude' => 15.775074, |
|
893 | ]; |
|
894 | ||
895 | $query = new LocationQuery( |
|
896 | [ |
|
897 | 'filter' => new Criterion\LogicalAnd( |
|
898 | [ |
|
899 | new Criterion\ContentTypeId($contentType->id), |
|
900 | new Criterion\MapLocationDistance( |
|
901 | 'maplocation', |
|
902 | Criterion\Operator::GTE, |
|
903 | 235, |
|
904 | $wellInVodice['latitude'], |
|
905 | $wellInVodice['longitude'] |
|
906 | ), |
|
907 | ] |
|
908 | ), |
|
909 | 'offset' => 0, |
|
910 | 'limit' => 10, |
|
911 | 'sortClauses' => [ |
|
912 | new SortClause\MapLocationDistance( |
|
913 | 'testtype', |
|
914 | 'maplocation', |
|
915 | $wellInVodice['latitude'], |
|
916 | $wellInVodice['longitude'], |
|
917 | LocationQuery::SORT_ASC |
|
918 | ), |
|
919 | ], |
|
920 | ] |
|
921 | ); |
|
922 | ||
923 | $searchService = $repository->getSearchService(); |
|
924 | $result = $searchService->findLocations($query); |
|
925 | ||
926 | $this->assertEquals(3, $result->totalCount); |
|
927 | $this->assertEquals( |
|
928 | $wildBoars->contentInfo->mainLocationId, |
|
929 | $result->searchHits[0]->valueObject->id |
|
930 | ); |
|
931 | $this->assertEquals( |
|
932 | $mushrooms->contentInfo->mainLocationId, |
|
933 | $result->searchHits[1]->valueObject->id |
|
934 | ); |
|
935 | $this->assertEquals( |
|
936 | $tree->contentInfo->mainLocationId, |
|
937 | $result->searchHits[2]->valueObject->id |
|
938 | ); |
|
939 | } |
|
940 | ||
941 | /** |
|
942 | * Test for the findLocations() method. |
|
@@ 947-1057 (lines=111) @@ | ||
944 | * @see \eZ\Publish\API\Repository\SearchService::findLocations() |
|
945 | * @group maplocation |
|
946 | */ |
|
947 | public function testMapLocationDistanceSortDescending() |
|
948 | { |
|
949 | $contentType = $this->createTestPlaceContentType(); |
|
950 | ||
951 | // Create a draft to account for behaviour with ContentType in different states |
|
952 | $repository = $this->getRepository(); |
|
953 | $contentTypeService = $repository->getContentTypeService(); |
|
954 | $contentService = $repository->getContentService(); |
|
955 | $contentTypeService->createContentTypeDraft($contentType); |
|
956 | $locationCreateStruct = $repository->getLocationService()->newLocationCreateStruct(2); |
|
957 | ||
958 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
959 | $createStruct->alwaysAvailable = false; |
|
960 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
961 | $createStruct->setField( |
|
962 | 'maplocation', |
|
963 | [ |
|
964 | 'latitude' => 45.894877, |
|
965 | 'longitude' => 15.972699, |
|
966 | 'address' => 'Here be wild boars', |
|
967 | ], |
|
968 | 'eng-GB' |
|
969 | ); |
|
970 | ||
971 | $draft = $contentService->createContent($createStruct, [$locationCreateStruct]); |
|
972 | $wildBoars = $contentService->publishVersion($draft->getVersionInfo()); |
|
973 | ||
974 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
975 | $createStruct->alwaysAvailable = false; |
|
976 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
977 | $createStruct->setField( |
|
978 | 'maplocation', |
|
979 | [ |
|
980 | 'latitude' => 45.927334, |
|
981 | 'longitude' => 15.934847, |
|
982 | 'address' => 'A lone tree', |
|
983 | ], |
|
984 | 'eng-GB' |
|
985 | ); |
|
986 | ||
987 | $draft = $contentService->createContent($createStruct, [$locationCreateStruct]); |
|
988 | $tree = $contentService->publishVersion($draft->getVersionInfo()); |
|
989 | ||
990 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
991 | $createStruct->alwaysAvailable = false; |
|
992 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
993 | $createStruct->setField( |
|
994 | 'maplocation', |
|
995 | [ |
|
996 | 'latitude' => 45.903777, |
|
997 | 'longitude' => 15.958788, |
|
998 | 'address' => 'Meadow with mushrooms', |
|
999 | ], |
|
1000 | 'eng-GB' |
|
1001 | ); |
|
1002 | ||
1003 | $draft = $contentService->createContent($createStruct, [$locationCreateStruct]); |
|
1004 | $mushrooms = $contentService->publishVersion($draft->getVersionInfo()); |
|
1005 | ||
1006 | $this->refreshSearch($repository); |
|
1007 | ||
1008 | $well = [ |
|
1009 | 'latitude' => 43.756825, |
|
1010 | 'longitude' => 15.775074, |
|
1011 | ]; |
|
1012 | ||
1013 | $query = new LocationQuery( |
|
1014 | [ |
|
1015 | 'filter' => new Criterion\LogicalAnd( |
|
1016 | [ |
|
1017 | new Criterion\ContentTypeId($contentType->id), |
|
1018 | new Criterion\MapLocationDistance( |
|
1019 | 'maplocation', |
|
1020 | Criterion\Operator::GTE, |
|
1021 | 235, |
|
1022 | $well['latitude'], |
|
1023 | $well['longitude'] |
|
1024 | ), |
|
1025 | ] |
|
1026 | ), |
|
1027 | 'offset' => 0, |
|
1028 | 'limit' => 10, |
|
1029 | 'sortClauses' => [ |
|
1030 | new SortClause\MapLocationDistance( |
|
1031 | 'testtype', |
|
1032 | 'maplocation', |
|
1033 | $well['latitude'], |
|
1034 | $well['longitude'], |
|
1035 | LocationQuery::SORT_DESC |
|
1036 | ), |
|
1037 | ], |
|
1038 | ] |
|
1039 | ); |
|
1040 | ||
1041 | $searchService = $repository->getSearchService(); |
|
1042 | $result = $searchService->findLocations($query); |
|
1043 | ||
1044 | $this->assertEquals(3, $result->totalCount); |
|
1045 | $this->assertEquals( |
|
1046 | $wildBoars->contentInfo->mainLocationId, |
|
1047 | $result->searchHits[2]->valueObject->id |
|
1048 | ); |
|
1049 | $this->assertEquals( |
|
1050 | $mushrooms->contentInfo->mainLocationId, |
|
1051 | $result->searchHits[1]->valueObject->id |
|
1052 | ); |
|
1053 | $this->assertEquals( |
|
1054 | $tree->contentInfo->mainLocationId, |
|
1055 | $result->searchHits[0]->valueObject->id |
|
1056 | ); |
|
1057 | } |
|
1058 | ||
1059 | /** |
|
1060 | * Test for the findLocations() method. |