1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Geocoder package. |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* @license MIT License |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Geocoder\Provider\Geoip\Tests; |
14
|
|
|
|
15
|
|
|
use Geocoder\IntegrationTest\BaseTestCase; |
16
|
|
|
use Geocoder\Location; |
17
|
|
|
use Geocoder\Query\GeocodeQuery; |
18
|
|
|
use Geocoder\Query\ReverseQuery; |
19
|
|
|
use Geocoder\Provider\Geoip\Geoip; |
20
|
|
|
|
21
|
|
|
class GeoipTest extends BaseTestCase |
22
|
|
|
{ |
23
|
|
|
protected function setUp() |
24
|
|
|
{ |
25
|
|
|
if (!function_exists('geoip_record_by_name')) { |
26
|
|
|
$this->markTestSkipped('You have to install GeoIP.'); |
27
|
|
|
} |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
protected function getCacheDir() |
31
|
|
|
{ |
32
|
|
|
return __DIR__.'/.cached_responses'; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testGetName() |
36
|
|
|
{ |
37
|
|
|
$provider = new Geoip(); |
38
|
|
|
$this->assertEquals('geoip', $provider->getName()); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @expectedException \Geocoder\Exception\UnsupportedOperation |
43
|
|
|
* @expectedExceptionMessage The Geoip provider does not support street addresses, only IPv4 addresses. |
44
|
|
|
*/ |
45
|
|
|
public function testGeocodeWithAddress() |
46
|
|
|
{ |
47
|
|
|
$provider = new Geoip(); |
48
|
|
|
$provider->geocodeQuery(GeocodeQuery::create('10 avenue Gambetta, Paris, France')); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testGeocodeWithLocalhostIPv4() |
52
|
|
|
{ |
53
|
|
|
$provider = new Geoip(); |
54
|
|
|
$results = $provider->geocodeQuery(GeocodeQuery::create('127.0.0.1')); |
55
|
|
|
|
56
|
|
|
$this->assertInstanceOf('Geocoder\Model\AddressCollection', $results); |
57
|
|
|
$this->assertCount(1, $results); |
58
|
|
|
|
59
|
|
|
/** @var Location $result */ |
60
|
|
|
$result = $results->first(); |
61
|
|
|
$this->assertInstanceOf('Geocoder\Model\Address', $result); |
62
|
|
|
$this->assertNull($result->getCoordinates()); |
63
|
|
|
|
64
|
|
|
$this->assertNull($result->getPostalCode()); |
65
|
|
|
$this->assertNull($result->getTimezone()); |
66
|
|
|
$this->assertEmpty($result->getAdminLevels()); |
67
|
|
|
$this->assertEquals('localhost', $result->getLocality()); |
68
|
|
|
$this->assertNotNull($result->getCountry()); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @expectedException \Geocoder\Exception\UnsupportedOperation |
73
|
|
|
* @expectedExceptionMessage The Geoip provider does not support IPv6 addresses, only IPv4 addresses. |
74
|
|
|
*/ |
75
|
|
|
public function testGeocodeWithLocalhostIPv6() |
76
|
|
|
{ |
77
|
|
|
$provider = new Geoip(); |
78
|
|
|
$provider->geocodeQuery(GeocodeQuery::create('::1')); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @expectedException \Geocoder\Exception\UnsupportedOperation |
83
|
|
|
* @expectedExceptionMessage The Geoip provider does not support IPv6 addresses, only IPv4 addresses. |
84
|
|
|
*/ |
85
|
|
|
public function testGeocodeWithRealIPv6() |
86
|
|
|
{ |
87
|
|
|
$provider = new Geoip(); |
88
|
|
|
$provider->geocodeQuery(GeocodeQuery::create('::ffff:74.200.247.59')); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @expectedException \Geocoder\Exception\UnsupportedOperation |
93
|
|
|
* @expectedExceptionMessage The Geoip provider is not able to do reverse geocoding. |
94
|
|
|
*/ |
95
|
|
|
public function testReverse() |
96
|
|
|
{ |
97
|
|
|
$provider = new Geoip(); |
98
|
|
|
$provider->reverseQuery(ReverseQuery::fromCoordinates(1, 2)); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|