You are here

function WebformLocalizationWebTestCase::createStringTranslation in Webform Localization 7.4

Same name and namespace in other branches
  1. 7 tests/webform_localization.test \WebformLocalizationWebTestCase::createStringTranslation()

Create translation for string in textgroup

Parameters

$translations: Optional array of langcode => translation. If not present, it will be generated.

1 call to WebformLocalizationWebTestCase::createStringTranslation()
WebformLocalizationStringTranslationTestCase::testWebformLocalizationStringTranslation in tests/webform_localization.test
Test creating a webform and enabling localization by string translation

File

tests/webform_localization.test, line 231
Webform localization module tests.

Class

WebformLocalizationWebTestCase
@file Webform localization module tests.

Code

function createStringTranslation($textgroup, $name, $translations = NULL) {

  // 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' => 'untranslated',
    '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), 'Search found the name.');
  $this
    ->assertRaw($language_indicator, 'Name is untranslated.');

  // 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 {
    $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];

  /*
   * 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.'), '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'));
  $this
    ->assertText(check_plain($name), 'Search found the name.');
  $this
    ->assertNoRaw($language_indicator, 'Name is translated.');
  return $translations;
}