You are here

cleaner_watchdog.test in Cleaner 7

Test Clearing Watchdog logs.

File

tests/cleaner_watchdog.test
View source
<?php

/**
 * @file
 * Test Clearing Watchdog logs.
 */

/**
 * Class CleanerTestWatchdogClearing.
 *
 * Check is the Watchdog logs are successfully cleared.
 */
class CleanerTestWatchdogClearing extends CleanerTestBase {

  /**
   * Setting a test info.
   *
   * @return array
   *   An array with an info data.
   */
  public static function getInfo() {
    return array(
      'name' => 'Cleaner test clearing Watchdog.',
      'description' => 'Check is the Watchdog logs are successfully cleared.',
      'group' => 'Cleaner',
    );
  }

  /**
   * Required setup processes before run a tests.
   */
  public function setUp() {
    parent::cleanerAdminSetUp();
  }

  /**
   * Test clearing Watchdog logs.
   */
  public function testWatchdogClearing() {

    // Prepare a Cleaner settings.
    $settings = array(
      'cleaner_empty_watchdog' => 1,
    );
    $this
      ->cleanerSettings($settings);

    // Generate a dummy watchdog logs.
    for ($i = 0; $i <= 10; $i++) {
      watchdog('Cleaner', $this
        ->randomString());
    }

    // Check if dummy logs has been generated.
    $this
      ->assertTrue(self::getWatchdogsCount() >= 10, 'Dummy logs has been generated.');

    // Run cleaner.
    $this
      ->cleanerExecute();

    // Check is watchdog logs has been cleared.
    $this
      ->assertTrue(self::getWatchdogsCount() <= 1, 'Logs has been cleared.');
  }

  /**
   * Get count of watchdog's rows.
   *
   * @return int
   *   Count of watchdog's rows.
   */
  protected static function getWatchdogsCount() {
    return db_query("SELECT COUNT(*) FROM {watchdog}")
      ->fetchField();
  }

}

Classes

Namesort descending Description
CleanerTestWatchdogClearing Class CleanerTestWatchdogClearing.