You are here

function TMGMTI18nStringSourceTestCase::testI18nStringSourceTaxonomy in Translation Management Tool 7

File

sources/i18n_string/tmgmt_i18n_string.test, line 23

Class

TMGMTI18nStringSourceTestCase
Basic i18n String Source tests.

Code

function testI18nStringSourceTaxonomy() {

  // Test translation of a vocabulary.

  /////////////////////////////////////
  $config = array(
    'name' => $this
      ->randomName(),
    'machine_name' => 'test_vocab',
    'i18n_mode' => I18N_MODE_LOCALIZE,
  );
  $vocabulary = entity_create('taxonomy_vocabulary', $config);
  taxonomy_vocabulary_save($vocabulary);
  $string_object_name = "taxonomy:vocabulary:" . $vocabulary->vid;
  $source_text = $vocabulary->name;

  // Create the new job and job item.
  $job = $this
    ->createJob();
  $job->translator = $this->translator->name;
  $job->settings = array();
  $job
    ->save();
  $item1 = $job
    ->addItem('i18n_string', 'taxonomy_vocabulary', $string_object_name);
  $this
    ->assertEqual(t('Vocabulary'), $item1
    ->getSourceType());
  $job
    ->requestTranslation();
  foreach ($job
    ->getItems() as $item) {

    /* @var $item TMGMTJobItem */
    $item
      ->acceptTranslation();
  }

  // Check the structure of the imported data.
  $this
    ->assertEqual($item1->item_id, $string_object_name, 'i18n Strings object correctly saved');

  // Check string translation.
  $this
    ->assertEqual(i18n_string_translate('taxonomy:vocabulary:' . $vocabulary->vid . ':name', $source_text, array(
    'langcode' => $job->target_language,
  )), $job->target_language . '_' . $source_text);

  // Test translation of a taxonomy term.

  /////////////////////////////////////
  $term = entity_create('taxonomy_term', array(
    'vid' => $vocabulary->vid,
    'name' => $this
      ->randomName(),
    'description' => $this
      ->randomName(),
  ));
  taxonomy_term_save($term);
  $string_object_name = "taxonomy:term:" . $term->tid;
  $source_text_name = $term->name;
  $source_text_description = $term->description;

  // Create the new job and job item.
  $job = $this
    ->createJob();
  $job->translator = $this->translator->name;
  $job->settings = array();
  $job
    ->save();
  $item1 = $job
    ->addItem('i18n_string', 'taxonomy_term', $string_object_name);
  $this
    ->assertEqual(t('Taxonomy term'), $item1
    ->getSourceType());
  $job
    ->requestTranslation();

  /* @var $item TMGMTJobItem */
  foreach ($job
    ->getItems() as $item) {

    // The source is available only in en.
    $this
      ->assertJobItemLangCodes($item, 'en', array(
      'en',
    ));
    $item
      ->acceptTranslation();

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

  // Check the structure of the imported data.
  $this
    ->assertEqual($item1->item_id, $string_object_name);

  // Check string translation.
  $this
    ->assertEqual(i18n_string_translate('taxonomy:term:' . $term->tid . ':name', $source_text_name, array(
    'langcode' => $job->target_language,
  )), $job->target_language . '_' . $source_text_name);
  $this
    ->assertEqual(i18n_string_translate('taxonomy:term:' . $term->tid . ':description', $source_text_description, array(
    'langcode' => $job->target_language,
  )), $job->target_language . '_' . $source_text_description);
}