protected function MongoDBLogTestCase::ZtestDBLogAddAndClear in MongoDB 8
Same name and namespace in other branches
- 7 mongodb_watchdog/mongodb_watchdog.test \MongoDBLogTestCase::ztestDbLogAddAndClear()
 
Login an admin user, create dblog event, and test clearing dblog functionality through the admin interface.
File
- mongodb_watchdog/
mongodb_watchdog.test, line 521  - Test class for MongoDB_watchdog.
 
Class
- MongoDBLogTestCase
 - Test the behaviour of watchdog() mongodb_watchdog, not dblog
 
Code
protected function ZtestDBLogAddAndClear() {
  global $base_root;
  // Get a count of how many watchdog entries there are.
  $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,
    'request_uri' => $base_root . request_uri(),
    'referer' => $_SERVER['HTTP_REFERER'],
    'ip' => ip_address(),
    'timestamp' => $this->request_time,
  );
  // Add a watchdog entry.
  dblog_watchdog($log);
  // Make sure the table count has actually incremented.
  $this
    ->assertEqual($count + 1, db_query('SELECT COUNT(*) FROM {watchdog}')
    ->fetchField(), t('dblog_watchdog() added an entry to the dblog :count', array(
    ':count' => $count,
  )));
  // Login the admin user.
  $this
    ->drupalLogin($this->big_user);
  // Now post to clear the db table.
  $this
    ->drupalPost('admin/reports/dblog', array(), t('Clear log messages'));
  // Count rows in watchdog that previously related to the deleted user.
  $count = db_query('SELECT COUNT(*) FROM {watchdog}')
    ->fetchField();
  $this
    ->assertEqual($count, 0, t('DBLog contains :count records after a clear.', array(
    ':count' => $count,
  )));
}