You are here

public function MonitoringCoreKernelTest::testStateValueSensorPluginMaintenanceMode in Monitoring 8

Tests maintenance mode sensor.

See also

\Drupal\monitoring\Plugin\monitoring\SensorPlugin\StateValueSensorPlugin

File

tests/src/Kernel/MonitoringCoreKernelTest.php, line 122

Class

MonitoringCoreKernelTest
Kernel tests for the core pieces of monitoring.

Namespace

Drupal\Tests\monitoring\Kernel

Code

public function testStateValueSensorPluginMaintenanceMode() {

  // Run sensor, all is OK.
  $result = $this
    ->runSensor('core_maintenance_mode');
  $this
    ->assertTrue($result
    ->isOk());

  // Enable maintenance mode and run sensor.
  \Drupal::state()
    ->set('system.maintenance_mode', TRUE);
  $result = $this
    ->runSensor('core_maintenance_mode');
  $this
    ->assertTrue($result
    ->isCritical());

  // Switch out of maintenance mode to continue regularly.
  \Drupal::state()
    ->set('system.maintenance_mode', FALSE);
  $this
    ->assertEqual($result
    ->getMessage(), 'TRUE, expected FALSE');
}