3 namespace Drupal\Tests\config\Functional;
5 use Drupal\Core\Language\LanguageInterface;
6 use Drupal\language\Entity\ConfigurableLanguage;
7 use Drupal\Tests\BrowserTestBase;
10 * Tests language overrides applied through the website.
14 class ConfigLanguageOverrideWebTest extends BrowserTestBase {
21 public static $modules = [
30 protected function setUp() {
35 * Tests translating the site name.
37 public function testSiteNameTranslation() {
38 $adminUser = $this->drupalCreateUser(['administer site configuration', 'administer languages']);
39 $this->drupalLogin($adminUser);
41 // Add a custom language.
43 $name = $this->randomMachineName(16);
45 'predefined_langcode' => 'custom',
46 'langcode' => $langcode,
48 'direction' => LanguageInterface::DIRECTION_LTR,
50 $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
51 \Drupal::languageManager()
52 ->getLanguageConfigOverride($langcode, 'system.site')
53 ->set('name', 'XX site name')
56 // Place branding block with site name into header region.
57 $this->drupalPlaceBlock('system_branding_block', ['region' => 'header']);
59 $this->drupalLogout();
61 // The home page in English should not have the override.
63 $this->assertNoText('XX site name');
65 // During path resolution the system.site configuration object is used to
66 // determine the front page. This occurs before language negotiation causing
67 // the configuration factory to cache an object without the correct
68 // overrides. We are testing that the configuration factory is
69 // re-initialised after language negotiation. Ensure that it applies when
70 // we access the XX front page.
71 // @see \Drupal\Core\PathProcessor::processInbound()
72 $this->drupalGet('xx');
73 $this->assertText('XX site name');
75 // Set the xx language to be the default language and delete the English
76 // language so the site is no longer multilingual and confirm configuration
77 // overrides still work.
78 $language_manager = \Drupal::languageManager()->reset();
79 $this->assertTrue($language_manager->isMultilingual(), 'The test site is multilingual.');
80 $this->config('system.site')->set('default_langcode', 'xx')->save();
82 ConfigurableLanguage::load('en')->delete();
83 $this->assertFalse($language_manager->isMultilingual(), 'The test site is monolingual.');
85 $this->drupalGet('xx');
86 $this->assertText('XX site name');