function LanguageHierarchyI18nStringTranslationWebTestCase::addI18nStringTranslation in Language Hierarchy 7
Create translation for string in textgroup
Adapted from Drupali18nTestCase::createStringTranslation().
Parameters
$translations: Optional array of langcode => translation. If not present, it will be generated.
1 call to LanguageHierarchyI18nStringTranslationWebTestCase::addI18nStringTranslation()
- LanguageHierarchyI18nStringTranslationWebTestCase::testI18nStringTranslation in tests/
language_hierarchy.test - Adds a language and tests i18n_string translation by users with the appropriate permissions.
File
- tests/
language_hierarchy.test, line 464 - Tests for Language Hierarchy module.
Class
- LanguageHierarchyI18nStringTranslationWebTestCase
- Functional tests for i18n_string (user-defined strings) translation.
Code
function addI18nStringTranslation($textgroup, $name, $translations) {
// 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.
foreach ($translations as $langcode => $translation) {
$this
->assertNoRaw($language_indicator . $langcode . '</em>', t('String is translated.'));
}
return $translations;
}