function ArgumentValidateTest::testArgumentValidateUserUid

Same name in other branches
  1. 9 core/modules/user/tests/src/Kernel/Views/ArgumentValidateTest.php \Drupal\Tests\user\Kernel\Views\ArgumentValidateTest::testArgumentValidateUserUid()
  2. 8.9.x core/modules/user/tests/src/Kernel/Views/ArgumentValidateTest.php \Drupal\Tests\user\Kernel\Views\ArgumentValidateTest::testArgumentValidateUserUid()
  3. 10 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 58

Class

ArgumentValidateTest
Tests user argument validators for ID and name.

Namespace

Drupal\Tests\user\Kernel\Views

Code

public function testArgumentValidateUserUid() : void {
    $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']);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.