function XssUnitTest::testT

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Common/XssUnitTest.php \Drupal\KernelTests\Core\Common\XssUnitTest::testT()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Common/XssUnitTest.php \Drupal\KernelTests\Core\Common\XssUnitTest::testT()
  3. 11.x core/tests/Drupal/KernelTests/Core/Common/XssUnitTest.php \Drupal\KernelTests\Core\Common\XssUnitTest::testT()

Tests t() functionality.

File

core/tests/Drupal/KernelTests/Core/Common/XssUnitTest.php, line 37

Class

XssUnitTest
Tests XSS filtering.

Namespace

Drupal\KernelTests\Core\Common

Code

public function testT() : void {
    $text = t('Simple text');
    $this->assertSame('Simple text', (string) $text, 't leaves simple text alone.');
    $text = t('Escaped text: @value', [
        '@value' => '<script>',
    ]);
    $this->assertSame('Escaped text: &lt;script&gt;', (string) $text, 't replaces and escapes string.');
    $text = t('Placeholder text: %value', [
        '%value' => '<script>',
    ]);
    $this->assertSame('Placeholder text: <em class="placeholder">&lt;script&gt;</em>', (string) $text, 't replaces, escapes and themes string.');
}

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