You are here

protected function TMGMTFileTestCase::getTransUnitsContent in Translation Management Tool 7

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

1 call to TMGMTFileTestCase::getTransUnitsContent()
TMGMTFileTestCase::testXLIFFTextProcessing in translators/file/tmgmt_file.test
Test the content processing for XLIFF export and import.

File

translators/file/tmgmt_file.test, line 202
Test cases for the file translator module.

Class

TMGMTFileTestCase
Basic tests for the file translator.

Code

protected function getTransUnitsContent(TMGMTJob $job) {
  $messages = $job
    ->getMessages();
  $message = reset($messages);
  $download_url = $message->variables['!link'];
  $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;
}