7 class NominatimTest extends \PHPUnit_Framework_TestCase
 
  10         protected function setUp()
 
  15         public function test_addQuotes()
 
  17                 // FIXME: not quoting existing quote signs is probably a bug
 
  18                 $this->assertSame("'St. John's'", addQuotes("St. John's"));
 
  19                 $this->assertSame("''", addQuotes(''));
 
  22         public function test_looksLikeLatLonPair()
 
  24                 // no coordinates expected
 
  25                 $this->assertNull(looksLikeLatLonPair(''));
 
  26                 $this->assertNull(looksLikeLatLonPair('abc'));
 
  27                 $this->assertNull(looksLikeLatLonPair('12 34'));
 
  28                 $this->assertNull(looksLikeLatLonPair('200.1 89.9')); // because latitude > 180
 
  30                 // coordinates expected
 
  31                 $this->assertNotNull(looksLikeLatLonPair('0.0 -0.0'));
 
  34                                 array( 'lat' => 12.456, 'lon' => -78.90, 'query' => 'abc   def'),
 
  35                                 looksLikeLatLonPair(' abc 12.456 -78.90 def ')
 
  39                                 array( 'lat' => 12.456, 'lon' => -78.90, 'query' => ''),
 
  40                                 looksLikeLatLonPair(' [12.456,-78.90] ')
 
  43                 // http://en.wikipedia.org/wiki/Geographic_coordinate_conversion
 
  44                 // these all represent the same location
 
  46                                         '40 26.767 N 79 58.933 W',
 
  47                                         '40° 26.767′ N 79° 58.933′ W',
 
  48                                         "40° 26.767' N 79° 58.933' W",
 
  49                                         'N 40 26.767, W 79 58.933',
 
  50                                         'N 40°26.767′, W 79°58.933′',
 
  51                                         "N 40°26.767', W 79°58.933'",
 
  53                                         '40 26 46 N 79 58 56 W',
 
  54                                         '40° 26′ 46″ N 79° 58′ 56″ W',
 
  55                                         'N 40 26 46 W 79 58 56',
 
  56                                         'N 40° 26′ 46″, W 79° 58′ 56″',
 
  57                                         'N 40° 26\' 46", W 79° 58\' 56"',
 
  61                                         '40.446° N 79.982° W',
 
  62                                         'N 40.446° W 79.982°',
 
  69                 foreach($aQueries as $sQuery){
 
  70                         $aRes = looksLikeLatLonPair($sQuery);
 
  71                         $this->assertEquals( 40.446, $aRes['lat'], 'degrees decimal ' . $sQuery, 0.01);
 
  72                         $this->assertEquals(-79.982, $aRes['lon'], 'degrees decimal ' . $sQuery, 0.01);