ConfigLanguageOverrideWebTest.php in Drupal 10
File
core/modules/config/tests/src/Functional/ConfigLanguageOverrideWebTest.php
View source
<?php
namespace Drupal\Tests\config\Functional;
use Drupal\Core\Language\LanguageInterface;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\BrowserTestBase;
class ConfigLanguageOverrideWebTest extends BrowserTestBase {
protected static $modules = [
'block',
'language',
'system',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
}
public function testSiteNameTranslation() {
$adminUser = $this
->drupalCreateUser([
'administer site configuration',
'administer languages',
]);
$this
->drupalLogin($adminUser);
$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();
$this
->drupalPlaceBlock('system_branding_block', [
'region' => 'header',
]);
$this
->drupalLogout();
$this
->drupalGet('');
$this
->assertSession()
->pageTextNotContains('XX site name');
$this
->drupalGet('xx');
$this
->assertSession()
->pageTextContains('XX site name');
$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');
}
}