1 locale.test | LocaleImportFunctionalTest::testStandalonePoFile() |
Test import of standalone .po files.
File
- core/
modules/ locale/ tests/ locale.test, line 792 - Tests for locale.module.
Class
- LocaleImportFunctionalTest
- Functional tests for the import of translation files.
Code
function testStandalonePoFile() {
// Try importing a .po file.
$this->importPoFile($this->getPoFile(), array(
'langcode' => 'fr',
));
// The import should automatically create the corresponding language.
$this->assertRaw(t('The language %language has been created.', array('%language' => 'French')), 'The language has been automatically created.');
// The import should have created 7 strings.
$this->assertRaw(t('The translation was successfully imported. There are %number newly created translated strings, %update strings were updated and %delete strings were removed.', array('%number' => 9, '%update' => 0, '%delete' => 0)), 'The translation file was successfully imported.');
// This import should have saved plural forms to have 2 variants.
$locale_plurals = state_get('locale_translation_plurals', array());
$this->assert($locale_plurals['fr']['plurals'] == 2, 'Plural number initialized.');
// Ensure we were redirected correctly.
$this->assertEqual($this->getUrl(), url('admin/config/regional/translate', array('absolute' => TRUE)), 'Correct page redirection.');
// Try importing a .po file with invalid tags.
$this->importPoFile($this->getBadPoFile(), array(
'langcode' => 'fr',
));
// The import should have created 1 string and rejected 2.
$this->assertRaw(t('The translation was successfully imported. There are %number newly created translated strings, %update strings were updated and %delete strings were removed.', array('%number' => 1, '%update' => 0, '%delete' => 0)), 'The translation file was successfully imported.');
$skip_message = format_plural(2, 'A translation string was skipped because of disallowed or malformed HTML. <a href="@url">See the log</a> for details.', '@count translation strings were skipped because of disallowed or malformed HTML. <a href="@url">See the log</a> for details.', array('@url' => url('admin/reports/dblog')));
$this->assertRaw($skip_message, 'Unsafe strings were skipped.');
// Try importing a .po file which doesn't exist.
$name = $this->randomName(16);
$this->backdropPost('admin/config/regional/translate/import', array(
'langcode' => 'fr',
'files[file]' => $name,
), t('Import'));
$this->assertEqual($this->getUrl(), url('admin/config/regional/translate/import', array('absolute' => TRUE)), 'Correct page redirection.');
$this->assertText(t('File to import not found.'), 'File to import not found message.');
// Try importing a .po file with overriding strings, and ensure existing
// strings are kept.
$this->importPoFile($this->getOverwritePoFile(), array(
'langcode' => 'fr',
'mode' => 1, // Existing strings are kept, only new strings are added.
));
// The import should have created 1 string.
$this->assertRaw(t('The translation was successfully imported. There are %number newly created translated strings, %update strings were updated and %delete strings were removed.', array('%number' => 1, '%update' => 0, '%delete' => 0)), 'The translation file was successfully imported.');
// Ensure string wasn't overwritten.
$search = array(
'string' => 'Montag',
'language' => 'fr',
'translation' => 'translated',
);
$this->backdropPost('admin/config/regional/translate/translate', $search, t('Filter'));
$this->assertText(t('No strings available.'), 'String not overwritten by imported string.');
// This import should not have changed number of plural forms.
$locale_plurals = state_get('locale_translation_plurals', array());
$this->assert($locale_plurals['fr']['plurals'] == 2, 'Plural numbers untouched.');
// Try importing a .po file with overriding strings, and ensure existing
// strings are overwritten.
$this->importPoFile($this->getOverwritePoFile(), array(
'langcode' => 'fr',
'mode' => 0, // Strings in the uploaded file replace existing ones, new ones are added.
));
// The import should have updated 2 strings.
$this->assertRaw(t('The translation was successfully imported. There are %number newly created translated strings, %update strings were updated and %delete strings were removed.', array('%number' => 0, '%update' => 2, '%delete' => 0)), 'The translation file was successfully imported.');
// Ensure string was overwritten.
$search = array(
'string' => 'Montag',
'language' => 'fr',
'translation' => 'translated',
);
$this->backdropPost('admin/config/regional/translate/translate', $search, t('Filter'));
$this->assertNoText(t('No strings available.'), 'String overwritten by imported string.');
// This import should have changed number of plural forms.
$locale_plurals = state_get('locale_translation_plurals', array());
$this->assert($locale_plurals['fr']['plurals'] == 3, 'Plural numbers changed.');
}