class InstallerExistingSettingsTest

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/FunctionalTests/Installer/InstallerExistingSettingsTest.php \Drupal\FunctionalTests\Installer\InstallerExistingSettingsTest

Tests the installer with an existing settings file.

@group Installer

Hierarchy

Expanded class hierarchy of InstallerExistingSettingsTest

File

core/tests/Drupal/FunctionalTests/Installer/InstallerExistingSettingsTest.php, line 14

Namespace

Drupal\FunctionalTests\Installer
View source
class InstallerExistingSettingsTest extends InstallerTestBase {
  
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';
  
  /**
   * {@inheritdoc}
   *
   * Fully configures a preexisting settings.php file before invoking the
   * interactive installer.
   */
  protected function prepareEnvironment() {
    parent::prepareEnvironment();
    // Pre-configure hash salt.
    // Any string is valid, so simply use the class name of this test.
    $this->settings['settings']['hash_salt'] = (object) [
      'value' => __CLASS__,
      'required' => TRUE,
    ];
    // Pre-configure database credentials.
    $connection_info = Database::getConnectionInfo();
    unset($connection_info['default']['pdo']);
    unset($connection_info['default']['init_commands']);
    $this->settings['databases']['default'] = (object) [
      'value' => $connection_info,
      'required' => TRUE,
    ];
    // Use the kernel to find the site path because the site.path service should
    // not be available at this point in the install process.
    $site_path = DrupalKernel::findSitePath(Request::createFromGlobals());
    // Pre-configure config directories.
    $this->settings['settings']['config_sync_directory'] = (object) [
      'value' => $site_path . '/files/config_sync',
      'required' => TRUE,
    ];
    mkdir($this->settings['settings']['config_sync_directory']->value, 0777, TRUE);
  }
  
  /**
   * Visits the interactive installer.
   */
  protected function visitInstaller() {
    // Should redirect to the installer.
    $this->drupalGet($GLOBALS['base_url']);
    // Ensure no database tables have been created yet.
    $this->assertSame([], Database::getConnection()->schema()
      ->findTables('%'));
    $this->assertSession()
      ->addressEquals($GLOBALS['base_url'] . '/core/install.php');
  }
  
  /**
   * {@inheritdoc}
   */
  protected function setUpSettings() {
    // This step should not appear, since settings.php is fully configured
    // already.
  }
  
  /**
   * Verifies that installation succeeded.
   */
  public function testInstaller() {
    $this->assertSession()
      ->addressEquals('user/1');
    $this->assertSession()
      ->statusCodeEquals(200);
    $this->assertEquals('testing', \Drupal::installProfile());
  }

}

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