Tests escaping and unescaping text.
function testEscaping() {
$plugin = $this->default_translator
->getPlugin();
$tests = array(
array(
'item' => array(
'#text' => 'no escaping',
),
'expected' => 'no escaping',
),
array(
'item' => array(
'#text' => 'single placeholder',
'#escape' => array(
7 => array(
'string' => 'placeholder',
),
),
),
'expected' => 'single [[[placeholder]]]',
),
array(
'item' => array(
'#text' => 'two placeholder, the second placeholder',
'#escape' => array(
4 => array(
'string' => 'placeholder',
),
28 => array(
'string' => 'placeholder',
),
),
),
'expected' => 'two [[[placeholder]]], the second [[[placeholder]]]',
),
array(
'item' => array(
'#text' => 'something, something else',
'#escape' => array(
0 => array(
'string' => 'something',
),
21 => array(
'string' => 'else',
),
),
),
'expected' => '[[[something]]], something [[[else]]]',
),
array(
'item' => array(
'#text' => 'something, something else',
'#escape' => array(
21 => array(
'string' => 'else',
),
11 => array(
'string' => 'something',
),
),
),
'expected' => 'something, [[[something]]] [[[else]]]',
),
);
foreach ($tests as $test) {
$escaped = $plugin
->escapeText($test['item']);
// Assert that the string was escaped as expected.
$this
->assertEquals($test['expected'], $escaped);
// Assert that the string is the same as the original when unescaped.
$this
->assertEquals($test['item']['#text'], $plugin
->unescapeText($escaped));
}
}