You are here

function i18nTaxonomyTestCase::testTaxonomyTermTranslate in Internationalization 7

File

i18n_taxonomy/i18n_taxonomy.test, line 108
Test case for multilingual taxonomy

Class

i18nTaxonomyTestCase
@file Test case for multilingual taxonomy

Code

function testTaxonomyTermTranslate() {

  // Create a translateable vocabulary.
  $vocab = $this
    ->createVocabulary(array(
    'i18n_mode' => I18N_MODE_TRANSLATE,
  ));
  $this
    ->assertEqual(i18n_taxonomy_vocabulary_mode($vocab->vid), I18N_MODE_TRANSLATE, 'A vocabulary has been created and it is translateable.');
  $this->field_select = $this
    ->createTermField($vocab->machine_name);
  $this->field_autocomplete = $this
    ->createTermField($vocab->machine_name, 'taxonomy_autocomplete');

  // Create a term to be translated.
  $en_term = $this
    ->createTerm(array(
    'vid' => $vocab->vid,
    'language' => $this->default_language,
  ));
  $es_term = $this
    ->createTerm(array(
    'vid' => $vocab->vid,
    'language' => $this->secondary_language,
  ));
  $this
    ->drupalLogin($this->admin_user);

  // Set terms as translations of each other.
  $edit = array(
    'translations[' . $this->default_language . ']' => $en_term->name,
    'translations[' . $this->secondary_language . ']' => $es_term->name,
  );
  $this
    ->drupalPost('admin/structure/taxonomy/' . $vocab->machine_name . '/list/sets/add', $edit, t('Save'));
  $this
    ->drupalGet('admin/structure/taxonomy/' . $vocab->machine_name . '/list/sets');

  // Freetagging creates terms with the correct language.
  $new_term_name = $this
    ->randomName();
  $langcode = LANGUAGE_NONE;
  $edit = array(
    "{$this->field_autocomplete}[{$langcode}]" => $new_term_name,
  );
  $this
    ->drupalPost($this->secondary_language . '/test-entity/add/test-bundle', $edit, t('Save'));
  $new_term = current(taxonomy_get_term_by_name($new_term_name));
  $this
    ->assertEqual($new_term->language, $this->secondary_language, 'Freetagging creates terms with the correct language.');

  // Term translations are used for language switching.
  $language_switcher = language_negotiation_get_switch_links(LANGUAGE_TYPE_INTERFACE, 'taxonomy/term/' . $en_term->tid);
  $this
    ->assertEqual($language_switcher->links[$this->secondary_language]['href'], 'taxonomy/term/' . $es_term->tid, 'Term translations are used for language switching.');
}