You are here

class MonitoringUITest in Monitoring 8

Tests for the Monitoring UI.

@group monitoring

Hierarchy

Expanded class hierarchy of MonitoringUITest

File

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

Namespace

Drupal\Tests\monitoring\Functional
View source
class MonitoringUITest extends MonitoringTestBase {
  public static $modules = array(
    'dblog',
    'node',
    'views',
    'file',
    'automated_cron',
  );

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();

    // Create the content type page in the setup as it is used by several tests.
    $this
      ->drupalCreateContentType(array(
      'type' => 'page',
    ));
  }

  /**
   * Test the monitoring settings UI.
   */
  public function testSettingsUI() {

    // Create a test user and log in.
    $account = $this
      ->drupalCreateUser(array(
      'access administration pages',
      'administer monitoring',
    ));
    $this
      ->drupalLogin($account);

    // Check the form.
    $this
      ->drupalGet('admin/config/system');
    $this
      ->assertText(t('Configure enabled monitoring products.'));
    $this
      ->clickLink(t('Monitoring settings'));
    $this
      ->assertField('sensor_call_logging');
    $this
      ->assertOptionSelected('edit-sensor-call-logging', 'on_request');
    $this
      ->assertText(t('Control local logging of sensor call results.'));
  }

  /**
   * Test the sensor settings UI.
   */
  public function testSensorSettingsUI() {
    $account = $this
      ->drupalCreateUser(array(
      'administer monitoring',
    ));
    $this
      ->drupalLogin($account);

    // The separate threshold settings tests have been split into separate
    // methods for better separation.
    $this
      ->doTestExceedsThresholdSettings();
    $this
      ->doTestFallsThresholdSettings();
    $this
      ->doTestInnerThresholdSettings();
    $this
      ->doTestOuterThresholdSettings();

    // Test that trying to access the sensors settings page of a non-existing
    // sensor results in a page not found response.
    $this
      ->drupalGet('admin/config/system/monitoring/sensors/non_existing_sensor');
    $this
      ->assertResponse(404);

    // Tests the fields 'Sensor Plugin' & 'Entity Type' appear.
    $this
      ->drupalGet('admin/config/system/monitoring/sensors/user_new');
    $this
      ->assertOptionSelected('edit-settings-entity-type', 'user');
    $this
      ->assertText('Sensor Plugin');
    $this
      ->assertText('Entity Aggregator');

    // Tests adding a condition to the log out sensor.
    $this
      ->drupalGet('admin/config/system/monitoring/sensors/user_session_logouts');
    $edit = array(
      'conditions[2][field]' => 'severity',
      'conditions[2][value]' => 5,
    );
    $this
      ->drupalPostForm(NULL, $edit, t('Save'));
    $this
      ->drupalGet('admin/config/system/monitoring/sensors/user_session_logouts');
    $this
      ->assertFieldByName('conditions[2][field]', 'severity');
    $this
      ->assertFieldByName('conditions[2][value]', 5);
  }

  /**
   * Tests the entity aggregator sensors.
   *
   * Tests the entity aggregator with time interval settings and verbosity.
   */
  public function testAggregateSensorTimeIntervalConfig() {
    $account = $this
      ->drupalCreateUser(array(
      'administer monitoring',
      'monitoring reports',
      'monitoring reports',
    ));
    $this
      ->drupalLogin($account);

    // Create some nodes.
    $node1 = $this
      ->drupalCreateNode(array(
      'type' => 'page',
    ));
    $node2 = $this
      ->drupalCreateNode(array(
      'type' => 'page',
    ));

    // Visit the overview and make sure the sensor is displayed.
    $this
      ->drupalGet('admin/reports/monitoring');
    $this
      ->assertText('2 druplicons in 1 day');

    // Visit the sensor edit form.
    $this
      ->drupalGet('admin/config/system/monitoring/sensors/entity_aggregate_test');

    // Test for the default value.
    $this
      ->assertFieldByName('settings[aggregation][time_interval_field]', 'created');
    $this
      ->assertFieldByName('settings[aggregation][time_interval_value]', 86400);

    // Visit the sensor detail page with verbose output.
    $this
      ->drupalGet('admin/reports/monitoring/sensors/entity_aggregate_test');

    // Check that there is no Save button on the detail page.
    $this
      ->assertNoLink('Save');
    $this
      ->drupalPostForm(NULL, array(), 'Run now');

    // The node labels should appear in verbose output.
    $this
      ->assertText('label');
    $this
      ->assertLink($node1
      ->getTitle());
    $this
      ->assertLink($node2
      ->getTitle());

    // Check the sensor overview to verify that the sensor result is
    // calculated and the sensor message is displayed.
    $this
      ->drupalGet('admin/reports/monitoring');
    $this
      ->assertText('2 druplicons in 1 day');

    // Update the time interval and set value to no restriction.
    $this
      ->drupalPostForm('admin/config/system/monitoring/sensors/entity_aggregate_test', array(
      'settings[aggregation][time_interval_value]' => 0,
    ), t('Save'));

    // Visit the overview and make sure that no time interval is displayed.
    $this
      ->drupalGet('admin/reports/monitoring');
    $this
      ->assertText('2 druplicons');
    $this
      ->assertNoText('2 druplicons in');

    // Update the time interval and empty interval field.
    $this
      ->drupalPostForm('admin/config/system/monitoring/sensors/entity_aggregate_test', array(
      'settings[aggregation][time_interval_field]' => '',
      'settings[aggregation][time_interval_value]' => 86400,
    ), t('Save'));

    // Visit the overview and make sure that no time interval is displayed
    // which also make sures no change in time interval applies.
    $this
      ->drupalGet('admin/reports/monitoring');
    $this
      ->assertText('2 druplicons');
    $this
      ->assertNoText('2 druplicons in');

    // Update the time interval field with an invalid value.
    $this
      ->drupalPostForm('admin/config/system/monitoring/sensors/entity_aggregate_test', array(
      'settings[aggregation][time_interval_field]' => 'invalid-field',
    ), t('Save'));

    // Assert the error message.
    $this
      ->assertText('The specified time interval field invalid-field does not exist or is not type timestamp.');
  }

  /**
   * Tests the sensor results overview and the global sensor log.
   */
  public function testSensorOverviewPage() {

    // Check access for the overviews.
    $this
      ->drupalGet('admin/reports/monitoring');
    $this
      ->assertResponse(403);
    $this
      ->drupalGet('admin/reports/monitoring/log');
    $this
      ->assertResponse(403);
    $account = $this
      ->drupalCreateUser(array(
      'monitoring reports',
    ));
    $this
      ->drupalLogin($account);

    // Run the test_sensor and update the timestamp in the cache to make the
    // result the oldest.
    $this
      ->runSensor('test_sensor');
    $cid = 'monitoring_sensor_result:test_sensor';
    $cache = \Drupal::cache('default')
      ->get($cid);
    $cache->data['timestamp'] = $cache->data['timestamp'] - 1000;
    \Drupal::cache('default')
      ->set($cid, $cache->data, \Drupal::time()
      ->getRequestTime() + 3600, array(
      'monitoring_sensor_result',
    ));
    $this
      ->drupalGet('admin/reports/monitoring');

    // Test if the Test sensor is listed as the oldest cached. We do not test
    // for the cached time as such test contains a risk of random fail.
    $this
      ->assertRaw(new FormattableMarkup('Sensor %sensor (%category) cached before', array(
      '%sensor' => 'Test sensor',
      '%category' => 'Test',
    )));

    // Assert if .js & .css are loaded.
    $this
      ->assertRaw('monitoring.js');
    $this
      ->assertRaw('monitoring.css');

    // Test the action buttons are clickable.
    $this
      ->assertLink(t('Details'));
    $this
      ->assertLink(t('Edit'));
    $this
      ->assertLink(t('Details'));

    // Test the overview table.
    $rows = $this
      ->getSession()
      ->getPage()
      ->findAll('css', '#monitoring-sensors-overview tbody tr');
    $i = 0;
    foreach (monitoring_sensor_config_by_categories() as $category => $category_sensor_config) {
      $tr = $rows[$i];
      $this
        ->assertEquals($category, $tr
        ->find('css', 'h3')
        ->getText());
      foreach ($category_sensor_config as $sensor_config) {
        $i++;
        $tr = $rows[$i];
        $this
          ->assertEquals($sensor_config
          ->getLabel(), $tr
          ->find('css', 'td:nth-child(1) span')
          ->getText());
      }
      $i++;
    }

    // Test the global sensor log.
    $this
      ->clickLink(t('Log'));
    $this
      ->assertText('test_sensor');
    $this
      ->assertText(t('OK'));
    $this
      ->assertText(t('No value'));
    $this
      ->assertRaw('class="monitoring-ok"');
    $this
      ->assertRaw('It is highly recommended that you configure this.');
    $this
      ->assertRaw('See Protecting against HTTP HOST Header attacks');
    $this
      ->clickLink('test_sensor');
    $this
      ->assertResponse(200);
    $this
      ->assertUrl(SensorConfig::load('test_sensor')
      ->toUrl('details-form'));
  }

  /**
   * Tests the sensor detail page.
   */
  public function testSensorDetailPage() {
    $account = $this
      ->drupalCreateUser(array(
      'monitoring reports',
      'monitoring verbose',
      'monitoring force run',
    ), 'integrity_test_user', TRUE);
    $this
      ->drupalLogin($account);
    $page = $this
      ->getSession()
      ->getPage();
    $assert_session = $this
      ->assertSession();
    $this
      ->drupalCreateNode(array(
      'promote' => NodeInterface::PROMOTED,
    ));
    $sensor_config = SensorConfig::load('entity_aggregate_test');
    $this
      ->drupalGet('admin/reports/monitoring/sensors/entity_aggregate_test');
    $this
      ->assertTitle(t('@label (@category) | Drupal', array(
      '@label' => $sensor_config
        ->getLabel(),
      '@category' => $sensor_config
        ->getCategory(),
    )));

    // Make sure that all relevant information is displayed.
    // @todo: Assert position/order.
    // Cannot use $this->runSensor() as the cache needs to remain.
    $result = monitoring_sensor_run('entity_aggregate_test');
    $this
      ->assertText(t('Description'));
    $this
      ->assertText($sensor_config
      ->getDescription());
    $this
      ->assertText(t('Status'));
    $this
      ->assertText('Warning');
    $this
      ->assertText(t('Message'));
    $this
      ->assertText('1 druplicons in 1 day, falls below 2');
    $this
      ->assertText(t('Execution time'));

    // The sensor is cached, so we have the same cached execution time.
    $this
      ->assertText($result
      ->getExecutionTime() . 'ms');
    $this
      ->assertText(t('Cache information'));
    $this
      ->assertText('Executed now, valid for 1 hour');
    $this
      ->assertRaw(t('Run again'));
    $this
      ->assertText(t('Verbose'));
    $this
      ->assertText(t('Settings'));

    // @todo Add asserts about displayed settings once we display them in a
    //   better way.
    $this
      ->assertText(t('Log'));
    $rows = $this
      ->getSession()
      ->getPage()
      ->findAll('css', '#edit-sensor-log tbody tr');
    $this
      ->assertEquals(1, count($rows));
    $this
      ->assertEquals('WARNING', $rows[0]
      ->find('css', 'td:nth-child(2)')
      ->getText());
    $this
      ->assertEquals('1 druplicons in 1 day, falls below 2', $rows[0]
      ->find('css', 'td:nth-child(3)')
      ->getText());

    // Create another node and run again.
    $node = $this
      ->drupalCreateNode(array(
      'promote' => '1',
    ));
    $this
      ->drupalPostForm(NULL, array(), t('Run again'));
    $this
      ->assertText('OK');
    $this
      ->assertText('2 druplicons in 1 day');
    $rows = $this
      ->getSession()
      ->getPage()
      ->findAll('css', '#edit-sensor-log tbody tr');
    $this
      ->assertEquals(2, count($rows));
    $this
      ->assertEquals('OK', $rows[0]
      ->find('css', 'td:nth-child(2)')
      ->getText());
    $this
      ->assertSession()
      ->elementTextContains('css', '#edit-sensor-log tbody tr.monitoring-ok td:nth-child(2)', 'OK');
    $this
      ->assertEquals('WARNING', $rows[1]
      ->find('css', 'td:nth-child(2)')
      ->getText());
    $this
      ->assertSession()
      ->elementTextContains('css', '#edit-sensor-log tbody tr.monitoring-warning td:nth-child(2)', 'WARNING');

    // Refresh the page, this not run the sensor again.
    $this
      ->drupalGet('admin/reports/monitoring/sensors/entity_aggregate_test');
    $this
      ->assertText('OK');
    $this
      ->assertText('2 druplicons in 1 day');
    $this
      ->assertText(t('Verbose output is not available for cached sensor results. Click force run to see verbose output.'));
    $rows = $this
      ->getSession()
      ->getPage()
      ->findAll('css', '#edit-sensor-log tbody tr');
    $this
      ->assertEquals(2, count($rows));

    // Test the verbose output.
    $this
      ->drupalPostForm(NULL, array(), t('Run now'));

    // Check that the verbose output is displayed.
    $this
      ->assertText('Verbose');
    $this
      ->assertText('id');
    $this
      ->assertText('label');
    $this
      ->assertText($node
      ->getTitle());

    // Check the if the sensor message includes value type.
    $this
      ->drupalGet('admin/reports/monitoring/sensors/core_cron_safe_threshold');
    $this
      ->assertText('FALSE');

    // Test that accessing a disabled or nisot-existing sensor results in an
    // access denied and a page not found response.
    monitoring_sensor_manager()
      ->disableSensor('test_sensor');
    $this
      ->drupalGet('admin/reports/monitoring/sensors/test_sensor');
    $this
      ->assertResponse(403);
    $this
      ->drupalGet('admin/reports/monitoring/sensors/non_existing_sensor');
    $this
      ->assertResponse(404);

    // Test user integrity sensor detail page.

    /** @var User $account */
    $account = User::load($account
      ->id());
    $this
      ->drupalGet('admin/reports/monitoring/sensors/user_integrity');
    $this
      ->assertText('1 privileged user(s)');

    // Check that is not showing the query or the query arguments.
    $this
      ->assertNoText(t('Query'));
    $this
      ->assertNoText(t('Arguments'));

    // Test the timestamp is formatted correctly.
    $expected_time = \Drupal::service('date.formatter')
      ->format($account
      ->getCreatedTime(), 'short');
    $assert_session
      ->elementContains('css', '#all_users_with_privileged_access tbody td:nth-child(3)', $expected_time);
    $expected_time = \Drupal::service('date.formatter')
      ->format($account
      ->getLastAccessedTime(), 'short');
    $assert_session
      ->elementContains('css', '#all_users_with_privileged_access tbody td:nth-child(4)', $expected_time);

    // Assert None output when we don't have restricted roles with permissions.
    $this
      ->assertText('List of roles with restricted permissions');
    $this
      ->assertText('None');
    $test_user = $this
      ->drupalCreateUser(array(
      'administer monitoring',
    ), 'test_user');
    $test_user
      ->save();
    $this
      ->drupalLogin($test_user);
    $this
      ->runSensor('user_integrity');
    $this
      ->drupalGet('admin/reports/monitoring/sensors/user_integrity');
    $this
      ->assertText('2 privileged user(s), 1 new user(s)');

    // Grant restricted permission to authenticated users.
    user_role_grant_permissions('authenticated', array(
      'administer account settings',
    ));

    // Run the sensor to check verbose output.
    $this
      ->drupalPostForm(NULL, array(), t('Run now'));

    // Check restricted permissions of Authenticated users.
    $this
      ->assertText('List of roles with restricted permissions');
    $this
      ->assertText('Authenticated user: administer account settings');

    // Check table of users with privileged access.
    $expected_header = [
      'User',
      'Roles',
      'Created',
      'Last accessed',
    ];
    $this
      ->assertText('All users with privileged access');
    $rows = $page
      ->findAll('css', '#all_users_with_privileged_access tbody tr');
    $this
      ->assertEquals(3, count($rows));
    $assert_session
      ->elementContains('css', '#all_users_with_privileged_access thead th:nth-child(1)', $expected_header[0]);
    $assert_session
      ->elementContains('css', '#all_users_with_privileged_access thead th:nth-child(2)', $expected_header[1]);
    $assert_session
      ->elementContains('css', '#all_users_with_privileged_access thead th:nth-child(3)', $expected_header[2]);
    $assert_session
      ->elementContains('css', '#all_users_with_privileged_access thead th:nth-child(4)', $expected_header[3]);

    // Assert roles are listed on the table.
    $assert_session
      ->elementContains('css', '#all_users_with_privileged_access tbody tr:nth-child(1) td:nth-child(2)', implode(', ', $test_user
      ->getRoles()));
    $assert_session
      ->elementContains('css', '#all_users_with_privileged_access tbody tr:nth-child(2) td:nth-child(2)', implode(', ', $account
      ->getRoles()));

    // Check the new user name in verbose output.
    $this
      ->assertText('test_user');

    // Reset the user data and run the sensor again.
    $this
      ->drupalPostForm('admin/config/system/monitoring/sensors/user_integrity', array(), t('Reset user data'));
    $this
      ->runSensor('user_integrity');
    $this
      ->drupalGet('admin/reports/monitoring/sensors/user_integrity');
    $this
      ->assertText('2 privileged user(s)');

    // Change user data and run sensor.
    $test_user
      ->setUsername('changed_name');
    $test_user
      ->save();
    $this
      ->runSensor('user_integrity');
    $this
      ->drupalGet('admin/reports/monitoring/sensors/user_integrity');
    $this
      ->assertText('3 privileged user(s), 1 changed user(s)');

    // Reset user data again and check sensor message.
    $this
      ->drupalPostForm('admin/config/system/monitoring/sensors/user_integrity', array(), t('Reset user data'));
    $this
      ->runSensor('user_integrity');
    $this
      ->drupalGet('admin/reports/monitoring/sensors/user_integrity');
    $this
      ->assertText('2 privileged user(s)');

    // Check the list of deleted users.
    $account
      ->delete();
    $this
      ->drupalPostForm('admin/reports/monitoring/sensors/user_integrity', array(), t('Run now'));
    $this
      ->assertText('Deleted users with privileged access');

    // Assert the deleted user is listed.
    $assert_session
      ->elementContains('css', '#deleted_users_with_privileged_access tbody tr:nth-child(1) td:nth-child(1)', 'integrity_test_user');

    // Test enabled sensor link works after save.
    $this
      ->drupalPostForm('admin/config/system/monitoring/sensors/user_integrity', array(), 'Save');
    $this
      ->clickLink('Privileged user integrity');
    $this
      ->assertResponse(200);
    $this
      ->assertUrl('admin/reports/monitoring/sensors/user_integrity');

    // Test disabled sensor link works and redirect to edit page.
    monitoring_sensor_manager()
      ->disableSensor('user_integrity');
    $this
      ->drupalPostForm('admin/config/system/monitoring/sensors/user_integrity', array(), 'Save');
    $this
      ->clickLink('Privileged user integrity');
    $this
      ->assertResponse(200);
    $this
      ->assertUrl('admin/config/system/monitoring/sensors/user_integrity');
  }

  /**
   * Tests the sensor detail page for actual and expected values.
   */
  public function testSensorEditPage() {
    $account = $this
      ->drupalCreateUser(array(
      'administer monitoring',
      'monitoring reports',
    ));
    $this
      ->drupalLogin($account);

    // Visit the edit page of "core theme default" (config value sensor)
    // and make sure the expected and current values are displayed.
    $this
      ->drupalGet('admin/config/system/monitoring/sensors/core_theme_default');
    $this
      ->assertText('The expected value of config system.theme:default, current value: ' . $this
      ->config('system.theme')
      ->get('default'));

    // Visit the edit page of "core maintainance mode" (state value sensor)
    // and make sure the expected and current values are displayed.
    $this
      ->drupalGet('admin/config/system/monitoring/sensors/core_maintenance_mode');
    $this
      ->assertText('The expected value of state system.maintenance_mode, current value: FALSE');

    // Make sure delete link is not available for this sensor.
    $this
      ->assertNoLink(t('Delete'));

    // Make sure details page is available for an enabled sensor.
    $this
      ->assertLink('Details');

    // Test the checkbox in edit sensor settings for the bool sensor
    // Cron safe threshold enabled/disabled.
    $this
      ->drupalGet('admin/config/system/monitoring/sensors/core_cron_safe_threshold');

    // Make sure delete action available for this sensor.
    $this
      ->assertLink(t('Delete'));
    $this
      ->assertNoFieldChecked('edit-settings-value');
    $this
      ->drupalPostForm(NULL, array(
      'settings[value]' => 'Checked',
    ), t('Save'));
    $this
      ->drupalGet('admin/config/system/monitoring/sensors/core_cron_safe_threshold');
    $this
      ->assertFieldChecked('edit-settings-value');

    // Test whether the details page is available.
    $this
      ->assertLink(t('Details'));
    $this
      ->clickLink(t('Details'));
    $this
      ->assertText('Result');
    $this
      ->assertLink(t('Edit'));
    $this
      ->clickLink(t('Edit'));
    $this
      ->assertText('Sensor plugin settings');

    // Test detail page is not available for a disabled sensor.
    $this
      ->drupalGet('admin/config/system/monitoring/sensors/node_new_all');
    $this
      ->assertNoLink('Details');
  }

  /**
   * Tests the force execute all and sensor specific force execute links.
   */
  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');
  }

  /**
   * Tests the UI of the requirements sensor.
   */
  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']));
  }

  /**
   * Tests the auto completion of the sensor category field.
   */
  public function testAutoComplete() {
    $account = $this
      ->drupalCreateUser(array(
      'administer monitoring',
    ));
    $this
      ->drupalLogin($account);

    // Test with "C", which matches Content and Cron.
    $categories = Json::decode($this
      ->drupalGet('/monitoring-category/autocomplete', [
      'query' => [
        'q' => 'C',
        '_format' => 'json',
      ],
    ]));
    $this
      ->assertEquals(2, count($categories));
    $this
      ->assertEquals('Content', $categories[0]['label']);
    $this
      ->assertEquals('Cron', $categories[1]['label']);

    // Check that a non-matching prefix returns no suggestions.
    $categories = Json::decode($this
      ->drupalGet('/monitoring-category/autocomplete', [
      'query' => [
        'q' => 'non_existing_category',
        '_format' => 'json',
      ],
    ]));
    $this
      ->assertTrue(empty($categories), 'No autocomplete suggestions for non-existing query string.');
  }

  /**
   * UI Tests for disappearing sensors.
   *
   * We provide a separate test method for the DisappearedSensorsSensorPlugin as we
   * need to install and uninstall additional modules.
   *
   * @see \Drupal\monitoring\Plugin\monitoring\SensorPlugin\DisappearedSensorsSensorPlugin
   */
  public function testSensorDisappearedSensorsUI() {
    $account = $this
      ->drupalCreateUser(array(
      'administer monitoring',
    ));
    $this
      ->drupalLogin($account);

    // Install comment module and the comment_new sensor.
    $this
      ->installModules(array(
      'comment',
    ));
    monitoring_sensor_manager()
      ->enableSensor('comment_new');

    // We should have the message that no sensors are missing.
    $this
      ->drupalGet('admin/config/system/monitoring/sensors/monitoring_disappeared_sensors');
    $this
      ->assertNoText(t('This action will clear the missing sensors and the critical sensor status will go away.'));

    // Disable sensor and the ininstall comment module. This is the correct
    // procedure and therefore there should be no missing sensors.
    monitoring_sensor_manager()
      ->disableSensor('comment_new');
    $this
      ->drupalGet('admin/config/system/monitoring/sensors/monitoring_disappeared_sensors');
    $this
      ->assertNoText(t('This action will clear the missing sensors and the critical sensor status will go away.'));

    // Install comment module and the comment_new sensor.
    $this
      ->installModules(array(
      'comment',
    ));
    monitoring_sensor_manager()
      ->enableSensor('comment_new');

    // Now uninstall the comment module to have the comment_new sensor disappear.
    $this
      ->uninstallModules(array(
      'comment',
    ));

    // Run the monitoring_disappeared_sensors sensor to get the status message
    // that should be found in the settings form.
    $this
      ->drupalGet('admin/config/system/monitoring/sensors/monitoring_disappeared_sensors');
    $this
      ->assertText('Missing sensor comment_new');

    // Now reset the sensor list - we should get the "no missing sensors"
    // message.
    $this
      ->drupalPostForm(NULL, array(), t('Clear missing sensors'));
    $this
      ->assertText(t('All missing sensors have been cleared.'));
    $this
      ->drupalGet('admin/config/system/monitoring/sensors/monitoring_disappeared_sensors');
    $this
      ->assertNoText('Missing sensor comment_new');
  }

  /**
   * Tests that the sensor list is displayed completely.
   */
  public function testSensorListLimit() {
    $account = $this
      ->drupalCreateUser(array(
      'administer monitoring',
    ));
    $this
      ->drupalLogin($account);

    // Check if we can access the sensor overview page.
    $this
      ->drupalGet('admin/config/system/monitoring/sensors');
    $this
      ->assertLink('Add Sensor');
    $sensors = count(SensorConfig::loadMultiple());
    $limit = 51;
    $values = array(
      'label' => 'test',
      'plugin_id' => 'entity_aggregator',
      'settings' => array(
        'entity_type' => 'node',
      ),
    );
    for ($i = 1; $i <= $limit - $sensors; $i++) {
      $values['id'] = 'test_sensor_overview' . $i;
      $created = SensorConfig::create($values);
      $created
        ->save();
    }
    $this
      ->drupalGet('admin/config/system/monitoring/sensors');

    // Check that all the rows are listed.
    $this
      ->assertEqual(count($this
      ->xpath('//tbody/tr')), $limit);
  }

  /**
   * Submits a threshold settings form for a given sensor.
   *
   * @param string $sensor_name
   *   The sensor name for the sensor that should be submitted.
   * @param array $thresholds
   *   Array of threshold values, keyed by the status, the value can be an
   *   integer or an array of integers for threshold types that need multiple
   *   values.
   */
  protected function submitThresholdSettings($sensor_name, array $thresholds) {
    $data = array();
    $sensor_config = SensorConfig::load($sensor_name);
    foreach ($thresholds as $key => $value) {
      $form_field_name = 'thresholds[' . $key . ']';
      $data[$form_field_name] = $value;
    }
    $this
      ->drupalPostForm('admin/config/system/monitoring/sensors/' . $sensor_config
      ->id(), $data, t('Save'));
  }

  /**
   * Asserts that defaults are set correctly in the settings form.
   *
   * @param string $sensor_name
   *   The sensor name for the sensor that should be submitted.
   * @param array $thresholds
   *   Array of threshold values, keyed by the status, the value can be an
   *   integer or an array of integers for threshold types that need multiple
   *   values.
   */
  protected function assertThresholdSettingsUIDefaults($sensor_name, $thresholds) {
    $sensor_config = SensorConfig::load($sensor_name);
    $this
      ->drupalGet('admin/config/system/monitoring/sensors/' . $sensor_name);
    $this
      ->assertTitle(t('@label settings (@category) | Drupal', array(
      '@label' => $sensor_config
        ->getLabel(),
      '@category' => $sensor_config
        ->getCategory(),
    )));
    foreach ($thresholds as $key => $value) {
      $form_field_name = 'thresholds[' . $key . ']';
      $this
        ->assertFieldByName($form_field_name, $value);
    }
  }

  /**
   * Tests exceeds threshold settings UI and validation.
   */
  protected function doTestExceedsThresholdSettings() {

    // Test with valid values.
    $thresholds = array(
      'critical' => 11,
      'warning' => 6,
    );
    $this
      ->submitThresholdSettings('test_sensor_exceeds', $thresholds);
    $this
      ->assertText(new FormattableMarkup('Sensor @label saved.', array(
      '@label' => 'Test sensor exceeds',
    )));
    $this
      ->assertThresholdSettingsUIDefaults('test_sensor_exceeds', $thresholds);

    // Make sure that it is possible to save empty thresholds.
    $thresholds = array(
      'critical' => '',
      'warning' => '',
    );
    $this
      ->submitThresholdSettings('test_sensor_exceeds', $thresholds);
    $this
      ->assertText(new FormattableMarkup('Sensor @label saved.', array(
      '@label' => 'Test sensor exceeds',
    )));
    $this
      ->assertThresholdSettingsUIDefaults('test_sensor_exceeds', $thresholds);
    monitoring_sensor_manager()
      ->resetCache();
    \Drupal::service('monitoring.sensor_runner')
      ->resetCache();
    $sensor_result = $this
      ->runSensor('test_sensor_exceeds');
    $this
      ->assertTrue($sensor_result
      ->isOk());

    // Test validation.
    $thresholds = array(
      'critical' => 5,
      'warning' => 10,
    );
    $this
      ->submitThresholdSettings('test_sensor_exceeds', $thresholds);
    $this
      ->assertText('Warning must be lower than critical or empty.');
    $thresholds = array(
      'critical' => 5,
      'warning' => 5,
    );
    $this
      ->submitThresholdSettings('test_sensor_exceeds', $thresholds);
    $this
      ->assertText('Warning must be lower than critical or empty.');
    $thresholds = array(
      'critical' => 'alphanumeric',
      'warning' => 'alphanumeric',
    );
    $this
      ->submitThresholdSettings('test_sensor_exceeds', $thresholds);
    $this
      ->assertText('Warning must be a number.');
    $this
      ->assertText('Critical must be a number.');

    // Test threshold exceeds with zero values for critical.
    $thresholds = [
      'critical' => 0,
      'warning' => '',
    ];
    $this
      ->submitThresholdSettings('test_sensor_exceeds', $thresholds);
    $test_sensor_result_data = [
      'sensor_value' => 7,
    ];
    \Drupal::state()
      ->set('monitoring_test.sensor_result_data', $test_sensor_result_data);
    $result = $this
      ->runSensor('test_sensor_exceeds');
    $this
      ->assertTrue($result
      ->isCritical());
    $test_sensor_result_data = [
      'sensor_value' => 0,
    ];
    \Drupal::state()
      ->set('monitoring_test.sensor_result_data', $test_sensor_result_data);
    $result = $this
      ->runSensor('test_sensor_exceeds');
    $this
      ->assertTrue($result
      ->isOk());

    // Test threshold exceeds with zero values for warning.
    $thresholds = [
      'critical' => '',
      'warning' => 0,
    ];
    $this
      ->submitThresholdSettings('test_sensor_exceeds', $thresholds);
    $test_sensor_result_data = [
      'sensor_value' => 7,
    ];
    \Drupal::state()
      ->set('monitoring_test.sensor_result_data', $test_sensor_result_data);
    $result = $this
      ->runSensor('test_sensor_exceeds');
    $this
      ->assertTrue($result
      ->isWarning());
    $test_sensor_result_data = [
      'sensor_value' => 0,
    ];
    \Drupal::state()
      ->set('monitoring_test.sensor_result_data', $test_sensor_result_data);
    $result = $this
      ->runSensor('test_sensor_exceeds');
    $this
      ->assertTrue($result
      ->isOk());
    return $thresholds;
  }

  /**
   * Tests falls threshold settings UI and validation.
   */
  protected function doTestFallsThresholdSettings() {

    // Test with valid values.
    $thresholds = array(
      'critical' => 6,
      'warning' => 11,
    );
    $this
      ->submitThresholdSettings('test_sensor_falls', $thresholds);
    $this
      ->assertText(new FormattableMarkup('Sensor @label saved.', array(
      '@label' => 'Test sensor falls',
    )));
    $this
      ->assertThresholdSettingsUIDefaults('test_sensor_falls', $thresholds);

    // Make sure that it is possible to save empty thresholds.
    $thresholds = array(
      'critical' => '',
      'warning' => '',
    );
    $this
      ->submitThresholdSettings('test_sensor_falls', $thresholds);
    $this
      ->assertText(new FormattableMarkup('Sensor @label saved.', array(
      '@label' => 'Test sensor falls',
    )));
    $this
      ->assertThresholdSettingsUIDefaults('test_sensor_falls', $thresholds);

    // Test validation.
    $thresholds = array(
      'critical' => 50,
      'warning' => 45,
    );
    $this
      ->submitThresholdSettings('test_sensor_falls', $thresholds);
    $this
      ->assertText('Warning must be higher than critical or empty.');
    $thresholds = array(
      'critical' => 5,
      'warning' => 5,
    );
    $this
      ->submitThresholdSettings('test_sensor_falls', $thresholds);
    $this
      ->assertText('Warning must be higher than critical or empty.');
    $thresholds = array(
      'critical' => 'alphanumeric',
      'warning' => 'alphanumeric',
    );
    $this
      ->submitThresholdSettings('test_sensor_falls', $thresholds);
    $this
      ->assertText('Warning must be a number.');
    $this
      ->assertText('Critical must be a number.');

    // Test threshold fall with zero values for critical.
    $thresholds = [
      'critical' => 0,
      'warning' => '',
    ];
    $this
      ->submitThresholdSettings('test_sensor_falls', $thresholds);
    $test_sensor_result_data = [
      'sensor_value' => -7,
    ];
    \Drupal::state()
      ->set('monitoring_test.sensor_result_data', $test_sensor_result_data);
    $result = $this
      ->runSensor('test_sensor_falls');
    $this
      ->assertTrue($result
      ->isCritical());
    $test_sensor_result_data = [
      'sensor_value' => 0,
    ];
    \Drupal::state()
      ->set('monitoring_test.sensor_result_data', $test_sensor_result_data);
    $result = $this
      ->runSensor('test_sensor_falls');
    $this
      ->assertTrue($result
      ->isOk());

    // Test threshold fall with zero values for warning.
    $thresholds = [
      'critical' => '',
      'warning' => 0,
    ];
    $this
      ->submitThresholdSettings('test_sensor_falls', $thresholds);
    $test_sensor_result_data = [
      'sensor_value' => -7,
    ];
    \Drupal::state()
      ->set('monitoring_test.sensor_result_data', $test_sensor_result_data);
    $result = $this
      ->runSensor('test_sensor_falls');
    $this
      ->assertTrue($result
      ->isWarning());
    $test_sensor_result_data = [
      'sensor_value' => 0,
    ];
    \Drupal::state()
      ->set('monitoring_test.sensor_result_data', $test_sensor_result_data);
    $result = $this
      ->runSensor('test_sensor_falls');
    $this
      ->assertTrue($result
      ->isOk());
    return $thresholds;
  }

  /**
   * Tests inner threshold settings UI and validation.
   */
  protected function doTestInnerThresholdSettings() {

    // Test with valid values.
    $thresholds = array(
      'critical_low' => 5,
      'warning_low' => 1,
      'critical_high' => 10,
      'warning_high' => 15,
    );
    $this
      ->submitThresholdSettings('test_sensor_inner', $thresholds);
    $this
      ->assertText(new FormattableMarkup('Sensor @label saved.', array(
      '@label' => 'Test sensor inner',
    )));
    $this
      ->assertThresholdSettingsUIDefaults('test_sensor_inner', $thresholds);

    // Make sure that it is possible to save empty inner thresholds.
    $thresholds = array(
      'critical_low' => '',
      'warning_low' => '',
      'critical_high' => '',
      'warning_high' => '',
    );
    $this
      ->submitThresholdSettings('test_sensor_inner', $thresholds);
    $this
      ->assertText(new FormattableMarkup('Sensor @label saved.', array(
      '@label' => 'Test sensor inner',
    )));
    $this
      ->assertThresholdSettingsUIDefaults('test_sensor_inner', $thresholds);

    // Test validation.
    $thresholds = array(
      'critical_low' => 5,
      'warning_low' => 15,
      'critical_high' => 10,
      'warning_high' => 20,
    );
    $this
      ->submitThresholdSettings('test_sensor_inner', $thresholds);
    $this
      ->assertText('Warning low must be lower than critical low or empty.');
    $thresholds = array(
      'critical_low' => 5,
      'warning_low' => 5,
      'critical_high' => 5,
      'warning_high' => 5,
    );
    $this
      ->submitThresholdSettings('test_sensor_inner', $thresholds);
    $this
      ->assertText('Warning low must be lower than warning high or empty.');
    $thresholds = array(
      'critical_low' => 50,
      'warning_low' => 95,
      'critical_high' => 55,
      'warning_high' => 100,
    );
    $this
      ->submitThresholdSettings('test_sensor_inner', $thresholds);
    $this
      ->assertText('Warning low must be lower than critical low or empty.');
    $thresholds = array(
      'critical_low' => 'alphanumeric',
      'warning_low' => 'alphanumeric',
      'critical_high' => 'alphanumeric',
      'warning_high' => 'alphanumeric',
    );
    $this
      ->submitThresholdSettings('test_sensor_inner', $thresholds);
    $this
      ->assertText('Warning low must be a number.');
    $this
      ->assertText('Warning high must be a number.');
    $this
      ->assertText('Critical low must be a number.');
    $this
      ->assertText('Critical high must be a number.');
    $thresholds = array(
      'critical_low' => 45,
      'warning_low' => 35,
      'critical_high' => 50,
      'warning_high' => 40,
    );
    $this
      ->submitThresholdSettings('test_sensor_inner', $thresholds);
    $this
      ->assertText('Warning high must be higher than critical high or empty.');
    return $thresholds;
  }

  /**
   * Tests outer threshold settings UI and validation.
   */
  protected function doTestOuterThresholdSettings() {

    // Test with valid values.
    $thresholds = array(
      'critical_low' => 5,
      'warning_low' => 6,
      'critical_high' => 15,
      'warning_high' => 14,
    );
    $this
      ->submitThresholdSettings('test_sensor_outer', $thresholds);
    $this
      ->assertText(new FormattableMarkup('Sensor @label saved.', array(
      '@label' => 'Test sensor outer',
    )));
    $this
      ->assertThresholdSettingsUIDefaults('test_sensor_outer', $thresholds);

    // Make sure that it is possible to save empty outer thresholds.
    $thresholds = array(
      'critical_low' => '',
      'warning_low' => '',
      'critical_high' => '',
      'warning_high' => '',
    );
    $this
      ->submitThresholdSettings('test_sensor_outer', $thresholds);
    $this
      ->assertText(new FormattableMarkup('Sensor @label saved.', array(
      '@label' => 'Test sensor outer',
    )));
    $this
      ->assertThresholdSettingsUIDefaults('test_sensor_outer', $thresholds);

    // Test validation.
    $thresholds = array(
      'critical_low' => 5,
      'warning_low' => 15,
      'critical_high' => 10,
      'warning_high' => 20,
    );
    $this
      ->submitThresholdSettings('test_sensor_outer', $thresholds);
    $this
      ->assertText('Warning high must be lower than critical high or empty.');
    $thresholds = array(
      'critical_low' => 5,
      'warning_low' => 5,
      'critical_high' => 5,
      'warning_high' => 5,
    );
    $this
      ->submitThresholdSettings('test_sensor_outer', $thresholds);
    $this
      ->assertText('Warning low must be lower than warning high or empty.');
    $thresholds = array(
      'critical_low' => 'alphanumeric',
      'warning_low' => 'alphanumeric',
      'critical_high' => 'alphanumeric',
      'warning_high' => 'alphanumeric',
    );
    $this
      ->submitThresholdSettings('test_sensor_outer', $thresholds);
    $this
      ->assertText('Warning low must be a number.');
    $this
      ->assertText('Warning high must be a number.');
    $this
      ->assertText('Critical low must be a number.');
    $this
      ->assertText('Critical high must be a number.');
    $thresholds = array(
      'critical_low' => 45,
      'warning_low' => 35,
      'critical_high' => 45,
      'warning_high' => 35,
    );
    $this
      ->submitThresholdSettings('test_sensor_outer', $thresholds);
    $this
      ->assertText('Warning low must be lower than warning high or empty.');
    $thresholds = array(
      'critical_low' => 50,
      'warning_low' => 95,
      'critical_high' => 55,
      'warning_high' => 100,
    );
    $this
      ->submitThresholdSettings('test_sensor_outer', $thresholds);
    $this
      ->assertText('Warning high must be lower than critical high or empty.');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AssertHelperTrait::castSafeStrings protected static function Casts MarkupInterface objects into strings.
AssertLegacyTrait::assert protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertTrue() instead.
AssertLegacyTrait::assertCacheTag protected function Asserts whether an expected cache tag was present in the last response.
AssertLegacyTrait::assertElementNotPresent protected function Asserts that the element with the given CSS selector is not present.
AssertLegacyTrait::assertElementPresent protected function Asserts that the element with the given CSS selector is present.
AssertLegacyTrait::assertEqual protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertEquals() instead.
AssertLegacyTrait::assertEscaped protected function Passes if the raw text IS found escaped on the loaded page, fail otherwise.
AssertLegacyTrait::assertField protected function Asserts that a field exists with the given name or ID.
AssertLegacyTrait::assertFieldById protected function Asserts that a field exists with the given ID and value.
AssertLegacyTrait::assertFieldByName protected function Asserts that a field exists with the given name and value.
AssertLegacyTrait::assertFieldByXPath protected function Asserts that a field exists in the current page by the given XPath.
AssertLegacyTrait::assertFieldChecked protected function Asserts that a checkbox field in the current page is checked.
AssertLegacyTrait::assertFieldsByValue protected function Asserts that a field exists in the current page with a given Xpath result.
AssertLegacyTrait::assertHeader protected function Checks that current response header equals value.
AssertLegacyTrait::assertIdentical protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertSame() instead.
AssertLegacyTrait::assertIdenticalObject protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertEquals() instead.
AssertLegacyTrait::assertLink protected function Passes if a link with the specified label is found.
AssertLegacyTrait::assertLinkByHref protected function Passes if a link containing a given href (part) is found.
AssertLegacyTrait::assertNoCacheTag protected function Asserts whether an expected cache tag was absent in the last response.
AssertLegacyTrait::assertNoEscaped protected function Passes if the raw text is not found escaped on the loaded page.
AssertLegacyTrait::assertNoField protected function Asserts that a field does NOT exist with the given name or ID.
AssertLegacyTrait::assertNoFieldById protected function Asserts that a field does not exist with the given ID and value.
AssertLegacyTrait::assertNoFieldByName protected function Asserts that a field does not exist with the given name and value.
AssertLegacyTrait::assertNoFieldByXPath protected function Asserts that a field does not exist or its value does not match, by XPath.
AssertLegacyTrait::assertNoFieldChecked protected function Asserts that a checkbox field in the current page is not checked.
AssertLegacyTrait::assertNoLink protected function Passes if a link with the specified label is not found.
AssertLegacyTrait::assertNoLinkByHref protected function Passes if a link containing a given href (part) is not found.
AssertLegacyTrait::assertNoOption protected function Asserts that a select option does NOT exist in the current page.
AssertLegacyTrait::assertNoPattern protected function Triggers a pass if the Perl regex pattern is not found in the raw content.
AssertLegacyTrait::assertNoRaw protected function Passes if the raw text IS not found on the loaded page, fail otherwise. 1
AssertLegacyTrait::assertNotEqual protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertNotEquals() instead.
AssertLegacyTrait::assertNoText protected function Passes if the page (with HTML stripped) does not contains the text. 1
AssertLegacyTrait::assertNotIdentical protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertNotSame() instead.
AssertLegacyTrait::assertNoUniqueText protected function Passes if the text is found MORE THAN ONCE on the text version of the page.
AssertLegacyTrait::assertOption protected function Asserts that a select option in the current page exists.
AssertLegacyTrait::assertOptionByText protected function Asserts that a select option with the visible text exists.
AssertLegacyTrait::assertOptionSelected protected function Asserts that a select option in the current page is checked.
AssertLegacyTrait::assertPattern protected function Triggers a pass if the Perl regex pattern is found in the raw content.
AssertLegacyTrait::assertRaw protected function Passes if the raw text IS found on the loaded page, fail otherwise. 1
AssertLegacyTrait::assertResponse protected function Asserts the page responds with the specified response code. 1
AssertLegacyTrait::assertText protected function Passes if the page (with HTML stripped) contains the text. 1
AssertLegacyTrait::assertTextHelper protected function Helper for assertText and assertNoText.
AssertLegacyTrait::assertTitle protected function Pass if the page title is the given string.
AssertLegacyTrait::assertUniqueText protected function Passes if the text is found ONLY ONCE on the text version of the page.
AssertLegacyTrait::assertUrl protected function Passes if the internal browser's URL matches the given path.
AssertLegacyTrait::buildXPathQuery protected function Builds an XPath query.
AssertLegacyTrait::constructFieldXpath protected function Helper: Constructs an XPath for the given set of attributes and value.
AssertLegacyTrait::getAllOptions protected function Get all option elements, including nested options, in a select.
AssertLegacyTrait::getRawContent protected function Gets the current raw content.
AssertLegacyTrait::pass protected function Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertTrue() instead.
AssertLegacyTrait::verbose protected function
BlockCreationTrait::placeBlock protected function Creates a block instance based on default settings. Aliased as: drupalPlaceBlock
BrowserHtmlDebugTrait::$htmlOutputBaseUrl protected property The Base URI to use for links to the output files.
BrowserHtmlDebugTrait::$htmlOutputClassName protected property Class name for HTML output logging.
BrowserHtmlDebugTrait::$htmlOutputCounter protected property Counter for HTML output logging.
BrowserHtmlDebugTrait::$htmlOutputCounterStorage protected property Counter storage for HTML output logging.
BrowserHtmlDebugTrait::$htmlOutputDirectory protected property Directory name for HTML output logging.
BrowserHtmlDebugTrait::$htmlOutputEnabled protected property HTML output output enabled.
BrowserHtmlDebugTrait::$htmlOutputFile protected property The file name to write the list of URLs to.
BrowserHtmlDebugTrait::$htmlOutputTestId protected property HTML output test ID.
BrowserHtmlDebugTrait::formatHtmlOutputHeaders protected function Formats HTTP headers as string for HTML output logging.
BrowserHtmlDebugTrait::getHtmlOutputHeaders protected function Returns headers in HTML output format. 1
BrowserHtmlDebugTrait::htmlOutput protected function Logs a HTML output message in a text file.
BrowserHtmlDebugTrait::initBrowserOutputFile protected function Creates the directory to store browser output.
BrowserTestBase::$baseUrl protected property The base URL.
BrowserTestBase::$configImporter protected property The config importer that can be used in a test.
BrowserTestBase::$customTranslations protected property An array of custom translations suitable for drupal_rewrite_settings().
BrowserTestBase::$databasePrefix protected property The database prefix of this test run.
BrowserTestBase::$mink protected property Mink session manager.
BrowserTestBase::$minkDefaultDriverArgs protected property
BrowserTestBase::$minkDefaultDriverClass protected property 1
BrowserTestBase::$originalContainer protected property The original container.
BrowserTestBase::$originalShutdownCallbacks protected property The original array of shutdown function callbacks.
BrowserTestBase::$preserveGlobalState protected property
BrowserTestBase::$profile protected property The profile to install as a basis for testing. 39
BrowserTestBase::$root protected property The app root.
BrowserTestBase::$runTestInSeparateProcess protected property Browser tests are run in separate processes to prevent collisions between code that may be loaded by tests.
BrowserTestBase::$timeLimit protected property Time limit in seconds for the test.
BrowserTestBase::$translationFilesDirectory protected property The translation file directory for the test environment.
BrowserTestBase::cleanupEnvironment protected function Clean up the Simpletest environment.
BrowserTestBase::config protected function Configuration accessor for tests. Returns non-overridden configuration.
BrowserTestBase::cssSelectToXpath protected function Translates a CSS expression to its XPath equivalent.
BrowserTestBase::drupalGetHeader protected function Gets the value of an HTTP response header.
BrowserTestBase::drupalGetHeaders Deprecated protected function Returns all response headers.
BrowserTestBase::filePreDeleteCallback public static function Ensures test files are deletable.
BrowserTestBase::getDefaultDriverInstance protected function Gets an instance of the default Mink driver.
BrowserTestBase::getDrupalSettings protected function Gets the JavaScript drupalSettings variable for the currently-loaded page. 1
BrowserTestBase::getHttpClient protected function Obtain the HTTP client for the system under test.
BrowserTestBase::getMinkDriverArgs protected function Get the Mink driver args from an environment variable, if it is set. Can be overridden in a derived class so it is possible to use a different value for a subset of tests, e.g. the JavaScript tests. 1
BrowserTestBase::getOptions protected function Helper function to get the options of select field.
BrowserTestBase::getResponseLogHandler protected function Provides a Guzzle middleware handler to log every response received. Overrides BrowserHtmlDebugTrait::getResponseLogHandler
BrowserTestBase::getSession public function Returns Mink session.
BrowserTestBase::getSessionCookies protected function Get session cookies from current session.
BrowserTestBase::getTestMethodCaller protected function Retrieves the current calling line in the class under test. Overrides BrowserHtmlDebugTrait::getTestMethodCaller
BrowserTestBase::initFrontPage protected function Visits the front page when initializing Mink. 3
BrowserTestBase::initMink protected function Initializes Mink sessions. 1
BrowserTestBase::installDrupal public function Installs Drupal into the Simpletest site. 1
BrowserTestBase::registerSessions protected function Registers additional Mink sessions.
BrowserTestBase::tearDown protected function 3
BrowserTestBase::translatePostValues protected function Transforms a nested array into a flat array suitable for drupalPostForm().
BrowserTestBase::xpath protected function Performs an xpath search on the contents of the internal browser.
BrowserTestBase::__construct public function 1
BrowserTestBase::__sleep public function Prevents serializing any properties.
ConfigTestTrait::configImporter protected function Returns a ConfigImporter object to import test configuration.
ConfigTestTrait::copyConfig protected function Copies configuration objects from source storage to target storage.
ContentTypeCreationTrait::createContentType protected function Creates a custom content type based on default settings. Aliased as: drupalCreateContentType 1
FunctionalTestSetupTrait::$apcuEnsureUniquePrefix protected property The flag to set 'apcu_ensure_unique_prefix' setting. 1
FunctionalTestSetupTrait::$classLoader protected property The class loader to use for installation and initialization of setup.
FunctionalTestSetupTrait::$configDirectories Deprecated protected property The config directories used in this test.
FunctionalTestSetupTrait::$rootUser protected property The "#1" admin user.
FunctionalTestSetupTrait::doInstall protected function Execute the non-interactive installer. 1
FunctionalTestSetupTrait::getDatabaseTypes protected function Returns all supported database driver installer objects.
FunctionalTestSetupTrait::initConfig protected function Initialize various configurations post-installation. 2
FunctionalTestSetupTrait::initKernel protected function Initializes the kernel after installation.
FunctionalTestSetupTrait::initSettings protected function Initialize settings created during install.
FunctionalTestSetupTrait::initUserSession protected function Initializes user 1 for the site to be installed.
FunctionalTestSetupTrait::installDefaultThemeFromClassProperty protected function Installs the default theme defined by `static::$defaultTheme` when needed.
FunctionalTestSetupTrait::installModulesFromClassProperty protected function Install modules defined by `static::$modules`. 1
FunctionalTestSetupTrait::installParameters protected function Returns the parameters that will be used when Simpletest installs Drupal. 9
FunctionalTestSetupTrait::prepareEnvironment protected function Prepares the current environment for running the test. 23
FunctionalTestSetupTrait::prepareRequestForGenerator protected function Creates a mock request and sets it on the generator.
FunctionalTestSetupTrait::prepareSettings protected function Prepares site settings and services before installation. 2
FunctionalTestSetupTrait::rebuildAll protected function Resets and rebuilds the environment after setup.
FunctionalTestSetupTrait::rebuildContainer protected function Rebuilds \Drupal::getContainer().
FunctionalTestSetupTrait::resetAll protected function Resets all data structures after having enabled new modules.
FunctionalTestSetupTrait::setContainerParameter protected function Changes parameters in the services.yml file.
FunctionalTestSetupTrait::setupBaseUrl protected function Sets up the base URL based upon the environment variable.
FunctionalTestSetupTrait::writeSettings protected function Rewrites the settings.php file of the test site.
MonitoringTestBase::$defaultTheme protected property The theme to install as the default for testing. Overrides BrowserTestBase::$defaultTheme
MonitoringTestTrait::doJsonRequest protected function Do the request.
MonitoringTestTrait::installModules protected function Install modules and fix test container.
MonitoringTestTrait::runSensor protected function Executes a sensor and returns the result.
MonitoringTestTrait::uninstallModules protected function Uninstall modules and fix test container.
MonitoringUITest::$modules public static property Modules to install. Overrides MonitoringTestBase::$modules
MonitoringUITest::assertThresholdSettingsUIDefaults protected function Asserts that defaults are set correctly in the settings form.
MonitoringUITest::doTestExceedsThresholdSettings protected function Tests exceeds threshold settings UI and validation.
MonitoringUITest::doTestFallsThresholdSettings protected function Tests falls threshold settings UI and validation.
MonitoringUITest::doTestInnerThresholdSettings protected function Tests inner threshold settings UI and validation.
MonitoringUITest::doTestOuterThresholdSettings protected function Tests outer threshold settings UI and validation.
MonitoringUITest::setUp protected function Overrides MonitoringTestBase::setUp
MonitoringUITest::submitThresholdSettings protected function Submits a threshold settings form for a given sensor.
MonitoringUITest::testAggregateSensorTimeIntervalConfig public function Tests the entity aggregator sensors.
MonitoringUITest::testAutoComplete public function Tests the auto completion of the sensor category field.
MonitoringUITest::testCoreRequirementsSensorUI public function Tests the UI of the requirements sensor.
MonitoringUITest::testForceExecute public function Tests the force execute all and sensor specific force execute links.
MonitoringUITest::testSensorDetailPage public function Tests the sensor detail page.
MonitoringUITest::testSensorDisappearedSensorsUI public function UI Tests for disappearing sensors.
MonitoringUITest::testSensorEditPage public function Tests the sensor detail page for actual and expected values.
MonitoringUITest::testSensorListLimit public function Tests that the sensor list is displayed completely.
MonitoringUITest::testSensorOverviewPage public function Tests the sensor results overview and the global sensor log.
MonitoringUITest::testSensorSettingsUI public function Test the sensor settings UI.
MonitoringUITest::testSettingsUI public function Test the monitoring settings UI.
NodeCreationTrait::createNode protected function Creates a node based on default settings. Aliased as: drupalCreateNode
NodeCreationTrait::getNodeByTitle public function Get a node from the database based on its title. Aliased as: drupalGetNodeByTitle
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
RandomGeneratorTrait::$randomGenerator protected property The random generator.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers. 1
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
RandomGeneratorTrait::randomStringValidate public function Callback for random string validation.
RefreshVariablesTrait::refreshVariables protected function Refreshes in-memory configuration and state information. 3
SessionTestTrait::$sessionName protected property The name of the session cookie.
SessionTestTrait::generateSessionName protected function Generates a session cookie name.
SessionTestTrait::getSessionName protected function Returns the session name in use on the child site.
StorageCopyTrait::replaceStorageContents protected static function Copy the configuration from one storage to another and remove stale items.
TestRequirementsTrait::checkModuleRequirements private function Checks missing module requirements.
TestRequirementsTrait::checkRequirements protected function Check module requirements for the Drupal use case. 1
TestRequirementsTrait::getDrupalRoot protected static function Returns the Drupal root directory.
TestSetupTrait::$configSchemaCheckerExclusions protected static property An array of config object names that are excluded from schema checking.
TestSetupTrait::$container protected property The dependency injection container used in the test.
TestSetupTrait::$kernel protected property The DrupalKernel instance used in the test.
TestSetupTrait::$originalSite protected property The site directory of the original parent site.
TestSetupTrait::$privateFilesDirectory protected property The private file directory for the test environment.
TestSetupTrait::$publicFilesDirectory protected property The public file directory for the test environment.
TestSetupTrait::$siteDirectory protected property The site directory of this test run.
TestSetupTrait::$strictConfigSchema protected property Set to TRUE to strict check all configuration saved. 2
TestSetupTrait::$tempFilesDirectory protected property The temporary file directory for the test environment.
TestSetupTrait::$testId protected property The test run ID.
TestSetupTrait::changeDatabasePrefix protected function Changes the database connection to the prefixed one.
TestSetupTrait::getConfigSchemaExclusions protected function Gets the config schema exclusions for this test.
TestSetupTrait::getDatabaseConnection public static function Returns the database connection to the site running Simpletest.
TestSetupTrait::prepareDatabasePrefix protected function Generates a database prefix for running tests. 2
UiHelperTrait::$loggedInUser protected property The current user logged in using the Mink controlled browser.
UiHelperTrait::$maximumMetaRefreshCount protected property The number of meta refresh redirects to follow, or NULL if unlimited.
UiHelperTrait::$metaRefreshCount protected property The number of meta refresh redirects followed during ::drupalGet().
UiHelperTrait::assertSession public function Returns WebAssert object. 1
UiHelperTrait::buildUrl protected function Builds an a absolute URL from a system path or a URL object.
UiHelperTrait::checkForMetaRefresh protected function Checks for meta refresh tag and if found call drupalGet() recursively.
UiHelperTrait::click protected function Clicks the element with the given CSS selector.
UiHelperTrait::clickLink protected function Follows a link by complete name.
UiHelperTrait::cssSelect protected function Searches elements using a CSS selector in the raw content.
UiHelperTrait::drupalGet protected function Retrieves a Drupal path or an absolute path. 3
UiHelperTrait::drupalLogin protected function Logs in a user using the Mink controlled browser.
UiHelperTrait::drupalLogout protected function Logs a user out of the Mink controlled browser and confirms.
UiHelperTrait::drupalPostForm protected function Executes a form submission.
UiHelperTrait::drupalUserIsLoggedIn protected function Returns whether a given user account is logged in.
UiHelperTrait::getAbsoluteUrl protected function Takes a path and returns an absolute path.
UiHelperTrait::getTextContent protected function Retrieves the plain-text content from the current page.
UiHelperTrait::getUrl protected function Get the current URL from the browser.
UiHelperTrait::prepareRequest protected function Prepare for a request to testing site. 1
UiHelperTrait::submitForm protected function Fills and submits a form.
UserCreationTrait::checkPermissions protected function Checks whether a given list of permission names is valid.
UserCreationTrait::createAdminRole protected function Creates an administrative role.
UserCreationTrait::createRole protected function Creates a role with specified permissions. Aliased as: drupalCreateRole
UserCreationTrait::createUser protected function Create a user with a given set of permissions. Aliased as: drupalCreateUser
UserCreationTrait::grantPermissions protected function Grant permissions to a user role.
UserCreationTrait::setCurrentUser protected function Switch the current logged in user.
UserCreationTrait::setUpCurrentUser protected function Creates a random user account and sets it as current user.
XdebugRequestTrait::extractCookiesFromRequest protected function Adds xdebug cookies, from request setup.