You are here

function MonitoringCoreTest::testSensorEnabledModulesUI in Monitoring 7

Tests the UI/settings of the enabled modules sensor.

File

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

Class

MonitoringCoreTest
Tests for cron sensor.

Code

function testSensorEnabledModulesUI() {
  $account = $this
    ->drupalCreateUser(array(
    'administer monitoring',
  ));
  $this
    ->drupalLogin($account);
  $form_key = monitoring_sensor_settings_key('monitoring_enabled_modules');

  // Test submitting the defaults and enabling the sensor.
  $this
    ->drupalPost('admin/config/system/monitoring/sensors/monitoring_enabled_modules', array(
    $form_key . '[enabled]' => TRUE,
  ), t('Save'));

  // Reset the sensor info so that it reflects changes done via POST.
  $this->sensorManager
    ->resetCache();

  // The sensor should now be OK.
  $result = $this
    ->runSensor('monitoring_enabled_modules');
  $this
    ->assertTrue($result
    ->isOk());

  // Expect the contact and book modules to be installed.
  $this
    ->drupalPost('admin/config/system/monitoring/sensors/monitoring_enabled_modules', array(
    $form_key . '[modules][contact]' => TRUE,
    $form_key . '[modules][book]' => TRUE,
  ), t('Save'));

  // Reset the sensor info so that it reflects changes done via POST.
  $this->sensorManager
    ->resetCache();

  // The sensor should escalate to CRITICAL.
  $result = $this
    ->runSensor('monitoring_enabled_modules');
  $this
    ->assertTrue($result
    ->isCritical());
  $this
    ->assertEqual($result
    ->getMessage(), '2 modules delta, expected 0, Following modules are expected to be installed: Book (book), Contact (contact)');
  $this
    ->assertEqual($result
    ->getValue(), 2);

  // The default setting is not to allow additional modules. Enable comment
  // and the sensor should escalate to CRITICAL.
  $this
    ->drupalPost('admin/config/system/monitoring/sensors/monitoring_enabled_modules', array(
    // Do not require contact and book as they are not installed.
    $form_key . '[modules][contact]' => FALSE,
    $form_key . '[modules][book]' => FALSE,
  ), t('Save'));

  // Reset the sensor info so that it reflects changes done via POST.
  $this->sensorManager
    ->resetCache();
  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, the sensor should not escalate.
  $this
    ->drupalPost('admin/config/system/monitoring/sensors/monitoring_enabled_modules', array(
    // Do not require contact and book as they are not installed.
    $form_key . '[allow_additional]' => TRUE,
  ), t('Save'));
  $this->sensorManager
    ->resetCache();
  $result = $this
    ->runSensor('monitoring_enabled_modules');
  $this
    ->assertTrue($result
    ->isOk());
}