class InstallerNonDefaultDatabaseDriverTest
Same name and namespace in other branches
- 11.x core/tests/Drupal/FunctionalTests/Installer/InstallerNonDefaultDatabaseDriverTest.php \Drupal\FunctionalTests\Installer\InstallerNonDefaultDatabaseDriverTest
- 10 core/tests/Drupal/FunctionalTests/Installer/InstallerNonDefaultDatabaseDriverTest.php \Drupal\FunctionalTests\Installer\InstallerNonDefaultDatabaseDriverTest
- 8.9.x core/tests/Drupal/FunctionalTests/Installer/InstallerNonDefaultDatabaseDriverTest.php \Drupal\FunctionalTests\Installer\InstallerNonDefaultDatabaseDriverTest
Tests the interactive installer.
@group Installer
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\FunctionalTests\Installer\InstallerTestBase uses \Drupal\Tests\RequirementsPageTrait extends \Drupal\Tests\BrowserTestBase
- class \Drupal\FunctionalTests\Installer\InstallerNonDefaultDatabaseDriverTest extends \Drupal\FunctionalTests\Installer\InstallerTestBase
- class \Drupal\FunctionalTests\Installer\InstallerTestBase uses \Drupal\Tests\RequirementsPageTrait extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of InstallerNonDefaultDatabaseDriverTest
File
-
core/
tests/ Drupal/ FunctionalTests/ Installer/ InstallerNonDefaultDatabaseDriverTest.php, line 14
Namespace
Drupal\FunctionalTests\InstallerView source
class InstallerNonDefaultDatabaseDriverTest extends InstallerTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* The name of the test database driver in use.
* @var string
*/
protected $testDriverName;
/**
* {@inheritdoc}
*/
protected function setUpSettings() {
$driver = Database::getConnection()->driver();
if (!in_array($driver, [
'mysql',
'pgsql',
])) {
$this->markTestSkipped("This test does not support the {$driver} database driver.");
}
$this->testDriverName = 'Drivertest' . ucfirst($driver);
// Assert that we are using the database drivers from the driver_test module.
$this->assertSession()
->elementTextEquals('xpath', '//label[@for="edit-driver-drivertestmysql"]', 'MySQL by the driver_test module');
$this->assertSession()
->elementTextEquals('xpath', '//label[@for="edit-driver-drivertestpgsql"]', 'PostgreSQL by the driver_test module');
$settings = $this->parameters['forms']['install_settings_form'];
$settings['driver'] = $this->testDriverName;
$settings[$this->testDriverName] = $settings[$driver];
unset($settings[$driver]);
$edit = $this->translatePostValues($settings);
$this->submitForm($edit, $this->translations['Save and continue']);
}
/**
* Confirms that the installation succeeded.
*/
public function testInstalled() {
$this->assertSession()
->addressEquals('user/1');
$this->assertSession()
->statusCodeEquals(200);
// Assert that in the settings.php the database connection array has the
// correct values set.
$contents = file_get_contents($this->container
->getParameter('app.root') . '/' . $this->siteDirectory . '/settings.php');
$this->assertStringContainsString("'namespace' => 'Drupal\\\\driver_test\\\\Driver\\\\Database\\\\{$this->testDriverName}',", $contents);
$this->assertStringContainsString("'driver' => '{$this->testDriverName}',", $contents);
$this->assertStringContainsString("'autoload' => 'core/modules/system/tests/modules/driver_test/src/Driver/Database/{$this->testDriverName}/',", $contents);
// Assert that the module "driver_test" has been installed.
$this->assertEquals(\Drupal::service('module_handler')->getModule('driver_test'), new Extension($this->root, 'module', 'core/modules/system/tests/modules/driver_test/driver_test.info.yml'));
// Change the default database connection to use the database driver from
// the module "driver_test".
$connection_info = Database::getConnectionInfo();
$driver_test_connection = $connection_info['default'];
$driver_test_connection['driver'] = $this->testDriverName;
$driver_test_connection['namespace'] = 'Drupal\\driver_test\\Driver\\Database\\' . $this->testDriverName;
$driver_test_connection['autoload'] = "core/modules/system/tests/modules/driver_test/src/Driver/Database/{$this->testDriverName}/";
Database::renameConnection('default', 'original_database_connection');
Database::addConnectionInfo('default', 'default', $driver_test_connection);
// The module "driver_test" should not be uninstallable, because it is
// providing the database driver.
try {
$this->container
->get('module_installer')
->uninstall([
'driver_test',
]);
$this->fail('Uninstalled driver_test module.');
} catch (ModuleUninstallValidatorException $e) {
$this->assertStringContainsString("The module 'Contrib database driver test' is providing the database driver '{$this->testDriverName}'.", $e->getMessage());
}
// Restore the old database connection.
Database::addConnectionInfo('default', 'default', $connection_info['default']);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.