You are here

public function ArgumentValidateTest::testArgumentValidateUserName in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/user/tests/src/Kernel/Views/ArgumentValidateTest.php \Drupal\Tests\user\Kernel\Views\ArgumentValidateTest::testArgumentValidateUserName()
  2. 9 core/modules/user/tests/src/Kernel/Views/ArgumentValidateTest.php \Drupal\Tests\user\Kernel\Views\ArgumentValidateTest::testArgumentValidateUserName()

Tests the UserName argument validator.

File

core/modules/user/tests/src/Kernel/Views/ArgumentValidateTest.php, line 76

Class

ArgumentValidateTest
Tests user argument validators for ID and name.

Namespace

Drupal\Tests\user\Kernel\Views

Code

public function testArgumentValidateUserName() {
  $view = Views::getView('test_view_argument_validate_username');
  $this
    ->executeView($view);
  $this
    ->assertTrue($view->argument['null']
    ->validateArgument($this->account
    ->getAccountName()));

  // Reset argument validation.
  $view->argument['null']->argument_validated = NULL;

  // Fail for a valid string, but for a user that doesn't exist
  $this
    ->assertFalse($view->argument['null']
    ->validateArgument($this
    ->randomMachineName()));
}