You are here

public function Ip2CountryTest::testDbDownload in IP-based Determination of a Visitor's Country 8

Tests DB download.

File

tests/src/Functional/Ip2CountryTest.php, line 274

Class

Ip2CountryTest
Tests operations of the IP to Country module.

Namespace

Drupal\Tests\ip2country\Functional

Code

public function testDbDownload() {
  \Drupal::service('ip2country.manager')
    ->emptyDatabase();
  $count = \Drupal::service('ip2country.manager')
    ->getRowCount();
  $this
    ->assertEquals(0, $count, 'Database is empty.');

  // Choose a random RIR.
  $rir = array_rand([
    // 'afrinic' => 'AFRINIC', // Don't use AFRINIC because it's incomplete.
    'arin' => 'ARIN',
    'apnic' => 'APNIC',
    'lacnic' => 'LACNIC',
    'ripe' => 'RIPE',
  ]);
  \Drupal::service('ip2country.manager')
    ->updateDatabase($rir);
  $count = \Drupal::service('ip2country.manager')
    ->getRowCount();
  $this
    ->assertNotEquals(0, $count, 'Database has been updated from ' . mb_strtoupper($rir) . ' with ' . $count . ' rows.');
  \Drupal::service('ip2country.manager')
    ->emptyDatabase();
  $count = \Drupal::service('ip2country.manager')
    ->getRowCount();
  $this
    ->assertEquals(0, $count, 'Database is empty.');
}