You are here

public function L10nUpdateTest::testUpdateImportSourceRemote in Localization update 7.2

Tests translation import from remote sources.

Test conditions:

  • Source: remote and local files
  • Import overwrite: all existing translations.

File

tests/L10nUpdateTest.test, line 135
Contains L10nUpdateTest.

Class

L10nUpdateTest
Tests for update translations.

Code

public function testUpdateImportSourceRemote() {

  // Build the test environment.
  $this
    ->setTranslationFiles();
  $this
    ->setCurrentTranslations();
  variable_set('l10n_update_default_filename', '%project-%release.%language._po');

  // Set the update conditions for this test.
  $edit = array(
    'l10n_update_check_mode' => L10N_UPDATE_USE_SOURCE_REMOTE_AND_LOCAL,
    'l10n_update_import_mode' => LOCALE_IMPORT_OVERWRITE,
  );
  $this
    ->drupalPost('admin/config/regional/language/update', $edit, t('Save configuration'));

  // Get the translation status.
  $this
    ->drupalGet('admin/config/regional/translate/check');

  // Check the status on the Available translation status page.
  $this
    ->assertRaw('<label class="element-invisible" for="edit-langcodes-de">Update German </label>', 'German language found');
  $this
    ->assertText('Updates for: Contributed module one, Contributed module two, Custom module one, Locale test', 'Updates found');
  $this
    ->assertText('Contributed module one (' . format_date($this->timestamp_new, 'medium') . ')', 'Updates for Contrib module one');
  $this
    ->assertText('Contributed module two (' . format_date($this->timestamp_new, 'medium') . ')', 'Updates for Contrib module two');

  // Execute the translation update.
  $this
    ->drupalPost('admin/config/regional/translate/update', array(), t('Update translations'));

  // Check if the translation has been updated, using the status cache.
  $status = l10n_update_get_status();
  $this
    ->assertEqual($status['contrib_module_one']['de']->type, L10N_UPDATE_CURRENT, 'Translation of contrib_module_one found');
  $this
    ->assertEqual($status['contrib_module_two']['de']->type, L10N_UPDATE_CURRENT, 'Translation of contrib_module_two found');
  $this
    ->assertEqual($status['contrib_module_three']['de']->type, L10N_UPDATE_CURRENT, 'Translation of contrib_module_three found');

  // Check the new translation status.
  // The static cache needs to be flushed first to get the most recent data
  // from the database. The function was called earlier during this test.
  drupal_static_reset('l10n_update_get_file_history');
  $history = l10n_update_get_file_history();
  $this
    ->assertTrue($history['contrib_module_one']['de']->timestamp >= $this->timestamp_now, 'Translation of contrib_module_one is imported');
  $this
    ->assertTrue($history['contrib_module_one']['de']->last_checked >= $this->timestamp_now, 'Translation of contrib_module_one is updated');
  $this
    ->assertEqual($history['contrib_module_two']['de']->timestamp, $this->timestamp_new, 'Translation of contrib_module_two is imported');
  $this
    ->assertTrue($history['contrib_module_two']['de']->last_checked >= $this->timestamp_now, 'Translation of contrib_module_two is updated');
  $this
    ->assertEqual($history['contrib_module_three']['de']->timestamp, $this->timestamp_medium, 'Translation of contrib_module_three is not imported');
  $this
    ->assertEqual($history['contrib_module_three']['de']->last_checked, $this->timestamp_medium, 'Translation of contrib_module_three is not updated');

  // Check whether existing translations have (not) been overwritten.
  $this
    ->assertEqual(t('January', array(), array(
    'langcode' => 'de',
  )), 'Januar_1', 'Translation of January');
  $this
    ->assertEqual(t('February', array(), array(
    'langcode' => 'de',
  )), 'Februar_2', 'Translation of February');
  $this
    ->assertEqual(t('March', array(), array(
    'langcode' => 'de',
  )), 'Marz_2', 'Translation of March');
  $this
    ->assertEqual(t('April', array(), array(
    'langcode' => 'de',
  )), 'April_2', 'Translation of April');
  $this
    ->assertEqual(t('May', array(), array(
    'langcode' => 'de',
  )), 'Mai_customized', 'Translation of May');
  $this
    ->assertEqual(t('June', array(), array(
    'langcode' => 'de',
  )), 'Juni', 'Translation of June');
  $this
    ->assertEqual(t('Monday', array(), array(
    'langcode' => 'de',
  )), 'Montag', 'Translation of Monday');
}