function InstallerIsolationLevelNoDatabaseSettingsTest::testInstaller

Same name in other branches
  1. 10 core/modules/mysql/tests/src/Functional/InstallerIsolationLevelNoDatabaseSettingsTest.php \Drupal\Tests\mysql\Functional\InstallerIsolationLevelNoDatabaseSettingsTest::testInstaller()

Verifies that the isolation_level was added to the database settings.

File

core/modules/mysql/tests/src/Functional/InstallerIsolationLevelNoDatabaseSettingsTest.php, line 38

Class

InstallerIsolationLevelNoDatabaseSettingsTest
Tests the isolation_level setting with no database settings.

Namespace

Drupal\Tests\mysql\Functional

Code

public function testInstaller() : void {
    $contents = file_get_contents($this->container
        ->getParameter('app.root') . '/' . $this->siteDirectory . '/settings.php');
    // Test that isolation_level was set to "READ COMMITTED".
    $this->assertStringContainsString("'isolation_level' => 'READ COMMITTED',", $contents);
    // Change the default database connection to use the isolation level from
    // the test.
    $connection_info = Database::getConnectionInfo();
    $driver_test_connection = $connection_info['default'];
    // We have asserted that the isolation level was set to 'READ COMMITTED'.
    $driver_test_connection['isolation_level'] = 'READ COMMITTED';
    unset($driver_test_connection['init_commands']);
    Database::renameConnection('default', 'original_database_connection');
    Database::addConnectionInfo('default', 'default', $driver_test_connection);
    // Close and reopen the database connection, so the database init commands
    // get executed.
    Database::closeConnection('default', 'default');
    $connection = Database::getConnection('default', 'default');
    $query = $connection->isMariaDb() ? 'SELECT @@SESSION.tx_isolation' : 'SELECT @@SESSION.transaction_isolation';
    // Test that transaction level is READ-COMMITTED.
    $this->assertEquals('READ-COMMITTED', $connection->query($query)
        ->fetchField());
    // Restore the old database connection.
    Database::addConnectionInfo('default', 'default', $connection_info['default']);
    Database::closeConnection('default', 'default');
    Database::getConnection('default', 'default');
}

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