You are here

public function HandlerFilterUserNameTest::testAdminUserInterface in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/user/tests/src/Functional/Views/HandlerFilterUserNameTest.php \Drupal\Tests\user\Functional\Views\HandlerFilterUserNameTest::testAdminUserInterface()
  2. 10 core/modules/user/tests/src/Functional/Views/HandlerFilterUserNameTest.php \Drupal\Tests\user\Functional\Views\HandlerFilterUserNameTest::testAdminUserInterface()

Tests using the user interface.

File

core/modules/user/tests/src/Functional/Views/HandlerFilterUserNameTest.php, line 92

Class

HandlerFilterUserNameTest
Tests the handler of the user: name filter.

Namespace

Drupal\Tests\user\Functional\Views

Code

public function testAdminUserInterface() {
  $admin_user = $this
    ->drupalCreateUser([
    'administer views',
    'administer site configuration',
  ]);
  $this
    ->drupalLogin($admin_user);
  $path = 'admin/structure/views/nojs/handler/test_user_name/default/filter/uid';
  $this
    ->drupalGet($path);

  // Pass in an invalid username, the validation should catch it.
  $users = [
    $this
      ->randomMachineName(),
  ];
  $users = array_map('strtolower', $users);
  $edit = [
    'options[value]' => implode(', ', $users),
  ];
  $this
    ->drupalPostForm($path, $edit, t('Apply'));
  $this
    ->assertRaw(t('There are no entities matching "%value".', [
    '%value' => implode(', ', $users),
  ]));

  // Pass in an invalid username and a valid username.
  $random_name = $this
    ->randomMachineName();
  $users = [
    $random_name,
    $this->names[0],
  ];
  $users = array_map('strtolower', $users);
  $edit = [
    'options[value]' => implode(', ', $users),
  ];
  $users = [
    $users[0],
  ];
  $this
    ->drupalPostForm($path, $edit, t('Apply'));
  $this
    ->assertRaw(t('There are no entities matching "%value".', [
    '%value' => implode(', ', $users),
  ]));

  // Pass in just valid usernames.
  $users = $this->names;
  $users = array_map('strtolower', $users);
  $edit = [
    'options[value]' => implode(', ', $users),
  ];
  $this
    ->drupalPostForm($path, $edit, t('Apply'));
  $this
    ->assertNoRaw(t('There are no entities matching "%value".', [
    '%value' => implode(', ', $users),
  ]));
}