You are here

protected function MonitoringUITest::doTestInnerThresholdSettings in Monitoring 8

Tests inner threshold settings UI and validation.

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

File

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

Class

MonitoringUITest
Tests for the Monitoring UI.

Namespace

Drupal\Tests\monitoring\Functional

Code

protected function doTestInnerThresholdSettings() {

  // Test with valid values.
  $thresholds = array(
    'critical_low' => 5,
    'warning_low' => 1,
    'critical_high' => 10,
    'warning_high' => 15,
  );
  $this
    ->submitThresholdSettings('test_sensor_inner', $thresholds);
  $this
    ->assertText(new FormattableMarkup('Sensor @label saved.', array(
    '@label' => 'Test sensor inner',
  )));
  $this
    ->assertThresholdSettingsUIDefaults('test_sensor_inner', $thresholds);

  // Make sure that it is possible to save empty inner thresholds.
  $thresholds = array(
    'critical_low' => '',
    'warning_low' => '',
    'critical_high' => '',
    'warning_high' => '',
  );
  $this
    ->submitThresholdSettings('test_sensor_inner', $thresholds);
  $this
    ->assertText(new FormattableMarkup('Sensor @label saved.', array(
    '@label' => 'Test sensor inner',
  )));
  $this
    ->assertThresholdSettingsUIDefaults('test_sensor_inner', $thresholds);

  // Test validation.
  $thresholds = array(
    'critical_low' => 5,
    'warning_low' => 15,
    'critical_high' => 10,
    'warning_high' => 20,
  );
  $this
    ->submitThresholdSettings('test_sensor_inner', $thresholds);
  $this
    ->assertText('Warning low must be lower than critical low or empty.');
  $thresholds = array(
    'critical_low' => 5,
    'warning_low' => 5,
    'critical_high' => 5,
    'warning_high' => 5,
  );
  $this
    ->submitThresholdSettings('test_sensor_inner', $thresholds);
  $this
    ->assertText('Warning low must be lower than warning high or empty.');
  $thresholds = array(
    'critical_low' => 50,
    'warning_low' => 95,
    'critical_high' => 55,
    'warning_high' => 100,
  );
  $this
    ->submitThresholdSettings('test_sensor_inner', $thresholds);
  $this
    ->assertText('Warning low must be lower than critical low or empty.');
  $thresholds = array(
    'critical_low' => 'alphanumeric',
    'warning_low' => 'alphanumeric',
    'critical_high' => 'alphanumeric',
    'warning_high' => 'alphanumeric',
  );
  $this
    ->submitThresholdSettings('test_sensor_inner', $thresholds);
  $this
    ->assertText('Warning low must be a number.');
  $this
    ->assertText('Warning high must be a number.');
  $this
    ->assertText('Critical low must be a number.');
  $this
    ->assertText('Critical high must be a number.');
  $thresholds = array(
    'critical_low' => 45,
    'warning_low' => 35,
    'critical_high' => 50,
    'warning_high' => 40,
  );
  $this
    ->submitThresholdSettings('test_sensor_inner', $thresholds);
  $this
    ->assertText('Warning high must be higher than critical high or empty.');
  return $thresholds;
}