Index: trunk/extensions/Maps/test/MapsCoordinateParserTest.php |
— | — | @@ -17,6 +17,11 @@ |
18 | 18 | */ |
19 | 19 | class MapsCoordinateParserTest extends PHPUnit_Framework_TestCase { |
20 | 20 | |
| 21 | + /** |
| 22 | + * Valid coordinates. |
| 23 | + * |
| 24 | + * @var array |
| 25 | + */ |
21 | 26 | public static $coordinates = array( |
22 | 27 | 'float' => array( |
23 | 28 | '55.7557860 N, 37.6176330 W', |
— | — | @@ -52,7 +57,13 @@ |
53 | 58 | ), |
54 | 59 | ); |
55 | 60 | |
56 | | - // Expected result => array( everything that should lead to it ) |
| 61 | + /** |
| 62 | + * Mappings between coordinate notations. |
| 63 | + * |
| 64 | + * Expected result => array( everything that should lead to it ) |
| 65 | + * |
| 66 | + * @var array |
| 67 | + */ |
57 | 68 | public static $coordinateMappings = array( |
58 | 69 | // Float to non-directional DMS |
59 | 70 | 'float-dms' => array( |
— | — | @@ -65,9 +76,33 @@ |
66 | 77 | '42.5 N, 42.5 W' => array( '42° 30\' 0", -42° 30\' 0"', '42° 30\' 0" N, 42° 30\' 0" W' ), |
67 | 78 | '42.5 S, 42.5 E' => array( '-42° 30\' 0", 42° 30\' 0"', '42° 30\' 0" S, 42° 30\' 0" E' ), |
68 | 79 | '42.4242 N, 42.4242 E' => array( '42° 25\' 27", 42° 25\' 27"', '42° 25\' 27" N, 42° 25\' 27" E' ) |
69 | | - ) |
| 80 | + ), |
70 | 81 | ); |
71 | 82 | |
| 83 | + /** |
| 84 | + * Parsing tests. |
| 85 | + * |
| 86 | + * @var array |
| 87 | + */ |
| 88 | + public static $parsingTests = array( |
| 89 | + '42.5, -42.5' => array( 'lat' => '42.5', 'lon' => '-42.5' ), |
| 90 | + '42° 30\' 0" N, 42° 30\' 0" W' => array( 'lat' => '42.5', 'lon' => '-42.5' ), |
| 91 | + ); |
| 92 | + |
| 93 | + /** |
| 94 | + * Formatting tests. |
| 95 | + * |
| 96 | + * @var array |
| 97 | + */ |
| 98 | + public static $formattingTests = array( |
| 99 | + |
| 100 | + ); |
| 101 | + |
| 102 | + /** |
| 103 | + * Invalid coordinates. |
| 104 | + * |
| 105 | + * @var array |
| 106 | + */ |
72 | 107 | public static $fakeCoordinates = array( |
73 | 108 | 'IN YOUR CODE, BEING TOTALLY REDICULOUSE', |
74 | 109 | '55.7557860 E, 37.6176330 W', |
— | — | @@ -117,6 +152,10 @@ |
118 | 153 | foreach ( self::$fakeCoordinates as $coord ) { |
119 | 154 | $this->assertFalse( MapsCoordinateParser::parseCoordinates( $coord ), "parseCoordinates did not return false for $coord." ); |
120 | 155 | } |
| 156 | + |
| 157 | + foreach ( self::$parsingTests as $coord => $destination ) { |
| 158 | + $this->assertEquals( $destination, MapsCoordinateParser::parseCoordinates( $coord ), "Parsing test failed at " . __METHOD__ ); |
| 159 | + } |
121 | 160 | } |
122 | 161 | |
123 | 162 | /** |
— | — | @@ -259,7 +298,17 @@ |
260 | 299 | ); |
261 | 300 | } |
262 | 301 | } |
| 302 | + |
| 303 | + foreach ( self::$coordinateMappings['dms-float-directional'] as $destination => $sources ) { |
| 304 | + foreach ( $sources as $source ) { |
| 305 | + $result = MapsCoordinateParser::parseAndFormat( $source, Maps_COORDS_FLOAT, true ); |
| 306 | + $this->assertEquals( |
| 307 | + $destination, |
| 308 | + $result, |
| 309 | + "$source parsed to \n$result, not \n$destination." |
| 310 | + ); |
| 311 | + } |
| 312 | + } |
263 | 313 | } |
264 | 314 | |
265 | | -} |
266 | | - |
| 315 | +} |
\ No newline at end of file |
Index: trunk/extensions/Maps/Includes/Maps_CoordinateParser.php |
— | — | @@ -468,7 +468,9 @@ |
469 | 469 | protected static function setDirectionalAngle( $coordinate, $isLat ) { |
470 | 470 | self::initializeDirectionLabels(); |
471 | 471 | |
| 472 | + $coordinate = (string)$coordinate; |
472 | 473 | $isNegative = $coordinate{0} == '-'; |
| 474 | + |
473 | 475 | if ( $isNegative ) $coordinate = substr( $coordinate, 1 ); |
474 | 476 | |
475 | 477 | if ( $isLat ) { |