1 dblog.test protected DBLogTestCase::testDBLogAddAndClear()

Tests the addition and clearing of log events through the admin interface.

Logs in the admin user, creates a database log event, and tests the functionality of clearing the database log through the admin interface.


core/modules/dblog/tests/dblog.test, line 433
Tests for dblog.module.


Tests logging messages to the database.


protected function testDBLogAddAndClear() {
  global $base_root;
  // Get a count of how many watchdog entries already exist.
  $count = db_query('SELECT COUNT(*) FROM {watchdog}')->fetchField();
  $log = array(
    'type' => 'custom',
    'message' => 'Log entry added to test the doClearTest clear down.',
    'variables' => array(),
    'severity' => WATCHDOG_NOTICE,
    'link' => NULL,
    'user' => $this->big_user,
    'uid' => isset($this->big_user->uid) ? $this->big_user->uid : 0,
    'request_uri' => $base_root . request_uri(),
    'referer' => $_SERVER['HTTP_REFERER'],
    'ip' => ip_address(),
    'timestamp' => REQUEST_TIME,
  // Add a watchdog entry.
  // Make sure the table count has actually been incremented.
  $this->assertEqual($count + 1, db_query('SELECT COUNT(*) FROM {watchdog}')->fetchField(), format_string('dblog_watchdog() added an entry to the dblog :count', array(':count' => $count)));
  // Login the admin user.
  // Post in order to clear the database table.
  $this->backdropPost('admin/reports/dblog', array(), t('Clear log messages'));
  // Count the rows in watchdog that previously related to the deleted user.
  $count = db_query('SELECT COUNT(*) FROM {watchdog}')->fetchField();
  $this->assertEqual($count, 0, format_string('DBLog contains :count records after a clear.', array(':count' => $count)));