You are here

public function PluginBaseTest::testViewsTokenReplaceWithDots in Drupal 8

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()

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

File

core/modules/views/tests/src/Kernel/Plugin/PluginBaseTest.php, line 49
Contains \Drupal\views\Tests\Plugin\PluginBaseTest.

Class

PluginBaseTest
Tests the PluginBase class.

Namespace

Drupal\Tests\views\Kernel\Plugin

Code

public function testViewsTokenReplaceWithDots() {
  $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
    ->assertIdentical($result, 'first comes before second');

  // 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
    ->assertIdentical($result, 'first comes before second');
}