You are here

protected function ThunderInstallerTest::setUp in Thunder 8.3

Same name and namespace in other branches
  1. 8.5 tests/src/Functional/Installer/ThunderInstallerTest.php \Drupal\Tests\thunder\Functional\Installer\ThunderInstallerTest::setUp()
  2. 8.2 tests/src/Functional/Installer/ThunderInstallerTest.php \Drupal\Tests\thunder\Functional\Installer\ThunderInstallerTest::setUp()
  3. 8.4 tests/src/Functional/Installer/ThunderInstallerTest.php \Drupal\Tests\thunder\Functional\Installer\ThunderInstallerTest::setUp()
  4. 6.2.x tests/src/Functional/Installer/ThunderInstallerTest.php \Drupal\Tests\thunder\Functional\Installer\ThunderInstallerTest::setUp()
  5. 6.0.x tests/src/Functional/Installer/ThunderInstallerTest.php \Drupal\Tests\thunder\Functional\Installer\ThunderInstallerTest::setUp()
  6. 6.1.x tests/src/Functional/Installer/ThunderInstallerTest.php \Drupal\Tests\thunder\Functional\Installer\ThunderInstallerTest::setUp()

Overrides InstallerTestBase::setUp

File

tests/src/Functional/Installer/ThunderInstallerTest.php, line 27

Class

ThunderInstallerTest
Tests the interactive installer installing the standard profile.

Namespace

Drupal\Tests\thunder\Functional\Installer

Code

protected function setUp() {
  $this->isInstalled = FALSE;
  $this
    ->setupBaseUrl();
  $this
    ->prepareDatabasePrefix();

  // Install Drupal test site.
  $this
    ->prepareEnvironment();

  // 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()
  $global_request = Request::createFromGlobals();
  $request = Request::create($GLOBALS['base_url'] . '/core/install.php', 'GET', [], $global_request->cookies
    ->all(), [], $global_request->server
    ->all());
  $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
    ->set('app.root', DRUPAL_ROOT);
  \Drupal::setContainer($this->container);

  // Setup Mink.
  $this
    ->initMink();

  // Set up the browser test output file.
  $this
    ->initBrowserOutputFile();
  $this
    ->visitInstaller();

  // Select language.
  $this
    ->setUpLanguage();

  // Select profile.
  $this
    ->setUpProfile();

  // Address the requirements problem screen, if any.
  $this
    ->setUpRequirementsProblem();

  // Configure settings.
  $this
    ->setUpSettings();

  // Configure site.
  $this
    ->setUpSite();

  // Configure modules.
  $this
    ->setUpModules();
  if ($this->isInstalled) {

    // Import new settings.php written by the installer.
    $request = Request::createFromGlobals();
    $class_loader = (require $this->container
      ->get('app.root') . '/autoload.php');
    Settings::initialize($this->container
      ->get('app.root'), DrupalKernel::findSitePath($request), $class_loader);
    foreach ($GLOBALS['config_directories'] as $type => $path) {
      $this->configDirectories[$type] = $path;
    }

    // After writing settings.php, the installer removes write permissions
    // from the site directory. To allow drupal_generate_test_ua() to write
    // a file containing the private key for drupal_valid_test_ua(), the site
    // directory has to be writable.
    // BrowserTestBase::tearDown() will delete the entire test site directory.
    // Not using File API; a potential error must trigger a PHP warning.
    chmod($this->container
      ->get('app.root') . '/' . $this->siteDirectory, 0777);
    $this->kernel = DrupalKernel::createFromRequest($request, $class_loader, 'prod', FALSE);
    $this->kernel
      ->prepareLegacyRequest($request);
    $this->container = $this->kernel
      ->getContainer();

    // Manually configure the test mail collector implementation to prevent
    // tests from sending out emails and collect them in state instead.
    $this->container
      ->get('config.factory')
      ->getEditable('system.mail')
      ->set('interface.default', 'test_mail_collector')
      ->save();
  }
}