$this->drupalGet('admin/modules'); $this->submitForm(['modules[config_install_fail_test][enable]' => TRUE], 'Install'); $this->submitForm([], 'Continue'); $this->assertSession()->responseContains('Unable to install Configuration install fail test, <em class="placeholder">config_test.dynamic.dotted.default</em> already exists in active configuration.');
// Test that collection configuration clashes during a module install are
// reported correctly.
\Drupal::service('module_installer')->install(['language']); $this->rebuildContainer(); ConfigurableLanguage::createFromLangcode('fr')->save(); \Drupal::languageManager() ->getLanguageConfigOverride('fr', 'config_test.dynamic.dotted.default') ->set('label', 'Je suis Charlie') ->save();
$this->drupalGet('admin/modules'); $this->submitForm(['modules[config_install_fail_test][enable]' => TRUE], 'Install'); $this->assertSession()->responseContains('Unable to install Configuration install fail test, <em class="placeholder">config_test.dynamic.dotted.default, language/fr/config_test.dynamic.dotted.default</em> already exist in active configuration.');
// Test installing a theme through the UI that has existing configuration.
// This relies on the fact the config_test has been installed and created
// the config_test.dynamic.dotted.default configuration and the translation
// override created still exists.
$overridden_sync = $sync->createCollection('language.fr'); $overridden_sync->write('system.site', ['name' => 'French site name']);
// Before we start the import, the change to the site name should not be
// present. This action also primes the cache in the config factory so that
// we can test whether the cached data is correctly updated.
$config = $this->config('system.site'); $this->assertNotEquals('English site name', $config->getRawData()['name']);
// Before the import is started the site name should not yet be overridden.
$this->assertFalse($config->hasOverrides()); $override = $language_manager->getLanguageConfigOverride('fr', 'system.site'); $this->assertTrue($override->isNew());
// Start the import of the new configuration.
$this->configImporter->reset()->import();
// Verify the new site name in the default language.
$config = $this->config('system.site')->getRawData(); $this->assertEquals('English site name', $config['name']);
// Verify the overridden site name.
$override = $language_manager->getLanguageConfigOverride('fr', 'system.site');
'd6_field_instance_option_translation', ]); }
/**
* Tests migration of file variables to file.settings.yml.
*/ publicfunctiontestFieldInstanceOptionTranslation(){ $language_manager = $this->container->get('language_manager');
// Set configuration values based on form submission and source values.
$base_config = $this->configFactory()->getEditable($name); $config_translation = $this->languageManager->getLanguageConfigOverride($this->language->getId(), $name);
// If no overrides, delete language specific configuration file.
$saved_config = $config_translation->get(); if(empty($saved_config)){ $config_translation->delete(); $this->messenger()->addStatus($this->t('@language translation was not added. To add a translation, you must modify the configuration.', ['@language' => $this->language->getName()])); } else{
/**
* Saves translation data from locale module.
*
* This will invoke LocaleConfigSubscriber through the event dispatcher. To
* make sure the configuration was persisted correctly, the configuration
* value is checked. Because LocaleConfigSubscriber temporarily disables the
* override state of the configuration factory we check that the correct value
* is restored afterwards.
*
* @param string $config_name
* The configuration name.
* @param string $key
* The configuration key.
* @param string $source
* The source string.
* @param string $translation
* The translation string to save.
* @param string $langcode
* The language code.
* @param bool $is_active
* Whether the update will affect the active configuration.
*/
'd7_menu', 'd7_menu_translation', ]); }
/**
* Tests migration of menu translations.
*/ publicfunctiontestMenuTranslation(){ $language_manager = \Drupal::service('language_manager');
$config_translation = $language_manager->getLanguageConfigOverride('is', 'system.menu.main'); $this->assertSame('is - Main menu', $config_translation->get('label')); $this->assertSame('is - Main menu description', $config_translation->get('description'));
$config_translation = $language_manager->getLanguageConfigOverride('fr', 'system.menu.main'); $this->assertSame('fr - Main menu', $config_translation->get('label')); $this->assertSame('fr - Main menu description', $config_translation->get('description'));
// Translate and localize menu.
$config_translation = $language_manager->getLanguageConfigOverride('fr', 'system.menu.menu-test-menu'); $this->assertSame('fr - Test menu description', $config_translation->get('description'));
$config_translation = $language_manager->getLanguageConfigOverride('fr', 'field.field.user.user.profile_biography'); $this->assertSame('fr - Biography', $config_translation->get('label')); $this->assertSame('fr - Tell people a little bit about yourself', $config_translation->get('description'));
// Ensure that the Spanish translation of anonymous is the one from
// configuration and not the PO file.
// cspell:disable-next-line
$this->assertSame('Anónimo', \Drupal::languageManager()->getLanguageConfigOverride('es', 'user.settings')->get('anonymous'));
/** @var \Drupal\locale\StringStorageInterface $locale_storage */ $locale_storage = \Drupal::service('locale.storage'); // If configuration contains a translation that is not in the po file then
// _install_config_locale_overrides_process_batch() will create a customized
// translation.
$translation = $locale_storage->findTranslation(['source' => 'Anonymous', 'language' => 'es']); $this->assertSame('Anónimo', $translation->getString()); $this->assertTrue((bool)$translation->customized, "A customized translation has been created for Anonymous");
// If configuration contains a translation that is in the po file then
// Installed in German, configuration should be in German. No German or
// English overrides should be present.
$config = \Drupal::config('user.settings'); $override_de = $language_manager->getLanguageConfigOverride('de', 'user.settings'); $override_en = $language_manager->getLanguageConfigOverride('en', 'user.settings'); $this->assertEquals('Anonymous de', $config->get('anonymous')); $this->assertEquals('de', $config->get('langcode')); $this->assertTrue($override_de->isNew()); $this->assertTrue($override_en->isNew());
// Assert that adding English makes the English override available.
$edit = ['predefined_langcode' => 'en']; $this->drupalGet('admin/config/regional/language/add'); $this->submitForm($edit, 'Add language'); $override_en = $language_manager->getLanguageConfigOverride('en', 'user.settings');
// Get translation and check we've only got the message.
$translation = \Drupal::languageManager()->getLanguageConfigOverride($this->langcode, 'system.maintenance')->get(); $this->assertCount(1, $translation, 'Got the right number of properties after translation.'); $this->assertEquals($message, $translation['message']);
// Check default medium date format exists and create a translation for it.
$string = $this->storage->findString(['source' => 'D, m/d/Y - H:i', 'context' => 'PHP date format', 'type' => 'configuration']); $this->assertNotEmpty($string, 'Configuration date formats have been created upon installation.');
// Translate using the UI so configuration is refreshed.
$search = [ 'string' => $string->source, 'langcode' => $this->langcode,
'd6_profile_field_option_translation', ]); }
/**
* Tests the Drupal 6 field option translation.
*/ publicfunctiontestFieldOptionTranslation(){ $language_manager = $this->container->get('language_manager');