function PluginBaseTest::testViewsTokenReplace

Same name in other branches
  1. 8.9.x core/modules/views/tests/src/Kernel/Plugin/PluginBaseTest.php \Drupal\Tests\views\Kernel\Plugin\PluginBaseTest::testViewsTokenReplace()
  2. 10 core/modules/views/tests/src/Kernel/Plugin/PluginBaseTest.php \Drupal\Tests\views\Kernel\Plugin\PluginBaseTest::testViewsTokenReplace()
  3. 11.x core/modules/views/tests/src/Kernel/Plugin/PluginBaseTest.php \Drupal\Tests\views\Kernel\Plugin\PluginBaseTest::testViewsTokenReplace()

Tests that the token replacement in views works correctly.

File

core/modules/views/tests/src/Kernel/Plugin/PluginBaseTest.php, line 38

Class

PluginBaseTest
Tests the PluginBase class.

Namespace

Drupal\Tests\views\Kernel\Plugin

Code

public function testViewsTokenReplace() {
    $text = '{{ langcode__value }} means {{ langcode }}';
    $tokens = [
        '{{ langcode }}' => Markup::create('English'),
        '{{ langcode__value }}' => 'en',
    ];
    $result = \Drupal::service('renderer')->executeInRenderContext(new RenderContext(), function () use ($text, $tokens) {
        return $this->testPluginBase
            ->viewsTokenReplace($text, $tokens);
    });
    $this->assertSame('en means English', $result);
}

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