|
@@ -4,31 +4,23 @@
|
|
|
* @file
|
|
|
* Webform localization module tests.
|
|
|
*/
|
|
|
-class WebformLocalizationTestCase extends DrupalWebTestCase {
|
|
|
+class WebformLocalizationWebTestCase extends DrupalWebTestCase {
|
|
|
|
|
|
+ // Webform test class instance.
|
|
|
public $wtc;
|
|
|
+ // Users.
|
|
|
public $admin_user;
|
|
|
public $translator;
|
|
|
public $normal_user;
|
|
|
|
|
|
- /**
|
|
|
- * Implements getInfo().
|
|
|
- */
|
|
|
- public static function getInfo() {
|
|
|
- return array(
|
|
|
- 'name' => t('Webform Localization'),
|
|
|
- 'description' => t('Webform localization features test.'),
|
|
|
- 'group' => t('Webform'),
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Implements setUp().
|
|
|
*/
|
|
|
- function setUp() {
|
|
|
- parent::setUp('locale', 'translation', 'translation_test', 'i18n', 'i18n_string', 'webform', 'webform_localization');
|
|
|
+ function setUp($modules = array()) {
|
|
|
+ $modules = array_merge($modules, array('locale', 'webform', 'webform_localization'));
|
|
|
+ parent::setUp($modules);
|
|
|
|
|
|
- // We load webform test class to reuse webform and components creation functions
|
|
|
+ // We load webform test class to reuse webform and components creation functions.
|
|
|
module_load_include('test', 'webform', 'tests/webform');
|
|
|
$this->wtc = new WebformTestCase;
|
|
|
|
|
@@ -38,17 +30,19 @@ class WebformLocalizationTestCase extends DrupalWebTestCase {
|
|
|
'access all webform results',
|
|
|
'edit all webform submissions',
|
|
|
'delete all webform submissions',
|
|
|
- 'translate interface'));
|
|
|
+ 'translate interface',
|
|
|
+ 'translate user-defined strings'));
|
|
|
|
|
|
$this->translator = $this->drupalCreateUser(array('translate content',
|
|
|
'create webform content',
|
|
|
'edit any webform content',
|
|
|
'access all webform results',
|
|
|
- 'translate interface'));
|
|
|
+ 'translate interface',
|
|
|
+ 'translate user-defined strings'));
|
|
|
|
|
|
$this->normal_user = $this->drupalCreateUser(array('access content', 'edit own webform submissions'));
|
|
|
|
|
|
- // Fix for reuse of webform test class
|
|
|
+ // Fix for reuse of webform test class.
|
|
|
$this->wtc->webform_users['admin'] = $this->admin_user;
|
|
|
$this->wtc->webform_users['admin']->profile_gender = array('Female', 'Male');
|
|
|
|
|
@@ -59,112 +53,15 @@ class WebformLocalizationTestCase extends DrupalWebTestCase {
|
|
|
$this->addLanguage('es');
|
|
|
$this->addLanguage('de');
|
|
|
|
|
|
- // Enable URL language detection and selection
|
|
|
+ // Enable URL language detection and selection.
|
|
|
$edit = array('language[enabled][locale-url]' => TRUE);
|
|
|
$this->drupalPost('admin/config/regional/language/configure', $edit, t('Save settings'));
|
|
|
- $this->assertRaw(t('Language negotiation configuration saved.'), t('URL language detection enabled.'));
|
|
|
+ $this->assertRaw(t('Language negotiation configuration saved.'), 'URL language detection enabled.');
|
|
|
drupal_static_reset('locale_url_outbound_alter');
|
|
|
-
|
|
|
- // Set "Webform" content type to use multilingual support with translation.
|
|
|
- $this->drupalGet('admin/structure/types/manage/webform');
|
|
|
- $edit = array();
|
|
|
- $edit['language_content_type'] = 2;
|
|
|
- $this->drupalPost('admin/structure/types/manage/webform', $edit, t('Save content type'));
|
|
|
- $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Webform')), t('Webform content type has been updated.'));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Test creating a webform and enabling localization by string translation
|
|
|
- */
|
|
|
- function testWebformLocalizationConfig() {
|
|
|
- $this->drupalLogin($this->admin_user);
|
|
|
- /**
|
|
|
- * 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.'), t('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'], t('The %c webform component is not present.', array('%c' => $value['name'])), 'Spanish Webform translation');
|
|
|
- CONTINUE;
|
|
|
- }
|
|
|
- $this->assertRaw($value['name'], t('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'], t('The %c webform component is not present.', array('%c' => $value['name'])), 'German Webform translation');
|
|
|
- CONTINUE;
|
|
|
- }
|
|
|
- $this->assertRaw($value['name'], t('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);
|
|
|
-
|
|
|
- // $refresh_node = node_load($node->nid,$node->vid, TRUE);
|
|
|
- // Translates webform components
|
|
|
- $translations = array();
|
|
|
- foreach ($options as $key => $value) {
|
|
|
- $name = $value['source'];
|
|
|
- $translations['de'] = 'de:' . $name;
|
|
|
- $translations['es'] = 'es:' . $name;
|
|
|
- $this->createStringTranslation('webform', $name, $translations);
|
|
|
- }
|
|
|
- $this->drupalGet('es/node/' . $node_translation1->nid);
|
|
|
- foreach ($options as $key => $value) {
|
|
|
- $name = $value['source'];
|
|
|
- $translation = 'es:' . $name;
|
|
|
- $this->assertRaw($translation, t('%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;
|
|
|
- $this->assertRaw($translation, t('%c translation is present.', array('%c' => $name)), 'Deutsch Webform translation');
|
|
|
- }
|
|
|
- /**
|
|
|
- * @todo
|
|
|
- * Pending to Fix deveral fails and exceptions
|
|
|
- */
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Create a webform node with test components
|
|
|
+ * Create a webform node with test components.
|
|
|
*/
|
|
|
function createWebformForm() {
|
|
|
if (isset($this->_webform_node)) {
|
|
@@ -183,7 +80,7 @@ class WebformLocalizationTestCase extends DrupalWebTestCase {
|
|
|
'translate' => '0',
|
|
|
'title' => 'Webform title in english',
|
|
|
'body' => array('en' => array(
|
|
|
- array('value' => 'Donec placerat. Nullam nibh dolor, blandit sed, fermentum id, imperdiet sit amet, neque. Nam mollis ultrices justo.
|
|
|
+ array('value' => 'Donec placerat. Nullam nibh dolor, blandit sed, fermentum id, imperdiet sit amet, neque. Nam mollis ultrices justo.
|
|
|
Sed tempor. Sed vitae tellus. Etiam sem arcu, eleifend sit amet, gravida eget, porta at, wisi. Nam non lacus vitae ipsum viverra
|
|
|
pretium. Phasellus massa. Fusce magna sem, gravida in, feugiat ac, molestie eget, wisi. Fusce consectetuer luctus ipsum.
|
|
|
Vestibulum nunc. Suspendisse dignissim adipiscing libero. Integer leo. Sed pharetra ligula a dui. Quisque ipsum nibh,
|
|
@@ -191,7 +88,7 @@ class WebformLocalizationTestCase extends DrupalWebTestCase {
|
|
|
retium quis, dapibus sed, varius non, lectus. Proin a quam. Praesent lacinia, eros quis aliquam porttitor, urna lacus
|
|
|
volutpat urna, ut fermentum neque mi egestas dolor.'))),
|
|
|
'teaser' => array('en' => array(
|
|
|
- array('value' => 'Donec placerat. Nullam nibh dolor, blandit sed, fermentum id, imperdiet sit amet, neque. Nam mollis ultrices justo.
|
|
|
+ array('value' => 'Donec placerat. Nullam nibh dolor, blandit sed, fermentum id, imperdiet sit amet, neque. Nam mollis ultrices justo.
|
|
|
Sed tempor. Sed vitae tellus. Etiam sem arcu, eleifend sit amet, gravida eget, porta at, wisi. Nam non lacus vitae ipsum
|
|
|
viverra pretium. Phasellus massa. Fusce magna sem, gravida in, feugiat ac, molestie eget, wisi. Fusce consectetuer luctus
|
|
|
ipsum. Vestibulum nunc. Suspendisse dignissim adipiscing libero. Integer leo. Sed pharetra ligula a dui. Quisque ipsum nibh,
|
|
@@ -199,23 +96,22 @@ class WebformLocalizationTestCase extends DrupalWebTestCase {
|
|
|
'log' => '',
|
|
|
'format' => '1',
|
|
|
'webform' => array(
|
|
|
- 'confirmation' => 'Thanks!',
|
|
|
- 'confirmation_format' => filter_default_format(),
|
|
|
- 'redirect_url' => '<confirmation>',
|
|
|
- 'teaser' => '0',
|
|
|
- 'allow_draft' => '1',
|
|
|
- 'submit_text' => '',
|
|
|
- 'submit_limit' => '-1',
|
|
|
- 'submit_interval' => '-1',
|
|
|
- 'submit_notice' => '1',
|
|
|
- 'roles' => array('1', '2'),
|
|
|
- 'components' => array(),
|
|
|
- 'emails' => array(),
|
|
|
- ),
|
|
|
+ 'confirmation' => 'Thanks!',
|
|
|
+ ) + webform_node_defaults(),
|
|
|
);
|
|
|
+ $components = $this->wtc->testWebformComponents();
|
|
|
+
|
|
|
+ /*
|
|
|
+ * @todo : We need further debug to find how to support
|
|
|
+ * this components or why are they breaking everything
|
|
|
+ */
|
|
|
+ unset($components['select_no_default_zero']);
|
|
|
+ unset($components['radios_zero']);
|
|
|
+ unset($components['select_zero']);
|
|
|
+ unset($components['select_optgroup']);
|
|
|
|
|
|
$cid = 0;
|
|
|
- foreach ($this->wtc->testWebformComponents() as $key => $component_info) {
|
|
|
+ foreach ($components as $key => $component_info) {
|
|
|
$cid++;
|
|
|
$settings['webform']['components'][$cid] = $component_info['component'];
|
|
|
$settings['webform']['components'][$cid]['cid'] = $cid;
|
|
@@ -247,10 +143,10 @@ class WebformLocalizationTestCase extends DrupalWebTestCase {
|
|
|
// Make sure we are not using a stale list.
|
|
|
drupal_static_reset('language_list');
|
|
|
$languages = language_list('language');
|
|
|
- $this->assertTrue(array_key_exists($language_code, $languages), t('Language was installed successfully.'));
|
|
|
+ $this->assertTrue(array_key_exists($language_code, $languages), 'Language was installed successfully.');
|
|
|
|
|
|
if (array_key_exists($language_code, $languages)) {
|
|
|
- $this->assertRaw(t('The language %language has been created and can now be used. More information is available on the <a href="@locale-help">help screen</a>.', array('%language' => $languages[$language_code]->name, '@locale-help' => url('admin/help/locale'))), t('Language has been created.'));
|
|
|
+ $this->assertRaw(t('The language %language has been created and can now be used. More information is available on the <a href="@locale-help">help screen</a>.', array('%language' => $languages[$language_code]->name, '@locale-help' => url('admin/help/locale'))), 'Language has been created.');
|
|
|
}
|
|
|
}
|
|
|
elseif ($this->xpath('//input[@type="checkbox" and @name=:name and @checked="checked"]', array(':name' => 'enabled[' . $language_code . ']'))) {
|
|
@@ -261,7 +157,7 @@ class WebformLocalizationTestCase extends DrupalWebTestCase {
|
|
|
// It's installed but not enabled. Enable it.
|
|
|
$this->assertTrue(TRUE, 'Language [' . $language_code . '] already installed.');
|
|
|
$this->drupalPost(NULL, array('enabled[' . $language_code . ']' => TRUE), t('Save configuration'));
|
|
|
- $this->assertRaw(t('Configuration saved.'), t('Language successfully enabled.'));
|
|
|
+ $this->assertRaw(t('Configuration saved.'), 'Language successfully enabled.');
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -288,14 +184,14 @@ class WebformLocalizationTestCase extends DrupalWebTestCase {
|
|
|
|
|
|
$edit = array();
|
|
|
$edit["title"] = $title;
|
|
|
- $edit[$body_key] = $body;
|
|
|
+ //$edit[$body_key] = $body;
|
|
|
$this->drupalPost(NULL, $edit, t('Save'));
|
|
|
- $this->assertRaw(t('Webform %title has been created.', array('%title' => $title)), t('Translation created.'));
|
|
|
+ $this->assertRaw(t('Webform %title has been created.', array('%title' => $title)), 'Translation created.');
|
|
|
|
|
|
// Check to make sure that translation was successful.
|
|
|
$translation = $this->drupalGetNodeByTitle($title);
|
|
|
- $this->assertTrue($translation, t('Node found in database.'));
|
|
|
- $this->assertTrue($translation->tnid == $node->nid, t('Translation set id correctly stored.'));
|
|
|
+ $this->assertTrue($translation, 'Node found in database.');
|
|
|
+ $this->assertTrue($translation->tnid == $node->nid, 'Translation set id correctly stored.');
|
|
|
|
|
|
return $translation;
|
|
|
}
|
|
@@ -307,14 +203,7 @@ class WebformLocalizationTestCase extends DrupalWebTestCase {
|
|
|
* Optional array of langcode => translation. If not present, it will be generated.
|
|
|
*/
|
|
|
function createStringTranslation($textgroup, $name, $translations = NULL) {
|
|
|
- // Generate translations if not found, they will be the same length as source string
|
|
|
- if (!$translations) {
|
|
|
- $length = drupal_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\">";
|
|
@@ -329,32 +218,43 @@ class WebformLocalizationTestCase extends DrupalWebTestCase {
|
|
|
// 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->assertNoUniqueText();
|
|
|
- $this->assertText(check_plain($name), t('Search found the name.'));
|
|
|
- $this->assertRaw($language_indicator, t('Name is untranslated.'));
|
|
|
+ $this->assertText(check_plain($name), 'Search found the name.');
|
|
|
+ $this->assertRaw($language_indicator, 'Name is untranslated.');
|
|
|
|
|
|
- // Is not always the only result, iif there is more than one click the first.
|
|
|
+ // Is not always the only result, if there is more than one click the first.
|
|
|
if ($this->countString(check_plain($name)) > 1) {
|
|
|
$this->clickLink(t('edit'), 0);
|
|
|
}
|
|
|
- else
|
|
|
+ else {
|
|
|
$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->assertRaw(check_plain($name), t($name . ' name found on edit screen.'));
|
|
|
+
|
|
|
+ /*
|
|
|
+ * Using check_plain() and wordwrap() as i18n_string_locale_translate_edit_form().
|
|
|
+ * Assert fails otherwise.
|
|
|
+ */
|
|
|
+ $this->assertRaw(check_plain(wordwrap($name, 0)), t($name . ' 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->assertText(t('The string has been saved.'), 'The string has been saved.');
|
|
|
+ $this->assertEqual($this->getUrl(), url('admin/config/regional/translate/translate', array('absolute' => TRUE)), 'Correct page redirection.');
|
|
|
+ $search = array(
|
|
|
+ 'string' => $name,
|
|
|
+ 'language' => 'all',
|
|
|
+ 'translation' => 'translated',
|
|
|
+ 'group' => $textgroup,
|
|
|
+ );
|
|
|
$this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
|
|
|
- // The indicator should not be here.
|
|
|
- //$this->assertNoRaw($language_indicator, t('String is translated.'));
|
|
|
+ $this->assertText(check_plain($name), 'Search found the name.');
|
|
|
+ $this->assertNoRaw($language_indicator, 'Name is translated.');
|
|
|
+
|
|
|
return $translations;
|
|
|
}
|
|
|
|
|
@@ -375,3 +275,180 @@ class WebformLocalizationTestCase extends DrupalWebTestCase {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+class WebformLocalizationStringTranslationTestCase extends WebformLocalizationWebTestCase {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Implements getInfo().
|
|
|
+ */
|
|
|
+ public static function getInfo() {
|
|
|
+ return array(
|
|
|
+ 'name' => 'Webform Localization',
|
|
|
+ 'description' => 'Webform localization String Translations Tests.',
|
|
|
+ 'group' => 'Webform Localization',
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Set up test.
|
|
|
+ */
|
|
|
+ public function setUp($modules = array()) {
|
|
|
+ parent::setUp(array('translation', 'i18n', 'i18n_string'));
|
|
|
+
|
|
|
+ // Set "Webform" content type to use multilingual support with translation.
|
|
|
+ $this->drupalGet('admin/structure/types/manage/webform');
|
|
|
+ $edit = array();
|
|
|
+ $edit['language_content_type'] = 2;
|
|
|
+ $this->drupalPost('admin/structure/types/manage/webform', $edit, t('Save content type'));
|
|
|
+ $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Webform')), 'Webform content type has been updated.');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Test creating a webform and enabling localization by string translation
|
|
|
+ */
|
|
|
+ function testWebformLocalizationStringTranslation() {
|
|
|
+ $this->drupalLogin($this->admin_user);
|
|
|
+ /**
|
|
|
+ * 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');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+class WebformLocalizationApiTestCase extends WebformLocalizationWebTestCase {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Test info.
|
|
|
+ */
|
|
|
+ public static function getInfo() {
|
|
|
+ return array(
|
|
|
+ 'name' => 'Test Webform Localization API.',
|
|
|
+ 'description' => 'Test webform and webform localization interaction at API level.',
|
|
|
+ 'group' => 'Webform Localization',
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Set up test.
|
|
|
+ */
|
|
|
+ public function setUp($modules = array()) {
|
|
|
+ parent::setUp(array('translation', 'i18n', 'i18n_string'));
|
|
|
+
|
|
|
+ // Set "Webform" content type to use multilingual support with translation.
|
|
|
+ $this->drupalGet('admin/structure/types/manage/webform');
|
|
|
+ $edit = array();
|
|
|
+ $edit['language_content_type'] = 2;
|
|
|
+ $this->drupalPost('admin/structure/types/manage/webform', $edit, t('Save content type'));
|
|
|
+ $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Webform')), 'Webform content type has been updated.');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Test submissions API function with webform localization presence.
|
|
|
+ */
|
|
|
+ function testWebformLocalizationApi() {
|
|
|
+ $this->drupalLogin($this->admin_user);
|
|
|
+ $node = $this->createWebformForm();
|
|
|
+ /**
|
|
|
+ * 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.');
|
|
|
+
|
|
|
+ module_load_include('inc', 'webform', 'includes/webform.submissions');
|
|
|
+ $this->assertFalse(webform_get_submissions($node->nid), "Function webform_get_submission($node->nid,1000) work correctly with empty submissions.");
|
|
|
+ }
|
|
|
+
|
|
|
+}
|