class CdnGeoLocatorTest in GeoIP API 8.2
Tests the CDN locator.
@coversDefaultClass \Drupal\geoip\Plugin\GeoLocator\Cdn
@group GeoIP
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\geoip\Unit\CdnGeoLocatorTest
Expanded class hierarchy of CdnGeoLocatorTest
File
- tests/
src/ Unit/ CdnGeoLocatorTest.php, line 18
Namespace
Drupal\Tests\geoip\UnitView source
class CdnGeoLocatorTest extends UnitTestCase {
/**
* Test the geolocate method for Cdn plugin.
*
* @covers ::geolocate
* @backupGlobals disabled
*/
public function testGeolocate() {
$config = $this
->prophesize(ImmutableConfig::class);
$config
->get('debug')
->willReturn(FALSE);
$config_factory = $this
->prophesize(ConfigFactoryInterface::class);
$config_factory
->get('geoip.geolocation')
->willReturn($config
->reveal());
$logger = $this
->prophesize(LoggerInterface::class);
$locator = new Cdn([], 'cdn', [
'label' => 'CDN',
'description' => 'Checks for geolocation headers sent by CDN services',
'weight' => 10,
], $config_factory
->reveal(), $logger
->reveal());
$this
->assertEquals(NULL, $locator
->geolocate('127.0.0.1'));
$_SERVER['HTTP_CF_IPCOUNTRY'] = 'US';
$this
->assertEquals('US', $locator
->geolocate('127.0.0.1'));
$_SERVER['HTTP_CLOUDFRONT_VIEWER_COUNTRY'] = 'CA';
// We can't equal CA since we manually check Cloudflare first.
$this
->assertNotEquals('CA', $locator
->geolocate('127.0.0.1'));
unset($_SERVER['HTTP_CF_IPCOUNTRY']);
$this
->assertEquals('CA', $locator
->geolocate('127.0.0.1'));
unset($_SERVER['HTTP_CLOUDFRONT_VIEWER_COUNTRY']);
$_SERVER['HTTP_MY_CUSTOM_HEADER'] = 'FR';
// @todo this needs to be updated when custom header implemented.
$this
->assertEquals(NULL, $locator
->geolocate('127.0.0.1'));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CdnGeoLocatorTest:: |
public | function | Test the geolocate method for Cdn plugin. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 |