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.


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


Test cancelling a user.


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.
    ->condition('uid', 1)

  // 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'));
  $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.');