| @@ 3121-3230 (lines=110) @@ | ||
| 3118 | * @see \eZ\Publish\API\Repository\SearchService::findContent() |
|
| 3119 | * @group maplocation |
|
| 3120 | */ |
|
| 3121 | public function testMapLocationDistanceSortAscending() |
|
| 3122 | { |
|
| 3123 | $contentType = $this->createTestPlaceContentType(); |
|
| 3124 | ||
| 3125 | // Create a draft to account for behaviour with ContentType in different states |
|
| 3126 | $repository = $this->getRepository(); |
|
| 3127 | $contentTypeService = $repository->getContentTypeService(); |
|
| 3128 | $contentService = $repository->getContentService(); |
|
| 3129 | $contentTypeService->createContentTypeDraft($contentType); |
|
| 3130 | ||
| 3131 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 3132 | $createStruct->alwaysAvailable = false; |
|
| 3133 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 3134 | $createStruct->setField( |
|
| 3135 | 'maplocation', |
|
| 3136 | [ |
|
| 3137 | 'latitude' => 45.894877, |
|
| 3138 | 'longitude' => 15.972699, |
|
| 3139 | 'address' => 'Here be wild boars', |
|
| 3140 | ], |
|
| 3141 | 'eng-GB' |
|
| 3142 | ); |
|
| 3143 | ||
| 3144 | $draft = $contentService->createContent($createStruct); |
|
| 3145 | $wildBoars = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 3146 | ||
| 3147 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 3148 | $createStruct->alwaysAvailable = false; |
|
| 3149 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 3150 | $createStruct->setField( |
|
| 3151 | 'maplocation', |
|
| 3152 | [ |
|
| 3153 | 'latitude' => 45.927334, |
|
| 3154 | 'longitude' => 15.934847, |
|
| 3155 | 'address' => 'A lone tree', |
|
| 3156 | ], |
|
| 3157 | 'eng-GB' |
|
| 3158 | ); |
|
| 3159 | ||
| 3160 | $draft = $contentService->createContent($createStruct); |
|
| 3161 | $tree = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 3162 | ||
| 3163 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 3164 | $createStruct->alwaysAvailable = false; |
|
| 3165 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 3166 | $createStruct->setField( |
|
| 3167 | 'maplocation', |
|
| 3168 | [ |
|
| 3169 | 'latitude' => 45.903777, |
|
| 3170 | 'longitude' => 15.958788, |
|
| 3171 | 'address' => 'Meadow with mushrooms', |
|
| 3172 | ], |
|
| 3173 | 'eng-GB' |
|
| 3174 | ); |
|
| 3175 | ||
| 3176 | $draft = $contentService->createContent($createStruct); |
|
| 3177 | $mushrooms = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 3178 | ||
| 3179 | $this->refreshSearch($repository); |
|
| 3180 | ||
| 3181 | $wellInVodice = [ |
|
| 3182 | 'latitude' => 43.756825, |
|
| 3183 | 'longitude' => 15.775074, |
|
| 3184 | ]; |
|
| 3185 | ||
| 3186 | $query = new Query( |
|
| 3187 | [ |
|
| 3188 | 'filter' => new Criterion\LogicalAnd( |
|
| 3189 | [ |
|
| 3190 | new Criterion\ContentTypeId($contentType->id), |
|
| 3191 | new Criterion\MapLocationDistance( |
|
| 3192 | 'maplocation', |
|
| 3193 | Criterion\Operator::GTE, |
|
| 3194 | 235, |
|
| 3195 | $wellInVodice['latitude'], |
|
| 3196 | $wellInVodice['longitude'] |
|
| 3197 | ), |
|
| 3198 | ] |
|
| 3199 | ), |
|
| 3200 | 'offset' => 0, |
|
| 3201 | 'limit' => 10, |
|
| 3202 | 'sortClauses' => [ |
|
| 3203 | new SortClause\MapLocationDistance( |
|
| 3204 | 'testtype', |
|
| 3205 | 'maplocation', |
|
| 3206 | $wellInVodice['latitude'], |
|
| 3207 | $wellInVodice['longitude'], |
|
| 3208 | Query::SORT_ASC |
|
| 3209 | ), |
|
| 3210 | ], |
|
| 3211 | ] |
|
| 3212 | ); |
|
| 3213 | ||
| 3214 | $searchService = $repository->getSearchService(); |
|
| 3215 | $result = $searchService->findContent($query); |
|
| 3216 | ||
| 3217 | $this->assertEquals(3, $result->totalCount); |
|
| 3218 | $this->assertEquals( |
|
| 3219 | $wildBoars->id, |
|
| 3220 | $result->searchHits[0]->valueObject->id |
|
| 3221 | ); |
|
| 3222 | $this->assertEquals( |
|
| 3223 | $mushrooms->id, |
|
| 3224 | $result->searchHits[1]->valueObject->id |
|
| 3225 | ); |
|
| 3226 | $this->assertEquals( |
|
| 3227 | $tree->id, |
|
| 3228 | $result->searchHits[2]->valueObject->id |
|
| 3229 | ); |
|
| 3230 | } |
|
| 3231 | ||
| 3232 | /** |
|
| 3233 | * Test for the findContent() method. |
|
| @@ 3238-3347 (lines=110) @@ | ||
| 3235 | * @see \eZ\Publish\API\Repository\SearchService::findContent() |
|
| 3236 | * @group maplocation |
|
| 3237 | */ |
|
| 3238 | public function testMapLocationDistanceSortDescending() |
|
| 3239 | { |
|
| 3240 | $contentType = $this->createTestPlaceContentType(); |
|
| 3241 | ||
| 3242 | // Create a draft to account for behaviour with ContentType in different states |
|
| 3243 | $repository = $this->getRepository(); |
|
| 3244 | $contentTypeService = $repository->getContentTypeService(); |
|
| 3245 | $contentService = $repository->getContentService(); |
|
| 3246 | $contentTypeService->createContentTypeDraft($contentType); |
|
| 3247 | ||
| 3248 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 3249 | $createStruct->alwaysAvailable = false; |
|
| 3250 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 3251 | $createStruct->setField( |
|
| 3252 | 'maplocation', |
|
| 3253 | [ |
|
| 3254 | 'latitude' => 45.894877, |
|
| 3255 | 'longitude' => 15.972699, |
|
| 3256 | 'address' => 'Here be wild boars', |
|
| 3257 | ], |
|
| 3258 | 'eng-GB' |
|
| 3259 | ); |
|
| 3260 | ||
| 3261 | $draft = $contentService->createContent($createStruct); |
|
| 3262 | $wildBoars = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 3263 | ||
| 3264 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 3265 | $createStruct->alwaysAvailable = false; |
|
| 3266 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 3267 | $createStruct->setField( |
|
| 3268 | 'maplocation', |
|
| 3269 | [ |
|
| 3270 | 'latitude' => 45.927334, |
|
| 3271 | 'longitude' => 15.934847, |
|
| 3272 | 'address' => 'A lone tree', |
|
| 3273 | ], |
|
| 3274 | 'eng-GB' |
|
| 3275 | ); |
|
| 3276 | ||
| 3277 | $draft = $contentService->createContent($createStruct); |
|
| 3278 | $tree = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 3279 | ||
| 3280 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 3281 | $createStruct->alwaysAvailable = false; |
|
| 3282 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 3283 | $createStruct->setField( |
|
| 3284 | 'maplocation', |
|
| 3285 | [ |
|
| 3286 | 'latitude' => 45.903777, |
|
| 3287 | 'longitude' => 15.958788, |
|
| 3288 | 'address' => 'Meadow with mushrooms', |
|
| 3289 | ], |
|
| 3290 | 'eng-GB' |
|
| 3291 | ); |
|
| 3292 | ||
| 3293 | $draft = $contentService->createContent($createStruct); |
|
| 3294 | $mushrooms = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 3295 | ||
| 3296 | $this->refreshSearch($repository); |
|
| 3297 | ||
| 3298 | $well = [ |
|
| 3299 | 'latitude' => 43.756825, |
|
| 3300 | 'longitude' => 15.775074, |
|
| 3301 | ]; |
|
| 3302 | ||
| 3303 | $query = new Query( |
|
| 3304 | [ |
|
| 3305 | 'filter' => new Criterion\LogicalAnd( |
|
| 3306 | [ |
|
| 3307 | new Criterion\ContentTypeId($contentType->id), |
|
| 3308 | new Criterion\MapLocationDistance( |
|
| 3309 | 'maplocation', |
|
| 3310 | Criterion\Operator::GTE, |
|
| 3311 | 235, |
|
| 3312 | $well['latitude'], |
|
| 3313 | $well['longitude'] |
|
| 3314 | ), |
|
| 3315 | ] |
|
| 3316 | ), |
|
| 3317 | 'offset' => 0, |
|
| 3318 | 'limit' => 10, |
|
| 3319 | 'sortClauses' => [ |
|
| 3320 | new SortClause\MapLocationDistance( |
|
| 3321 | 'testtype', |
|
| 3322 | 'maplocation', |
|
| 3323 | $well['latitude'], |
|
| 3324 | $well['longitude'], |
|
| 3325 | Query::SORT_DESC |
|
| 3326 | ), |
|
| 3327 | ], |
|
| 3328 | ] |
|
| 3329 | ); |
|
| 3330 | ||
| 3331 | $searchService = $repository->getSearchService(); |
|
| 3332 | $result = $searchService->findContent($query); |
|
| 3333 | ||
| 3334 | $this->assertEquals(3, $result->totalCount); |
|
| 3335 | $this->assertEquals( |
|
| 3336 | $wildBoars->id, |
|
| 3337 | $result->searchHits[2]->valueObject->id |
|
| 3338 | ); |
|
| 3339 | $this->assertEquals( |
|
| 3340 | $mushrooms->id, |
|
| 3341 | $result->searchHits[1]->valueObject->id |
|
| 3342 | ); |
|
| 3343 | $this->assertEquals( |
|
| 3344 | $tree->id, |
|
| 3345 | $result->searchHits[0]->valueObject->id |
|
| 3346 | ); |
|
| 3347 | } |
|
| 3348 | ||
| 3349 | /** |
|
| 3350 | * Test for the findContent() method. |
|