Index: trunk/extensions/Maps/test/MapsDistanceParserTest.php |
— | — | @@ -2,6 +2,12 @@ |
3 | 3 | |
4 | 4 | require_once 'PHPUnit\Framework\TestCase.php'; |
5 | 5 | |
| 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 | + |
6 | 12 | /** |
7 | 13 | * MapsDistanceParser test case. |
8 | 14 | * |
— | — | @@ -11,7 +17,36 @@ |
12 | 18 | */ |
13 | 19 | class MapsDistanceParserTest extends PHPUnit_Framework_TestCase { |
14 | 20 | |
| 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 | + |
15 | 35 | /** |
| 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 | + /** |
16 | 51 | * @var MapsDistanceParser |
17 | 52 | */ |
18 | 53 | private $MapsDistanceParser; |
— | — | @@ -22,20 +57,13 @@ |
23 | 58 | protected function setUp() { |
24 | 59 | parent::setUp (); |
25 | 60 | |
26 | | - // TODO Auto-generated MapsDistanceParserTest::setUp() |
27 | | - |
28 | | - |
29 | 61 | $this->MapsDistanceParser = new MapsDistanceParser(/* parameters */); |
30 | | - |
31 | 62 | } |
32 | 63 | |
33 | 64 | /** |
34 | 65 | * Cleans up the environment after running a test. |
35 | 66 | */ |
36 | 67 | protected function tearDown() { |
37 | | - // TODO Auto-generated MapsDistanceParserTest::tearDown() |
38 | | - |
39 | | - |
40 | 68 | $this->MapsDistanceParser = null; |
41 | 69 | |
42 | 70 | parent::tearDown (); |
— | — | @@ -45,18 +73,16 @@ |
46 | 74 | * Constructs the test case. |
47 | 75 | */ |
48 | 76 | public function __construct() { |
49 | | - // TODO Auto-generated constructor |
| 77 | + |
50 | 78 | } |
51 | 79 | |
52 | 80 | /** |
53 | 81 | * Tests MapsDistanceParser::parseDistance() |
54 | 82 | */ |
55 | 83 | 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 | + } |
61 | 87 | } |
62 | 88 | |
63 | 89 | /** |
— | — | @@ -125,5 +151,4 @@ |
126 | 152 | |
127 | 153 | } |
128 | 154 | |
129 | | -} |
130 | | - |
| 155 | +} |
\ No newline at end of file |