You are here

function LoggingTest::testEnableMultiConnectionLogging in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Database/LoggingTest.php \Drupal\system\Tests\Database\LoggingTest::testEnableMultiConnectionLogging()

Tests that we can log queries separately on different connections.

File

core/modules/system/src/Tests/Database/LoggingTest.php, line 110
Contains \Drupal\system\Tests\Database\LoggingTest.

Class

LoggingTest
Tests the query logging facility.

Namespace

Drupal\system\Tests\Database

Code

function testEnableMultiConnectionLogging() {

  // Clone the primary credentials to a fake connection.
  // That both connections point to the same physical database is irrelevant.
  $connection_info = Database::getConnectionInfo('default');
  Database::addConnectionInfo('test2', 'default', $connection_info['default']);
  Database::startLog('testing1');
  Database::startLog('testing1', 'test2');
  db_query('SELECT name FROM {test} WHERE age > :age', array(
    ':age' => 25,
  ))
    ->fetchCol();
  $old_key = db_set_active('test2');
  db_query('SELECT age FROM {test} WHERE name = :name', array(
    ':name' => 'Ringo',
  ), array(
    'target' => 'replica',
  ))
    ->fetchCol();
  db_set_active($old_key);
  $queries1 = Database::getLog('testing1');
  $queries2 = Database::getLog('testing1', 'test2');
  $this
    ->assertEqual(count($queries1), 1, 'Correct number of queries recorded for first connection.');
  $this
    ->assertEqual(count($queries2), 1, 'Correct number of queries recorded for second connection.');
}