function DatabaseLoggingTestCase::testEnableTargetLogging

Test that we can log queries against multiple targets on the same connection.

File

modules/simpletest/tests/database_test.test, line 3188

Class

DatabaseLoggingTestCase
Query logging tests.

Code

function testEnableTargetLogging() {
    // Clone the master credentials to a slave connection and to another fake
    // connection.
    $connection_info = Database::getConnectionInfo('default');
    Database::addConnectionInfo('default', 'slave', $connection_info['default']);
    Database::startLog('testing1');
    db_query('SELECT name FROM {test} WHERE age > :age', array(
        ':age' => 25,
    ))->fetchCol();
    db_query('SELECT age FROM {test} WHERE name = :name', array(
        ':name' => 'Ringo',
    ), array(
        'target' => 'slave',
    ));
    
    //->fetchCol();
    $queries1 = Database::getLog('testing1');
    $this->assertEqual(count($queries1), 2, 'Recorded queries from all targets.');
    $this->assertEqual($queries1[0]['target'], 'default', 'First query used default target.');
    $this->assertEqual($queries1[1]['target'], 'slave', 'Second query used slave target.');
}

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