function ConfigLanguageOverrideWebTest::testSiteNameTranslation
Same name in other branches
- 8.9.x core/modules/config/tests/src/Functional/ConfigLanguageOverrideWebTest.php \Drupal\Tests\config\Functional\ConfigLanguageOverrideWebTest::testSiteNameTranslation()
- 10 core/modules/config/tests/src/Functional/ConfigLanguageOverrideWebTest.php \Drupal\Tests\config\Functional\ConfigLanguageOverrideWebTest::testSiteNameTranslation()
- 11.x core/modules/config/tests/src/Functional/ConfigLanguageOverrideWebTest.php \Drupal\Tests\config\Functional\ConfigLanguageOverrideWebTest::testSiteNameTranslation()
Tests translating the site name.
File
-
core/
modules/ config/ tests/ src/ Functional/ ConfigLanguageOverrideWebTest.php, line 42
Class
- ConfigLanguageOverrideWebTest
- Tests language overrides applied through the website.
Namespace
Drupal\Tests\config\FunctionalCode
public function testSiteNameTranslation() {
$adminUser = $this->drupalCreateUser([
'administer site configuration',
'administer languages',
]);
$this->drupalLogin($adminUser);
// Add a custom language.
$langcode = 'xx';
$name = $this->randomMachineName(16);
$edit = [
'predefined_langcode' => 'custom',
'langcode' => $langcode,
'label' => $name,
'direction' => LanguageInterface::DIRECTION_LTR,
];
$this->drupalGet('admin/config/regional/language/add');
$this->submitForm($edit, 'Add custom language');
\Drupal::languageManager()->getLanguageConfigOverride($langcode, 'system.site')
->set('name', 'XX site name')
->save();
// Place branding block with site name into header region.
$this->drupalPlaceBlock('system_branding_block', [
'region' => 'header',
]);
$this->drupalLogout();
// The home page in English should not have the override.
$this->drupalGet('');
$this->assertSession()
->pageTextNotContains('XX site name');
// During path resolution the system.site configuration object is used to
// determine the front page. This occurs before language negotiation causing
// the configuration factory to cache an object without the correct
// overrides. We are testing that the configuration factory is
// re-initialized after language negotiation. Ensure that it applies when
// we access the XX front page.
// @see \Drupal\Core\PathProcessor::processInbound()
$this->drupalGet('xx');
$this->assertSession()
->pageTextContains('XX site name');
// Set the xx language to be the default language and delete the English
// language so the site is no longer multilingual and confirm configuration
// overrides still work.
$language_manager = \Drupal::languageManager()->reset();
$this->assertTrue($language_manager->isMultilingual(), 'The test site is multilingual.');
$this->config('system.site')
->set('default_langcode', 'xx')
->save();
ConfigurableLanguage::load('en')->delete();
$this->assertFalse($language_manager->isMultilingual(), 'The test site is monolingual.');
$this->drupalGet('xx');
$this->assertSession()
->pageTextContains('XX site name');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.