1 user.test protected UserCreateTestCase::testUserAdd()

Create a user through the administration interface and ensure that it displays in the user list.

File

core/modules/user/tests/user.test, line 1963
Tests for user.module.

Class

UserCreateTestCase
Test the create user administration page.

Code

protected function testUserAdd() {
  $user = $this->backdropCreateUser(array('administer users'));
  $this->backdropLogin($user);

  // Test user creation page for valid fields.
  $this->backdropGet('admin/people/create');
  $this->assertFieldbyId('edit-status-0', 0, 'The user status option Blocked exists.', 'User login');
  $this->assertFieldbyId('edit-status-1', 1, 'The user status option Active exists.', 'User login');
  $this->assertFieldByXPath('//input[@type="radio" and @id="edit-status-1" and @checked="checked"]', NULL, 'Default setting for user status is active.');

  // We create two users, notifying one and not notifying the other, to
  // ensure that the tests work in both cases.
  foreach (array(FALSE, TRUE) as $notify) {
    $name = $this->randomName();
    $edit = array(
      'name' => $name,
      'mail' => $this->randomName() . '@example.com',
      'pass' => $pass = $this->randomString(),
      'notify' => $notify,
    );
    $this->backdropPost('admin/people/create', $edit, t('Create new account'));

    if ($notify) {
      $this->assertText(t('A welcome message with further instructions has been emailed to the new user @name.', array('@name' => $edit['name'])), 'User created');
      $this->assertEqual(count($this->backdropGetMails()), 1, 'Notification email sent');
    }
    else {
      $this->assertText(t('Created a new user account for @name. No email has been sent.', array('@name' => $edit['name'])), 'User created');
      $this->assertEqual(count($this->backdropGetMails()), 0, 'Notification email not sent');
    }

    $this->backdropGet('admin/people');
    $this->assertText($edit['name'], 'User found in list of users');
    $user = user_load_by_name($name);
    $this->assertEqual($user->status == 1, 'User is not blocked');
  }

  // Test that '0' is considered a password. We have to disable password
  // required score for that.
  config_set('system.core', 'user_password_reject_weak', FALSE);
  $name = $this->randomName();
  $edit = array(
    'name' => $name,
    'mail' => $name . '@example.com',
    'pass' => 0,
    'notify' => FALSE,
  );
  $this->backdropPost('admin/people/create', $edit, t('Create new account'));
  $this->assertText(t('Created a new user account for @name. No email has been sent.', array('@name' => $edit['name'])), 'User created with password 0');
  $this->assertNoText('Password field is required');
}