function ConfigNamesMapperTest::testGetLangcode
Same name in other branches
- 8.9.x core/modules/config_translation/tests/src/Unit/ConfigNamesMapperTest.php \Drupal\Tests\config_translation\Unit\ConfigNamesMapperTest::testGetLangcode()
- 10 core/modules/config_translation/tests/src/Unit/ConfigNamesMapperTest.php \Drupal\Tests\config_translation\Unit\ConfigNamesMapperTest::testGetLangcode()
- 11.x core/modules/config_translation/tests/src/Unit/ConfigNamesMapperTest.php \Drupal\Tests\config_translation\Unit\ConfigNamesMapperTest::testGetLangcode()
Tests ConfigNamesMapper::getLangcode().
File
-
core/
modules/ config_translation/ tests/ src/ Unit/ ConfigNamesMapperTest.php, line 417
Class
- ConfigNamesMapperTest
- Tests the functionality provided by the configuration names mapper.
Namespace
Drupal\Tests\config_translation\UnitCode
public function testGetLangcode() {
// Test that the getLangcode() falls back to 'en', if no explicit language
// code is provided.
$config_factory = $this->getConfigFactoryStub([
'system.site' => [
'key' => 'value',
],
]);
$this->configNamesMapper
->setConfigFactory($config_factory);
$result = $this->configNamesMapper
->getLangcode();
$this->assertSame('en', $result);
// Test that getLangcode picks up the language code provided by the
// configuration.
$config_factory = $this->getConfigFactoryStub([
'system.site' => [
'langcode' => 'xx',
],
]);
$this->configNamesMapper
->setConfigFactory($config_factory);
$result = $this->configNamesMapper
->getLangcode();
$this->assertSame('xx', $result);
// Test that getLangcode() works for multiple configuration names.
$this->configNamesMapper
->addConfigName('system.maintenance');
$config_factory = $this->getConfigFactoryStub([
'system.site' => [
'langcode' => 'xx',
],
'system.maintenance' => [
'langcode' => 'xx',
],
]);
$this->configNamesMapper
->setConfigFactory($config_factory);
$result = $this->configNamesMapper
->getLangcode();
$this->assertSame('xx', $result);
// Test that getLangcode() throws an exception when different language codes
// are given.
$config_factory = $this->getConfigFactoryStub([
'system.site' => [
'langcode' => 'xx',
],
'system.maintenance' => [
'langcode' => 'yy',
],
]);
$this->configNamesMapper
->setConfigFactory($config_factory);
try {
$this->configNamesMapper
->getLangcode();
$this->fail();
} catch (\RuntimeException $e) {
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.