function InstallerTestBase::installDrupal

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/FunctionalTests/Installer/InstallerTestBase.php \Drupal\FunctionalTests\Installer\InstallerTestBase::installDrupal()

We are testing the installer, so set up a minimal environment for that.

Overrides BrowserTestBase::installDrupal

File

core/tests/Drupal/FunctionalTests/Installer/InstallerTestBase.php, line 98

Class

InstallerTestBase
Base class for testing the interactive installer.

Namespace

Drupal\FunctionalTests\Installer

Code

public function installDrupal() {
  // Define information about the user 1 account.
  $this->rootUser = new UserSession([
    'uid' => 1,
    'name' => 'admin',
    'mail' => 'admin@example.com',
    'pass_raw' => $this->randomMachineName(),
  ]);
  // If any $settings are defined for this test, copy and prepare an actual
  // settings.php, so as to resemble a regular installation.
  if (!empty($this->settings)) {
    // Not using File API; a potential error must trigger a PHP warning.
    copy(DRUPAL_ROOT . '/sites/default/default.settings.php', DRUPAL_ROOT . '/' . $this->siteDirectory . '/settings.php');
    $this->writeSettings($this->settings);
  }
  // Note that FunctionalTestSetupTrait::installParameters() returns form
  // input values suitable for a programmed
  // \Drupal::formBuilder()->submitForm().
  // @see InstallerTestBase::translatePostValues()
  $this->parameters = $this->installParameters();
  // Set up a minimal container (required by BrowserTestBase). Set cookie and
  // server information so that XDebug works.
  // @see install_begin_request()
  $request = Request::create($GLOBALS['base_url'] . '/core/install.php', 'GET', [], $_COOKIE, [], $_SERVER);
  $request->setSession(new Session(new MockArraySessionStorage()));
  $this->container = new ContainerBuilder();
  $request_stack = new RequestStack();
  $request_stack->push($request);
  $this->container
    ->set('request_stack', $request_stack);
  $this->container
    ->setParameter('language.default_values', Language::$defaultValues);
  $this->container
    ->register('language.default', 'Drupal\\Core\\Language\\LanguageDefault')
    ->addArgument('%language.default_values%');
  $this->container
    ->register('string_translation', 'Drupal\\Core\\StringTranslation\\TranslationManager')
    ->addArgument(new Reference('language.default'));
  $this->container
    ->register('http_client', 'GuzzleHttp\\Client')
    ->setFactory('http_client_factory:fromOptions');
  $this->container
    ->register('http_client_factory', 'Drupal\\Core\\Http\\ClientFactory')
    ->setArguments([
    new Reference('http_handler_stack'),
  ]);
  $handler_stack = HandlerStack::create();
  $test_http_client_middleware = new TestHttpClientMiddleware();
  $handler_stack->push($test_http_client_middleware(), 'test.http_client.middleware');
  $this->container
    ->set('http_handler_stack', $handler_stack);
  $this->container
    ->setParameter('app.root', DRUPAL_ROOT);
  \Drupal::setContainer($this->container);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.