You are here

function TMGMTLocaleSourceTestCase::testRequestDataForSpecificLanguage in Translation Management Tool 7

Test if the source is able to pull content in requested language.

File

sources/locale/tmgmt_locale.test, line 92

Class

TMGMTLocaleSourceTestCase
Basic Locale Source tests.

Code

function testRequestDataForSpecificLanguage() {
  $this
    ->setEnvironment('cs');
  _locale_import_po($this->pofile, $this->langcode, LOCALE_IMPORT_OVERWRITE, $this->context);
  $locale_object = db_query('SELECT * FROM {locales_source} WHERE source = :source LIMIT 1', array(
    ':source' => 'Hello World',
  ))
    ->fetchObject();
  $plugin = new TMGMTLocaleSourcePluginController('locale', 'locale');
  $reflection_plugin = new ReflectionClass('TMGMTLocaleSourcePluginController');
  $updateTranslation = $reflection_plugin
    ->getMethod('updateTranslation');
  $updateTranslation
    ->setAccessible(TRUE);
  $updateTranslation
    ->invoke($plugin, $locale_object->lid, 'de', 'de translation');

  // Create the new job and job item.
  $job = $this
    ->createJob('de', 'cs');
  $job
    ->save();
  $job
    ->addItem('locale', 'default', $locale_object->lid);
  $data = $job
    ->getData();
  $this
    ->assertEqual($data[1]['singular']['#text'], 'de translation');

  // Create new job item with a source language for which the translation
  // does not exit.
  $job = $this
    ->createJob('es', 'cs');
  $job
    ->save();
  try {
    $job
      ->addItem('locale', 'default', $locale_object->lid);
    $this
      ->fail('The job item should not be added as there is no translation for language "es"');
  } catch (TMGMTException $e) {
    $languages = language_list();
    $this
      ->assertEqual(t('Unable to load %language translation for the locale %id', array(
      '%language' => $languages['es']->name,
      '%id' => $locale_object->lid,
    )), $e
      ->getMessage());
  }
}