/** * Tests ConfigNamesMapper::getLangcode(). */ public function testGetLangcode() { // Test that the getLangcode() falls back to 'en', if no explicit language // code is provided. $config_factory = $this->getConfigFactoryStub(array('system.site' => array('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(array('system.site' => array('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(array('system.site' => array('langcode' => 'xx'), 'system.maintenance' => array('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(array('system.site' => array('langcode' => 'xx'), 'system.maintenance' => array('langcode' => 'yy'))); $this->configNamesMapper->setConfigFactory($config_factory); try { $this->configNamesMapper->getLangcode(); $this->fail(); } catch (\RuntimeException $e) { } }