You are here

function TMGMTFileTestCase::testHTML in Translation Management Tool 7

Tests export and import for the HTML format.

File

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

Class

TMGMTFileTestCase
Basic tests for the file translator.

Code

function testHTML() {
  $translator = $this
    ->createTranslator();
  $translator->plugin = 'file';
  $translator->settings = array(
    'export_format' => 'html',
  );
  $translator
    ->save();
  $job = $this
    ->createJob();
  $job->translator = $translator->name;
  $job
    ->addItem('test_source', 'test', '1');
  $job
    ->addItem('test_source', 'test', '2');
  $job
    ->requestTranslation();
  $messages = $job
    ->getMessages();
  $message = reset($messages);
  $download_url = $message->variables['!link'];

  // "Translate" items.
  $xml = simplexml_load_file($download_url);
  $translated_text = array();
  foreach ($xml->body
    ->children() as $group) {
    for ($i = 0; $i < $group
      ->count(); $i++) {

      // This does not actually override the whole object, just the content.
      $group->div[$i] = (string) $xml->head->meta[3]['content'] . '_' . (string) $group->div[$i];

      // Store the text to allow assertions later on.
      $translated_text[(string) $group['id']][(string) $group->div[$i]['id']] = (string) $group->div[$i];
    }
  }
  $translated_file = 'public://tmgmt_file/translated.html';
  $xml
    ->asXML($translated_file);
  $this
    ->importFile($translated_file, $translated_text, $job);
}