r69466 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69465‎ | r69466 | r69467 >
Date:03:35, 17 July 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Added unit tests and fixed coordinate formatting bug
Modified paths:
  • /trunk/extensions/Maps/Includes/Maps_CoordinateParser.php (modified) (history)
  • /trunk/extensions/Maps/test/MapsCoordinateParserTest.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/test/MapsCoordinateParserTest.php
@@ -17,6 +17,11 @@
1818 */
1919 class MapsCoordinateParserTest extends PHPUnit_Framework_TestCase {
2020
 21+ /**
 22+ * Valid coordinates.
 23+ *
 24+ * @var array
 25+ */
2126 public static $coordinates = array(
2227 'float' => array(
2328 '55.7557860 N, 37.6176330 W',
@@ -52,7 +57,13 @@
5358 ),
5459 );
5560
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+ */
5768 public static $coordinateMappings = array(
5869 // Float to non-directional DMS
5970 'float-dms' => array(
@@ -65,9 +76,33 @@
6677 '42.5 N, 42.5 W' => array( '42° 30\' 0", -42° 30\' 0"', '42° 30\' 0" N, 42° 30\' 0" W' ),
6778 '42.5 S, 42.5 E' => array( '-42° 30\' 0", 42° 30\' 0"', '42° 30\' 0" S, 42° 30\' 0" E' ),
6879 '42.4242 N, 42.4242 E' => array( '42° 25\' 27", 42° 25\' 27"', '42° 25\' 27" N, 42° 25\' 27" E' )
69 - )
 80+ ),
7081 );
7182
 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+ */
72107 public static $fakeCoordinates = array(
73108 'IN YOUR CODE, BEING TOTALLY REDICULOUSE',
74109 '55.7557860 E, 37.6176330 W',
@@ -117,6 +152,10 @@
118153 foreach ( self::$fakeCoordinates as $coord ) {
119154 $this->assertFalse( MapsCoordinateParser::parseCoordinates( $coord ), "parseCoordinates did not return false for $coord." );
120155 }
 156+
 157+ foreach ( self::$parsingTests as $coord => $destination ) {
 158+ $this->assertEquals( $destination, MapsCoordinateParser::parseCoordinates( $coord ), "Parsing test failed at " . __METHOD__ );
 159+ }
121160 }
122161
123162 /**
@@ -259,7 +298,17 @@
260299 );
261300 }
262301 }
 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+ }
263313 }
264314
265 -}
266 -
 315+}
\ No newline at end of file
Index: trunk/extensions/Maps/Includes/Maps_CoordinateParser.php
@@ -468,7 +468,9 @@
469469 protected static function setDirectionalAngle( $coordinate, $isLat ) {
470470 self::initializeDirectionLabels();
471471
 472+ $coordinate = (string)$coordinate;
472473 $isNegative = $coordinate{0} == '-';
 474+
473475 if ( $isNegative ) $coordinate = substr( $coordinate, 1 );
474476
475477 if ( $isLat ) {

Status & tagging log