Setup the environment containting local and remote translation files.
Update tests require a simulated environment for local and remote files. Normally remote files are located at a remote server (e.g. ftp.drupal.org). For testing we can not rely on this. A directory in the file system of the test site is designated for remote files and is addressed using an absolute URL. Because Drupal does not allow files with a po extension to be accessed (denied in .htaccess) the translation files get a _po extension. Another directory is designated for local translation files.
The environment is set up with the following files. File creation times are set to create different variations in test conditions. contrib_module_one
contrib_module_two
contrib_module_three
custom_module_one
Time stamp of current translation set by setCurrentTranslations() is always timestamp medium. This makes it easy to predict which translation will be imported.
private function setTranslationFiles() {
$config = config('locale.settings');
// A flag is set to let the locale_test module replace the project data with
// a set of test projects which match the below project files.
\Drupal::state()
->set('locale.test_projects_alter', TRUE);
// Setup the environment.
$public_path = variable_get('file_public_path', conf_path() . '/files');
$this
->setTranslationsDirectory($public_path . '/local');
$config
->set('translation.default_filename', '%project-%version.%language._po')
->save();
// Setting up sets of translations for the translation files.
$translations_one = array(
'January' => 'Januar_1',
'February' => 'Februar_1',
'March' => 'Marz_1',
);
$translations_two = array(
'February' => 'Februar_2',
'March' => 'Marz_2',
'April' => 'April_2',
);
$translations_three = array(
'April' => 'April_3',
'May' => 'Mai_3',
'June' => 'Juni_3',
);
// Add a number of files to the local file system to serve as remote
// translation server and match the project definitions set in
// locale_test_locale_translation_projects_alter().
$this
->makePoFile('remote/8.x/contrib_module_one', 'contrib_module_one-8.x-1.1.de._po', $this->timestamp_new, $translations_one);
$this
->makePoFile('remote/8.x/contrib_module_two', 'contrib_module_two-8.x-2.0-beta4.de._po', $this->timestamp_old, $translations_two);
$this
->makePoFile('remote/8.x/contrib_module_three', 'contrib_module_three-8.x-1.0.de._po', $this->timestamp_old, $translations_three);
// Add a number of files to the local file system to serve as local
// translation files and match the project definitions set in
// locale_test_locale_translation_projects_alter().
$this
->makePoFile('local', 'contrib_module_one-8.x-1.1.de._po', $this->timestamp_old, $translations_one);
$this
->makePoFile('local', 'contrib_module_two-8.x-2.0-beta4.de._po', $this->timestamp_new, $translations_two);
$this
->makePoFile('local', 'contrib_module_three-8.x-1.0.de._po', $this->timestamp_old, $translations_three);
$this
->makePoFile('local', 'custom_module_one.de.po', $this->timestamp_new);
}