DatabaseDriverProvidedByModuleTest.php in Drupal 9
File
core/modules/system/tests/src/Functional/System/DatabaseDriverProvidedByModuleTest.php
View source
<?php
namespace Drupal\Tests\system\Functional\System;
use Drupal\Core\Database\Database;
use Drupal\Tests\BrowserTestBase;
class DatabaseDriverProvidedByModuleTest extends BrowserTestBase {
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$admin_user = $this
->drupalCreateUser([
'administer site configuration',
]);
$this
->drupalLogin($admin_user);
}
public function testDatabaseDriverIsProvidedByModuleButTheModuleIsNotEnabled() : void {
$driver = Database::getConnection()
->driver();
if (!in_array($driver, [
'mysql',
'pgsql',
])) {
$this
->markTestSkipped("This test does not support the {$driver} database driver.");
}
$connection_info = Database::getConnectionInfo();
$database = [
'database' => $connection_info['default']['database'],
'username' => $connection_info['default']['username'],
'password' => $connection_info['default']['password'],
'prefix' => $connection_info['default']['prefix'],
'host' => $connection_info['default']['host'],
'driver' => 'Drivertest' . ucfirst($driver),
'namespace' => 'Drupal\\driver_test\\Driver\\Database\\Drivertest' . ucfirst($driver),
'autoload' => 'core/modules/system/tests/modules/driver_test/src/Driver/Database/Drivertest' . ucfirst($driver),
];
if (isset($connection_info['default']['port'])) {
$database['port'] = $connection_info['default']['port'];
}
$settings['databases']['default']['default'] = (object) [
'value' => $database,
'required' => TRUE,
];
$this
->writeSettings($settings);
$this
->drupalGet('admin/reports/status');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('Database driver provided by module');
$this
->assertSession()
->pageTextContains('The current database driver is provided by the module: driver_test. The module is currently not enabled. You should immediately enable the module.');
}
}