You are here

public function ArgumentValidateTest::testArgumentValidateUserUid in Drupal 8

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

Tests the User (ID) argument validator.

File

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

Class

ArgumentValidateTest
Tests user argument validators for ID and name.

Namespace

Drupal\Tests\user\Kernel\Views

Code

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

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

  // Fail for a valid numeric, but for a user that doesn't exist
  $this
    ->assertFalse($view->argument['null']
    ->validateArgument(32));
  $form = [];
  $form_state = new FormState();
  $view->argument['null']
    ->buildOptionsForm($form, $form_state);
  $sanitized_id = ArgumentPluginBase::encodeValidatorId('entity:user');
  $this
    ->assertTrue($form['validate']['options'][$sanitized_id]['roles']['#states']['visible'][':input[name="options[validate][options][' . $sanitized_id . '][restrict_roles]"]']['checked']);
}