You are here

public function LoginSecurityUserBlockingTest::testLoginMessage in Login Security 2.x

Test login message.

File

tests/src/Functional/LoginSecurityUserBlockingTest.php, line 267

Class

LoginSecurityUserBlockingTest
Test Login Security's user-blocking restrictions and default messages.

Namespace

Drupal\Tests\login_security\Functional

Code

public function testLoginMessage() {
  $config = \Drupal::configFactory()
    ->getEditable('login_security.settings');
  $normal_user = $this
    ->drupalCreateUser();
  $config
    ->set('last_login_timestamp', 1)
    ->save();
  $config
    ->set('last_access_timestamp', 1)
    ->save();
  $this
    ->drupalLogin($normal_user);

  // This is the very first login ever, so there should be no previous login
  // to show.
  $this
    ->assertNoTextLastLoginMessage();
  $config
    ->set('last_login_timestamp', 0)
    ->save();
  $config
    ->set('last_access_timestamp', 0)
    ->save();
  $this
    ->drupalLogin($normal_user);
  $this
    ->assertNoTextLastLoginMessage();
  $this
    ->assertNoTextLastPageAccess();
  $config
    ->set('last_login_timestamp', 1)
    ->save();
  $this
    ->drupalLogin($normal_user);
  $this
    ->assertTextLastLoginMessage();
  $this
    ->assertNoTextLastPageAccess();
  $config
    ->set('last_login_timestamp', 0)
    ->save();
  $config
    ->set('last_access_timestamp', 1)
    ->save();
  $this
    ->drupalLogin($normal_user);
  $this
    ->assertNoTextLastLoginMessage();
  $this
    ->assertTextLastPageAccess();
  $config
    ->set('last_login_timestamp', 1)
    ->save();
  $this
    ->drupalLogin($normal_user);
  $this
    ->assertTextLastLoginMessage();
  $this
    ->assertTextLastPageAccess();
}