You are here

public function RequirementsTest::testRequirements in GeoIP API 8.2

Tests the requirements.

File

tests/src/Kernel/RequirementsTest.php, line 30

Class

RequirementsTest
Tests the default GeoLocator plugins.

Namespace

Drupal\Tests\geoip\Kernel

Code

public function testRequirements() {
  module_load_install('geoip');
  $requirements = geoip_requirements('install');

  // Class is available due to build. No warnings.
  $this
    ->assertTrue(!isset($requirements['geoip_local_database']['severity']));
  $requirements = geoip_requirements('runtime');
  $this
    ->assertNotEmpty($requirements['geoip_local_database']['title']);
  $this
    ->assertEquals($requirements['geoip_local_database']['severity'], REQUIREMENT_WARNING);
  $file = file_unmanaged_copy(__DIR__ . '/../../fixtures/GeoLite2-Country.mmdb', 'public://GeoLite2-Country.mmdb');
  $requirements = geoip_requirements('runtime');
  $this
    ->assertNotEmpty($requirements['geoip_local_database']['title']);
  $this
    ->assertEquals($requirements['geoip_local_database']['severity'], REQUIREMENT_OK);
  touch($file);
  $this
    ->assertNotEmpty($requirements['geoip_local_database_age']['title']);
  $this
    ->assertEquals(REQUIREMENT_OK, $requirements['geoip_local_database_age']['severity']);
  touch($file, strtotime('2 months ago'));
  $requirements = geoip_requirements('runtime');
  $this
    ->assertNotEmpty($requirements['geoip_local_database_age']['title']);
  $this
    ->assertEquals(REQUIREMENT_WARNING, $requirements['geoip_local_database_age']['severity']);
}