| @@ 3203-3312 (lines=110) @@ | ||
| 3200 | * @see \eZ\Publish\API\Repository\SearchService::findContent() |
|
| 3201 | * @group maplocation |
|
| 3202 | */ |
|
| 3203 | public function testMapLocationDistanceSortAscending() |
|
| 3204 | { |
|
| 3205 | $contentType = $this->createTestPlaceContentType(); |
|
| 3206 | ||
| 3207 | // Create a draft to account for behaviour with ContentType in different states |
|
| 3208 | $repository = $this->getRepository(); |
|
| 3209 | $contentTypeService = $repository->getContentTypeService(); |
|
| 3210 | $contentService = $repository->getContentService(); |
|
| 3211 | $contentTypeService->createContentTypeDraft($contentType); |
|
| 3212 | ||
| 3213 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 3214 | $createStruct->alwaysAvailable = false; |
|
| 3215 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 3216 | $createStruct->setField( |
|
| 3217 | 'maplocation', |
|
| 3218 | array( |
|
| 3219 | 'latitude' => 45.894877, |
|
| 3220 | 'longitude' => 15.972699, |
|
| 3221 | 'address' => 'Here be wild boars', |
|
| 3222 | ), |
|
| 3223 | 'eng-GB' |
|
| 3224 | ); |
|
| 3225 | ||
| 3226 | $draft = $contentService->createContent($createStruct); |
|
| 3227 | $wildBoars = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 3228 | ||
| 3229 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 3230 | $createStruct->alwaysAvailable = false; |
|
| 3231 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 3232 | $createStruct->setField( |
|
| 3233 | 'maplocation', |
|
| 3234 | array( |
|
| 3235 | 'latitude' => 45.927334, |
|
| 3236 | 'longitude' => 15.934847, |
|
| 3237 | 'address' => 'A lone tree', |
|
| 3238 | ), |
|
| 3239 | 'eng-GB' |
|
| 3240 | ); |
|
| 3241 | ||
| 3242 | $draft = $contentService->createContent($createStruct); |
|
| 3243 | $tree = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 3244 | ||
| 3245 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 3246 | $createStruct->alwaysAvailable = false; |
|
| 3247 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 3248 | $createStruct->setField( |
|
| 3249 | 'maplocation', |
|
| 3250 | array( |
|
| 3251 | 'latitude' => 45.903777, |
|
| 3252 | 'longitude' => 15.958788, |
|
| 3253 | 'address' => 'Meadow with mushrooms', |
|
| 3254 | ), |
|
| 3255 | 'eng-GB' |
|
| 3256 | ); |
|
| 3257 | ||
| 3258 | $draft = $contentService->createContent($createStruct); |
|
| 3259 | $mushrooms = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 3260 | ||
| 3261 | $this->refreshSearch($repository); |
|
| 3262 | ||
| 3263 | $wellInVodice = array( |
|
| 3264 | 'latitude' => 43.756825, |
|
| 3265 | 'longitude' => 15.775074, |
|
| 3266 | ); |
|
| 3267 | ||
| 3268 | $query = new Query( |
|
| 3269 | array( |
|
| 3270 | 'filter' => new Criterion\LogicalAnd( |
|
| 3271 | array( |
|
| 3272 | new Criterion\ContentTypeId($contentType->id), |
|
| 3273 | new Criterion\MapLocationDistance( |
|
| 3274 | 'maplocation', |
|
| 3275 | Criterion\Operator::GTE, |
|
| 3276 | 235, |
|
| 3277 | $wellInVodice['latitude'], |
|
| 3278 | $wellInVodice['longitude'] |
|
| 3279 | ), |
|
| 3280 | ) |
|
| 3281 | ), |
|
| 3282 | 'offset' => 0, |
|
| 3283 | 'limit' => 10, |
|
| 3284 | 'sortClauses' => array( |
|
| 3285 | new SortClause\MapLocationDistance( |
|
| 3286 | 'testtype', |
|
| 3287 | 'maplocation', |
|
| 3288 | $wellInVodice['latitude'], |
|
| 3289 | $wellInVodice['longitude'], |
|
| 3290 | Query::SORT_ASC |
|
| 3291 | ), |
|
| 3292 | ), |
|
| 3293 | ) |
|
| 3294 | ); |
|
| 3295 | ||
| 3296 | $searchService = $repository->getSearchService(); |
|
| 3297 | $result = $searchService->findContent($query); |
|
| 3298 | ||
| 3299 | $this->assertEquals(3, $result->totalCount); |
|
| 3300 | $this->assertEquals( |
|
| 3301 | $wildBoars->id, |
|
| 3302 | $result->searchHits[0]->valueObject->id |
|
| 3303 | ); |
|
| 3304 | $this->assertEquals( |
|
| 3305 | $mushrooms->id, |
|
| 3306 | $result->searchHits[1]->valueObject->id |
|
| 3307 | ); |
|
| 3308 | $this->assertEquals( |
|
| 3309 | $tree->id, |
|
| 3310 | $result->searchHits[2]->valueObject->id |
|
| 3311 | ); |
|
| 3312 | } |
|
| 3313 | ||
| 3314 | /** |
|
| 3315 | * Test for the findContent() method. |
|
| @@ 3320-3429 (lines=110) @@ | ||
| 3317 | * @see \eZ\Publish\API\Repository\SearchService::findContent() |
|
| 3318 | * @group maplocation |
|
| 3319 | */ |
|
| 3320 | public function testMapLocationDistanceSortDescending() |
|
| 3321 | { |
|
| 3322 | $contentType = $this->createTestPlaceContentType(); |
|
| 3323 | ||
| 3324 | // Create a draft to account for behaviour with ContentType in different states |
|
| 3325 | $repository = $this->getRepository(); |
|
| 3326 | $contentTypeService = $repository->getContentTypeService(); |
|
| 3327 | $contentService = $repository->getContentService(); |
|
| 3328 | $contentTypeService->createContentTypeDraft($contentType); |
|
| 3329 | ||
| 3330 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 3331 | $createStruct->alwaysAvailable = false; |
|
| 3332 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 3333 | $createStruct->setField( |
|
| 3334 | 'maplocation', |
|
| 3335 | array( |
|
| 3336 | 'latitude' => 45.894877, |
|
| 3337 | 'longitude' => 15.972699, |
|
| 3338 | 'address' => 'Here be wild boars', |
|
| 3339 | ), |
|
| 3340 | 'eng-GB' |
|
| 3341 | ); |
|
| 3342 | ||
| 3343 | $draft = $contentService->createContent($createStruct); |
|
| 3344 | $wildBoars = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 3345 | ||
| 3346 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 3347 | $createStruct->alwaysAvailable = false; |
|
| 3348 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 3349 | $createStruct->setField( |
|
| 3350 | 'maplocation', |
|
| 3351 | array( |
|
| 3352 | 'latitude' => 45.927334, |
|
| 3353 | 'longitude' => 15.934847, |
|
| 3354 | 'address' => 'A lone tree', |
|
| 3355 | ), |
|
| 3356 | 'eng-GB' |
|
| 3357 | ); |
|
| 3358 | ||
| 3359 | $draft = $contentService->createContent($createStruct); |
|
| 3360 | $tree = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 3361 | ||
| 3362 | $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); |
|
| 3363 | $createStruct->alwaysAvailable = false; |
|
| 3364 | $createStruct->mainLanguageCode = 'eng-GB'; |
|
| 3365 | $createStruct->setField( |
|
| 3366 | 'maplocation', |
|
| 3367 | array( |
|
| 3368 | 'latitude' => 45.903777, |
|
| 3369 | 'longitude' => 15.958788, |
|
| 3370 | 'address' => 'Meadow with mushrooms', |
|
| 3371 | ), |
|
| 3372 | 'eng-GB' |
|
| 3373 | ); |
|
| 3374 | ||
| 3375 | $draft = $contentService->createContent($createStruct); |
|
| 3376 | $mushrooms = $contentService->publishVersion($draft->getVersionInfo()); |
|
| 3377 | ||
| 3378 | $this->refreshSearch($repository); |
|
| 3379 | ||
| 3380 | $well = array( |
|
| 3381 | 'latitude' => 43.756825, |
|
| 3382 | 'longitude' => 15.775074, |
|
| 3383 | ); |
|
| 3384 | ||
| 3385 | $query = new Query( |
|
| 3386 | array( |
|
| 3387 | 'filter' => new Criterion\LogicalAnd( |
|
| 3388 | array( |
|
| 3389 | new Criterion\ContentTypeId($contentType->id), |
|
| 3390 | new Criterion\MapLocationDistance( |
|
| 3391 | 'maplocation', |
|
| 3392 | Criterion\Operator::GTE, |
|
| 3393 | 235, |
|
| 3394 | $well['latitude'], |
|
| 3395 | $well['longitude'] |
|
| 3396 | ), |
|
| 3397 | ) |
|
| 3398 | ), |
|
| 3399 | 'offset' => 0, |
|
| 3400 | 'limit' => 10, |
|
| 3401 | 'sortClauses' => array( |
|
| 3402 | new SortClause\MapLocationDistance( |
|
| 3403 | 'testtype', |
|
| 3404 | 'maplocation', |
|
| 3405 | $well['latitude'], |
|
| 3406 | $well['longitude'], |
|
| 3407 | Query::SORT_DESC |
|
| 3408 | ), |
|
| 3409 | ), |
|
| 3410 | ) |
|
| 3411 | ); |
|
| 3412 | ||
| 3413 | $searchService = $repository->getSearchService(); |
|
| 3414 | $result = $searchService->findContent($query); |
|
| 3415 | ||
| 3416 | $this->assertEquals(3, $result->totalCount); |
|
| 3417 | $this->assertEquals( |
|
| 3418 | $wildBoars->id, |
|
| 3419 | $result->searchHits[2]->valueObject->id |
|
| 3420 | ); |
|
| 3421 | $this->assertEquals( |
|
| 3422 | $mushrooms->id, |
|
| 3423 | $result->searchHits[1]->valueObject->id |
|
| 3424 | ); |
|
| 3425 | $this->assertEquals( |
|
| 3426 | $tree->id, |
|
| 3427 | $result->searchHits[0]->valueObject->id |
|
| 3428 | ); |
|
| 3429 | } |
|
| 3430 | ||
| 3431 | /** |
|
| 3432 | * Test for the findContent() method. |
|