View source
<?php
class DomainIntegrationLoginRestrictTest extends DomainTestCase {
protected $domains;
protected $user;
public static function getInfo() {
return array(
'name' => 'Check login restrictions',
'description' => 'Check that login restrictions apply.',
'group' => 'Domain Access',
);
}
public function setUp($list = []) {
$list[] = 'domain_integration_login_restrict';
parent::setUp($list);
$this->domains = $this
->domainCreateDomains();
$this->user = $this
->drupalCreateUser();
}
public function testRestrictLogin() {
$user = user_save($this->user, array(
'domain_user' => array(
1 => 1,
),
));
$this
->drupalLogin($user);
$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();
$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.');
$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.');
$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.');
$this
->assertText('Sorry, you cannot log in on this domain.');
$this
->assertText('Welcome to TestDomainSitename');
$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.');
}
protected function drupalLoginNoSuccessCheck(stdClass $account) {
if ($this->loggedInUser) {
$this
->drupalLogout();
}
$edit = array(
'name' => $account->name,
'pass' => $account->pass_raw,
);
$this
->drupalPost('user', $edit, t('Log in'));
}
}