diff --git a/core/modules/user/lib/Drupal/user/Tests/Views/BulkFormTest.php b/core/modules/user/lib/Drupal/user/Tests/Views/BulkFormTest.php index 2e8a845..51f9b4a 100644 --- a/core/modules/user/lib/Drupal/user/Tests/Views/BulkFormTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/Views/BulkFormTest.php @@ -25,7 +25,7 @@ public static function getInfo() { return array( 'name' => 'User: Bulk form', 'description' => 'Tests a user bulk form.', - 'group' => 'Views Modules', + 'group' => 'Views module integration', ); } @@ -48,8 +48,32 @@ public function testBulkForm() { $this->drupalGet('test-user-bulk-form'); $this->assertText(t('No users selected.')); - // Block a user using the bulk form. + // Assign a role to a user. $account = $this->users[0]; + $roles = user_role_names(TRUE); + unset($roles[DRUPAL_AUTHENTICATED_RID]); + $role = key($roles); + + $this->assertTrue(!isset($account->roles[$role]), 'The user currently does not have a custom role.'); + $edit = array( + 'user_bulk_form[1]' => TRUE, + 'action' => 'add_role-' . $role, + ); + $this->drupalPost(NULL, $edit, t('Apply')); + // Re-load the user and check their roles. + $account = entity_load('user', $account->id(), TRUE); + $this->assertTrue(isset($account->roles[$role]), 'The user now has the custom role.'); + + $edit = array( + 'user_bulk_form[1]' => TRUE, + 'action' => 'remove_role-' . $role, + ); + $this->drupalPost(NULL, $edit, t('Apply')); + // Re-load the user and check their roles. + $account = entity_load('user', $account->id(), TRUE); + $this->assertTrue(!isset($account->roles[$role]), 'The user no longer has the custom role.'); + + // Block a user using the bulk form. $this->assertTrue($account->status); $this->assertRaw($account->label(), 'The user is found in the table.'); $edit = array( @@ -58,7 +82,7 @@ public function testBulkForm() { ); $this->drupalPost(NULL, $edit, t('Apply')); // Re-load the user and check their status. - $account = entity_load('user', $account->id()); + $account = entity_load('user', $account->id(), TRUE); $this->assertFalse($account->status); $this->assertNoRaw($account->label(), 'The user is not found in the table.'); diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 03949d2..d0bc3d8 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -2011,7 +2011,7 @@ function user_role_revoke_permissions($rid, array $permissions = array()) { /** * Implements hook_user_operations(). */ -function user_user_operations($form = array(), $selected_operation = FALSE) { +function user_user_operations($selected_operation = FALSE) { $operations = array( 'unblock' => array( 'label' => t('Unblock the selected users'), @@ -2121,14 +2121,12 @@ function user_user_operations_cancel($accounts) { * Callback function for admin mass adding/deleting a user role. */ function user_multiple_role_edit($accounts, $operation, $rid) { - $role_name = entity_load('user_role', $rid)->label(); - switch ($operation) { case 'add_role': foreach ($accounts as $account) { // Skip adding the role to the user if they already have it. if ($account !== FALSE && !isset($account->roles[$rid])) { - $roles = $account->roles + array($rid => $role_name); + $roles = $account->roles + array($rid => $rid); // For efficiency manually save the original account before applying // any changes. $account->original = clone $account; @@ -2141,7 +2139,7 @@ function user_multiple_role_edit($accounts, $operation, $rid) { foreach ($accounts as $account) { // Skip removing the role from the user if they already don't have it. if ($account !== FALSE && isset($account->roles[$rid])) { - $roles = array_diff($account->roles, array($rid => $role_name)); + $roles = array_diff($account->roles, array($rid => $rid)); // For efficiency manually save the original account before applying // any changes. $account->original = clone $account;