function Drupali18nTestCase::createStringTranslation in Internationalization 7
Create translation for string in textgroup
Parameters
$translations: Optional array of langcode => translation. If not present, it will be generated.
8 calls to Drupali18nTestCase::createStringTranslation()
- i18nBlocksTestCase::i18nTranslateBlock in i18n_block/
i18n_block.test - Translate block fields to all languages
- i18nBlocksTestCase::testBlockTranslation in i18n_block/
i18n_block.test - i18nFieldTestCase::testListFieldTranslation in i18n_field/
i18n_field.test - Test the translation of list fields, including allowed values.
- i18nFieldTestCase::testTextFieldTranslation in i18n_field/
i18n_field.test - Test the translation of text fields, including default values.
- i18nMenuTestCase::testNodeMenuItems in i18n_menu/
i18n_menu.test - Test menu items for nodes.
File
- ./
i18n.test, line 314 - Base class for Internationalization tests
Class
- Drupali18nTestCase
- @file Base class for Internationalization tests
Code
function createStringTranslation($textgroup, $name, $translations = NULL) {
// Generate translations if not found, they will be the same length as source string
if (!$translations) {
$length = strlen($name);
foreach ($this
->getOtherLanguages() as $language) {
$translations[$language->language] = $this
->randomName($length);
}
}
$this
->drupalLogin($this->translator);
// This is the language indicator on the translation search screen for
// untranslated strings. Copied straight from locale.inc.
$language_indicator = "<em class=\"locale-untranslated\">";
// Search for the name and translate it.
$search = array(
'string' => $name,
'language' => 'all',
'translation' => 'all',
'group' => $textgroup,
);
$this
->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
// assertText() seems to remove the input field where $name always could be
// found, so this is not a false assert. See how assertNoText succeeds
// later.
$this
->assertText(check_plain($name), t('Search found the name.'));
$this
->assertRaw($language_indicator, t('Name is untranslated.'));
// Assume this is the only result, given the random name.
$this
->clickLink(t('edit'));
// We save the lid from the path.
$matches = array();
preg_match('!admin/config/regional/translate/edit/(\\d+)!', $this
->getUrl(), $matches);
$lid = $matches[1];
// No t() here, it's surely not translated yet.
$this
->assertText(check_plain($name), t('name found on edit screen.'));
foreach ($translations as $langcode => $translation) {
$edit["translations[{$langcode}]"] = $translation;
}
$this
->drupalPost(NULL, $edit, t('Save translations'));
$this
->assertText(t('The string has been saved.'), t('The string has been saved.'));
$this
->assertEqual($this
->getUrl(), url('admin/config/regional/translate/translate', array(
'absolute' => TRUE,
)), t('Correct page redirection.'));
$this
->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
// The indicator should not be here.
$this
->assertNoRaw($language_indicator, t('String is translated.'));
return $translations;
}