From 20a4cab57e461aadac9213c24c8f767e2c3b0589 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Thu, 16 Mar 2017 22:12:20 +0100 Subject: [PATCH] add tests for nearpoint sql functions --- lib/NearPoint.php | 8 +------- test/php/Nominatim/NearPointTest.php | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/NearPoint.php b/lib/NearPoint.php index 6a0e7598..16b6dff5 100644 --- a/lib/NearPoint.php +++ b/lib/NearPoint.php @@ -34,13 +34,7 @@ class NearPoint public function withinSQL($sObj) { - return sprintf( - 'ST_DWithin(%S, ST_SetSRID(ST_Point(%F,%F),4326), %F)', - $sObj, - $this->fLon, - $this->fLat, - $this->fRadius - ); + return sprintf('ST_DWithin(%s, %s, %F)', $sObj, $this->sSQL, $this->fRadius); } /** diff --git a/test/php/Nominatim/NearPointTest.php b/test/php/Nominatim/NearPointTest.php index 4d1a5b43..eb11ee5b 100644 --- a/test/php/Nominatim/NearPointTest.php +++ b/test/php/Nominatim/NearPointTest.php @@ -65,4 +65,24 @@ class NearPointTest extends \PHPUnit_Framework_TestCase $this->assertEquals(-79.982, $aRes['pt']->lon(), 'degrees decimal ' . $sQuery, 0.01); } } + + public function testWithinSQL() + { + $np = new NearPoint(0.1, 23, 1); + + $this->assertEquals( + 'ST_DWithin(foo, ST_SetSRID(ST_Point(23,0.1),4326), 1.000000)', + $np->withinSQL('foo') + ); + } + + public function testDistanceSQL() + { + $np = new NearPoint(0.1, 23, 1); + + $this->assertEquals( + 'ST_Distance(ST_SetSRID(ST_Point(23,0.1),4326), foo)', + $np->distanceSQL('foo') + ); + } } -- 2.39.5