Skip to content

Commit

Permalink
fix encoding issue for maxmind provider
Browse files Browse the repository at this point in the history
  • Loading branch information
toin0u authored and willdurand committed Jan 7, 2015
1 parent 26c3bb6 commit 07dca92
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Geocoder/Provider/MaxMindProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected function executeQuery($query)
$data['country'] = $this->countryCodeToCountryName($data['countryCode']);
}

return array(array_merge($this->getDefaults(), $data));
return array($this->fixEncoding(array_merge($this->getDefaults(), $data)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
s:215:"BR,Brazil,26,"Santa Catarina",Florian�polis,-27.5833,-48.5667,,,America/Sao_Paulo,SA,,"Global Village Telecom","Global Village Telecom",gvt.net.br,"AS18881 Global Village Telecom",Cable/DSL,residential,18,99,52,92,,";
32 changes: 32 additions & 0 deletions tests/Geocoder/Tests/Provider/MaxMindProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,38 @@ public function testGetGeocodedDataOmniServiceWithRealIPv4()
$this->assertEquals('America/Chicago', $result['timezone']);
}

public function testGeocodeOmniServiceWithRealIPv4WithSslAndEncoding()
{
if (!isset($_SERVER['MAXMIND_API_KEY'])) {
$this->markTestSkipped('You need to configure the MAXMIND_API_KEY value in phpunit.xml');
}

$provider = new MaxMindProvider($this->getAdapter(), $_SERVER['MAXMIND_API_KEY'],
MaxMindProvider::OMNI_SERVICE, true);
$result = $provider->getGeocodedData('189.26.128.80');

$this->assertInternalType('array', $result);
$this->assertCount(1, $result);

$result = $result[0];
$this->assertInternalType('array', $result);
$this->assertEquals(-27.5833, $result['latitude'], '', 0.1);
$this->assertEquals(-48.5666, $result['longitude'], '', 0.1);
$this->assertEquals('Florianópolis', $result['city']);
$this->assertNull($result['zipcode']);
$this->assertEquals('26', $result['regionCode']);
$this->assertEquals('Brazil', $result['country']);
$this->assertEquals('BR', $result['countryCode']);
$this->assertNull($result['bounds']);
$this->assertNull($result['streetNumber']);
$this->assertNull($result['streetName']);
$this->assertNull($result['cityDistrict']);
$this->assertNull($result['county']);
$this->assertNull($result['countyCode']);
$this->assertEquals('Santa Catarina', $result['region']);
$this->assertEquals('America/Sao_Paulo', $result['timezone']);
}

public function testGetGeocodedDataWithRealIPv6()
{
if (!isset($_SERVER['MAXMIND_API_KEY'])) {
Expand Down

0 comments on commit 07dca92

Please sign in to comment.