r69688 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69687‎ | r69688 | r69689 >
Date:16:19, 21 July 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Added unit tests
Modified paths:
  • /trunk/extensions/Maps/Includes/Maps_DistanceParser.php (modified) (history)
  • /trunk/extensions/Maps/test/MapsDistanceParserTest.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/test/MapsDistanceParserTest.php
@@ -18,10 +18,10 @@
1919 class MapsDistanceParserTest extends PHPUnit_Framework_TestCase {
2020
2121 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,
2626 '1.1' => 1.1,
2727 '1,1' => 1.1,
2828 '1 km' => 1000,
@@ -33,6 +33,15 @@
3434 '1.0nautical mile' => 1852,
3535 );
3636
 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+
3746 /**
3847 * Invalid distances.
3948 *
@@ -95,11 +104,9 @@
96105 * Tests MapsDistanceParser::formatDistance()
97106 */
98107 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+ }
104111 }
105112
106113 /**
Index: trunk/extensions/Maps/Includes/Maps_DistanceParser.php
@@ -168,7 +168,7 @@
169169 * @return string
170170 */
171171 protected static function normalizeDistance( $distance ) {
172 - $distance = (string)$distance;
 172+ $distance = trim( (string)$distance );
173173 $strlen = strlen( $distance );
174174
175175 for ( $i = 0; $i < $strlen; $i++ ) {

Status & tagging log