You are here

public function LocaleConfigTranslationImportTest::testConfigTranslationModuleInstall in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/locale/src/Tests/LocaleConfigTranslationImportTest.php \Drupal\locale\Tests\LocaleConfigTranslationImportTest::testConfigTranslationModuleInstall()

Test update changes configuration translations if enabled after language.

File

core/modules/locale/src/Tests/LocaleConfigTranslationImportTest.php, line 75
Contains \Drupal\locale\Tests\LocaleConfigTranslationImportTest.

Class

LocaleConfigTranslationImportTest
Tests translation update's effects on configuration translations.

Namespace

Drupal\locale\Tests

Code

public function testConfigTranslationModuleInstall() {

  // Enable locale, block and config_translation modules.
  $this->container
    ->get('module_installer')
    ->install([
    'block',
    'config_translation',
  ]);
  $this
    ->resetAll();

  // The testing profile overrides locale.settings to disable translation
  // import. Test that this override is in place.
  $this
    ->assertFalse($this
    ->config('locale.settings')
    ->get('translation.import_enabled'), 'Translations imports are disabled by default in the Testing profile.');
  $admin_user = $this
    ->drupalCreateUser(array(
    'administer modules',
    'administer site configuration',
    'administer languages',
    'access administration pages',
    'administer permissions',
    'translate configuration',
  ));
  $this
    ->drupalLogin($admin_user);

  // Enable import of translations. By default this is disabled for automated
  // tests.
  $this
    ->config('locale.settings')
    ->set('translation.import_enabled', TRUE)
    ->save();

  // Add predefined language.
  $this
    ->drupalPostForm('admin/config/regional/language/add', [
    'predefined_langcode' => 'af',
  ], t('Add language'));

  // Add the system branding block to the page.
  $this
    ->drupalPlaceBlock('system_branding_block', array(
    'region' => 'header',
    'id' => 'site-branding',
  ));
  $this
    ->drupalPostForm('admin/config/system/site-information', [
    'site_slogan' => 'Test site slogan',
  ], 'Save configuration');
  $this
    ->drupalPostForm('admin/config/system/site-information/translate/af/edit', [
    'translation[config_names][system.site][slogan]' => 'Test site slogan in Afrikaans',
  ], 'Save translation');

  // Get the front page and ensure that the translated configuration appears.
  $this
    ->drupalGet('af');
  $this
    ->assertText('Test site slogan in Afrikaans');
  $override = \Drupal::languageManager()
    ->getLanguageConfigOverride('af', 'locale_test_translate.settings');
  $this
    ->assertEqual('Locale can translate Afrikaans', $override
    ->get('translatable_default_with_translation'));

  // Update test configuration.
  $override
    ->set('translatable_no_default', 'This translation is preserved')
    ->set('translatable_default_with_translation', 'This translation is preserved')
    ->set('translatable_default_with_no_translation', 'This translation is preserved')
    ->save();

  // Install any module.
  $this
    ->drupalPostForm('admin/modules', [
    'modules[Core][dblog][enable]' => 'dblog',
  ], t('Install'));
  $this
    ->assertText('Module Database Logging has been enabled.');

  // Get the front page and ensure that the translated configuration still
  // appears.
  $this
    ->drupalGet('af');
  $this
    ->assertText('Test site slogan in Afrikaans');
  $this
    ->rebuildContainer();
  $override = \Drupal::languageManager()
    ->getLanguageConfigOverride('af', 'locale_test_translate.settings');
  $expected = [
    'translatable_no_default' => 'This translation is preserved',
    'translatable_default_with_translation' => 'This translation is preserved',
    'translatable_default_with_no_translation' => 'This translation is preserved',
  ];
  $this
    ->assertEqual($expected, $override
    ->get());
}