You are here

public function MonitoringRebuildTest::testRebuildNonAddable in Monitoring 8

Tests creating non-addable sensors.

See also

\Drupal\monitoring\Controller\RebuildSensorList::rebuild()

File

tests/src/Functional/MonitoringRebuildTest.php, line 26

Class

MonitoringRebuildTest
Tests the updating of the sensor list.

Namespace

Drupal\Tests\monitoring\Functional

Code

public function testRebuildNonAddable() {

  // Create and login user with permission to view monitoring reports.
  $test_user = $this
    ->drupalCreateUser([
    'monitoring reports',
    'administer monitoring',
  ]);
  $this
    ->drupalLogin($test_user);

  // Delete sensors from install and optional directory.
  SensorConfig::load('twig_debug_mode')
    ->delete();
  SensorConfig::load('ultimate_cron_errors')
    ->delete();
  SensorConfig::load('update_core')
    ->delete();
  $sensor = SensorConfig::load('core_requirements_monitoring_test');
  $this
    ->assertNotNull($sensor);
  $result = $this
    ->runSensor('core_requirements_monitoring_test');
  $this
    ->assertTrue($result
    ->isOk());
  $result = $this
    ->runSensor('monitoring_disappeared_sensors');
  $this
    ->assertTrue($result
    ->isOk());

  // Disable the requirements hook.
  \Drupal::state()
    ->set('monitoring_test_requirements_enabled', FALSE);

  // Rebuild and make sure they are created again.
  $this
    ->drupalGet('/admin/config/system/monitoring/sensors');
  $this
    ->clickLink('Rebuild sensor list');
  $this
    ->assertText('The sensor Ultimate cron errors has been created.');
  $this
    ->assertText('The sensor Twig debug mode has been created.');
  $this
    ->assertNotNull(SensorConfig::load('twig_debug_mode'));
  $this
    ->assertNotNull(SensorConfig::load('ultimate_cron_errors'));
  $this
    ->assertNotNull(SensorConfig::load('update_core'));

  // Make sure the requirements sensor was removed
  $this
    ->assertNull(SensorConfig::load('core_requirements_monitoring_test'));
  $result = $this
    ->runSensor('monitoring_disappeared_sensors');
  $this
    ->assertTrue($result
    ->isOk());
}