function PluginBaseTest::testViewsTokenReplaceWithDots

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

Tests that the token replacement in views works correctly with dots.

File

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

Class

PluginBaseTest
Tests the PluginBase class.

Namespace

Drupal\Tests\views\Kernel\Plugin

Code

public function testViewsTokenReplaceWithDots() : void {
  $text = '{{ argument.first }} comes before {{ argument.second }}';
  $tokens = [
    '{{ argument.first }}' => 'first',
    '{{ argument.second }}' => 'second',
  ];
  $result = \Drupal::service('renderer')->executeInRenderContext(new RenderContext(), function () use ($text, $tokens) {
    return $this->testPluginBase
      ->viewsTokenReplace($text, $tokens);
  });
  $this->assertSame('first comes before second', $result);
  // Test tokens with numeric indexes.
  $text = '{{ argument.0.first }} comes before {{ argument.1.second }}';
  $tokens = [
    '{{ argument.0.first }}' => 'first',
    '{{ argument.1.second }}' => 'second',
  ];
  $result = \Drupal::service('renderer')->executeInRenderContext(new RenderContext(), function () use ($text, $tokens) {
    return $this->testPluginBase
      ->viewsTokenReplace($text, $tokens);
  });
  $this->assertSame('first comes before second', $result);
}

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