You are here

user_restrictions.test in User restrictions 7

TestCase for the User restrictions module.

File

user_restrictions.test
View source
<?php

/**
 * @file
 * TestCase for the User restrictions module.
 */
class UserRestrictionsTestCase extends DrupalWebTestCase {
  protected function addMask($mask, $type, $status = 0) {
    db_insert('user_restrictions')
      ->fields(array(
      'mask' => $mask,
      'type' => $type,
      'status' => $status,
    ))
      ->execute();
  }
  static function getInfo() {
    return array(
      'name' => 'User restrictions',
      'description' => 'Assure that negative and positive access rules behave as designed.',
      'group' => 'User restrictions',
    );
  }
  function setUp() {
    parent::setUp('user_restrictions');
  }
  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.'));
  }

}

Classes

Namesort descending Description
UserRestrictionsTestCase @file TestCase for the User restrictions module.