1 user.test UserEditRebuildTestCase::testUserEditFormRebuild()

Test user edit page when the form is set to rebuild.

File

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

Class

UserEditRebuildTestCase
Tests editing a user account with and without a form rebuild.

Code

function testUserEditFormRebuild() {
  $user1 = $this->backdropCreateUser(array('change own username'));
  $this->backdropLogin($user1);

  $roles = array_keys($user1->roles);
  // Save the user form twice.
  $edit = array();
  $edit['current_pass'] = $user1->pass_raw;
  $this->backdropPost("user/$user1->uid/edit", $edit, t('Save'));
  $this->assertRaw(t("The changes have been saved."));
  $this->backdropPost("user/$user1->uid/edit", $edit, t('Save'));
  $this->assertRaw(t("The changes have been saved."));
  $saved_user1 = entity_load_unchanged('user', $user1->uid);
  $this->assertEqual(count($roles), count($saved_user1->roles), 'Count of user roles in database matches original count.');
  $diff = array_diff(array_keys($saved_user1->roles), $roles);
  $this->assertTrue(empty($diff), format_string('User roles in database match original: @roles', array('@roles' => implode(', ', $saved_user1->roles))));
  // Set variable that causes the form to be rebuilt in user_form_test.module.
  state_set('user_form_test_user_profile_form_rebuild', TRUE);
  $this->backdropPost("user/$user1->uid/edit", $edit, t('Save'));
  $this->assertRaw(t("The changes have been saved."));
  $this->backdropPost(NULL, $edit, t('Save'));
  $this->assertRaw(t("The changes have been saved."));
  $saved_user1 = entity_load_unchanged('user', $user1->uid);
  $this->assertEqual(count($roles), count($saved_user1->roles), 'Count of user roles in database matches original count.');
  $diff = array_diff(array_keys($saved_user1->roles), $roles);
  $this->assertTrue(empty($diff), format_string('User roles in database match original: @roles', array('@roles' => implode(', ', $saved_user1->roles))));
}