You are here

function LocaleSourceTest::testEscaping in Translation Management Tool 8

Verifies that strings that need escaping are correctly identified.

File

sources/locale/tests/src/Kernel/LocaleSourceTest.php, line 141

Class

LocaleSourceTest
Basic Locale Source tests.

Namespace

Drupal\Tests\tmgmt_locale\Kernel

Code

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
    ->assertEqual($data['singular']['#escape'], $expected_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']));
}