You are here

public function XmlPluginTest::testEscapingUnEscapingOfPluralStringDelimiterSymbolOnExportImportSteps in TMGMT Translator Smartling 8.3

Same name and namespace in other branches
  1. 8.4 tests/src/Kernel/XmlPluginTest.php \Drupal\Tests\tmgmt_smartling\Kernel\XmlPluginTest::testEscapingUnEscapingOfPluralStringDelimiterSymbolOnExportImportSteps()

Test filtering unrelated directives.

File

tests/src/Kernel/XmlPluginTest.php, line 27

Class

XmlPluginTest
Tests for smartling xml plugin.

Namespace

Drupal\Tests\tmgmt_smartling\Kernel

Code

public function testEscapingUnEscapingOfPluralStringDelimiterSymbolOnExportImportSteps() {
  $source_string = "1 new comment\3@count new comments\3@count brand new comments";
  \Drupal::state()
    ->set('tmgmt.test_source_data', [
    'dummy' => [
      'deep_nesting' => [
        '#text' => $source_string,
        '#label' => 'Label of deep nested item @id',
      ],
      '#label' => 'Dummy item',
    ],
  ]);
  $job = parent::createJob();
  $job
    ->addItem('test_source', 'test', 1);
  $job->settings = [];
  $job->translator = 'smartling';
  $xml_plugin = new Xml();
  $exported_content = $xml_plugin
    ->export($job) . PHP_EOL;
  $this
    ->assertTrue(strstr($exported_content, "1 new comment!PLURAL_STRING_DELIMITER@count new comments!PLURAL_STRING_DELIMITER@count brand new comments") !== FALSE);
  $file = file_save_data($exported_content, "public://test.xml", FILE_EXISTS_REPLACE);
  $imported_string = $xml_plugin
    ->import($file
    ->getFileUri())[1]['dummy']['deep_nesting']['#text'];
  $this
    ->assertEquals($source_string, $imported_string);
}