r69684 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69683‎ | r69684 | r69685 >
Date:14:59, 21 July 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Added unit tests
Modified paths:
  • /trunk/extensions/Maps/test/MapsDistanceParserTest.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/test/MapsDistanceParserTest.php
@@ -2,6 +2,12 @@
33
44 require_once 'PHPUnit\Framework\TestCase.php';
55
 6+// Trick MW into thinking this is a command line script.
 7+// This is obviously not a good approach, as it will not work on other setups then my own.
 8+unset( $_SERVER['REQUEST_METHOD'] );
 9+$argv = array( 'over9000failz' );
 10+require_once '../../../smw/maintenance/commandLine.inc';
 11+
612 /**
713 * MapsDistanceParser test case.
814 *
@@ -11,7 +17,36 @@
1218 */
1319 class MapsDistanceParserTest extends PHPUnit_Framework_TestCase {
1420
 21+ public static $distances = array(
 22+ '1' => 1,
 23+ '1m' => 1,
 24+ '1 m' => 1,
 25+ ' 1 m ' => 1,
 26+ '1.1' => 1.1,
 27+ '1,1' => 1.1,
 28+ '1 km' => 1000,
 29+ '42 km' => 42000,
 30+ '4.2 km' => 4200,
 31+ '4,20km' => 4200,
 32+ '1 mile' => 1609.344,
 33+ );
 34+
1535 /**
 36+ * Invalid distances.
 37+ *
 38+ * @var array
 39+ */
 40+ public static $fakeDistances = array(
 41+ 'IN YOUR CODE, BEING TOTALLY REDICULOUSE',
 42+ '0x20 km',
 43+ 'km 42',
 44+ '42 42 km',
 45+ '42 km km',
 46+ '42 foo',
 47+ '3.4.2 km'
 48+ );
 49+
 50+ /**
1651 * @var MapsDistanceParser
1752 */
1853 private $MapsDistanceParser;
@@ -22,20 +57,13 @@
2358 protected function setUp() {
2459 parent::setUp ();
2560
26 - // TODO Auto-generated MapsDistanceParserTest::setUp()
27 -
28 -
2961 $this->MapsDistanceParser = new MapsDistanceParser(/* parameters */);
30 -
3162 }
3263
3364 /**
3465 * Cleans up the environment after running a test.
3566 */
3667 protected function tearDown() {
37 - // TODO Auto-generated MapsDistanceParserTest::tearDown()
38 -
39 -
4068 $this->MapsDistanceParser = null;
4169
4270 parent::tearDown ();
@@ -45,18 +73,16 @@
4674 * Constructs the test case.
4775 */
4876 public function __construct() {
49 - // TODO Auto-generated constructor
 77+
5078 }
5179
5280 /**
5381 * Tests MapsDistanceParser::parseDistance()
5482 */
5583 public function testParseDistance() {
56 - // TODO Auto-generated MapsDistanceParserTest::testParseDistance()
57 - $this->markTestIncomplete ( "parseDistance test not implemented" );
58 -
59 - MapsDistanceParser::parseDistance(/* parameters */);
60 -
 84+ foreach ( self::$distances as $rawValue => $parsedValue ) {
 85+ $this->assertEquals( $parsedValue, MapsDistanceParser::parseDistance( $rawValue ), "'$rawValue' was not parsed to '$parsedValue':" );
 86+ }
6187 }
6288
6389 /**
@@ -125,5 +151,4 @@
126152
127153 }
128154
129 -}
130 -
 155+}
\ No newline at end of file

Follow-up revisions

RevisionCommit summaryAuthorDate
r69685Fixed issues with distance parsing found with unit tests added in r69684jeroendedauw15:07, 21 July 2010

Status & tagging log