1.20.x common.test | CommonXssUnitTestCase::testFormatStringAndT() |
Test t() and format_string() replacement functionality.
File
- modules/
simpletest/ tests/ common.test, line 499 - Tests for common.inc functionality.
Class
- CommonXssUnitTestCase
- 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.');
}
}