5 require '../../lib/NearPoint.php';
7 class NearPointTest extends \PHPUnit_Framework_TestCase
9 protected function setUp()
13 public function testExtractFromQuery()
15 // no coordinates expected
16 $this->assertFalse(NearPoint::extractFromQuery(''));
17 $this->assertFalse(NearPoint::extractFromQuery('abc'));
18 $this->assertFalse(NearPoint::extractFromQuery('12 34'));
19 $this->assertFalse(NearPoint::extractFromQuery('200.1 89.9')); // because latitude > 180
21 // coordinates expected
22 $this->assertNotNull(NearPoint::extractFromQuery('0.0 -0.0'));
24 $aRes = NearPoint::extractFromQuery(' abc 12.456 -78.90 def ');
25 $this->assertEquals($aRes['pt']->lat(), 12.456);
26 $this->assertEquals($aRes['pt']->lon(), -78.90);
27 $this->assertEquals($aRes['pt']->radius(), 0.1);
28 $this->assertEquals($aRes['query'], 'abc def');
30 $aRes = NearPoint::extractFromQuery(' [12.456,-78.90] ');
31 $this->assertEquals($aRes['pt']->lat(), 12.456);
32 $this->assertEquals($aRes['pt']->lon(), -78.90);
33 $this->assertEquals($aRes['pt']->radius(), 0.1);
34 $this->assertEquals($aRes['query'], '');
36 // http://en.wikipedia.org/wiki/Geographic_coordinate_conversion
37 // these all represent the same location
39 '40 26.767 N 79 58.933 W',
40 '40° 26.767′ N 79° 58.933′ W',
41 "40° 26.767' N 79° 58.933' W",
42 'N 40 26.767, W 79 58.933',
43 'N 40°26.767′, W 79°58.933′',
44 "N 40°26.767', W 79°58.933'",
46 '40 26 46 N 79 58 56 W',
47 '40° 26′ 46″ N 79° 58′ 56″ W',
48 'N 40 26 46 W 79 58 56',
49 'N 40° 26′ 46″, W 79° 58′ 56″',
50 'N 40° 26\' 46", W 79° 58\' 56"',
54 '40.446° N 79.982° W',
55 'N 40.446° W 79.982°',
62 foreach ($aQueries as $sQuery) {
63 $aRes = NearPoint::extractFromQuery($sQuery);
64 $this->assertEquals(40.446, $aRes['pt']->lat(), 'degrees decimal ' . $sQuery, 0.01);
65 $this->assertEquals(-79.982, $aRes['pt']->lon(), 'degrees decimal ' . $sQuery, 0.01);