You are here

function UserCancelTestCase::testUserCancelByAdmin in Drupal 7

Create an administrative user and delete another user.

File

modules/user/user.test, line 1179
Tests for user.module.

Class

UserCancelTestCase
Test cancelling a user.

Code

function testUserCancelByAdmin() {
  variable_set('user_cancel_method', 'user_cancel_reassign');

  // Create a regular user.
  $account = $this
    ->drupalCreateUser(array());

  // Create administrative user.
  $admin_user = $this
    ->drupalCreateUser(array(
    'administer users',
  ));
  $this
    ->drupalLogin($admin_user);

  // Delete regular user.
  $this
    ->drupalGet('user/' . $account->uid . '/edit');
  $this
    ->drupalPost(NULL, NULL, t('Cancel account'));
  $this
    ->assertRaw(t('Are you sure you want to cancel the account %name?', array(
    '%name' => $account->name,
  )), 'Confirmation form to cancel account displayed.');
  $this
    ->assertText(t('Select the method to cancel the account above.'), 'Allows to select account cancellation method.');

  // Confirm deletion.
  $this
    ->drupalPost(NULL, NULL, t('Cancel account'));
  $this
    ->assertRaw(t('%name has been deleted.', array(
    '%name' => $account->name,
  )), 'User deleted.');
  $this
    ->assertFalse(user_load($account->uid), 'User is not found in the database.');
}