InstallerExistingDatabaseSettingsTest.php

Same filename and directory in other branches
  1. 8.9.x core/tests/Drupal/FunctionalTests/Installer/InstallerExistingDatabaseSettingsTest.php
  2. 10 core/tests/Drupal/FunctionalTests/Installer/InstallerExistingDatabaseSettingsTest.php
  3. 11.x core/tests/Drupal/FunctionalTests/Installer/InstallerExistingDatabaseSettingsTest.php

Namespace

Drupal\FunctionalTests\Installer

File

core/tests/Drupal/FunctionalTests/Installer/InstallerExistingDatabaseSettingsTest.php

View source
<?php

namespace Drupal\FunctionalTests\Installer;

use Drupal\Core\Database\Database;

/**
 * Tests installation with database information in an existing settings file.
 *
 * @group Installer
 */
class InstallerExistingDatabaseSettingsTest extends InstallerTestBase {
    
    /**
     * {@inheritdoc}
     */
    protected $defaultTheme = 'stark';
    
    /**
     * {@inheritdoc}
     */
    protected function prepareEnvironment() {
        parent::prepareEnvironment();
        // Pre-configure database credentials in settings.php.
        $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,
        ];
    }
    
    /**
     * {@inheritdoc}
     *
     * @todo The database settings form is not supposed to appear if settings.php
     *   contains a valid database connection already (but e.g. no config
     *   directories yet).
     */
    protected function setUpSettings() {
        // All database settings should be pre-configured, except password.
        $values = $this->parameters['forms']['install_settings_form'];
        $driver = $values['driver'];
        $edit = [];
        if (isset($values[$driver]['password']) && $values[$driver]['password'] !== '') {
            $edit = $this->translatePostValues([
                $driver => [
                    'password' => $values[$driver]['password'],
                ],
            ]);
        }
        $this->submitForm($edit, $this->translations['Save and continue']);
    }
    
    /**
     * Verifies that installation succeeded.
     */
    public function testInstaller() {
        $this->assertSession()
            ->addressEquals('user/1');
        $this->assertSession()
            ->statusCodeEquals(200);
    }

}

Classes

Title Deprecated Summary
InstallerExistingDatabaseSettingsTest Tests installation with database information in an existing settings file.

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