You are here

protected function BlockedIpsExpireCron::setUp in Blocked IPs Expire 7

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

Generates a random database prefix and installs Drupal with the specified installation profile in DrupalWebTestCase::$profile into the prefixed database. Afterwards, installs any additional modules specified by the test.

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.

Parameters

...: List of modules to enable for the duration of the test. This can be either a single array or a variable number of string arguments.

Overrides BlockedIpsExpireTestCase::setUp

See also

DrupalWebTestCase::prepareDatabasePrefix()

DrupalWebTestCase::changeDatabasePrefix()

DrupalWebTestCase::prepareEnvironment()

File

tests/blocked_ips_expire.cron.test, line 62
Contains \BlockedIpsExpireCron.

Class

BlockedIpsExpireCron
Tests that expired IPs will be unblocked on cron run.

Code

protected function setUp() {

  // SimpleTest Turbo makes things really fast. Let's use it if we can.
  if (module_exists('simpletest_turbo')) {
    $id = simpletest_turbo_id('simpletest_turboOptimized');
    if (db_table_exists('fasttest' . $id . 'node')) {
      $this
        ->prepareDatabasePrefix();
      $this
        ->prepareEnvironment();
      $this
        ->changeDatabasePrefix();
      simpletest_turbo_copy_tables('fasttest' . $id, $this->databasePrefix);
      variable_set('file_public_path', $this->public_files_directory);
      variable_set('file_private_path', $this->private_files_directory);
      variable_set('file_temporary_path', $this->temp_files_directory);
      $this->setup = TRUE;
    }
    else {
      parent::setUp();
      simpletest_turbo_copy_tables($this->databasePrefix, 'fasttest' . $id);
    }
  }
  else {
    parent::setUp();
  }

  // Set up variables.
  $this->expiredIpAddress = BlockedIpsExpireCron::generateIpAddress();
  $this->expiredDate = BlockedIpsExpireCron::randomDatetimeInPast();
  $this->notYetExpiredIpAddress = BlockedIpsExpireCron::generateIpAddress();
  $this->notYetExpiredDate = BlockedIpsExpireCron::randomDatetimeInFuture();

  // Log in as an administrative user.
  $this->adminUser = $this
    ->drupalCreateUser(array(
    'access content',
    'access administration pages',
    'administer site configuration',
  ));
  $this
    ->drupalLogin($this->adminUser);
}