function LocaleSourceTest::testSingularTerm in Translation Management Tool 8
Tests translation of a locale singular term.
File
- sources/
locale/ tests/ src/ Kernel/ LocaleSourceTest.php, line 43
Class
- LocaleSourceTest
- Basic Locale Source tests.
Namespace
Drupal\Tests\tmgmt_locale\KernelCode
function testSingularTerm() {
// Obtain one locale string with translation.
$locale_object = \Drupal::database()
->query('SELECT * FROM {locales_source} WHERE source = :source LIMIT 1', array(
':source' => 'Hello World',
))
->fetchObject();
$source_text = $locale_object->source;
// Create the new job and job item.
$job = $this
->createJob();
$job->translator = $this->default_translator
->id();
$job->settings = array();
$job
->save();
$item1 = $job
->addItem('locale', 'default', $locale_object->lid);
// Check the structure of the imported data.
$this
->assertEqual($item1
->getItemId(), $locale_object->lid, 'Locale Strings object correctly saved');
$this
->assertEqual('Locale', $item1
->getSourceType());
$this
->assertEqual('Hello World', $item1
->getSourceLabel());
$job
->requestTranslation();
foreach ($job
->getItems() as $item) {
/* @var $item JobItemInterface */
$item
->acceptTranslation();
$this
->assertTrue($item
->isAccepted());
// The source is now available in en and de.
$this
->assertJobItemLangCodes($item, 'en', array(
'en',
'de',
));
}
// Check string translation.
$expected_translation = $job
->getTargetLangcode() . '(' . $job
->getRemoteTargetLanguage() . '): ' . $source_text;
$this
->assertTranslation($locale_object->lid, 'de', $expected_translation);
// Translate the german translation to spanish.
$target_langcode = 'es';
$job = $this
->createJob('de', $target_langcode);
$job->translator = $this->default_translator
->id();
$job->settings = array();
$job
->save();
$item1 = $job
->addItem('locale', 'default', $locale_object->lid);
$this
->assertEqual('Locale', $item1
->getSourceType());
$this
->assertEqual($expected_translation, $item1
->getSourceLabel());
$job
->requestTranslation();
foreach ($job
->getItems() as $item) {
/* @var $item JobItemInterface */
$item
->acceptTranslation();
$this
->assertTrue($item
->isAccepted());
// The source should be now available for en, de and es languages.
$this
->assertJobItemLangCodes($item, 'en', array(
'en',
'de',
'es',
));
}
// Check string translation.
$this
->assertTranslation($locale_object->lid, $target_langcode, $job
->getTargetLangcode() . ': ' . $expected_translation);
}