You are here

public function DomainIntegrationLoginRestrictTest::testRestrictLogin in Domain Integration (Drupal 7) 7

Tests the restrictions on login.

File

modules/domain_integration_login_restrict/domain_integration_login_restrict.test, line 41

Class

DomainIntegrationLoginRestrictTest
Class DomainIntegrationLoginRestrictTest

Code

public function testRestrictLogin() {

  // Assign the user to domain one and try to log in.
  $user = user_save($this->user, array(
    'domain_user' => array(
      1 => 1,
    ),
  ));
  $this
    ->drupalLogin($user);

  // Assign the user to domain two and try to log in.
  $user = user_save($this->user, array(
    'domain_user' => array(
      $this->domains['two']['domain_id'] => $this->domains['two']['domain_id'],
    ),
  ));
  $this
    ->drupalLoginNoSuccessCheck($user);
  $this
    ->assertText('Sorry, you cannot log in on this domain.');
  $this
    ->drupalLogout();

  // Try to obtain a one time login on a domain where the user has no access.
  // Try using a username.
  $edit = array(
    'name' => $this->user->name,
  );
  $this
    ->drupalPost('user/password', $edit, 'E-mail new password');
  $this
    ->assertText('Sorry, you cannot log in on this domain.');

  // Try using a email.
  $edit = array(
    'name' => $this->user->mail,
  );
  $this
    ->drupalPost('user/password', $edit, 'E-mail new password');
  $this
    ->assertText('Sorry, you cannot log in on this domain.');

  // Use a one-time login link to log into the main domain when the user has
  // no access to the domain.
  $one_time_login = user_pass_reset_url($user);
  $this
    ->drupalGet($one_time_login);
  $this
    ->drupalPost(NULL, array(), t('Log in'));
  $this
    ->assertNoText('You have just used your one-time login link. It is no longer necessary to use this link to log in. Please change your password.');

  // Make sure we've been redirected to the front page.
  $this
    ->assertText('Sorry, you cannot log in on this domain.');
  $this
    ->assertText('Welcome to TestDomainSitename');

  // For a logged-out user, expect no secondary links.
  $element = $this
    ->xpath('//ul[@id=:menu_id]', array(
    ':menu_id' => 'secondary-menu-links',
  ));
  $this
    ->assertEqual(count($element), 0, 'No secondary-menu for logged-out users.');
}