function CommonXssUnitTest::testFormatStringAndT
7.x common.test | CommonXssUnitTest::testFormatStringAndT() |
Test t() and format_string() replacement functionality.
File
- drupal-7.x/
modules/ simpletest/ tests/ common.test, line 399 - 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: <script>', $function . ' replaces and escapes string.');
$text = $function('Placeholder text: %value', array('%value' => '<script>'));
$this->assertEqual($text, 'Placeholder text: <em class="placeholder"><script></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.');
}
}