GeoLocatorPluginTest.php in GeoIP API 8.2
File
tests/src/Kernel/GeoLocatorPluginTest.php
View source
<?php
namespace Drupal\Tests\geoip\Kernel;
use Drupal\KernelTests\KernelTestBase;
class GeoLocatorPluginTest extends KernelTestBase {
public static $modules = [
'system',
'geoip',
];
protected function setUp() {
parent::setUp();
$this
->installSchema('system', 'file');
}
public function testCdn() {
$this
->config('geoip.geolocation')
->set('plugin_id', 'cdn')
->save();
$_SERVER['HTTP_CF_IPCOUNTRY'] = 'US';
$this
->assertEquals('US', $this->container
->get('geoip.geolocation')
->geolocate('127.0.0.1'));
unset($_SERVER['HTTP_CF_IPCOUNTRY']);
$_SERVER['HTTP_CLOUDFRONT_VIEWER_COUNTRY'] = 'CA';
$this
->assertEquals('CA', $this->container
->get('geoip.geolocation')
->geolocate('192.168.1.1'));
}
public function testLocal() {
$file = file_unmanaged_copy(__DIR__ . '/../../fixtures/GeoLite2-Country.mmdb', 'public://GeoLite2-Country.mmdb');
$this
->config('geoip.geolocation')
->set('plugin_id', 'local')
->save();
$this
->assertEquals('US', $this->container
->get('geoip.geolocation')
->geolocate('75.86.161.59'));
}
}