function i18nStringTestCase::testStringsAPI in Internationalization 7
Test base i18n_string API
File
- i18n_string/
i18n_string.test, line 35 - Test case for multilingual string
Class
- i18nStringTestCase
- Class for testing i18n_string and modules using these features
Code
function testStringsAPI() {
// Create a bunch of strings for all languages
$textgroup = 'menu';
$strings = $this
->stringCreateArray(2);
$translations = array();
// Save source strings and store translations
foreach ($strings as $key => $string) {
$name = "{$textgroup}:item:{$key}:title";
i18n_string_update($name, $string);
$translations[$key] = $this
->createStringTranslation($textgroup, $string);
}
// Reset cache for text group
i18n_string_textgroup($textgroup)
->cache_reset();
// Check translations using the API
foreach ($this
->getOtherLanguages() as $language) {
foreach ($strings as $key => $value) {
$name = "{$textgroup}:item:{$key}:title";
$translation = i18n_string_translate($name, 'NOT FOUND', array(
'langcode' => $language->language,
));
$this
->assertEqual($translation, $translations[$key][$language->language], "The right {$language->name} ({$language->language}) translation has been retrieved for {$name}, {$translation}");
}
}
// Test that regular strings can be translated. Use 'Built-in interface' as
// filter, and translate first one.
$search = array(
'language' => 'all',
'translation' => 'all',
'group' => 'default',
'string' => '',
);
$this
->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
$this
->clickLink(t('edit'));
// Just add a random translation.
$translation = $this
->randomName();
$edit = array();
foreach ($this
->getOtherLanguages() as $language) {
$langcode = $language->language;
$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.'));
}