function TokenTest::providerTestReplaceEscaping

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Utility/TokenTest.php \Drupal\Tests\Core\Utility\TokenTest::providerTestReplaceEscaping()
  2. 10 core/tests/Drupal/Tests/Core/Utility/TokenTest.php \Drupal\Tests\Core\Utility\TokenTest::providerTestReplaceEscaping()
  3. 11.x core/tests/Drupal/Tests/Core/Utility/TokenTest.php \Drupal\Tests\Core\Utility\TokenTest::providerTestReplaceEscaping()

File

core/tests/Drupal/Tests/Core/Utility/TokenTest.php, line 278

Class

TokenTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Utility%21Token.php/class/Token/8.9.x" title="Drupal placeholder/token replacement system." class="local">\Drupal\Core\Utility\Token</a> @group Utility

Namespace

Drupal\Tests\Core\Utility

Code

public function providerTestReplaceEscaping() {
    $data = [];
    // No tokens. The first argument to Token::replace() should not be escaped.
    $data['no-tokens'] = [
        'muh',
        [],
        'muh',
    ];
    $data['html-in-string'] = [
        '<h1>Giraffe</h1>',
        [],
        '<h1>Giraffe</h1>',
    ];
    $data['html-in-string-quote'] = [
        '<h1>Giraffe"</h1>',
        [],
        '<h1>Giraffe"</h1>',
    ];
    $data['simple-placeholder-with-plain-text'] = [
        '<h1>[token:meh]</h1>',
        [
            '[token:meh]' => 'Giraffe"',
        ],
        '<h1>' . Html::escape('Giraffe"') . '</h1>',
    ];
    $data['simple-placeholder-with-safe-html'] = [
        '<h1>[token:meh]</h1>',
        [
            '[token:meh]' => Markup::create('<em>Emphasized</em>'),
        ],
        '<h1><em>Emphasized</em></h1>',
    ];
    return $data;
}

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