function DatabaseLoggingTestCase::testEnableTargetLoggingNoTarget
Test that logs to separate targets collapse to the same connection properly.
This test is identical to the one above, except that it doesn't create a fake target so the query should fall back to running on the default target.
File
-
modules/
simpletest/ tests/ database_test.test, line 3214
Class
- DatabaseLoggingTestCase
- Query logging tests.
Code
function testEnableTargetLoggingNoTarget() {
Database::startLog('testing1');
db_query('SELECT name FROM {test} WHERE age > :age', array(
':age' => 25,
))->fetchCol();
// We use "fake" here as a target because any non-existent target will do.
// However, because all of the tests in this class share a single page
// request there is likely to be a target of "slave" from one of the other
// unit tests, so we use a target here that we know with absolute certainty
// does not exist.
db_query('SELECT age FROM {test} WHERE name = :name', array(
':name' => 'Ringo',
), array(
'target' => 'fake',
))->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'], 'default', 'Second query used default target as fallback.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.