You are here

public function MetatagTestBase::saveTranslationString in Metatag 7

Save a {locales_target} translation string to the database.

Parameters

int $lid: The {locales_source}.lid primary key.

string $context: The {locales_source}.context value for this string.

string $langcode: The language the string is being translated into.

string $string_source: The string that is being translated.

string $string_target: The destination string.

9 calls to MetatagTestBase::saveTranslationString()
MetatagContextWithI18nTest::testContextI18n in metatag_context/tests/MetatagContextWithI18nTest.test
Verify that strings are added to the translation system.
MetatagContextWithI18nTest::testExportedContext in metatag_context/tests/MetatagContextWithI18nTest.test
Test the Metatag:Context translations for an exported configuration.
MetatagCoreLocaleTest::testNodeFormTranslations in tests/MetatagCoreLocaleTest.test
Test that the node form meta tag fields are translated correctly.
MetatagCoreWithI18nConfigTest::testI18nCustomConfig in tests/MetatagCoreWithI18nConfigTest.test
Test translations of the custom configurations.
MetatagCoreWithI18nConfigTest::testI18nDefaultConfig in tests/MetatagCoreWithI18nConfigTest.test
Test translation functionality with i18n on config defaults.

... See full list

File

tests/MetatagTestBase.test, line 475
A base class for the Metatag tests, provides shared methods.

Class

MetatagTestBase
A base class for the Metatag tests, provides shared methods.

Code

public function saveTranslationString($lid, $context, $langcode, $string_source, $string_target) {

  // Load the translation page for the front page's title tag.
  $this
    ->drupalGet('admin/config/regional/translate/edit/' . $lid);
  $this
    ->assertResponse(200, 'Loaded the front page title tag string translation page.');
  $this
    ->assertEqual($this
    ->getUrl(), url('admin/config/regional/translate/edit/' . $lid, array(
    'absolute' => TRUE,
  )));

  // Confirm that the permission-check text is not found.
  $this
    ->assertNoText(t('This is a user-defined string. You are not allowed to translate these strings.'));

  // Look for the existing string. The string gets mungled by the Locale
  // module, so need to replicate its behaviour.
  $this
    ->assertText(check_plain(wordwrap($string_source, 0)));

  // Look for the context value; the context value is empty for all default
  // i.e. interface strings, so don't test this when the context is empty.
  if (!empty($context)) {
    $this
      ->assertText($context);
  }

  // Confirm that the destination strings exist.
  $source_locale = language_default('language');
  if (function_exists('i18n_string_source_language')) {
    $source_locale = i18n_string_source_language();
  }
  if ($source_locale != 'en') {
    $this
      ->assertField('translations[en]', 'Found the English translation string field.');
  }
  if ($source_locale != 'fr') {
    $this
      ->assertField('translations[fr]', 'Found the French translation string field.');
  }
  if ($source_locale != 'es') {
    $this
      ->assertField('translations[es]', 'Found the Spanish translation string field.');
  }

  // Translate the string.
  $edit = array(
    "translations[{$langcode}]" => $string_target,
  );
  $this
    ->drupalPost(NULL, $edit, t('Save translations'));
  $this
    ->assertResponse(200);

  // Confirm the save worked.
  $this
    ->assertText(t('The string has been saved.'));
  $this
    ->assertEqual($this
    ->getUrl(), url('admin/config/regional/translate/translate', array(
    'absolute' => TRUE,
  )));

  // Debug output.
  $this
    ->debugLocalesTargetsByContext($context);

  // Clear the Metatag caches.
  metatag_flush_caches();
}