You are here

public function RestrictByIPWebTestBase::setUp in Restrict Login or Role Access by IP Address 8.4

Sets up a Drupal site for running functional and integration tests.

Installs Drupal with the installation profile specified in \Drupal\simpletest\WebTestBase::$profile into the prefixed database.

Afterwards, installs any additional modules specified in the static \Drupal\simpletest\WebTestBase::$modules property of each class in the class hierarchy.

After installation all caches are flushed and several configuration values are reset to the values of the parent site executing the test, since the default values may be incompatible with the environment in which tests are being executed.

Overrides WebTestBase::setUp

3 calls to RestrictByIPWebTestBase::setUp()
RedirectTest::setUp in src/Tests/RedirectTest.php
Sets up a Drupal site for running functional and integration tests.
RoleTest::setUp in src/Tests/RoleTest.php
Sets up a Drupal site for running functional and integration tests.
UiTest::setUp in src/Tests/UiTest.php
Sets up a Drupal site for running functional and integration tests.
3 methods override RestrictByIPWebTestBase::setUp()
RedirectTest::setUp in src/Tests/RedirectTest.php
Sets up a Drupal site for running functional and integration tests.
RoleTest::setUp in src/Tests/RoleTest.php
Sets up a Drupal site for running functional and integration tests.
UiTest::setUp in src/Tests/UiTest.php
Sets up a Drupal site for running functional and integration tests.

File

src/Tests/RestrictByIPWebTestBase.php, line 37

Class

RestrictByIPWebTestBase
Setup shared data and determine IP ranges to use for current testing environment.

Namespace

Drupal\restrict_by_ip\Tests

Code

public function setUp() {

  // Enable modules needed for these tests.
  parent::setUp();
  $this->conf = $this
    ->config('restrict_by_ip.settings');

  // Create a user that we'll use to test logins.
  $this->regularUser = $this
    ->drupalCreateUser();
  $outOfRangeCIDRs = [
    '10' => '10.0.0.0/8',
    '172' => '172.16.0.0/12',
    '192' => '192.168.0.0/16',
  ];
  $adminUser = $this
    ->drupalCreateUser([
    'administer restrict by ip',
  ]);
  $this
    ->drupalLogin($adminUser);
  $this
    ->drupalGet('admin/config/people/restrict_by_ip/login');
  $pageContent = $this
    ->getTextContent();
  preg_match('#is (.*?). If#', $pageContent, $matches);
  $this
    ->drupalLogout();

  // The IP address when testing if client DOES matches restrictions.
  $this->currentIPCIDR = $matches[1] . '/32';

  // The IP address when testing if client DOESN'T match restrictions.
  unset($outOfRangeCIDRs[explode('.', $this->currentIPCIDR)[0]]);
  $this->outOfRangeCIDR = array_shift($outOfRangeCIDRs);
}