/**
  * Role comparison must be done on role name, not role display name.
  *
  * @ticket 38234
  */
 public function test_get_users_with_no_role_matches_on_role_name()
 {
     // Create a role with a display name which would not match the role name
     // in a case-insentive SQL query.
     wp_roles()->add_role('somerole', 'Some role display name');
     $someuser = self::factory()->user->create(array('role' => 'somerole'));
     $users = wp_get_users_with_no_role();
     wp_roles()->remove_role('somerole');
     $this->assertEmpty($users);
 }
 /**
  * Prepare the users list for display.
  *
  * @since 3.1.0
  * @access public
  *
  * @global string $role
  * @global string $usersearch
  */
 public function prepare_items()
 {
     global $role, $usersearch;
     $usersearch = isset($_REQUEST['s']) ? wp_unslash(trim($_REQUEST['s'])) : '';
     $role = isset($_REQUEST['role']) ? $_REQUEST['role'] : '';
     $per_page = $this->is_site_users ? 'site_users_network_per_page' : 'users_per_page';
     $users_per_page = $this->get_items_per_page($per_page);
     $paged = $this->get_pagenum();
     if ('none' === $role) {
         $args = array('number' => $users_per_page, 'offset' => ($paged - 1) * $users_per_page, 'include' => wp_get_users_with_no_role(), 'search' => $usersearch, 'fields' => 'all_with_meta');
     } else {
         $args = array('number' => $users_per_page, 'offset' => ($paged - 1) * $users_per_page, 'role' => $role, 'search' => $usersearch, 'fields' => 'all_with_meta');
     }
     if ('' !== $args['search']) {
         $args['search'] = '*' . $args['search'] . '*';
     }
     if ($this->is_site_users) {
         $args['blog_id'] = $this->site_id;
     }
     if (isset($_REQUEST['orderby'])) {
         $args['orderby'] = $_REQUEST['orderby'];
     }
     if (isset($_REQUEST['order'])) {
         $args['order'] = $_REQUEST['order'];
     }
     /**
      * Filter the query arguments used to retrieve users for the current users list table.
      *
      * @since 4.4.0
      *
      * @param array $args Arguments passed to WP_User_Query to retrieve items for the current
      *                    users list table.
      */
     $args = apply_filters('users_list_table_query_args', $args);
     // Query the user IDs for this page
     $wp_user_search = new WP_User_Query($args);
     $this->items = $wp_user_search->get_results();
     $this->set_pagination_args(array('total_items' => $wp_user_search->get_total(), 'per_page' => $users_per_page));
 }
 /**
  * @ticket 22993
  * @group multisite
  */
 public function test_get_users_with_no_role_multisite_is_accurate()
 {
     if (!is_multisite()) {
         $this->markTestSkipped('Test requires multisite');
     }
     // Setup users
     $admin = self::factory()->user->create(array('role' => 'administrator'));
     $editor = self::factory()->user->create(array('role' => 'editor'));
     $nobody = self::factory()->user->create(array('role' => ''));
     // Setup blogs
     $blog_1 = (int) self::factory()->blog->create(array('user_id' => $editor));
     // Add users to blogs
     add_user_to_blog($blog_1, $editor, 'editor');
     // Test users on root site
     $users = wp_get_users_with_no_role();
     $this->assertSame(array(), $users);
     // Test users counts on blog 1
     switch_to_blog($blog_1);
     $users = wp_get_users_with_no_role();
     restore_current_blog();
     // Test users on root site
     $this->assertSame(array(), $users);
 }