1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Maps\Test; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @covers MapsNominatimGeocoder |
7
|
|
|
* |
8
|
|
|
* @since 4.0 |
9
|
|
|
* |
10
|
|
|
* @group Maps |
11
|
|
|
* |
12
|
|
|
* @licence GNU GPL v2+ |
13
|
|
|
* @author Peter Grassberger < [email protected] > |
14
|
|
|
*/ |
15
|
|
|
class NominatimGeocoderTest extends \PHPUnit_Framework_TestCase { |
16
|
|
|
|
17
|
|
|
protected static function getMethod( $name ) { |
18
|
|
|
$class = new \ReflectionClass( 'MapsNominatimGeocoder' ); |
19
|
|
|
$method = $class->getMethod( $name ); |
20
|
|
|
$method->setAccessible( true ); |
21
|
|
|
return $method; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function addressProvider() { |
25
|
|
|
return [ |
26
|
|
|
['New York', 'https://nominatim.openstreetmap.org/search?q=New%2BYork&format=jsonv2&limit=1'], |
27
|
|
|
]; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @covers MapsNominatimGeocoder::getRequestUrl |
32
|
|
|
* |
33
|
|
|
* @dataProvider addressProvider |
34
|
|
|
*/ |
35
|
|
|
public function testGetRequestUrl( $address, $expected ) { |
36
|
|
|
$getRequestUrl = self::getMethod('getRequestUrl'); |
37
|
|
|
$geocoder = new \MapsNominatimGeocoder( 'nominatim' ); |
38
|
|
|
$actual = $getRequestUrl->invokeArgs($geocoder, array( $address )); |
39
|
|
|
$this->assertSame( $expected, $actual ); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function responseProvider() { |
43
|
|
|
return [ |
44
|
|
|
[ |
45
|
|
|
'[{"place_id":"97961780","licence":"Data © OpenStreetMap contributors, ODbL 1.0. http:\/\/www.openstreetmap.org\/copyright","osm_type":"way","osm_id":"161387758","boundingbox":["40.763858","40.7642664","-73.9548572","-73.954092"],"lat":"40.7642499","lon":"-73.9545249","display_name":"NewYork Hospital Drive, Upper East Side, Manhattan, New York County, New York City, New York, 10021, United States of America","place_rank":"27","category":"highway","type":"service","importance":0.275}]', |
46
|
|
|
['lat' => 40.7642499, 'lon' => -73.9545249] |
47
|
|
|
] |
48
|
|
|
]; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @covers MapsNominatimGeocoder::parseResponse |
53
|
|
|
* |
54
|
|
|
* @dataProvider responseProvider |
55
|
|
|
*/ |
56
|
|
|
public function testParseResponse( $response, $expected ) { |
57
|
|
|
$parseResponse = self::getMethod('parseResponse'); |
58
|
|
|
$geocoder = new \MapsNominatimGeocoder( 'nominatim' ); |
59
|
|
|
$actual = $parseResponse->invokeArgs($geocoder, array( $response )); |
60
|
|
|
$this->assertSame( $expected, $actual ); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|