public function LanguageHierarchyStringTranslationWebTestCase::testStringTranslation in Language Hierarchy 7
Adds a language and tests string translation by users with the appropriate permissions.
File
- tests/
language_hierarchy.test, line 325 - Tests for Language Hierarchy module.
Class
- LanguageHierarchyStringTranslationWebTestCase
- Functional tests for string (interface) translation.
Code
public function testStringTranslation() {
// This will be the string to be translated.
$string = $this
->randomName(16);
// This will be the translation of $string.
$translation = $this
->randomName(16);
$this
->loginAdminUser();
// Add languages used by this test case.
$this
->addLanguages();
$this
->drupalLogout();
// Search for the string and translate it.
$this
->loginTranslatorUser();
// Add strings to database.
foreach ($this->languages as $language) {
t($string, array(), array(
'langcode' => $language['langcode'],
));
}
// Reset locale cache.
locale_reset();
$parent_langcode = $this->languages[0]['langcode'];
$child_langcode = $this->languages[1]['langcode'];
$child_langcode2 = $this->languages[2]['langcode'];
// Translate $string for parent language.
$this
->addStringTranslation($string, $translation, $parent_langcode);
// Translate $string for one of child languages.
$translation2 = $this
->randomName(16);
$this
->addStringTranslation($string, $translation2, $child_langcode2);
// Check if t() works as expected.
$parent_translation = t($string, array(), array(
'langcode' => $parent_langcode,
));
$this
->assertTrue($string != $translation && $parent_translation == $translation, 't() works for parent.');
// Check if inheritance of t() works as expected.
$child_translation = t($string, array(), array(
'langcode' => $child_langcode,
));
$this
->assertTrue($string != $translation && $child_translation == $translation, 't() inherited from parent.');
// Check if translated string for child language works as expected.
$child_translation2 = t($string, array(), array(
'langcode' => $child_langcode2,
));
$this
->assertTrue($string != $translation2 && $child_translation2 == $translation2, 't() with translation for child.');
}