You are here

monitoring_munin.test in Monitoring 7

Monitoring munin tests.

File

modules/monitoring_munin/monitoring_munin.test
View source
<?php

/**
 * @file
 * Monitoring munin tests.
 */

/**
 * Class MonitoringAPITest
 */
class MonitoringMuninTest extends MonitoringTestBase {

  /**
   * {@inheritdoc}
   */
  public static function getInfo() {
    return array(
      'name' => 'Monitoring Munin',
      'description' => 'Monitoring Munin tests.',
      'group' => 'Monitoring',
    );
  }

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    parent::setUp(array(
      'dblog',
    ));

    // @todo Enable monitoring_munin separately, otherwise the class autoloading
    //   does not work.
    module_enable(array(
      'monitoring_munin',
    ));
  }

  /**
   * Tests the multigraph API/CRUD
   */
  function testMultigraphsAPI() {

    // Test adding a multigraph.
    monitoring_munin_multigraph_save('test multigraph', 'test unit');
    $multigraphs = monitoring_munin_multigraphs();
    $this
      ->assertEqual($multigraphs['test multigraph']['title'], 'test multigraph');
    $this
      ->assertEqual($multigraphs['test multigraph']['vlabel'], 'test unit');

    // Add multigraph to a sensor.
    $settings = monitoring_sensor_settings_get('dblog_404');
    $settings['munin']['multigraphs'][] = 'test multigraph';
    monitoring_sensor_settings_save('dblog_404', $settings);

    // Deleting the multigraph must remove it form sensors settings as well.
    monitoring_munin_multigraph_delete('test multigraph');
    monitoring_sensor_manager()
      ->resetCache();
    $info = $this->sensorManager
      ->getSensorInfoByName('dblog_404');
    $munin_settings = $info
      ->getSetting('munin');
    $this
      ->assertTrue(!in_array('test multigraph', $munin_settings['multigraphs']));
  }

  /**
   * Tests Munin default settings enabled after module installation.
   */
  function testMultigraphsDefaultSettings() {

    // When enabled we should have Watchdog and User activity multigraphs
    // created.
    $multigraphs = monitoring_munin_multigraphs();
    $this
      ->assertEqual($multigraphs, array(
      'Watchdog' => array(
        'title' => 'Watchdog',
        'vlabel' => 'Watchdog items',
      ),
      'User activity' => array(
        'title' => 'User activity',
        'vlabel' => 'Users',
      ),
    ));
    foreach (monitoring_sensor_info_by_categories() as $category => $sensors) {
      if (!isset($multigraphs[$category])) {
        continue;
      }

      /** @var \Drupal\monitoring\Sensor\SensorInfo $sensor */
      foreach ($sensors as $sensor) {
        $munin_settings = $sensor
          ->getSetting('munin');
        $this
          ->assertTrue($munin_settings['munin_enabled']);
        $this
          ->assertEqual($munin_settings['multigraphs'], array(
          $category,
        ));
      }
    }
  }

}

Classes

Namesort descending Description
MonitoringMuninTest Class MonitoringAPITest