function WebformLocalizationStringTranslationTestCase::testWebformLocalizationStringTranslation in Webform Localization 7
Same name and namespace in other branches
- 7.4 tests/webform_localization.test \WebformLocalizationStringTranslationTestCase::testWebformLocalizationStringTranslation()
Test creating a webform and enabling localization by string translation
File
- tests/
webform_localization.test, line 363 - Webform localization module tests.
Class
Code
function testWebformLocalizationStringTranslation() {
$this
->drupalLogin($this->adminuser);
/**
* Create the Webform test node, and enable
* localization by string translation feature
*/
$node = $this
->createWebformForm();
// Submit translation in Spanish.
$node_translation_title = 'Webform title in Spanish';
$node_translation_body = 'Content in Spanish';
$node_translation1 = $this
->createWebformTranslation($node, $node_translation_title, $node_translation_body, 'es');
// Submit translation in German.
$node_translation_title = 'Webform title in German';
$node_translation_body = 'Content in German';
$node_translation2 = $this
->createWebformTranslation($node, $node_translation_title, $node_translation_body, 'de');
/**
* Enables localization by string translation and reuse the single webform
* across the translation set.
*/
$edit = array();
$edit['expose_strings'] = TRUE;
$edit['single_webform'] = TRUE;
$this
->drupalPost('node/' . $node->nid . '/webform/configure', $edit, t('Save configuration'));
$this
->assertRaw(t('The form settings have been updated.'), 'Webform string translation and single webform enabled.');
// Checks for webform components in the Spanish node
$this
->drupalGet('es/node/' . $node_translation1->nid);
foreach ($node->webform['components'] as $key => $value) {
if ($value['name'] == 'Hidden') {
$this
->assertNoRaw($value['name'], format_string('The %c webform component is not present.', array(
'%c' => $value['name'],
)), 'Spanish Webform translation');
continue;
}
$this
->assertRaw($value['name'], format_string('The %c webform component is present.', array(
'%c' => $value['name'],
)), 'Spanish Webform translation');
}
// Checks for webform components in the Deutsch node
$this
->drupalGet('de/node/' . $node_translation2->nid);
foreach ($node->webform['components'] as $key => $value) {
if ($value['name'] == 'Hidden') {
$this
->assertNoRaw($value['name'], format_string('The %c webform component is not present.', array(
'%c' => $value['name'],
)), 'German Webform translation');
continue;
}
$this
->assertRaw($value['name'], format_string('The %c webform component is present.', array(
'%c' => $value['name'],
)), 'Deutsch Webform translation');
}
// Refresh webform strings
$edit = array();
$edit['groups[webform]'] = 'webform';
$this
->drupalPost('admin/config/regional/translate/i18n_string', $edit, t('Refresh strings'));
// Select webform localization options that match this node ID.
$options = db_select('locales_source')
->fields('locales_source')
->condition('textgroup', 'webform', '=')
->execute()
->fetchAllAssoc('lid', PDO::FETCH_ASSOC);
// Translates webform components.
$translations = array();
$extra_translations = array();
foreach ($options as $key => $value) {
$name = $value['source'];
$translations['de'] = 'de:' . $name;
$translations['es'] = 'es:' . $name;
$this
->createStringTranslation('webform', $name, $translations);
// We take out confirmation to check after submit.
if (strpos($value['location'], 'confirmation')) {
$extra_translations['confirmation'] = $value['source'];
unset($options[$key]);
}
}
$this
->drupalGet('es/node/' . $node_translation1->nid);
foreach ($options as $key => $value) {
list(, $cid, ) = explode(':', $value['context']);
$component = $node->webform['components'][$cid];
$name = $value['source'];
$translation = 'es:' . $name;
if ($name == 'Hidden') {
continue;
}
$this
->assertRaw($translation, format_string('%c translation is present.', array(
'%c' => $name,
)), 'Spanish Webform translation');
}
$this
->drupalGet('de/node/' . $node_translation2->nid);
foreach ($options as $key => $value) {
$name = $value['source'];
$translation = 'de:' . $name;
if ($name == 'Hidden') {
continue;
}
$this
->assertRaw($translation, format_string('%c translation is present.', array(
'%c' => $name,
)), 'Deutsch Webform translation');
}
}