function UserRoleAdminTestCase::testRoleWeightChange

7.x user.test UserRoleAdminTestCase::testRoleWeightChange()

Test user role weight change operation.

File

drupal-7.x/modules/user/user.test, line 2037
Tests for user.module.

Class

UserRoleAdminTestCase
Test case to test adding, editing and deleting roles.

Code

function testRoleWeightChange() {
  $this->drupalLogin($this->admin_user);

  // Pick up a random role and get its weight.
  $rid = array_rand(user_roles());
  $role = user_role_load($rid);
  $old_weight = $role->weight;

  // Change the role weight and submit the form.
  $edit = array('roles[' . $rid . '][weight]' => $old_weight + 1);
  $this->drupalPost('admin/people/permissions/roles', $edit, t('Save order'));
  $this->assertText(t('The role settings have been updated.'), 'The role settings form submitted successfully.');

  // Retrieve the saved role and compare its weight.
  $role = user_role_load($rid);
  $new_weight = $role->weight;
  $this->assertTrue(($old_weight + 1) == $new_weight, 'Role weight updated successfully.');
}