You are here

protected function MonitoringCoreWebTest::doTestWatchdogAggregatorSensorPlugin in Monitoring 8

Tests successful user logins through watchdog sensor.

See also

\Drupal\monitoring\Plugin\monitoring\SensorPlugin\DatabaseAggregatorSensorPlugin

1 call to MonitoringCoreWebTest::doTestWatchdogAggregatorSensorPlugin()
MonitoringCoreWebTest::testSensors in tests/src/Functional/MonitoringCoreWebTest.php
Tests individual sensors.

File

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

Class

MonitoringCoreWebTest
Integration tests for the core pieces of monitoring.

Namespace

Drupal\Tests\monitoring\Functional

Code

protected function doTestWatchdogAggregatorSensorPlugin() {

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

  // Test output and default message replacement.
  $this
    ->drupalGet('admin/reports/monitoring/sensors/user_successful_logins');
  $rows = $this
    ->getSession()
    ->getPage()
    ->findAll('css', '#unaggregated_result tbody tr');
  $message = $rows[0]
    ->find('css', 'td:nth-child(2)')
    ->getText();
  $this
    ->assertEquals(5, count($rows), 'There are 5 results in the table.');
  $this
    ->assertTrue(!empty($rows[0]
    ->find('css', 'a')
    ->getText()), 'Found WID in verbose output');
  $this
    ->assertEquals("Session opened for {$test_user->getDisplayName()}.", $message, 'Found replaced message in output.');
  $this
    ->assertText('Session opened for ' . $test_user
    ->label());

  // Remove variables from the fields and assert message has no replacements.
  $this
    ->drupalPostForm('admin/config/system/monitoring/sensors/user_successful_logins', [
    'verbose_fields[variables][field_key]' => '',
  ], t('Save'));
  $this
    ->drupalGet('admin/reports/monitoring/sensors/user_successful_logins');
  $rows = $this
    ->getSession()
    ->getPage()
    ->findAll('css', '#unaggregated_result tbody tr');
  $message = $rows[0]
    ->find('css', 'td:nth-child(2)')
    ->getText();
  $this
    ->assertTrue(!empty($rows[0]
    ->find('css', 'td:nth-child(1)')
    ->getText()), 'Found WID in verbose output');
  $this
    ->assertEquals('Session opened for %name.', $message, 'Found unreplaced message in output.');
}