Index: trunk/extensions/Maps/test/MapsDistanceParserTest.php |
— | — | @@ -18,10 +18,10 @@ |
19 | 19 | class MapsDistanceParserTest extends PHPUnit_Framework_TestCase { |
20 | 20 | |
21 | 21 | public static $distances = array( |
22 | | - //'1' => 1, |
23 | | - //'1m' => 1, |
24 | | - //'1 m' => 1, |
25 | | - //' 1 m ' => 1, |
| 22 | + '1' => 1, |
| 23 | + '1m' => 1, |
| 24 | + '1 m' => 1, |
| 25 | + ' 1 m ' => 1, |
26 | 26 | '1.1' => 1.1, |
27 | 27 | '1,1' => 1.1, |
28 | 28 | '1 km' => 1000, |
— | — | @@ -33,6 +33,15 @@ |
34 | 34 | '1.0nautical mile' => 1852, |
35 | 35 | ); |
36 | 36 | |
| 37 | + public static $formatTests = array( |
| 38 | + 'km' => array( |
| 39 | + '0.001 km' => 1, |
| 40 | + '1 km' => 1000, |
| 41 | + '4,24 km' => 4242, |
| 42 | + ), |
| 43 | + |
| 44 | + ); |
| 45 | + |
37 | 46 | /** |
38 | 47 | * Invalid distances. |
39 | 48 | * |
— | — | @@ -95,11 +104,9 @@ |
96 | 105 | * Tests MapsDistanceParser::formatDistance() |
97 | 106 | */ |
98 | 107 | public function testFormatDistance() { |
99 | | - // TODO Auto-generated MapsDistanceParserTest::testFormatDistance() |
100 | | - $this->markTestIncomplete ( "formatDistance test not implemented" ); |
101 | | - |
102 | | - MapsDistanceParser::formatDistance(/* parameters */); |
103 | | - |
| 108 | + foreach ( self::$distances['km'] as $rawValue => $parsedValue ) { |
| 109 | + $this->assertEquals( $rawValue, MapsDistanceParser::formatDistance( $parsedValue, 'km' ), "'$parsedValue' was not formatted to '$rawValue':" ); |
| 110 | + } |
104 | 111 | } |
105 | 112 | |
106 | 113 | /** |
Index: trunk/extensions/Maps/Includes/Maps_DistanceParser.php |
— | — | @@ -168,7 +168,7 @@ |
169 | 169 | * @return string |
170 | 170 | */ |
171 | 171 | protected static function normalizeDistance( $distance ) { |
172 | | - $distance = (string)$distance; |
| 172 | + $distance = trim( (string)$distance ); |
173 | 173 | $strlen = strlen( $distance ); |
174 | 174 | |
175 | 175 | for ( $i = 0; $i < $strlen; $i++ ) { |