public function HandlerFilterUserNameTest::testUserAutocomplete

Tests the autocomplete function.

See also

views_ajax_autocomplete_user

File

drupal/core/modules/views/lib/Drupal/views/Tests/User/HandlerFilterUserNameTest.php, line 181
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 testUserAutocomplete() {
  module_load_include('inc', 'views', 'includes/ajax');

  // Nothing should return no user.
  $result = (array) json_decode(views_ajax_autocomplete_user(''));
  $this
    ->assertFalse($result);

  // A random user should also not be findable.
  $result = (array) json_decode(views_ajax_autocomplete_user($this
    ->randomName())
    ->getContent());
  $this
    ->assertFalse($result);

  // A valid user should be found.
  $result = (array) json_decode(views_ajax_autocomplete_user($this->names[0])
    ->getContent());
  $expected_result = array(
    $this->names[0] => $this->names[0],
  );
  $this
    ->assertIdentical($result, $expected_result);
}