Chris@0: installSchema('locale', ['locales_location', 'locales_source', 'locales_target']); Chris@0: $this->installConfig(['locale_test']); Chris@0: $locale_config_manager = \Drupal::service('locale.config_manager'); Chris@0: Chris@0: $language = ConfigurableLanguage::createFromLangcode('de'); Chris@0: $language->save(); Chris@0: $result = $locale_config_manager->hasTranslation('locale_test.no_translation', $language->getId()); Chris@0: $this->assertFalse($result, 'There is no translation for locale_test.no_translation configuration.'); Chris@0: Chris@0: $result = $locale_config_manager->hasTranslation('locale_test.translation', $language->getId()); Chris@0: $this->assertTrue($result, 'There is a translation for locale_test.translation configuration.'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests getStringTranslation(). Chris@0: */ Chris@0: public function testGetStringTranslation() { Chris@0: $this->installSchema('locale', ['locales_location', 'locales_source', 'locales_target']); Chris@0: $this->installConfig(['locale_test']); Chris@0: Chris@0: $locale_config_manager = \Drupal::service('locale.config_manager'); Chris@0: Chris@0: $language = ConfigurableLanguage::createFromLangcode('de'); Chris@0: $language->save(); Chris@0: Chris@0: $translation_before = $locale_config_manager->getStringTranslation('locale_test.no_translation', $language->getId(), 'Test', ''); Chris@0: $this->assertTrue($translation_before->isNew()); Chris@0: $translation_before->setString('translation')->save(); Chris@0: Chris@0: $translation_after = $locale_config_manager->getStringTranslation('locale_test.no_translation', $language->getId(), 'Test', ''); Chris@0: $this->assertFalse($translation_after->isNew()); Chris@0: $translation_after->setString('updated_translation')->save(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests getDefaultConfigLangcode(). Chris@0: */ Chris@0: public function testGetDefaultConfigLangcode() { Chris@0: // Install the Language module's configuration so we can use the Chris@0: // module_installer service. Chris@0: $this->installConfig(['language']); Chris@0: $this->assertNull(\Drupal::service('locale.config_manager')->getDefaultConfigLangcode('locale_test_translate.settings'), 'Before installing a module the locale config manager can not access the shipped configuration.'); Chris@0: \Drupal::service('module_installer')->install(['locale_test_translate']); Chris@0: $this->assertEqual('en', \Drupal::service('locale.config_manager')->getDefaultConfigLangcode('locale_test_translate.settings'), 'After installing a module the locale config manager can get the shipped configuration langcode.'); Chris@0: Chris@0: $simple_config = \Drupal::configFactory()->getEditable('locale_test_translate.simple_config_extra'); Chris@0: $simple_config->set('foo', 'bar')->save(); Chris@0: $this->assertNull(\Drupal::service('locale.config_manager')->getDefaultConfigLangcode($simple_config->getName()), 'Simple config created through the API is not treated as shipped configuration.'); Chris@0: Chris@0: $block = Block::create([ Chris@0: 'id' => 'test_default_config', Chris@0: 'theme' => 'classy', Chris@0: 'status' => TRUE, Chris@0: 'region' => 'content', Chris@0: 'plugin' => 'local_tasks_block', Chris@0: 'settings' => [ Chris@0: 'id' => 'local_tasks_block', Chris@0: 'label' => $this->randomMachineName(), Chris@0: 'provider' => 'core', Chris@0: 'label_display' => FALSE, Chris@0: 'primary' => TRUE, Chris@0: 'secondary' => TRUE, Chris@0: ], Chris@0: ]); Chris@0: $block->save(); Chris@0: Chris@0: // Install the theme after creating the block as installing the theme will Chris@0: // install the block provided by the locale_test module. Chris@0: \Drupal::service('theme_installer')->install(['classy']); Chris@0: Chris@0: // The test_default_config block provided by the locale_test module will not Chris@0: // be installed because a block with the same ID already exists. Chris@0: $this->installConfig(['locale_test']); Chris@0: $this->assertNull(\Drupal::service('locale.config_manager')->getDefaultConfigLangcode('block.block.test_default_config'), 'The block.block.test_default_config is not shipped configuration.'); Chris@0: // Delete the block so we can install the one provided by the locale_test Chris@0: // module. Chris@0: $block->delete(); Chris@0: $this->installConfig(['locale_test']); Chris@0: $this->assertEqual('en', \Drupal::service('locale.config_manager')->getDefaultConfigLangcode('block.block.test_default_config'), 'The block.block.test_default_config is shipped configuration.'); Chris@0: Chris@0: // Test the special case for configurable_language config entities. Chris@0: $fr_language = ConfigurableLanguage::createFromLangcode('fr'); Chris@0: $fr_language->save(); Chris@0: $this->assertEqual('en', \Drupal::service('locale.config_manager')->getDefaultConfigLangcode('language.entity.fr'), 'The language.entity.fr is treated as shipped configuration because it is a configurable_language config entity and in the standard language list.'); Chris@0: $custom_language = ConfigurableLanguage::createFromLangcode('custom'); Chris@0: $custom_language->save(); Chris@0: $this->assertNull(\Drupal::service('locale.config_manager')->getDefaultConfigLangcode('language.entity.custom'), 'The language.entity.custom is not shipped configuration because it is not in the standard language list.'); Chris@0: } Chris@0: Chris@0: }