You are here

function CommonXssUnitTest::testFormatStringAndT in Drupal 7

Test t() and format_string() replacement functionality.

File

modules/simpletest/tests/common.test, line 510
Tests for common.inc functionality.

Class

CommonXssUnitTest
Tests for check_plain(), filter_xss(), format_string(), and check_url().

Code

function testFormatStringAndT() {
  foreach (array(
    'format_string',
    't',
  ) as $function) {
    $text = $function('Simple text');
    $this
      ->assertEqual($text, 'Simple text', $function . ' leaves simple text alone.');
    $text = $function('Escaped text: @value', array(
      '@value' => '<script>',
    ));
    $this
      ->assertEqual($text, 'Escaped text: &lt;script&gt;', $function . ' replaces and escapes string.');
    $text = $function('Placeholder text: %value', array(
      '%value' => '<script>',
    ));
    $this
      ->assertEqual($text, 'Placeholder text: <em class="placeholder">&lt;script&gt;</em>', $function . ' replaces, escapes and themes string.');
    $text = $function('Verbatim text: !value', array(
      '!value' => '<script>',
    ));
    $this
      ->assertEqual($text, 'Verbatim text: <script>', $function . ' replaces verbatim string as-is.');
  }
}