Verifies that strings that need escaping are correctly identified.
function testEscaping() {
$lid = \Drupal::database()
->insert('locales_source')
->fields(array(
'source' => '@place-holders need %to be !esc_aped.',
'context' => '',
))
->execute();
$job = $this
->createJob('en', 'de');
$job->translator = $this->default_translator
->id();
$job->settings = array();
$job
->save();
$item = $job
->addItem('locale', 'default', $lid);
$data = $item
->getData();
$expected_escape = array(
0 => array(
'string' => '@place-holders',
),
20 => array(
'string' => '%to',
),
27 => array(
'string' => '!esc_aped',
),
);
$this
->assertEquals($expected_escape, $data['singular']['#escape']);
// Invalid patterns that should be ignored.
$lid = \Drupal::database()
->insert('locales_source')
->fields(array(
'source' => '@ % ! example',
'context' => '',
))
->execute();
$item = $job
->addItem('locale', 'default', $lid);
$data = $item
->getData();
$this
->assertTrue(empty($data[$lid]['#escape']));
}