You are here

public function ConnectionTest::testPerTablePrefixOption in Drupal 9

Same name and namespace in other branches
  1. 10 core/tests/Drupal/KernelTests/Core/Database/ConnectionTest.php \Drupal\KernelTests\Core\Database\ConnectionTest::testPerTablePrefixOption()

Tests per-table prefix connection option.

File

core/tests/Drupal/KernelTests/Core/Database/ConnectionTest.php, line 171

Class

ConnectionTest
Tests of the core database system.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testPerTablePrefixOption() {
  $connection_info = Database::getConnectionInfo('default');
  $new_connection_info = $connection_info['default'];
  $new_connection_info['prefix'] = [
    'default' => $connection_info['default']['prefix'],
    'test_table' => $connection_info['default']['prefix'] . '_bar',
  ];
  Database::addConnectionInfo('default', 'foo', $new_connection_info);
  $foo_connection = Database::getConnection('foo', 'default');
  $this
    ->assertInstanceOf(Connection::class, $foo_connection);
  $this
    ->assertIsString($foo_connection
    ->getConnectionOptions()['prefix']);
  $this
    ->assertSame($connection_info['default']['prefix'], $foo_connection
    ->getConnectionOptions()['prefix']);
  $this
    ->assertSame([
    'test_table' => $connection_info['default']['prefix'] . '_bar',
  ], $foo_connection
    ->getConnectionOptions()['extra_prefix']);
}