diff --git a/core/tests/Drupal/FunctionalTests/ExistingDrupal8StyleDatabaseConnectionInSettingsPhpTest.php b/core/tests/Drupal/FunctionalTests/ExistingDrupal8StyleDatabaseConnectionInSettingsPhpTest.php index 855387f695..e49f3ee7e9 100644 --- a/core/tests/Drupal/FunctionalTests/ExistingDrupal8StyleDatabaseConnectionInSettingsPhpTest.php +++ b/core/tests/Drupal/FunctionalTests/ExistingDrupal8StyleDatabaseConnectionInSettingsPhpTest.php @@ -2,6 +2,7 @@ namespace Drupal\FunctionalTests; +use Drupal\Core\Database\Connection; use Drupal\Core\Database\Database; use Drupal\Tests\BrowserTestBase; @@ -35,6 +36,19 @@ protected function setUp(): void { $namespace_search = "'namespace' => 'Drupal\\\\$driver\\\\Driver\\\\Database\\\\$driver',"; $namespace_replace = "'namespace' => 'Drupal\\\\Core\\\\Database\\\\Driver\\\\$driver',"; $contents = str_replace($namespace_search, $namespace_replace, $contents); + + // Add a replica connection to the database settings. + $contents .= "\$databases['default']['replica'][] = array (\n"; + $contents .= " 'database' => 'dbtest',\n"; + $contents .= " 'username' => 'db',\n"; + $contents .= " 'password' => 'db',\n"; + $contents .= " 'prefix' => 'test22806835',\n"; + $contents .= " 'host' => 'db',\n"; + $contents .= " 'port' => 3306,\n"; + $contents .= " 'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',\n"; + $contents .= " 'driver' => 'mysql',\n"; + $contents .= ");\n"; + file_put_contents($filename, $contents); } @@ -56,4 +70,14 @@ public function testExistingDrupal8StyleDatabaseConnectionInSettingsPhp() { $this->assertStringNotContainsString("'autoload' => 'core/modules/$driver/src/Driver/Database/$driver/", $contents); } + /** + * Confirms that the replica database connection works. + */ + public function testReplicaDrupal8StyleDatabaseConnectionInSettingsPhp() { + $this->drupalLogin($this->drupalCreateUser()); + + $replica = Database::getConnection('replica', 'default'); + $this->assertInstanceOf(Connection::class, $replica); + } + }