1 user.test | UserRoleAdminTestCase::testRoleWeightChange() |
Test user role weight change operation.
File
- core/
modules/ user/ tests/ user.test, line 2503 - Tests for user.module.
Class
- UserRoleAdminTestCase
- Test case to test adding, editing and deleting roles.
Code
function testRoleWeightChange() {
$this->backdropLogin($this->admin_user);
// Pick up a role and get its weight.
$role_name = $this->admin_user->roles[count($this->admin_user->roles) - 1];
$role = user_role_load($role_name);
$old_weight = $role->weight;
// Change the role weight and submit the form.
$edit = array('roles[' . $role_name . '][weight]' => $old_weight + 1);
$this->backdropPost('admin/config/people/roles', $edit, t('Save configuration'));
$this->assertText(t('The role settings have been updated.'), 'The role settings form submitted successfully.');
// Retrieve the saved role and compare its weight.
backdrop_static_reset('user_roles');
$role = user_role_load($role_name);
$new_weight = $role->weight;
$this->assertTrue(($old_weight + 1) == $new_weight, 'Role weight updated successfully.');
}