public function HandlerFilterUserNameTest::testExposedFilter

Tests exposed filters.

File

drupal/core/modules/views/lib/Drupal/views/Tests/User/HandlerFilterUserNameTest.php, line 140
Definition of Drupal\views\Tests\User\HandlerFilterUserNameTest.

Class

HandlerFilterUserNameTest
Tests the handler of the user: name filter.

Namespace

Drupal\views\Tests\User

Code

public function testExposedFilter() {
  $path = 'test_user_name';
  $options = array();

  // Pass in an invalid username, the validation should catch it.
  $users = array(
    $this
      ->randomName(),
  );
  $users = array_map('strtolower', $users);
  $options['query']['uid'] = implode(', ', $users);
  $this
    ->drupalGet($path, $options);
  $message = format_plural(count($users), 'Unable to find user: @users', 'Unable to find users: @users', array(
    '@users' => implode(', ', $users),
  ));
  $this
    ->assertRaw($message);

  // Pass in an invalid username and a valid username.
  $users = array(
    $this
      ->randomName(),
    $this->names[0],
  );
  $options['query']['uid'] = implode(', ', $users);
  $users = array_map('strtolower', $users);
  $users = array(
    $users[0],
  );
  $this
    ->drupalGet($path, $options);
  $message = format_plural(count($users), 'Unable to find user: @users', 'Unable to find users: @users', array(
    '@users' => implode(', ', $users),
  ));
  $this
    ->assertRaw($message);

  // Pass in just valid usernames.
  $users = $this->names;
  $options['query']['uid'] = implode(', ', $users);
  $users = array_map('strtolower', $users);
  $this
    ->drupalGet($path, $options);
  $this
    ->assertNoRaw('Unable to find user');

  // The actual result should contain all of the user ids.
  foreach ($this->accounts as $account) {
    $this
      ->assertRaw($account->uid);
  }
}