From 71b3aa9cca3f9a3fd6a5f8e0e51c0b99463d7e66 Mon Sep 17 00:00:00 2001 From: Marc Tobias Metten Date: Wed, 9 Mar 2016 19:43:03 +0100 Subject: [PATCH] Reverse geocode include geometry - added bounding box tests --- lib/Geocode.php | 5 +---- lib/template/search-json.php | 2 +- tests/features/api/reverse.feature | 9 +++++++++ tests/features/api/search_params.feature | 2 ++ tests/steps/api_result.py | 9 +++++++++ website/reverse.php | 6 +----- 6 files changed, 23 insertions(+), 10 deletions(-) diff --git a/lib/Geocode.php b/lib/Geocode.php index cf7dfbe6..1dbde919 100644 --- a/lib/Geocode.php +++ b/lib/Geocode.php @@ -1647,10 +1647,7 @@ $oPlaceLookup->setPolygonSimplificationThreshold($this->fPolygonSimplificationThreshold); $aOutlineResult = $oPlaceLookup->getOutlines($aResult['place_id'], $aResult['lon'], $aResult['lat'], $fDiameter/2); - foreach($aOutlineResult as $k => $v) - { - $aResult[$k] = $v; - } + $aResult = array_merge($aResult, $aOutlineResult); if ($aResult['extra_place'] == 'city') { diff --git a/lib/template/search-json.php b/lib/template/search-json.php index 06859919..fc50ee0e 100644 --- a/lib/template/search-json.php +++ b/lib/template/search-json.php @@ -18,7 +18,7 @@ if (isset($aPointDetails['aBoundingBox'])) { - $aPlace['boundingbox'] = $aPointDetails['aBoundingBox'][0]; + $aPlace['boundingbox'] = $aPointDetails['aBoundingBox']; if (isset($aPointDetails['aPolyPoints']) && $bShowPolygons) { diff --git a/tests/features/api/reverse.feature b/tests/features/api/reverse.feature index 4d0c5549..39519177 100644 --- a/tests/features/api/reverse.feature +++ b/tests/features/api/reverse.feature @@ -11,6 +11,15 @@ Feature: Reverse geocoding | ID | country | 0 | Deutschland + + Scenario: Boundingbox is returned + Given the request parameters + | format | zoom + | xml | 4 + When looking up coordinates 53.9788769,13.0830313 + And results contain valid boundingboxes + + @Tiger Scenario: TIGER house number Given the request parameters diff --git a/tests/features/api/search_params.feature b/tests/features/api/search_params.feature index fa0e63b7..150d6bdc 100644 --- a/tests/features/api/search_params.feature +++ b/tests/features/api/search_params.feature @@ -8,6 +8,7 @@ Feature: Search queries And result 0 has attributes lat,lon,display_name And result 0 has attributes class,type,importance,icon And result 0 has not attributes address + And results contain valid boundingboxes Scenario: Simple JSON search When sending json search query "Vaduz" @@ -15,6 +16,7 @@ Feature: Search queries And result 0 has attributes osm_type,osm_id,boundingbox And result 0 has attributes lat,lon,display_name,importance And result 0 has not attributes address + And results contain valid boundingboxes Scenario: JSON search with addressdetails When sending json search query "Montevideo" with address diff --git a/tests/steps/api_result.py b/tests/steps/api_result.py index 5e1bcc90..2644d4a2 100644 --- a/tests/steps/api_result.py +++ b/tests/steps/api_result.py @@ -211,6 +211,15 @@ def api_result_contains(step): m = re.match("%s$" % (v,), curres[k]) assert_is_not_none(m, msg="field %s does not match: %s$ != %s." % (k, v, curres[k])) +@step(u'results contain valid boundingboxes$') +def api_result_address_contains(step): + step.given('the result is valid') + for curres in world.results: + bb = curres['boundingbox'] + if world.response_format == 'json': + bb = ','.join(bb) + m = re.match('^(-?\d+\.\d+),(-?\d+\.\d+),(-?\d+\.\d+),(-?\d+\.\d+)$', bb) + assert_is_not_none(m, msg="invalid boundingbox: %s." % (curres['boundingbox'])) @step(u'result addresses contain$') def api_result_address_contains(step): diff --git a/website/reverse.php b/website/reverse.php index ca823d3c..d1c554a4 100755 --- a/website/reverse.php +++ b/website/reverse.php @@ -104,11 +104,7 @@ $fRadius = $fDiameter = getResultDiameter($aPlace); $aOutlineResult = $oPlaceLookup->getOutlines($aPlace['place_id'],$aPlace['lon'],$aPlace['lat'],$fRadius); - foreach($aOutlineResult as $k => $v) - { - $aPlace[$k] = $v; - } - + $aPlace = array_merge($aPlace, $aOutlineResult); } else { -- 2.39.5