You are here

public function MonitoringCoreKernelTest::testUserFailedLoginsSensorPlugin in Monitoring 8

Tests failed user logins sensor.

See also

\Drupal\monitoring\Plugin\monitoring\SensorPlugin\UserFailedLoginsSensorPlugin

File

tests/src/Kernel/MonitoringCoreKernelTest.php, line 574

Class

MonitoringCoreKernelTest
Kernel tests for the core pieces of monitoring.

Namespace

Drupal\Tests\monitoring\Kernel

Code

public function testUserFailedLoginsSensorPlugin() {

  // Fake some login failed dblog records.
  \Drupal::logger('user')
    ->notice('Login attempt failed for %user.', array(
    '%user' => 'user1',
  ));
  \Drupal::logger('user')
    ->notice('Login attempt failed for %user.', array(
    '%user' => 'user1',
  ));
  \Drupal::logger('user')
    ->notice('Login attempt failed for %user.', array(
    '%user' => 'user2',
  ));
  \Drupal::logger('user')
    ->notice('Login attempt failed for %user.', array(
    '%user' => 'user2',
  ));
  \Drupal::logger('user')
    ->notice('Login attempt failed for %user.', array(
    '%user' => 'user2',
  ));

  // Run sensor and test the output.
  $result = $this
    ->runSensor('user_failed_logins');
  $this
    ->assertEqual($result
    ->getValue(), 5);
  $this
    ->assertEqual($result
    ->getMessage(), '5 login attempts in 1 day, user2: 3, user1: 2');
}