You are here

public function LocaleUpdateTest::testUpdateCheckStatus in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/locale/src/Tests/LocaleUpdateTest.php \Drupal\locale\Tests\LocaleUpdateTest::testUpdateCheckStatus()

Checks if local or remote translation sources are detected.

The translation status process by default checks the status of the installed projects. For testing purpose a predefined set of modules with fixed file names and release versions is used. This custom project definition is applied using a hook_locale_translation_projects_alter implementation in the locale_test module.

This test generates a set of local and remote translation files in their respective local and remote translation directory. The test checks whether the most recent files are selected in the different check scenarios: check for local files only, check for both local and remote files.

File

core/modules/locale/src/Tests/LocaleUpdateTest.php, line 67
Contains \Drupal\locale\Tests\LocaleUpdateTest.

Class

LocaleUpdateTest
Tests for updating the interface translations of projects.

Namespace

Drupal\locale\Tests

Code

public function testUpdateCheckStatus() {

  // Case when contributed modules are absent.
  $this
    ->drupalGet('admin/reports/translations');
  $this
    ->assertText(t('Missing translations for one project'));
  $config = $this
    ->config('locale.settings');

  // Set a flag to let the locale_test module replace the project data with a
  // set of test projects.
  \Drupal::state()
    ->set('locale.test_projects_alter', TRUE);

  // Create local and remote translations files.
  $this
    ->setTranslationFiles();
  $config
    ->set('translation.default_filename', '%project-%version.%language._po')
    ->save();

  // Set the test conditions.
  $edit = array(
    'use_source' => LOCALE_TRANSLATION_USE_SOURCE_LOCAL,
  );
  $this
    ->drupalPostForm('admin/config/regional/translate/settings', $edit, t('Save configuration'));

  // Get status of translation sources at local file system.
  $this
    ->drupalGet('admin/reports/translations/check');
  $result = locale_translation_get_status();
  $this
    ->assertEqual($result['contrib_module_one']['de']->type, LOCALE_TRANSLATION_LOCAL, 'Translation of contrib_module_one found');
  $this
    ->assertEqual($result['contrib_module_one']['de']->timestamp, $this->timestampOld, 'Translation timestamp found');
  $this
    ->assertEqual($result['contrib_module_two']['de']->type, LOCALE_TRANSLATION_LOCAL, 'Translation of contrib_module_two found');
  $this
    ->assertEqual($result['contrib_module_two']['de']->timestamp, $this->timestampNew, 'Translation timestamp found');
  $this
    ->assertEqual($result['locale_test']['de']->type, LOCALE_TRANSLATION_LOCAL, 'Translation of locale_test found');
  $this
    ->assertEqual($result['custom_module_one']['de']->type, LOCALE_TRANSLATION_LOCAL, 'Translation of custom_module_one found');

  // Set the test conditions.
  $edit = array(
    'use_source' => LOCALE_TRANSLATION_USE_SOURCE_REMOTE_AND_LOCAL,
  );
  $this
    ->drupalPostForm('admin/config/regional/translate/settings', $edit, t('Save configuration'));

  // Get status of translation sources at both local and remote locations.
  $this
    ->drupalGet('admin/reports/translations/check');
  $result = locale_translation_get_status();
  $this
    ->assertEqual($result['contrib_module_one']['de']->type, LOCALE_TRANSLATION_REMOTE, 'Translation of contrib_module_one found');
  $this
    ->assertEqual($result['contrib_module_one']['de']->timestamp, $this->timestampNew, 'Translation timestamp found');
  $this
    ->assertEqual($result['contrib_module_two']['de']->type, LOCALE_TRANSLATION_LOCAL, 'Translation of contrib_module_two found');
  $this
    ->assertEqual($result['contrib_module_two']['de']->timestamp, $this->timestampNew, 'Translation timestamp found');
  $this
    ->assertEqual($result['contrib_module_three']['de']->type, LOCALE_TRANSLATION_LOCAL, 'Translation of contrib_module_three found');
  $this
    ->assertEqual($result['contrib_module_three']['de']->timestamp, $this->timestampOld, 'Translation timestamp found');
  $this
    ->assertEqual($result['locale_test']['de']->type, LOCALE_TRANSLATION_LOCAL, 'Translation of locale_test found');
  $this
    ->assertEqual($result['custom_module_one']['de']->type, LOCALE_TRANSLATION_LOCAL, 'Translation of custom_module_one found');
}