You are here

public function MongoDBLogTestCase::testWatchdogLimit in MongoDB 6

Same name and namespace in other branches
  1. 8 mongodb_watchdog/mongodb_watchdog.test \MongoDBLogTestCase::testWatchdogLimit()
  2. 7 mongodb_watchdog/mongodb_watchdog.test \MongoDBLogTestCase::testWatchdogLimit()

Test the default and non-default mongodb_watchdog insertion behaviours.

Make sure the module applies the watchdog_limit variable,

File

mongodb_watchdog/mongodb_watchdog.test, line 184
Test class for MongoDB_watchdog.

Class

MongoDBLogTestCase
Test the behaviour of watchdog() mongodb_watchdog, not dblog.

Code

public function testWatchdogLimit() {

  // Bypass test if testing system does not have a MongoDB connection.
  if (!$this
    ->checkCollection()) {
    return;
  }

  // Default limit should be WATCHDOG_DEBUG
  $this->group = t('Defaults');
  $this
    ->assertEqual(variable_get(self::LIMIT_VARIABLE, WATCHDOG_DEBUG), WATCHDOG_DEBUG, t('%name defaults to WATCHDOG_DEBUG', array(
    '%name' => self::LIMIT_VARIABLE,
  )), $this->group);

  // Test at this default level.
  $message = $this
    ->randomString(32);
  $this
    ->pass(t('Logging %message', array(
    '%message' => $message,
  )), $this->group);
  watchdog(self::MODULE, $message, array(), WATCHDOG_DEBUG);
  $this
    ->assertEntry($message);

  // Now request a higher level: unimportant events should be ignored...
  $this->group = t('Ignoring');
  variable_set(self::LIMIT_VARIABLE, WATCHDOG_NOTICE);
  $message = $this
    ->randomString(32);
  $this
    ->pass(t('Logging %message', array(
    '%message' => $message,
  )), $this->group);
  watchdog(self::MODULE, $message, array(), WATCHDOG_DEBUG);
  $this
    ->assertNoEntry($message);

  // ... but events at the limit or more important should be logged.
  $this->group = t('Logging');
  $message = $this
    ->randomString(32);
  $this
    ->pass(t('Logging %message', array(
    '%message' => $message,
  )), $this->group);
  watchdog(self::MODULE, $message, array(), WATCHDOG_NOTICE);
  $this
    ->assertEntry($message);
  $message = $this
    ->randomString(32);
  $this
    ->pass(t('Logging %message', array(
    '%message' => $message,
  )), $this->group);
  watchdog(self::MODULE, $message, array(), WATCHDOG_ERROR);
  $this
    ->assertEntry($message);
}