public function LocaleUpdateTest::testUpdateImportSourceRemote in Drupal 8
Same name and namespace in other branches
- 9 core/modules/locale/tests/src/Functional/LocaleUpdateTest.php \Drupal\Tests\locale\Functional\LocaleUpdateTest::testUpdateImportSourceRemote()
- 10 core/modules/locale/tests/src/Functional/LocaleUpdateTest.php \Drupal\Tests\locale\Functional\LocaleUpdateTest::testUpdateImportSourceRemote()
Tests translation import from remote sources.
Test conditions:
- Source: remote and local files
- Import overwrite: all existing translations
File
- core/
modules/ locale/ tests/ src/ Functional/ LocaleUpdateTest.php, line 111
Class
- LocaleUpdateTest
- Tests for updating the interface translations of projects.
Namespace
Drupal\Tests\locale\FunctionalCode
public function testUpdateImportSourceRemote() {
$config = $this
->config('locale.settings');
// Build the test environment.
$this
->setTranslationFiles();
$this
->setCurrentTranslations();
$config
->set('translation.default_filename', '%project-%version.%language._po');
// Set the update conditions for this test.
$edit = [
'use_source' => LOCALE_TRANSLATION_USE_SOURCE_REMOTE_AND_LOCAL,
'overwrite' => LOCALE_TRANSLATION_OVERWRITE_ALL,
];
$this
->drupalPostForm('admin/config/regional/translate/settings', $edit, t('Save configuration'));
// Get the translation status.
$this
->drupalGet('admin/reports/translations/check');
// Check the status on the Available translation status page.
$this
->assertRaw('<label for="edit-langcodes-de" class="visually-hidden">Update German</label>', 'German language found');
$this
->assertText('Updates for: Contributed module one, Contributed module two, Custom module one, Locale test', 'Updates found');
/** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */
$date_formatter = $this->container
->get('date.formatter');
$this
->assertText('Contributed module one (' . $date_formatter
->format($this->timestampNew, 'html_date') . ')', 'Updates for Contrib module one');
$this
->assertText('Contributed module two (' . $date_formatter
->format($this->timestampNew, 'html_date') . ')', 'Updates for Contrib module two');
// Execute the translation update.
$this
->drupalPostForm('admin/reports/translations', [], t('Update translations'));
// Check if the translation has been updated, using the status cache.
$status = locale_translation_get_status();
$this
->assertEqual($status['contrib_module_one']['de']->type, LOCALE_TRANSLATION_CURRENT, 'Translation of contrib_module_one found');
$this
->assertEqual($status['contrib_module_two']['de']->type, LOCALE_TRANSLATION_CURRENT, 'Translation of contrib_module_two found');
$this
->assertEqual($status['contrib_module_three']['de']->type, LOCALE_TRANSLATION_CURRENT, 'Translation of contrib_module_three found');
// Check the new translation status.
// The static cache needs to be flushed first to get the most recent data
// from the database. The function was called earlier during this test.
drupal_static_reset('locale_translation_get_file_history');
$history = locale_translation_get_file_history();
$this
->assertTrue($history['contrib_module_one']['de']->timestamp >= $this->timestampNow, 'Translation of contrib_module_one is imported');
$this
->assertTrue($history['contrib_module_one']['de']->last_checked >= $this->timestampNow, 'Translation of contrib_module_one is updated');
$this
->assertEqual($history['contrib_module_two']['de']->timestamp, $this->timestampNew, 'Translation of contrib_module_two is imported');
$this
->assertTrue($history['contrib_module_two']['de']->last_checked >= $this->timestampNow, 'Translation of contrib_module_two is updated');
$this
->assertEqual($history['contrib_module_three']['de']->timestamp, $this->timestampMedium, 'Translation of contrib_module_three is not imported');
$this
->assertEqual($history['contrib_module_three']['de']->last_checked, $this->timestampMedium, 'Translation of contrib_module_three is not updated');
// Check whether existing translations have (not) been overwritten.
$this
->assertEqual(t('January', [], [
'langcode' => 'de',
]), 'Januar_1', 'Translation of January');
$this
->assertEqual(t('February', [], [
'langcode' => 'de',
]), 'Februar_2', 'Translation of February');
$this
->assertEqual(t('March', [], [
'langcode' => 'de',
]), 'Marz_2', 'Translation of March');
$this
->assertEqual(t('April', [], [
'langcode' => 'de',
]), 'April_2', 'Translation of April');
$this
->assertEqual(t('May', [], [
'langcode' => 'de',
]), 'Mai_customized', 'Translation of May');
$this
->assertEqual(t('June', [], [
'langcode' => 'de',
]), 'Juni', 'Translation of June');
$this
->assertEqual(t('Monday', [], [
'langcode' => 'de',
]), 'Montag', 'Translation of Monday');
}