You are here

function TMGMTLocaleSourceTestCase::testSingularTerm in Translation Management Tool 7

Tests translation of a locale singular term.

File

sources/locale/tmgmt_locale.test, line 30

Class

TMGMTLocaleSourceTestCase
Basic Locale Source tests.

Code

function testSingularTerm() {

  // Load PO file to create a locale structure in the database.
  _locale_import_po($this->pofile, $this->langcode, LOCALE_IMPORT_OVERWRITE, $this->context);

  // Obtain one locale string with translation.
  $locale_object = db_query('SELECT * FROM {locales_source} WHERE source = :source LIMIT 1', array(
    ':source' => 'Hello World',
  ))
    ->fetchObject();
  $source_text = $locale_object->source;

  // Create the new job and job item.
  $job = $this
    ->createJob();
  $job->translator = $this->default_translator->name;
  $job->settings = array();
  $job
    ->save();
  $item1 = $job
    ->addItem('locale', 'default', $locale_object->lid);

  // Check the structure of the imported data.
  $this
    ->assertEqual($item1->item_id, $locale_object->lid, 'Locale Strings object correctly saved');
  $this
    ->assertEqual('Locale', $item1
    ->getSourceType());
  $this
    ->assertEqual('Hello World', $item1
    ->getSourceLabel());
  $job
    ->requestTranslation();
  foreach ($job
    ->getItems() as $item) {

    /* @var $item TMGMTJobItem */
    $item
      ->acceptTranslation();
    $this
      ->assertTrue($item
      ->isAccepted());

    // The source is now available in en and de.
    $this
      ->assertJobItemLangCodes($item, 'en', array(
      'en',
      'de',
    ));
  }

  // Check string translation.
  $expected_translation = $job->target_language . '_' . $source_text;
  $this
    ->assertTranslation($locale_object->lid, 'de', $expected_translation);

  // Translate the german translation to spanish.
  $target_langcode = 'es';
  $job = $this
    ->createJob('de', $target_langcode);
  $job->translator = $this->default_translator->name;
  $job->settings = array();
  $job
    ->save();
  $item1 = $job
    ->addItem('locale', 'default', $locale_object->lid);
  $this
    ->assertEqual('Locale', $item1
    ->getSourceType());
  $this
    ->assertEqual($expected_translation, $item1
    ->getSourceLabel());
  $job
    ->requestTranslation();
  foreach ($job
    ->getItems() as $item) {

    /* @var $item TMGMTJobItem */
    $item
      ->acceptTranslation();
    $this
      ->assertTrue($item
      ->isAccepted());

    // The source should be now available for en, de and es languages.
    $this
      ->assertJobItemLangCodes($item, 'en', array(
      'en',
      'de',
      'es',
    ));
  }

  // Check string translation.
  $this
    ->assertTranslation($locale_object->lid, $target_langcode, $job->target_language . '_' . $expected_translation);
}