You are here

public function TokenReplaceTest::testTokenReplacementNoResults in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Kernel/TokenReplaceTest.php \Drupal\Tests\views\Kernel\TokenReplaceTest::testTokenReplacementNoResults()
  2. 9 core/modules/views/tests/src/Kernel/TokenReplaceTest.php \Drupal\Tests\views\Kernel\TokenReplaceTest::testTokenReplacementNoResults()

Tests core token replacements generated from a view without results.

File

core/modules/views/tests/src/Kernel/TokenReplaceTest.php, line 112

Class

TokenReplaceTest
Tests core view token replacement.

Namespace

Drupal\Tests\views\Kernel

Code

public function testTokenReplacementNoResults() {
  $token_handler = \Drupal::token();
  $view = Views::getView('test_tokens');
  $view
    ->setDisplay('page_2');
  $this
    ->executeView($view);
  $expected = [
    '[view:page-count]' => '1',
  ];
  foreach ($expected as $token => $expected_output) {
    $output = $token_handler
      ->replace($token, [
      'view' => $view,
    ]);
    $this
      ->assertSame($expected_output, $output, new FormattableMarkup('Token %token replaced correctly.', [
      '%token' => $token,
    ]));
  }
}