You are here

function MonitoringCoreTest::testSensorEnabledModulesAPI in Monitoring 7

Test cases for SensorEnabledModules sensor.

We use separate test method as we need to enable/disable modules.

File

test/tests/monitoring.core.test, line 509
Contains \MonitoringCoreTest.

Class

MonitoringCoreTest
Tests for cron sensor.

Code

function testSensorEnabledModulesAPI() {

  // The initial run of the sensor will acknowledge all installed modules as
  // expected and so the status should be OK.
  $result = $this
    ->runSensor('monitoring_enabled_modules');
  $this
    ->assertTrue($result
    ->isOk());

  // Install additional module. As the setting "allow_additional" is not
  // enabled by default this should result in sensor escalation to critical.
  module_enable(array(
    'comment',
  ));
  $result = $this
    ->runSensor('monitoring_enabled_modules');
  $this
    ->assertTrue($result
    ->isCritical());
  $this
    ->assertEqual($result
    ->getMessage(), '1 modules delta, expected 0, Following modules are NOT expected to be installed: Comment (comment)');
  $this
    ->assertEqual($result
    ->getValue(), 1);

  // Allow additional modules and run the sensor - it should not escalate now.
  $settings = monitoring_sensor_settings_get('monitoring_enabled_modules');
  $settings['allow_additional'] = TRUE;
  monitoring_sensor_settings_save('monitoring_enabled_modules', $settings);
  $result = $this
    ->runSensor('monitoring_enabled_modules');
  $this
    ->assertTrue($result
    ->isOk());

  // Add comment module to be expected and disable the module. The sensor
  // should escalate to critical.
  $settings = monitoring_sensor_settings_get('monitoring_enabled_modules');
  $settings['modules']['comment'] = 'comment';
  monitoring_sensor_settings_save('monitoring_enabled_modules', $settings);
  module_disable(array(
    'comment',
  ));
  $result = $this
    ->runSensor('monitoring_enabled_modules');
  $this
    ->assertTrue($result
    ->isCritical());
  $this
    ->assertEqual($result
    ->getMessage(), '1 modules delta, expected 0, Following modules are expected to be installed: Comment (comment)');
  $this
    ->assertEqual($result
    ->getValue(), 1);
}