You are here

function SimpleNewsI18nTestCase::testCategoryTranslation in Simplenews 7

File

tests/simplenews.test, line 1686
Simplenews test functions.

Class

SimpleNewsI18nTestCase
Tests for I18N integration.

Code

function testCategoryTranslation() {
  $this
    ->drupalLogin($this->admin_user);

  // Make Input Format "Filtered Text" translatable
  $edit = array(
    // The testing profile has no filtered_html mode.

    //'i18n_string_allowed_formats[filtered_html]' => 'filtered_html',
    'i18n_string_allowed_formats[plain_text]' => 'plain_text',
  );
  $this
    ->drupalPost('admin/config/regional/i18n/strings', $edit, t('Save configuration'));
  $vocabulary = taxonomy_vocabulary_machine_name_load('newsletter');
  $vocabulary->i18n_mode = I18N_MODE_LOCALIZE;
  taxonomy_vocabulary_save($vocabulary);
  drupal_static_reset('i18n_taxonomy_vocabulary_mode');

  // Refresh strings.
  // @todo: simplenews_category_save() should probably take care of this.
  // Currently done separately in simplenews_admin_category_form_submit()
  // for the admin UI.
  $tid = $this
    ->getRandomNewsletter();
  $term = taxonomy_term_load($tid);
  taxonomy_term_save($term);
  $tid = array_shift(simplenews_categories_load_multiple())->tid;

  // Translate term to spanish.
  list($textgroup, $context) = i18n_string_context(array(
    'taxonomy',
    'term',
    $tid,
    'name',
  ));
  i18n_string_textgroup($textgroup)
    ->update_translation($context, 'es', $es_name = $this
    ->randomName());
  list($textgroup, $context) = i18n_string_context(array(
    'taxonomy',
    'term',
    $tid,
    'description',
  ));
  i18n_string_textgroup($textgroup)
    ->update_translation($context, 'es', $es_description = $this
    ->randomName());

  // Visit newsletter selection page in english.
  $this
    ->drupalGet('user/' . $this->admin_user->uid . '/edit/simplenews');
  $this
    ->assertText(t('Drupal newsletter'));

  // And now in spanish.
  $this
    ->drupalGet('es/user/' . $this->admin_user->uid . '/edit/simplenews');
  $this
    ->assertText($es_name, t('Category name is translated.'));
}