1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ipGeolocation\tests; |
4
|
|
|
|
5
|
|
|
use ipGeolocation\GeoIPLocation; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Tests for GeoIPLocation class |
10
|
|
|
* |
11
|
|
|
* PHP version 7 |
12
|
|
|
* |
13
|
|
|
* @author yasir khurshid <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
class GeoIPLocationTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
public function testGetGeoLocation() |
18
|
|
|
{ |
19
|
|
|
$_SERVER['REMOTE_ADDR'] = '188.110.9.8'; |
20
|
|
|
$location = (new GeoIPLocation())->getGeoLocation(); |
21
|
|
|
|
22
|
|
|
$this->assertInstanceOf('ipGeolocation\Location', $location); |
23
|
|
|
|
24
|
|
|
$this->assertTrue($location->getStatus()); |
25
|
|
|
$this->assertSame('Wesseling', $location->getCity()); |
26
|
|
|
$this->assertSame('Germany', $location->getCountry()); |
27
|
|
|
$this->assertSame('DE', $location->getCountryCode()); |
28
|
|
|
$this->assertSame(50.8271, $location->getLatitude()); |
29
|
|
|
$this->assertSame(6.9747, $location->getLongitude()); |
30
|
|
|
$this->assertSame('NW', $location->getRegionCode()); |
31
|
|
|
$this->assertSame('North Rhine-Westphalia', $location->getRegionName()); |
32
|
|
|
$this->assertSame('Europe/Berlin', $location->getTimezone()); |
33
|
|
|
$this->assertSame(50389, $location->getPostalCode()); |
34
|
|
|
$this->assertSame('EUR', $location->getCurrencyIso()); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testGetGeoLocationFail() |
38
|
|
|
{ |
39
|
|
|
$_SERVER['REMOTE_ADDR'] = ''; |
40
|
|
|
$location = (new GeoIPLocation())->getGeoLocation(); |
41
|
|
|
|
42
|
|
|
$this->assertInstanceOf('ipGeolocation\Location', $location); |
43
|
|
|
|
44
|
|
|
$this->assertFalse($location->getStatus()); |
45
|
|
|
$this->assertSame('reserved range', $location->getMessage()); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|