You are here

public function LanguageTest::testLanguageTokenReplacement in Token 8

Tests the language tokens.

@dataProvider languageTokenReplacementDataProvider

File

tests/src/Kernel/LanguageTest.php, line 129

Class

LanguageTest
Tests language tokens.

Namespace

Drupal\Tests\token\Kernel

Code

public function testLanguageTokenReplacement($token, $langcode, $expected_result) {
  $bubbleable_metadata = new BubbleableMetadata();
  $options = $langcode ? [
    'langcode' => $langcode,
  ] : [];

  // The part of the token name between the last `:` and the closing bracket
  // is the machine name of the token.
  preg_match('/\\[.+:(.+)\\]/', $token, $matches);
  $name = $matches[1];
  $replacements = $this->token
    ->generate('language', [
    $name => $token,
  ], [], $options, $bubbleable_metadata);
  $this
    ->assertEquals($expected_result, $replacements[$token]);
}