function FileTranslatorTest::testHTML in Translation Management Tool 8
Tests export and import for the HTML format.
File
- translators/
tmgmt_file/ tests/ src/ Functional/ FileTranslatorTest.php, line 249
Class
- FileTranslatorTest
- Tests for the file translator.
Namespace
Drupal\Tests\tmgmt_file\FunctionalCode
function testHTML() {
$translator = Translator::load('file');
$translator
->setSetting('export_format', 'html')
->save();
$job = $this
->createJob();
$job->translator = $translator
->id();
$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'};
$this
->assertFalse((bool) strpos('< a', $download_url));
// "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);
}