You are here

public function L10nUpdateTest::testEnableLanguage in Localization update 7.2

Tests automatic translation import when a langauge is enabled.

When a language is added, the system will check for translations files of enabled modules and will import them. When a language is removed the system will remove all translations of that langugue from the database.

File

tests/L10nUpdateTest.test, line 352
Contains L10nUpdateTest.

Class

L10nUpdateTest
Tests for update translations.

Code

public function testEnableLanguage() {

  // Make the hidden test modules look like a normal custom module.
  variable_set('l10n_update_test_system_info_alter', TRUE);

  // Enable a module.
  $edit = array(
    'modules[Testing][l10n_update_test_translate][enable]' => '1',
  );
  $this
    ->drupalPost('admin/modules', $edit, t('Save configuration'));

  // Check if there is no Dutch translation yet.
  $this
    ->assertTranslation('Extraday', '', 'nl');
  $this
    ->assertTranslation('Tuesday', 'Dienstag', 'de');

  // Add a language.
  $this
    ->addLanguage('nl');

  // Check if the right number of translations are added.
  // @TODO: Find out why this currently returns 0 translations.
  $this
    ->assertRaw(t('One translation file imported. %number translations were added, %update translations were updated and %delete translations were removed.', array(
    '%number' => 0,
    '%update' => 0,
    '%delete' => 0,
  )), 'One language added.');
  $this
    ->assertTranslation('Extraday', 'extra dag', 'nl');

  // Check if the language data is added to the database.
  $result = db_query("SELECT project FROM {l10n_update_file} WHERE language='nl'")
    ->fetchField();
  $this
    ->assertTrue((bool) $result, 'Files removed from file history');

  // Remove a language.
  $this
    ->drupalPost('admin/config/regional/language/delete/nl', array(), t('Delete'));

  // Check if the language data is removed from the database.
  $result = db_query("SELECT project FROM {l10n_update_file} WHERE language='nl'")
    ->fetchField();
  $this
    ->assertFalse($result, 'Files removed from file history');

  // Check that the Dutch translation is gone.
  $this
    ->assertTranslation('Extraday', '', 'nl');
  $this
    ->assertTranslation('Tuesday', 'Dienstag', 'de');
}