function LocaleUpdateTest::testUpdateCheckStatus
Same name in other branches
- 9 core/modules/locale/tests/src/Functional/LocaleUpdateTest.php \Drupal\Tests\locale\Functional\LocaleUpdateTest::testUpdateCheckStatus()
- 10 core/modules/locale/tests/src/Functional/LocaleUpdateTest.php \Drupal\Tests\locale\Functional\LocaleUpdateTest::testUpdateCheckStatus()
- 11.x core/modules/locale/tests/src/Functional/LocaleUpdateTest.php \Drupal\Tests\locale\Functional\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/ tests/ src/ Functional/ LocaleUpdateTest.php, line 55
Class
- LocaleUpdateTest
- Tests for updating the interface translations of projects.
Namespace
Drupal\Tests\locale\FunctionalCode
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 = [
'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 = [
'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');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.