You are here

public function LoginSecurityUserBlockingTest::testDrupalErrorToggle in Login Security 7

Same name and namespace in other branches
  1. 6 login_security.test \LoginSecurityUserBlockingTest::testDrupalErrorToggle()

Test disable core login error toggle.

File

./login_security.test, line 137
Test the basic functions of the Login Security module.

Class

LoginSecurityUserBlockingTest
Test login_security user blocking.

Code

public function testDrupalErrorToggle() {
  $normal_user = $this
    ->drupalCreateUser(array(
    'access content',
  ));

  // Intentionally break the password to repeat invalid logins.
  $normal_user->pass_raw = user_password();
  variable_set('login_security_disable_core_login_error', 0);
  $this
    ->drupalLoginLite($normal_user);
  $this
    ->assertRaw(t('Sorry, unrecognized username or password. <a href="@password">Have you forgotten your password?</a>', array(
    '@password' => url('user/password', array(
      'query' => array(
        'name' => $normal_user->name,
      ),
    )),
  )), t('Drupal "...Have you forgotten your password?" login error message found.'));

  // Block user.
  user_save($normal_user, array(
    'status' => 0,
  ));
  $this
    ->drupalLoginLite($normal_user);
  $this
    ->assertRaw(t('The username %name has not been activated or is blocked.', array(
    '%name' => $normal_user->name,
  )), t('Drupal "...has not been activated or is blocked." login error message found.'));
  variable_set('login_security_disable_core_login_error', 1);

  // Unblock user.
  user_save($normal_user, array(
    'status' => 1,
  ));
  $this
    ->drupalLoginLite($normal_user);
  $this
    ->assertNoRaw(t('Sorry, unrecognized username or password. <a href="@password">Have you forgotten your password?</a>', array(
    '@password' => url('user/password', array(
      'query' => array(
        'name' => $normal_user->name,
      ),
    )),
  )), t('Drupal "...Have you forgotten your password?" login error message not found.'));

  // Block user.
  user_save($normal_user, array(
    'status' => 0,
  ));
  $this
    ->drupalLoginLite($normal_user);
  $this
    ->assertNoRaw(t('The username %name has not been activated or is blocked.', array(
    '%name' => $normal_user->name,
  )), t('Drupal "...has not been activated or is blocked." login error message not found.'));
}