public function LanguageFormTest::testAddingCustomLanguage in Lingotek Translation 8
Tests adding a custom language with a custom locale.
File
- src/
Tests/ Form/ LanguageFormTest.php, line 71
Class
- LanguageFormTest
- Test the Drupal language form alters.
Namespace
Drupal\lingotek\Tests\FormCode
public function testAddingCustomLanguage() {
// Check that there is a select for locales.
$this
->drupalGet('admin/config/regional/language/add');
$this
->assertField('lingotek_locale', 'There is a field for adding the Lingotek locale.');
// Assert that the locale is empty.
$this
->assertFieldByName('lingotek_locale', '', 'The Lingotek locale is empty by default.');
$edit = [
'predefined_langcode' => 'custom',
'langcode' => 'es-DE',
'label' => 'Spanish (Germany)',
'direction' => 'ltr',
'lingotek_locale' => 'es-ES',
];
$this
->drupalPostForm(NULL, $edit, 'Add custom language');
$this
->assertText('The language Spanish (Germany) has been created and can now be used.');
// Ensure the language is created and with the right locale.
$language = ConfigurableLanguage::load('es-DE');
$this
->assertEqual('es_ES', $language
->getThirdPartySetting('lingotek', 'locale'), 'The Lingotek locale has been saved successfully.');
// Ensure the locale and langcode are correctly mapped.
/** @var LanguageLocaleMapperInterface $locale_mapper */
$locale_mapper = \Drupal::service('lingotek.language_locale_mapper');
$this
->assertEqual('es_ES', $locale_mapper
->getLocaleForLangcode('es-DE'), 'The language locale mapper correctly guesses the locale.');
$this
->assertEqual('es-DE', $locale_mapper
->getConfigurableLanguageForLocale('es_ES')
->getId(), 'The language locale mapper correctly guesses the langcode.');
}