public function LocaleImportFunctionalTest::testConfigPoFile in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/locale/src/Tests/LocaleImportFunctionalTest.php \Drupal\locale\Tests\LocaleImportFunctionalTest::testConfigPoFile()
Tests .po file import with configuration translation.
File
- core/
modules/ locale/ src/ Tests/ LocaleImportFunctionalTest.php, line 281 - Contains \Drupal\locale\Tests\LocaleImportFunctionalTest.
Class
- LocaleImportFunctionalTest
- Tests the import of locale files.
Namespace
Drupal\locale\TestsCode
public function testConfigPoFile() {
// Values for translations to assert. Config key, original string,
// translation and config property name.
$config_strings = array(
'system.maintenance' => array(
'@site is currently under maintenance. We should be back shortly. Thank you for your patience.',
'@site karbantartás alatt áll. Rövidesen visszatérünk. Köszönjük a türelmet.',
'message',
),
'user.role.anonymous' => array(
'Anonymous user',
'Névtelen felhasználó',
'label',
),
);
// Add custom language for testing.
$langcode = 'xx';
$edit = array(
'predefined_langcode' => 'custom',
'langcode' => $langcode,
'label' => $this
->randomMachineName(16),
'direction' => LanguageInterface::DIRECTION_LTR,
);
$this
->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
// Check for the source strings we are going to translate. Adding the
// custom language should have made the process to export configuration
// strings to interface translation executed.
$locale_storage = $this->container
->get('locale.storage');
foreach ($config_strings as $config_string) {
$string = $locale_storage
->findString(array(
'source' => $config_string[0],
'context' => '',
'type' => 'configuration',
));
$this
->assertTrue($string, 'Configuration strings have been created upon installation.');
}
// Import a .po file to translate.
$this
->importPoFile($this
->getPoFileWithConfig(), array(
'langcode' => $langcode,
));
// Translations got recorded in the interface translation system.
foreach ($config_strings as $config_string) {
$search = array(
'string' => $config_string[0],
'langcode' => $langcode,
'translation' => 'all',
);
$this
->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
$this
->assertText($config_string[1], format_string('Translation of @string found.', array(
'@string' => $config_string[0],
)));
}
// Test that translations got recorded in the config system.
$overrides = \Drupal::service('language.config_factory_override');
foreach ($config_strings as $config_key => $config_string) {
$override = $overrides
->getOverride($langcode, $config_key);
$this
->assertEqual($override
->get($config_string[2]), $config_string[1]);
}
}