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.
function testUpdateCheckStatus() {
$config = 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
->drupalPost('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 = \Drupal::state()
->get('locale.translation_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->timestamp_old, '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->timestamp_new, '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
->drupalPost('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 = \Drupal::state()
->get('locale.translation_status');
$this
->assertEqual($result['contrib_module_one']['de']->type, 'remote', 'Translation of contrib_module_one found');
$this
->assertEqual($result['contrib_module_one']['de']->timestamp, $this->timestamp_new, '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->timestamp_new, '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->timestamp_old, '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');
}