protected function InstallerTest::setUp

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 Drupal\simpletest\WebTestBase::$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 WebTestBase::setUp

See also

Drupal\simpletest\WebTestBase::prepareDatabasePrefix()

Drupal\simpletest\WebTestBase::changeDatabasePrefix()

Drupal\simpletest\WebTestBase::prepareEnvironment()

File

drupal/core/modules/system/lib/Drupal/system/Tests/InstallerTest.php, line 26
Contains \Drupal\system\Tests\InstallerTest.

Class

InstallerTest
Allows testing of the interactive installer.

Namespace

Drupal\system\Tests

Code

protected function setUp() {
  global $conf;

  // When running tests through the SimpleTest UI (vs. on the command line),
  // SimpleTest's batch conflicts with the installer's batch. Batch API does
  // not support the concept of nested batches (in which the nested is not
  // progressive), so we need to temporarily pretend there was no batch.
  // Back up the currently running SimpleTest batch.
  $this->originalBatch = batch_get();

  // Create the database prefix for this test.
  $this
    ->prepareDatabasePrefix();

  // Prepare the environment for running tests.
  $this
    ->prepareEnvironment();
  if (!$this->setupEnvironment) {
    return FALSE;
  }

  // Reset all statics and variables to perform tests in a clean environment.
  $conf = array();
  drupal_static_reset();

  // Change the database prefix.
  // All static variables need to be reset before the database prefix is
  // changed, since \Drupal\Core\Utility\CacheArray implementations attempt to
  // write back to persistent caches when they are destructed.
  $this
    ->changeDatabasePrefix();
  if (!$this->setupDatabasePrefix) {
    return FALSE;
  }
  $variable_groups = array(
    'system.file' => array(
      'path.private' => $this->private_files_directory,
      'path.temporary' => $this->temp_files_directory,
    ),
    'locale.settings' => array(
      'translation.path' => $this->translation_files_directory,
    ),
  );
  foreach ($variable_groups as $config_base => $variables) {
    foreach ($variables as $name => $value) {
      NestedArray::setValue($GLOBALS['conf'], array_merge(array(
        $config_base,
      ), explode('.', $name)), $value);
    }
  }
  $settings['conf_path'] = (object) array(
    'value' => $this->public_files_directory,
    'required' => TRUE,
  );
  $settings['config_directories'] = (object) array(
    'value' => array(),
    'required' => TRUE,
  );
  $this
    ->writeSettings($settings);
  $this
    ->drupalGet($GLOBALS['base_url'] . '/core/install.php?langcode=en&profile=minimal');
  $this
    ->drupalPost(NULL, array(), 'Save and continue');

  // Reload config directories.
  include $this->public_files_directory . '/settings.php';
  $prefix = substr($this->public_files_directory, strlen(conf_path() . '/files/'));
  foreach ($config_directories as $type => $data) {
    $GLOBALS['config_directories'][$type]['path'] = $prefix . '/files/' . $data['path'];
  }
  $this
    ->rebuildContainer();
  foreach ($variable_groups as $config_base => $variables) {
    $config = config($config_base);
    foreach ($variables as $name => $value) {
      $config
        ->set($name, $value);
    }
    $config
      ->save();
  }

  // Use the test mail class instead of the default mail handler class.
  config('system.mail')
    ->set('interface.default', 'Drupal\\Core\\Mail\\VariableLog')
    ->save();
  drupal_set_time_limit($this->timeLimit);

  // When running from run-tests.sh we don't get an empty current path which
  // would indicate we're on the home page.
  $path = current_path();
  if (empty($path)) {
    _current_path('run-tests');
  }
  $this->setup = TRUE;
}