You are here

public function MonitoringUITest::testForceExecute in Monitoring 8

Tests the force execute all and sensor specific force execute links.

File

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

Class

MonitoringUITest
Tests for the Monitoring UI.

Namespace

Drupal\Tests\monitoring\Functional

Code

public function testForceExecute() {
  $account = $this
    ->drupalCreateUser(array(
    'monitoring force run',
    'monitoring reports',
  ));
  $this
    ->drupalLogin($account);

  // Set a specific test sensor result to look for.
  $test_sensor_result_data = array(
    'sensor_message' => 'First message',
  );
  \Drupal::state()
    ->set('monitoring_test.sensor_result_data', $test_sensor_result_data);
  $this
    ->drupalGet('admin/reports/monitoring');
  $this
    ->assertText('First message');

  // Update the sensor message.
  $test_sensor_result_data['sensor_message'] = 'Second message';
  \Drupal::state()
    ->set('monitoring_test.sensor_result_data', $test_sensor_result_data);

  // Access the page again, we should still see the first message because the
  // cached result is returned.
  $this
    ->drupalGet('admin/reports/monitoring');
  $this
    ->assertText('First message');

  // Force sensor execution, the changed message should be displayed now.
  $this
    ->clickLink(t('Force execute all'));
  $this
    ->assertNoText('First message');
  $this
    ->assertText('Second message');

  // Update the sensor message again.
  $test_sensor_result_data['sensor_message'] = 'Third message';
  \Drupal::state()
    ->set('monitoring_test.sensor_result_data', $test_sensor_result_data);

  // Simulate a click on Force execution, there are many of those so we just
  // verify that such links exist and visit the path manually.
  $this
    ->assertLink(t('Force execution'));
  $this
    ->drupalGet('monitoring/sensors/force/test_sensor');
  $this
    ->assertNoText('Second message');
  $this
    ->assertText('Third message');
}