function ViewExecutableTest::testArgumentValidatorValueOverride

Same name and namespace in other branches
  1. 11.x core/modules/views/tests/src/Kernel/ViewExecutableTest.php \Drupal\Tests\views\Kernel\ViewExecutableTest::testArgumentValidatorValueOverride()
  2. 10 core/modules/views/tests/src/Kernel/ViewExecutableTest.php \Drupal\Tests\views\Kernel\ViewExecutableTest::testArgumentValidatorValueOverride()
  3. 9 core/modules/views/tests/src/Kernel/ViewExecutableTest.php \Drupal\Tests\views\Kernel\ViewExecutableTest::testArgumentValidatorValueOverride()
  4. 8.9.x core/modules/views/tests/src/Kernel/ViewExecutableTest.php \Drupal\Tests\views\Kernel\ViewExecutableTest::testArgumentValidatorValueOverride()

Tests if argument overrides by validators are propagated to tokens.

File

core/modules/views/tests/src/Kernel/ViewExecutableTest.php, line 543

Class

ViewExecutableTest
Tests the ViewExecutable class.

Namespace

Drupal\Tests\views\Kernel

Code

public function testArgumentValidatorValueOverride() : void {
  $account = User::create([
    'name' => $this->randomString(),
  ]);
  $account->save();
  $view = Views::getView('test_argument_dependency');
  $view->setDisplay('page_1');
  // The view has two arguments: uid_touch (comment module) and uid (with
  // argument_validator_test as its validator). Both are needed to verify
  // that calculateDependencies() picks up dependencies from both default
  // and validator plugins. uid receives the value the validator intercepts
  // and overrides to '1'.
  $view->setArguments([
    $account->id(),
    'this value should be replaced',
  ]);
  $view->execute();
  $account = User::load(1);
  $expected = [
    '{{ arguments.uid_touch }}' => $account->label(),
    '{{ raw_arguments.uid_touch }}' => (string) $account->id(),
    '{{ arguments.uid }}' => $account->label(),
    '{{ raw_arguments.uid }}' => (string) $account->id(),
  ];
  $this->assertEquals($expected, $view->build_info['substitutions']);
}

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