function TokenReplaceTest::testTokenReplacementNoPath

Same name in other branches
  1. 9 core/modules/views/tests/src/Kernel/TokenReplaceTest.php \Drupal\Tests\views\Kernel\TokenReplaceTest::testTokenReplacementNoPath()
  2. 10 core/modules/views/tests/src/Kernel/TokenReplaceTest.php \Drupal\Tests\views\Kernel\TokenReplaceTest::testTokenReplacementNoPath()
  3. 11.x core/modules/views/tests/src/Kernel/TokenReplaceTest.php \Drupal\Tests\views\Kernel\TokenReplaceTest::testTokenReplacementNoPath()

Tests path token replacements generated from a view without a path.

File

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

Class

TokenReplaceTest
Tests core view token replacement.

Namespace

Drupal\Tests\views\Kernel

Code

public function testTokenReplacementNoPath() {
    $token_handler = \Drupal::token();
    $view = Views::getView('test_invalid_tokens');
    $view->setDisplay('block_1');
    $this->executeView($view);
    $expected = [
        '[view:url]' => '',
    ];
    foreach ($expected as $token => $expected_output) {
        $output = $token_handler->replace($token, [
            'view' => $view,
        ]);
        $this->assertIdentical($output, $expected_output, new FormattableMarkup('Token %token replaced correctly.', [
            '%token' => $token,
        ]));
    }
}

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