function XssUnitTest::testT

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Common/XssUnitTest.php \Drupal\KernelTests\Core\Common\XssUnitTest::testT()
  2. 10 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 31

Class

XssUnitTest
Confirm that <a href="/api/drupal/core%21lib%21Drupal%21Component%21Utility%21Xss.php/function/Xss%3A%3Afilter/8.9.x" title="Filters HTML to prevent cross-site-scripting (XSS) vulnerabilities." class="local">\Drupal\Component\Utility\Xss::filter</a>() and <a href="/api/drupal/core%21includes%21common.inc/function/check_url/8.9.x" title="Strips dangerous protocols from a URI and encodes it for output to HTML." class="local">check_url</a>() work correctly, including invalid multi-byte sequences.

Namespace

Drupal\KernelTests\Core\Common

Code

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

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