You are here

protected function InstallerTestBase::setUp in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/simpletest/src/InstallerTestBase.php \Drupal\simpletest\InstallerTestBase::setUp()

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

8 calls to InstallerTestBase::setUp()
ConfigInstallProfileUnmetDependenciesTest::setUp in core/modules/config/src/Tests/ConfigInstallProfileUnmetDependenciesTest.php
Sets up a Drupal site for running functional and integration tests.
DistributionProfileTest::setUp in core/modules/system/src/Tests/Installer/DistributionProfileTest.php
Sets up a Drupal site for running functional and integration tests.
InstallerEmptySettingsTest::setUp in core/modules/system/src/Tests/Installer/InstallerEmptySettingsTest.php
Sets up a Drupal site for running functional and integration tests.
InstallerExistingDatabaseSettingsTest::setUp in core/modules/system/src/Tests/Installer/InstallerExistingDatabaseSettingsTest.php
Sets up a Drupal site for running functional and integration tests.
InstallerExistingInstallationTest::setUp in core/modules/system/src/Tests/Installer/InstallerExistingInstallationTest.php
Sets up a Drupal site for running functional and integration tests.

... See full list

8 methods override InstallerTestBase::setUp()
ConfigInstallProfileUnmetDependenciesTest::setUp in core/modules/config/src/Tests/ConfigInstallProfileUnmetDependenciesTest.php
Sets up a Drupal site for running functional and integration tests.
DistributionProfileTest::setUp in core/modules/system/src/Tests/Installer/DistributionProfileTest.php
Sets up a Drupal site for running functional and integration tests.
InstallerEmptySettingsTest::setUp in core/modules/system/src/Tests/Installer/InstallerEmptySettingsTest.php
Sets up a Drupal site for running functional and integration tests.
InstallerExistingDatabaseSettingsTest::setUp in core/modules/system/src/Tests/Installer/InstallerExistingDatabaseSettingsTest.php
Sets up a Drupal site for running functional and integration tests.
InstallerExistingInstallationTest::setUp in core/modules/system/src/Tests/Installer/InstallerExistingInstallationTest.php
Sets up a Drupal site for running functional and integration tests.

... See full list

File

core/modules/simpletest/src/InstallerTestBase.php, line 77
Contains \Drupal\simpletest\InstallerTestBase.

Class

InstallerTestBase
Base class for testing the interactive installer.

Namespace

Drupal\simpletest

Code

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

  // Define information about the user 1 account.
  $this->rootUser = new UserSession(array(
    '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 WebTestBase::installParameters() returns form input values
  // suitable for a programmed \Drupal::formBuilder()->submitForm().
  // @see WebTestBase::translatePostValues()
  $this->parameters = $this
    ->installParameters();

  // Set up a minimal container (required by WebTestBase).
  // @see install_begin_request()
  $request = Request::create($GLOBALS['base_url'] . '/core/install.php');
  $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
    ->set('app.root', DRUPAL_ROOT);
  \Drupal::setContainer($this->container);
  $this
    ->drupalGet($GLOBALS['base_url'] . '/core/install.php');

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

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

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

  // @todo Allow test classes based on this class to act on further installer
  //   screens.
  // Configure site.
  $this
    ->setUpSite();
  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.
    // WebTestBase::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();
  }
}