You are here

public function MonitoringUITest::testCoreRequirementsSensorUI in Monitoring 8

Tests the UI of the requirements sensor.

File

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

Class

MonitoringUITest
Tests for the Monitoring UI.

Namespace

Drupal\Tests\monitoring\Functional

Code

public function testCoreRequirementsSensorUI() {
  $account = $this
    ->drupalCreateUser(array(
    'administer monitoring',
  ));
  $this
    ->drupalLogin($account);
  $this
    ->drupalGet('admin/reports/monitoring/sensors/core_requirements_system');
  $this
    ->assertNoText('Array');
  $this
    ->assertText('Run cron');
  $this
    ->assertText('more information');
  $this
    ->drupalGet('admin/config/system/monitoring/sensors/core_requirements_system');

  // Verify the current keys to exclude.
  $this
    ->assertText('cron');

  // Change the excluded keys.
  $this
    ->drupalPostForm(NULL, array(
    'settings[exclude_keys]' => 'requirement_excluded',
  ), t('Save'));
  $this
    ->assertText(new FormattableMarkup('Sensor @label saved.', array(
    '@label' => 'Module system',
  )));
  $this
    ->drupalGet('admin/config/system/monitoring/sensors/core_requirements_system');

  // Verify the change in excluded keys.
  $this
    ->assertText('requirement_excluded');
  $this
    ->assertNoText('cron');

  // Test the 'Ignore' link to exclude a required sensor key.
  $this
    ->drupalGet('admin/reports/monitoring/sensors/core_requirements_system');
  $this
    ->assertFieldByXPath('//div/table/tbody/tr[1]/td[2]', '');
  $this
    ->clickLink(t('Ignore'), 0);

  // Assert drupal_set_message for successful excluded sensor key.
  $this
    ->assertText(t('Added the sensor @label (@key) into the excluded list.', array(
    '@label' => 'Module system',
    '@key' => 'drupal',
  )));
  $this
    ->assertFieldByXPath('//div/table/tbody/tr[1]/td[2]', 'Yes');

  // Verify the current keys to exclude.
  $this
    ->drupalGet('admin/config/system/monitoring/sensors/core_requirements_system');
  $sensor_config = SensorConfig::load('core_requirements_system');
  $this
    ->assertTrue(in_array('drupal', $sensor_config->settings['exclude_keys']));

  // Test the 'Unignore' link to re-include a required sensor key.
  $this
    ->drupalGet('admin/reports/monitoring/sensors/core_requirements_system');
  $this
    ->drupalPostForm(NULL, array(), 'Run now');
  $this
    ->assertFieldByXPath('//div/table/tbody/tr[1]/td[2]', 'Yes');
  $this
    ->clickLink(t('Unignore'), 0);

  // Assert drupal_set_message for successful re-included sensor key.
  $this
    ->assertText(t('Removed the sensor @label (@key) from the excluded list.', array(
    '@label' => 'Module system',
    '@key' => 'drupal',
  )));
  $this
    ->assertFieldByXPath('//div/table/tbody/tr[1]/td[2]', '');

  // Verify the current keys to exclude.
  $this
    ->drupalGet('admin/config/system/monitoring/sensors/core_requirements_system');
  $sensor_config = SensorConfig::load('core_requirements_system');
  $this
    ->assertFalse(in_array('drupal', $sensor_config->settings['exclude_keys']));
}