You are here

protected function FileTranslatorTest::getTransUnitsContent in Translation Management Tool 8

Gets trans-unit content from the XLIFF file that has been exported for the given job as last.

1 call to FileTranslatorTest::getTransUnitsContent()
FileTranslatorTest::testXLIFFTextProcessing in translators/tmgmt_file/tests/src/Functional/FileTranslatorTest.php
Test the content processing for XLIFF export and import.

File

translators/tmgmt_file/tests/src/Functional/FileTranslatorTest.php, line 219

Class

FileTranslatorTest
Tests for the file translator.

Namespace

Drupal\Tests\tmgmt_file\Functional

Code

protected function getTransUnitsContent(JobInterface $job) {
  $messages = $job
    ->getMessages();
  $message = reset($messages);
  $download_url = $message->variables->{'@link'};
  $this
    ->assertFalse((bool) strpos('< a', $download_url));
  $xml_string = file_get_contents($download_url);
  $xml = simplexml_load_string($xml_string);

  // Register the xliff namespace, required for xpath.
  $xml
    ->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:1.2');
  $reader = new \XMLReader();
  $data = array();
  $i = 0;
  foreach ($xml
    ->xpath('//xliff:trans-unit') as $unit) {
    $reader
      ->XML($unit->source
      ->asXML());
    $reader
      ->read();
    $data[$i]['source'] = $reader
      ->readInnerXML();
    $reader
      ->XML($unit->target
      ->asXML());
    $reader
      ->read();
    $data[$i]['target'] = $reader
      ->readInnerXML();
    $i++;
  }
  return $data;
}