Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->setUpDefaultLanguage();
     $this->installSchema('locale', ['locales_source', 'locales_target', 'locales_location']);
     $this->setupLanguages();
     $this->installConfig(['locale_test']);
     // Simulate this hook invoked which would happen if in a non-kernel test
     // or normal environment.
     // @see locale_modules_installed()
     // @see locale_system_update()
     locale_system_set_config_langcodes();
     $langcodes = array_keys(\Drupal::languageManager()->getLanguages());
     $names = Locale::config()->getComponentNames();
     Locale::config()->updateConfigTranslations($names, $langcodes);
     $this->configFactory = $this->container->get('config.factory');
     $this->stringStorage = $this->container->get('locale.storage');
     $this->localeConfigManager = $this->container->get('locale.config_manager');
     $this->languageManager = $this->container->get('language_manager');
     $this->setUpLocale();
 }
 /**
  * Test removing a string from Locale deletes configuration translations.
  */
 function testLocaleRemovalAndConfigOverrideDelete()
 {
     // Enable the locale module.
     $this->container->get('module_installer')->install(['locale']);
     $this->resetAll();
     $admin_user = $this->drupalCreateUser(array('administer modules', 'administer site configuration', 'administer languages', 'access administration pages', 'administer permissions', 'translate interface'));
     $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'));
     $override = \Drupal::languageManager()->getLanguageConfigOverride('af', 'locale_test_translate.settings');
     $this->assertEqual(['translatable_default_with_translation' => 'Locale can translate Afrikaans'], $override->get());
     // Remove the string from translation to simulate a Locale removal. Note
     // that is no current way of doing this in the UI.
     $locale_storage = \Drupal::service('locale.storage');
     $string = $locale_storage->findString(array('source' => 'Locale can translate'));
     \Drupal::service('locale.storage')->delete($string);
     // Force a rebuild of config translations.
     $count = Locale::config()->updateConfigTranslations(['locale_test_translate.settings'], ['af']);
     $this->assertEqual($count, 1, 'Correct count of updated translations');
     $override = \Drupal::languageManager()->getLanguageConfigOverride('af', 'locale_test_translate.settings');
     $this->assertEqual([], $override->get());
     $this->assertTrue($override->isNew(), 'The configuration override was deleted when the Locale string was deleted.');
 }