You are here

protected function MonitoringUITest::doTestFallsThresholdSettings in Monitoring 8

Tests falls threshold settings UI and validation.

1 call to MonitoringUITest::doTestFallsThresholdSettings()
MonitoringUITest::testSensorSettingsUI in tests/src/Functional/MonitoringUITest.php
Test the sensor settings UI.

File

tests/src/Functional/MonitoringUITest.php, line 790

Class

MonitoringUITest
Tests for the Monitoring UI.

Namespace

Drupal\Tests\monitoring\Functional

Code

protected function doTestFallsThresholdSettings() {

  // Test with valid values.
  $thresholds = array(
    'critical' => 6,
    'warning' => 11,
  );
  $this
    ->submitThresholdSettings('test_sensor_falls', $thresholds);
  $this
    ->assertText(new FormattableMarkup('Sensor @label saved.', array(
    '@label' => 'Test sensor falls',
  )));
  $this
    ->assertThresholdSettingsUIDefaults('test_sensor_falls', $thresholds);

  // Make sure that it is possible to save empty thresholds.
  $thresholds = array(
    'critical' => '',
    'warning' => '',
  );
  $this
    ->submitThresholdSettings('test_sensor_falls', $thresholds);
  $this
    ->assertText(new FormattableMarkup('Sensor @label saved.', array(
    '@label' => 'Test sensor falls',
  )));
  $this
    ->assertThresholdSettingsUIDefaults('test_sensor_falls', $thresholds);

  // Test validation.
  $thresholds = array(
    'critical' => 50,
    'warning' => 45,
  );
  $this
    ->submitThresholdSettings('test_sensor_falls', $thresholds);
  $this
    ->assertText('Warning must be higher than critical or empty.');
  $thresholds = array(
    'critical' => 5,
    'warning' => 5,
  );
  $this
    ->submitThresholdSettings('test_sensor_falls', $thresholds);
  $this
    ->assertText('Warning must be higher than critical or empty.');
  $thresholds = array(
    'critical' => 'alphanumeric',
    'warning' => 'alphanumeric',
  );
  $this
    ->submitThresholdSettings('test_sensor_falls', $thresholds);
  $this
    ->assertText('Warning must be a number.');
  $this
    ->assertText('Critical must be a number.');

  // Test threshold fall with zero values for critical.
  $thresholds = [
    'critical' => 0,
    'warning' => '',
  ];
  $this
    ->submitThresholdSettings('test_sensor_falls', $thresholds);
  $test_sensor_result_data = [
    'sensor_value' => -7,
  ];
  \Drupal::state()
    ->set('monitoring_test.sensor_result_data', $test_sensor_result_data);
  $result = $this
    ->runSensor('test_sensor_falls');
  $this
    ->assertTrue($result
    ->isCritical());
  $test_sensor_result_data = [
    'sensor_value' => 0,
  ];
  \Drupal::state()
    ->set('monitoring_test.sensor_result_data', $test_sensor_result_data);
  $result = $this
    ->runSensor('test_sensor_falls');
  $this
    ->assertTrue($result
    ->isOk());

  // Test threshold fall with zero values for warning.
  $thresholds = [
    'critical' => '',
    'warning' => 0,
  ];
  $this
    ->submitThresholdSettings('test_sensor_falls', $thresholds);
  $test_sensor_result_data = [
    'sensor_value' => -7,
  ];
  \Drupal::state()
    ->set('monitoring_test.sensor_result_data', $test_sensor_result_data);
  $result = $this
    ->runSensor('test_sensor_falls');
  $this
    ->assertTrue($result
    ->isWarning());
  $test_sensor_result_data = [
    'sensor_value' => 0,
  ];
  \Drupal::state()
    ->set('monitoring_test.sensor_result_data', $test_sensor_result_data);
  $result = $this
    ->runSensor('test_sensor_falls');
  $this
    ->assertTrue($result
    ->isOk());
  return $thresholds;
}