You are here

function UserRestrictionsTestCase::testAccess in User restrictions 7

File

./user_restrictions.test, line 31
TestCase for the User restrictions module.

Class

UserRestrictionsTestCase
@file TestCase for the User restrictions module.

Code

function testAccess() {

  // To avoid conflicts with non allowed account creations.
  variable_set('user_register', 1);
  $this
    ->addMask('simpletest_block%', 'name');
  $this
    ->addMask('simpletest_block_allow%', 'name', 1);

  // First try the blocked user.
  $name = 'simpletest_block_' . $this
    ->randomName(6);
  $mail = "{$name}@example.com";
  $edit = array(
    'name' => $name,
    'mail' => $mail,
  );
  $this
    ->drupalPost('user/register', $edit, t('Create new account'));
  $this
    ->assertText(t('The name @name is not allowed.', array(
    '@name' => $name,
  )));
  $user = user_load_by_name($name);
  $this
    ->assertFalse($user, t('User was not created.'));

  // Now try the allowed user.
  $name = 'simpletest_block_allow_' . $this
    ->randomName(6);
  $mail = "{$name}@example.com";
  $edit = array(
    'name' => $name,
    'mail' => $mail,
  );
  $this
    ->drupalPost('user/register', $edit, t('Create new account'));
  $this
    ->assertNoText(t('The name @name is not allowed.', array(
    '@name' => $name,
  )));
  $user = user_load_by_name($name);
  $this
    ->assertTrue(isset($user->uid), t('user->uid is set.'));
  $this
    ->assertTrue($user->uid > 0, t('The user ID is greater than zero.'));
}