| @@ 2986-3095 (lines=110) @@ | ||
| 2983 | * @see \eZ\Publish\API\Repository\SearchService::findContent() |
|
| 2984 | * @group maplocation |
|
| 2985 | */ |
|
| 2986 | public function testMapLocationDistanceSortAscending() |
|
| 2987 | { |
|
| 2988 | $contentType = $this->createTestPlaceContentType(); |
|
| 2989 | ||
| 2990 | // Create a draft to account for behaviour with ContentType in different states |
|
| 2991 | $repository = $this->getRepository(); |
|
| 2992 | $contentTypeService = $repository->getContentTypeService(); |
|
| 2993 | $contentService = $repository->getContentService(); |
|
| 2994 | $contentTypeService->createContentTypeDraft($contentType); |
|
| 2995 | ||
| 2996 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 2997 | $createStruct->alwaysAvailable = false; |
|
| 2998 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 2999 | $createStruct->setField( |
|
| 3000 | 'maplocation', |
|
| 3001 | array( |
|
| 3002 | 'latitude' => 45.894877, |
|
| 3003 | 'longitude' => 15.972699, |
|
| 3004 | 'address' => 'Here be wild boars', |
|
| 3005 | ), |
|
| 3006 | 'eng-GB' |
|
| 3007 | ); |
|
| 3008 | ||
| 3009 | $draft = $contentService->createContent($createStruct); |
|
| 3010 | $wildBoars = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 3011 | ||
| 3012 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 3013 | $createStruct->alwaysAvailable = false; |
|
| 3014 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 3015 | $createStruct->setField( |
|
| 3016 | 'maplocation', |
|
| 3017 | array( |
|
| 3018 | 'latitude' => 45.927334, |
|
| 3019 | 'longitude' => 15.934847, |
|
| 3020 | 'address' => 'A lone tree', |
|
| 3021 | ), |
|
| 3022 | 'eng-GB' |
|
| 3023 | ); |
|
| 3024 | ||
| 3025 | $draft = $contentService->createContent($createStruct); |
|
| 3026 | $tree = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 3027 | ||
| 3028 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 3029 | $createStruct->alwaysAvailable = false; |
|
| 3030 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 3031 | $createStruct->setField( |
|
| 3032 | 'maplocation', |
|
| 3033 | array( |
|
| 3034 | 'latitude' => 45.903777, |
|
| 3035 | 'longitude' => 15.958788, |
|
| 3036 | 'address' => 'Meadow with mushrooms', |
|
| 3037 | ), |
|
| 3038 | 'eng-GB' |
|
| 3039 | ); |
|
| 3040 | ||
| 3041 | $draft = $contentService->createContent($createStruct); |
|
| 3042 | $mushrooms = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 3043 | ||
| 3044 | $this->refreshSearch($repository); |
|
| 3045 | ||
| 3046 | $wellInVodice = array( |
|
| 3047 | 'latitude' => 43.756825, |
|
| 3048 | 'longitude' => 15.775074, |
|
| 3049 | ); |
|
| 3050 | ||
| 3051 | $query = new Query( |
|
| 3052 | array( |
|
| 3053 | 'filter' => new Criterion\LogicalAnd( |
|
| 3054 | array( |
|
| 3055 | new Criterion\ContentTypeId($contentType->id), |
|
| 3056 | new Criterion\MapLocationDistance( |
|
| 3057 | 'maplocation', |
|
| 3058 | Criterion\Operator::GTE, |
|
| 3059 | 235, |
|
| 3060 | $wellInVodice['latitude'], |
|
| 3061 | $wellInVodice['longitude'] |
|
| 3062 | ), |
|
| 3063 | ) |
|
| 3064 | ), |
|
| 3065 | 'offset' => 0, |
|
| 3066 | 'limit' => 10, |
|
| 3067 | 'sortClauses' => array( |
|
| 3068 | new SortClause\MapLocationDistance( |
|
| 3069 | 'testtype', |
|
| 3070 | 'maplocation', |
|
| 3071 | $wellInVodice['latitude'], |
|
| 3072 | $wellInVodice['longitude'], |
|
| 3073 | Query::SORT_ASC |
|
| 3074 | ), |
|
| 3075 | ), |
|
| 3076 | ) |
|
| 3077 | ); |
|
| 3078 | ||
| 3079 | $searchService = $repository->getSearchService(); |
|
| 3080 | $result = $searchService->findContent($query); |
|
| 3081 | ||
| 3082 | $this->assertEquals(3, $result->totalCount); |
|
| 3083 | $this->assertEquals( |
|
| 3084 | $wildBoars->id, |
|
| 3085 | $result->searchHits[0]->valueObject->id |
|
| 3086 | ); |
|
| 3087 | $this->assertEquals( |
|
| 3088 | $mushrooms->id, |
|
| 3089 | $result->searchHits[1]->valueObject->id |
|
| 3090 | ); |
|
| 3091 | $this->assertEquals( |
|
| 3092 | $tree->id, |
|
| 3093 | $result->searchHits[2]->valueObject->id |
|
| 3094 | ); |
|
| 3095 | } |
|
| 3096 | ||
| 3097 | /** |
|
| 3098 | * Test for the findContent() method. |
|
| @@ 3103-3212 (lines=110) @@ | ||
| 3100 | * @see \eZ\Publish\API\Repository\SearchService::findContent() |
|
| 3101 | * @group maplocation |
|
| 3102 | */ |
|
| 3103 | public function testMapLocationDistanceSortDescending() |
|
| 3104 | { |
|
| 3105 | $contentType = $this->createTestPlaceContentType(); |
|
| 3106 | ||
| 3107 | // Create a draft to account for behaviour with ContentType in different states |
|
| 3108 | $repository = $this->getRepository(); |
|
| 3109 | $contentTypeService = $repository->getContentTypeService(); |
|
| 3110 | $contentService = $repository->getContentService(); |
|
| 3111 | $contentTypeService->createContentTypeDraft($contentType); |
|
| 3112 | ||
| 3113 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 3114 | $createStruct->alwaysAvailable = false; |
|
| 3115 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 3116 | $createStruct->setField( |
|
| 3117 | 'maplocation', |
|
| 3118 | array( |
|
| 3119 | 'latitude' => 45.894877, |
|
| 3120 | 'longitude' => 15.972699, |
|
| 3121 | 'address' => 'Here be wild boars', |
|
| 3122 | ), |
|
| 3123 | 'eng-GB' |
|
| 3124 | ); |
|
| 3125 | ||
| 3126 | $draft = $contentService->createContent($createStruct); |
|
| 3127 | $wildBoars = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 3128 | ||
| 3129 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 3130 | $createStruct->alwaysAvailable = false; |
|
| 3131 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 3132 | $createStruct->setField( |
|
| 3133 | 'maplocation', |
|
| 3134 | array( |
|
| 3135 | 'latitude' => 45.927334, |
|
| 3136 | 'longitude' => 15.934847, |
|
| 3137 | 'address' => 'A lone tree', |
|
| 3138 | ), |
|
| 3139 | 'eng-GB' |
|
| 3140 | ); |
|
| 3141 | ||
| 3142 | $draft = $contentService->createContent($createStruct); |
|
| 3143 | $tree = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 3144 | ||
| 3145 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 3146 | $createStruct->alwaysAvailable = false; |
|
| 3147 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 3148 | $createStruct->setField( |
|
| 3149 | 'maplocation', |
|
| 3150 | array( |
|
| 3151 | 'latitude' => 45.903777, |
|
| 3152 | 'longitude' => 15.958788, |
|
| 3153 | 'address' => 'Meadow with mushrooms', |
|
| 3154 | ), |
|
| 3155 | 'eng-GB' |
|
| 3156 | ); |
|
| 3157 | ||
| 3158 | $draft = $contentService->createContent($createStruct); |
|
| 3159 | $mushrooms = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 3160 | ||
| 3161 | $this->refreshSearch($repository); |
|
| 3162 | ||
| 3163 | $well = array( |
|
| 3164 | 'latitude' => 43.756825, |
|
| 3165 | 'longitude' => 15.775074, |
|
| 3166 | ); |
|
| 3167 | ||
| 3168 | $query = new Query( |
|
| 3169 | array( |
|
| 3170 | 'filter' => new Criterion\LogicalAnd( |
|
| 3171 | array( |
|
| 3172 | new Criterion\ContentTypeId($contentType->id), |
|
| 3173 | new Criterion\MapLocationDistance( |
|
| 3174 | 'maplocation', |
|
| 3175 | Criterion\Operator::GTE, |
|
| 3176 | 235, |
|
| 3177 | $well['latitude'], |
|
| 3178 | $well['longitude'] |
|
| 3179 | ), |
|
| 3180 | ) |
|
| 3181 | ), |
|
| 3182 | 'offset' => 0, |
|
| 3183 | 'limit' => 10, |
|
| 3184 | 'sortClauses' => array( |
|
| 3185 | new SortClause\MapLocationDistance( |
|
| 3186 | 'testtype', |
|
| 3187 | 'maplocation', |
|
| 3188 | $well['latitude'], |
|
| 3189 | $well['longitude'], |
|
| 3190 | Query::SORT_DESC |
|
| 3191 | ), |
|
| 3192 | ), |
|
| 3193 | ) |
|
| 3194 | ); |
|
| 3195 | ||
| 3196 | $searchService = $repository->getSearchService(); |
|
| 3197 | $result = $searchService->findContent($query); |
|
| 3198 | ||
| 3199 | $this->assertEquals(3, $result->totalCount); |
|
| 3200 | $this->assertEquals( |
|
| 3201 | $wildBoars->id, |
|
| 3202 | $result->searchHits[2]->valueObject->id |
|
| 3203 | ); |
|
| 3204 | $this->assertEquals( |
|
| 3205 | $mushrooms->id, |
|
| 3206 | $result->searchHits[1]->valueObject->id |
|
| 3207 | ); |
|
| 3208 | $this->assertEquals( |
|
| 3209 | $tree->id, |
|
| 3210 | $result->searchHits[0]->valueObject->id |
|
| 3211 | ); |
|
| 3212 | } |
|
| 3213 | ||
| 3214 | /** |
|
| 3215 | * Test for the findContent() method. |
|