]> git.openstreetmap.org Git - nominatim.git/commitdiff
add tests for nearpoint sql functions
authorSarah Hoffmann <lonvia@denofr.de>
Thu, 16 Mar 2017 21:12:20 +0000 (22:12 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Thu, 16 Mar 2017 21:12:20 +0000 (22:12 +0100)
lib/NearPoint.php
test/php/Nominatim/NearPointTest.php

index 6a0e7598627f25d9a3b5673e5be0b01a50975a54..16b6dff5276be2ff79f07486fc69cfd9152dd8e2 100644 (file)
@@ -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);
     }
 
     /**
index 4d1a5b43d23a9653893efa77371ed6617aab991b..eb11ee5b1f3c532d18bfc1b876aca807db032ec4 100644 (file)
@@ -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')
+        );
+    }
 }