1 database_test.test DatabaseLoggingTestCase::testEnableLogging()

Test that we can log the existence of a query.

File

core/modules/simpletest/tests/database_test.test, line 2843
Database tests.

Class

DatabaseLoggingTestCase
Query logging tests.

Code

function testEnableLogging() {
  $log = Database::startLog('testing');

  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'))->fetchCol();

  // Trigger a call that does not have file in the backtrace.
  call_user_func_array('db_query', array('SELECT age FROM {test} WHERE name = :name', array(':name' => 'Ringo')))->fetchCol();

  $queries = Database::getLog('testing', 'default');

  $this->assertEqual(count($queries), 3, 'Correct number of queries recorded.');

  foreach ($queries as $query) {
    $this->assertEqual($query['caller']['function'], __FUNCTION__, 'Correct function in query log.');
  }
}