1 user.test UserCancelTestCase::testUserCancelUid1()

Tests that user account for uid 1 cannot be cancelled.

This should never be possible, or the site owner would become unable to administer the site.

File

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

Class

UserCancelTestCase
Test cancelling a user.

Code

function testUserCancelUid1() {
  // Update uid 1's name and password to we know it.
  $password = user_password();
  require_once BACKDROP_ROOT . '/' . settings_get('password_inc', 'core/includes/password.inc');
  $account = array(
    'name' => 'user1',
    'pass' => user_hash_password(trim($password)),
  );
  // We cannot use $account->save() here, because this would result in the
  // password being hashed again.
  db_update('users')
    ->fields($account)
    ->condition('uid', 1)
    ->execute();

  // Reload and log in uid 1.
  $user1 = user_load(1, TRUE);
  $user1->pass_raw = $password;

  // Try to cancel uid 1's account with a different user.
  $this->admin_user = $this->backdropCreateUser(array('administer users'));
  $this->backdropLogin($this->admin_user);
  $edit = array(
    'action' => 'user_cancel_user_action',
    'bulk_form[0]' => TRUE,
  );
  $this->backdropPost('admin/people', $edit, t('Execute'));

  // Verify that uid 1's account was not cancelled.
  $user1 = user_load(1, TRUE);
  $this->assertEqual($user1->status, 1, 'User #1 still exists and is not blocked.');
}