You are here

public function MonitoringCoreWebTest::testSensorInstalledModulesAPI in Monitoring 8

Tests enabled modules sensor.

We use separate test method as we need to install/uninstall modules.

See also

\Drupal\monitoring\Plugin\monitoring\SensorPlugin\EnabledModulesSensorPlugin

File

tests/src/Functional/MonitoringCoreWebTest.php, line 516

Class

MonitoringCoreWebTest
Integration tests for the core pieces of monitoring.

Namespace

Drupal\Tests\monitoring\Functional

Code

public function testSensorInstalledModulesAPI() {

  // The initial run of the sensor will acknowledge all installed modules as
  // expected and so the status should be OK.
  $result = $this
    ->runSensor('monitoring_installed_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.
  $this
    ->installModules(array(
    'contact',
  ));
  $result = $this
    ->runSensor('monitoring_installed_modules');
  $this
    ->assertTrue($result
    ->isCritical());
  $this
    ->assertEqual($result
    ->getMessage(), '1 modules delta, expected 0, Following modules are NOT expected to be installed: Contact (contact)');
  $this
    ->assertEqual($result
    ->getValue(), 1);

  // Allow additional modules and run the sensor - it should not escalate now.
  $sensor_config = SensorConfig::load('monitoring_installed_modules');
  $sensor_config->settings['allow_additional'] = TRUE;
  $sensor_config
    ->save();
  $result = $this
    ->runSensor('monitoring_installed_modules');
  $this
    ->assertTrue($result
    ->isOk());

  // Install comment module to be expected and uninstall the module again.
  // The sensor should escalate to critical.
  $sensor_config->settings['modules']['contact'] = 'contact';
  $sensor_config
    ->save();
  $this
    ->uninstallModules(array(
    'contact',
  ));
  $result = $this
    ->runSensor('monitoring_installed_modules');
  $this
    ->assertTrue($result
    ->isCritical());
  $this
    ->assertEqual($result
    ->getMessage(), '1 modules delta, expected 0, Following modules are expected to be installed: Contact (contact)');
  $this
    ->assertEqual($result
    ->getValue(), 1);
}